ag-ui-protocol / ag-ui-protocol/ag-ui

LangGraph TS adapter drops a tool call that starts on the chunk ending streamed text

Đang mở
#2,606 0 bình luận 0 reaction 0 người được giao Xem trên GitHub
Ngôn ngữ chính
Python
Star
15.9k
Fork
1.4k
Merge trung bình
1 ngày 17 giờ
Pull request đã merge (30 ngày)
163

Mô tả

## Bug

`@ag-ui/langgraph` (TypeScript, 0.0.43 and the current `main`) loses a tool call when the model streams text and then a tool call inside the same assistant message.

Anthropic streams a message as content blocks: a `text` block, then a `tool_use` block. The chunk that carries the `tool_use` block arrives while the text message is still in progress. In `handleSingleEvent`, `OnChatModelStream`, `isMessageEndEvent` is true for that chunk, so the handler emits `TEXT_MESSAGE_END` and `break`s. The `TOOL_CALL_START` check runs only for chunks with no message in progress, so it never fires for this chunk, and the following `input_json_delta` chunks find no tool call in progress and are ignored.

Result: no `TOOL_CALL_START` / `TOOL_CALL_ARGS` / `TOOL_CALL_END` for that call. If the call runs in a `ToolNode`, `on_tool_end` re-emits the whole call at the end (no streaming). If the call is handled by a custom node (a frontend tool, for example the injected A2UI render tool), the client never sees it at all.

The Python adapter (`ag_ui_langgraph` 0.0.44, `agent.py`) handles this transition: it ends the text message and then treats the same chunk as a tool-call start.

## Repro

Feed these `on_chat_model_stream` events into `handleSingleEvent` with a text message in progress:

1. chunk `content: [{type:"text", text:"Building the dashboard."}]`
2. chunk `content: [{type:"tool_use", id:"call-1", name:"render_ui", input:{}}]`, `tool_call_chunks: [{name:"render_ui", args:"", id:"call-1"}]`
3. chunk `tool_call_chunks: [{args:'{"surfaceId":"x"}'}]`
4. empty chunk

Emitted: `TEXT_MESSAGE_START, TEXT_MESSAGE_CONTENT, TEXT_MESSAGE_END`. Expected: `..., TOOL_CALL_START, TOOL_CALL_ARGS, TOOL_CALL_END`.

## Fix

After emitting `TEXT_MESSAGE_END`, fall through to the tool-call start when the chunk carries a named tool call. PR follows.

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Đánh giá

Issue này chưa được đánh giá.

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.