LangChain 在 2026 年 5 月 21 日介紹 From Token Streams to Agent Streams。核心觀點很清楚:現代 agent 前端不能只把 token 一個字一個字吐出來。
單一 chatbot 的 streaming 很簡單,模型產生文字,前端顯示 token。但 agent 會做更多事:呼叫工具、委派 subagent、更新 state、等待 approval、產出 media、恢復 thread。這些都不是扁平文字 stream 能清楚表示的。
Agent Streams 解決什麼問題?
一個 research agent 可能同時:
- 主 agent 正在寫答案。
- 三個 subagents 正在查不同資料。
- 某個 tool call 正在組裝 arguments。
- 某個步驟需要 human approval。
- state 被更新。
- 圖片或音訊正在生成。
- 使用者刷新瀏覽器後要 reconnect。
如果所有東西都塞進同一條 token stream,前端會很難判斷哪個 event 來自哪個節點,也很難只顯示使用者正在看的部分。
Typed events 是什麼?
Agent Streams 把執行過程拆成 typed events。每個 event 都標示:
- 事件類型。
- 來自 agent tree 的哪個位置。
- 屬於哪個 channel。
- 是否和 message、tool、state、subagent 或 custom event 有關。
常見 channels 包括:
- messages。
- values。
- updates。
- tools。
- lifecycle。
- checkpoints。
- custom channels。
這讓前端不用自己從 raw chunks 裡猜測語意。
Projections 讓前端更好寫
大多數前端不應直接處理 raw protocol events,而應訂閱 projections。
例如:
run.messages:顯示文字和 content blocks。run.subagents:顯示 subagent status。toolsprojection:顯示 tool call lifecycle。- custom projection:顯示產品自己定義的 domain events。
Runtime 負責 assembly、ordering 和 reconnection,前端專注在 UI 呈現。
Scoped subscriptions 為什麼重要?
如果一個 agent tree 很大,前端不應該下載所有 subagent 的完整輸出。
Scoped subscriptions 讓 UI 只訂閱正在顯示的部分。例如使用者打開某個 subagent inspector,前端才訂閱該 subagent 的 messages、tools 和 state changes。
這對 long-running production workloads 很重要,因為 agent UI 可能同時有:
- 主任務 timeline。
- Subagent panels。
- Tool call details。
- Approval queue。
- Cost dashboard。
- Artifact preview。
對產品 UX 的影響
Agent Streams 讓前端可以做更豐富的 UX:
- 即時顯示 agent plan。
- 顯示 tool calls 正在執行。
- 顯示 subagent status。
- 顯示等待 approval 的節點。
- 顯示 reasoning 和 final answer 的不同區塊。
- 顯示 media generation progress。
- Browser refresh 後接回 running thread。
這些能力會讓 agent 產品從「等待一段回答」變成「看見工作正在進行」。
官方來源
結論
Agent Streams 的重點,是把 streaming 從文字輸出改成 application event model。
未來 agent 前端不會只是一個 chat bubble,而會像任務監控台:能看到主 agent、subagent、tools、state、approvals 和 artifacts。要做到這點,前端需要 typed events、projections 和 scoped subscriptions,而不是只靠 token stream。