Skip to content

feat: stream provisional agent responses - #64

Merged
devhims merged 1 commit into
mainfrom
feat/agent-response-streaming
Sep 20, 2026
Merged

devhims merged 1 commit into
mainfrom
feat/agent-response-streaming

Conversation

@devhims

@devhims devhims commented Sep 20, 2026

Copy link
Copy Markdown
Owner

Problem / Motivation

Agent runs already stream phase and tool snapshots, but the answer stays blank until final validation finishes. Users wait through the full finalization window without seeing the response being written.

Why it matters

Finalization can take much of the run. Showing provisional text makes the wait useful while keeping the saved answer subject to the existing grounding and citation checks.

What changed

The finalizer now reads AI SDK structured partial output and publishes visible text at most every 500 ms. It never exposes generated citation fields. The existing complete-answer validation still decides which answer is saved.

The Agent Durable Object stores the latest bounded draft. SSE snapshots restore that draft after reconnects. Completion, failure, cancellation, and account deletion clear it. A rejected attempt clears the old text and reports that the answer is being revised.

The dashboard labels provisional content as Draft. It does not offer the copy action until the validated answer atomically replaces the draft.

flowchart LR
  subgraph Before
    M1[finalizer model]:::ctx --> V1[validate full answer]:::ctx --> S1[terminal SSE snapshot]:::removed --> U1[user sees answer]:::ctx
  end
  subgraph After
    M2[finalizer model]:::ctx --> D2[persist bounded draft]:::added --> S2[live SSE snapshots]:::added --> U2[user sees draft]:::added
    M2 --> V2[validate full answer]:::changed --> F2[replace draft with saved answer]:::added
  end
  classDef added fill:#DCFCE7,stroke:#16A34A,color:#14532D,stroke-width:2px
  classDef changed fill:#FEF3C7,stroke:#D97706,color:#78350F,stroke-width:2px
  classDef removed fill:#FEE2E2,stroke:#DC2626,color:#7F1D1D,stroke-dasharray:4 3
  classDef ctx fill:#E0F2FE,stroke:#0284C7,color:#0C4A6E
  linkStyle 0,1,2 stroke:#DC2626,stroke-dasharray:4 3
  linkStyle 3,4,5,6,7 stroke:#16A34A,stroke-width:2px
Loading

🟩 added · 🟨 changed · 🟥 removed · 🟦 unchanged

Users now see provisional answer text during finalization, while only validated output becomes conversation history.

Tests

  • Platform TypeScript build passed.
  • 53 structured-answer and finalizer tests passed.
  • 34 Durable Object integration tests passed.
  • Web TypeScript check passed.
  • 32 web tests passed.
  • Documentation consistency check passed.
  • Playwright discovered the new browser case for draft display and atomic replacement.

Manual verification

The full Next build and browser execution are left to CI because the development host had 1.4 GB free memory. After Vercel creates the preview, complete an agent run and confirm the draft appears during finalization, then disappears when the cited answer arrives.

Screenshots / video

Pending the Vercel preview generated by this PR. The browser regression captures streaming-draft.png during CI.

Issue link

no linked issue: requested directly during development.

@vercel

vercel Bot commented Sep 20, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
video2ctx-web Ready Ready Preview Sep 20, 2026 4:02pm UTC

@devhims

devhims commented Sep 20, 2026

Copy link
Copy Markdown
Owner Author

Intent: Show reconnect-safe provisional answer text during agent finalization while preserving the existing validated answer as the only saved conversation result.
Not a goal: Stream raw JSON, expose model-written citation markers, weaken grounding checks, or change research tool progress.

@devhims
devhims force-pushed the feat/agent-response-streaming branch from d6e4ea0 to 7ea9097 Compare September 20, 2026 16:01
@devhims
devhims merged commit aaa2d7e into main Sep 20, 2026
7 checks passed
@devhims
devhims deleted the feat/agent-response-streaming branch September 20, 2026 16:08

This branch was successfully deployed

1 active deployment
Preview 7ea9097d Deployed Sep 20, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant