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

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

Aperta
#2,606 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub
Lingua principale
Python
Stelle
15.9k
Fork
1.4k
Merge medio
1g 17h
PR unite (30g)
163

Descrizione

## 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.

Guida per i contributori

Apri la guida per i contributori

Valutazione

Questa issue non è ancora stata valutata.

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.