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

[Bug]: [langgraph/typescript] Text content dropped when tool_call_chunk arrives in the same chunk; text↔tool stream transitions lose events

オープン
#2,008 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る
bug Integration
主要言語
Python
スター
15.9k
フォーク
1.4k
平均マージ
1日 17時間
マージ済み PR(30日)
163

説明

## Description

The TypeScript `OnChatModelStream` handler uses mutually-exclusive boolean flags and an `if/break` ladder, which causes three related silent-drop bugs when a chunk carries mixed payloads or the stream type changes mid-sequence.

### Bug A — Interleaved text + tool in one chunk

Some providers (e.g. Anthropic) emit a single chunk with both `content` text and a `tool_call_chunk`. The guard:

```ts
const isMessageContentEvent = Boolean(!toolCallData && messageContent);
```

evaluates to `false` whenever `toolCallData` is present. Text is silently dropped; only the tool event is routed.

```ts
// chunk: { content: "Looking that up", tool_call_chunks: [{ id: "tc-1", name: "search" }] }
// Actual: TOOL_CALL_START only
// Expected: TEXT_MESSAGE_START, TEXT_MESSAGE_CONTENT, TEXT_MESSAGE_END, TOOL_CALL_START
```

### Bug B — text→tool transition: TOOL_CALL_START is lost along with all subsequent arg chunks

When a text message is open and the next chunk opens a new tool call:

```ts
const isToolCallStartEvent = !hasCurrentStream && toolCallData?.name;
// → false, because hasCurrentStream is true (text message open)
```

`TEXT_MESSAGE_END` fires and breaks. The tool call is never opened, so every subsequent arg chunk is also dropped (no `toolCallId` was ever recorded).

### Bug C — tool→text transition: text content dropped

When a tool call is open and a chunk arrives with text but no `tool_call_chunk`, `isToolCallEndEvent` fires and breaks. Any text content on the same chunk is dropped.

## Root cause

All three bugs share the same design: the handler picks **at most one** payload kind per chunk via an early-break ladder. A chunk that carries multiple payload kinds cannot be correctly handled.

## Affected component

`integrations/langgraph/typescript`

コントリビューションガイド

コントリビューションガイドを開く

評価

この issue はまだ評価されていません。

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。