docs/thinking/portal-agent-architecture

Portal Agent Architecture — Decision Flow

System Graph

flowchart TD
    subgraph INPUT["šŸ“„ Case Intake"]
        A[Case arrives in portal] --> B{Source?}
        B -->|Portal scrape| C["šŸ¤– Read Agent<br/><em>pulls case details,<br/>member info, clinical docs</em>"]
        B -->|Manual entry| D[User enters case ID<br/>in dashboard]
        B -->|Batch queue| E["Job queue feeds<br/>cases sequentially"]
    end

    subgraph AI["🧠 AI Review"]
        C --> F
        D --> F
        E --> F
        F["AI Clinical Review<br/><em>prior-auth-review skill</em>"] --> G{Determination}
        G -->|Approve| H["āœ… Approve<br/>+ rationale + criteria cited"]
        G -->|Deny| I["āŒ Deny<br/>+ rationale + criteria cited"]
        G -->|Need more info| J["āš ļø Request Info<br/>+ what's missing"]
        G -->|Uncertain| K["šŸ” Human Review<br/>AI confidence too low"]
    end

    subgraph VERIFY1["šŸ‘ļø Screen 1: Review Determination"]
        H --> L
        I --> L
        J --> L
        L["Dashboard shows:<br/>• AI decision + confidence<br/>• Clinical criteria matched<br/>• Supporting evidence<br/>• Rationale text"]
        L --> M{User approves?}
        M -->|Yes| N[Proceed to submission]
        M -->|Edit| O[User modifies decision/rationale]
        M -->|Reject| P[Back to manual review]
        O --> N
        K --> P
    end

    subgraph RPA["šŸ–„ļø Browser Agent"]
        N --> Q["Launch headless Chrome"]
        Q --> R["Step 1: Navigate to portal login"]
        R --> S["Step 2: Enter credentials"]
        S --> T{Login success?}
        T -->|No| U["āŒ Auth failed<br/>alert user"]
        T -->|Yes| V["Step 3: Find case in portal"]
        V --> W{Case found?}
        W -->|No| X["Fallback: direct URL nav"]
        X --> W2{Found now?}
        W2 -->|No| Y["āŒ Case not found<br/>alert user"]
        W2 -->|Yes| Z
        W -->|Yes| Z["Step 4: Verify case detail"]
        Z --> AA["Step 5: Upload attachments<br/><em>(if any)</em>"]
        AA --> BB["Step 6: Select decision + submit"]
        BB --> CC{Submission success?}
        CC -->|No| DD["Retry up to 2x"]
        DD -->|Still fails| EE["āŒ Submission failed<br/>screenshots captured"]
        CC -->|Yes| FF["Step 7: Extract confirmation #"]
    end

    subgraph VERIFY2["šŸ‘ļø Screen 2: Live Agent View"]
        direction LR
        R -.->|screenshot| LV["Browser viewport<br/><em>live screenshots<br/>per step</em>"]
        S -.->|screenshot| LV
        V -.->|screenshot| LV
        Z -.->|screenshot| LV
        BB -.->|screenshot| LV
        FF -.->|screenshot| LV
    end

    subgraph VERIFY3["šŸ‘ļø Screen 3: Job Result"]
        FF --> GG["Dashboard shows:<br/>• āœ… Confirmation number<br/>• Step-by-step log<br/>• Duration per step<br/>• Click any step → screenshot<br/>• Full Playwright trace (debug)"]
        EE --> HH["Dashboard shows:<br/>• āŒ Error + which step failed<br/>• Screenshot at failure point<br/>• Playwright trace for debugging"]
        U --> HH
        Y --> HH
    end

    subgraph EVIDENCE["šŸ“ Evidence Package"]
        GG --> II["Saved to disk:<br/>• result.json<br/>• screenshot per step (.png)<br/>• trace.zip (Playwright)<br/>• Kept for 7 days / 20 jobs"]
    end

    style INPUT fill:#1a1a2e,stroke:#4a4a6a,color:#e0e0e0
    style AI fill:#1a2e1a,stroke:#4a6a4a,color:#e0e0e0
    style VERIFY1 fill:#2e2e1a,stroke:#6a6a4a,color:#e0e0e0
    style RPA fill:#1a1a2e,stroke:#4a4a6a,color:#e0e0e0
    style VERIFY2 fill:#2e2e1a,stroke:#6a6a4a,color:#e0e0e0
    style VERIFY3 fill:#2e2e1a,stroke:#6a6a4a,color:#e0e0e0
    style EVIDENCE fill:#1a2e2e,stroke:#4a6a6a,color:#e0e0e0

What Exists vs. What's Needed

LayerStatusWhat's ThereWhat's Missing
Browser Agent (RPA)āœ… BuiltSkill engine, step runner, retries, fallbacks, evidence capture, SSE streaming—
Mock Portalāœ… BuiltLogin, case list, case detail, decision submission, confirmation—
Live View (Screen 2)āœ… BuiltPer-step screenshots, progress bar, step list, error display—
Job Result (Screen 3)āœ… BuiltConfirmation #, step log, duration, job historyClick-to-view screenshots of past jobs
Concurrency + Authāœ… BuiltNextAuth, job lock, rate limit, timeout, cleanup—
AI ReviewšŸ”¶ Exists separatelyprior-auth-review skill does clinical assessmentNot wired to portal agent — they're separate systems
Review Screen (Screen 1)āŒ Missing—Dashboard screen showing AI determination for user approval before submission
Read AgentāŒ Missing—Skill that scrapes case details FROM portal to feed into AI review
Job QueueāŒ Missing—Batch mode: feed N cases, agent processes sequentially
Real Portal SkillsāŒ Missing—Skills for Premera's actual portal(s) — needs portal access

User Decision Points

#DecisionScreenWhat User SeesOptions
1Which case to process?Portal Agents dashboardCase ID input (or future: queue)Enter ID / select from queue
2Approve AI determination?Review screen (to build)AI decision, confidence, rationale, criteriaApprove / Edit / Reject to manual
3Monitor agent execution?Live ViewReal-time screenshots, step progressWatch / ignore (runs anyway)
4Accept result?Job ResultConfirmation # or error + evidenceDone / retry / escalate
5Debug failures?Job Result (expanded)Screenshot at failure, trace.zipDownload trace → Playwright viewer

The Pipeline (What "Useful" Looks Like)

Portal → Read Agent → AI Review → User Approval → Submit Agent → Confirmation
  ↑                                                                    ↓
  └──────────────── Evidence package saved for audit ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”˜

The missing piece that makes everything click: Screen 1 (Review Determination). This is where the nurse sees the AI's work, agrees or edits, and triggers submission. Without it, the AI and the agent are two separate tools.

Daisy

v1

What do you need?

I can pull up the fundraise pipeline, CRM accounts, hot board, meeting notes — anything in the OS.

Sonnet Ā· read-only