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

Offen
#2,008 0 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen
bug Integration
Vorherrschende Sprache
Python
Sterne
15.9k
Forks
1.4k
Ø Merge
1 T. 17 Std.
Gemergte PRs (30 T.)
163

Beschreibung

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

Beitragsleitfaden

Beitragsleitfaden öffnen

Bewertung

Dieses Issue wurde noch nicht bewertet.

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.