Skip to content
Source
Sign inSign up
TanStack/ai

fix(ai): omit subagent text from non-streaming chat results #2300

Openpcbeingused33(GitHub profile, opens in a new tab)wants to merge 1 commit intomain fromrefs/pull/2300/headopened View on GitHub

Showing 6 changed files with 8 additions and 2 deletions (loading 3).

x
0 of 6 viewed, 6 left
5 additions and 0 deletions.changeset/omit-subagent-text-from-parent.mdAdded
View file
@@ -0,0 +1,5 @@
+---
+"@tanstack/ai": patch
+---
+​
+`chat({ stream: false }).text` and `streamToText` leave out child text. A `TEXT_MESSAGE_CONTENT` chunk with `subagentRunId` stays in `chunks` and is not joined into `text`.
1 addition and 0 deletionsdocs/chat/subagents-advanced.mdModified
View file
@@ -248,6 +248,7 @@
- `run` can return a promise of any value. The value arrives on `SUBAGENT_FINISHED.result`, and the parent model gets it as the tool result.
- A string result also streams as the text of the child, so the card shows it. The parent model gets the full string.
- The result of `ctx.chat({ stream: false })` streams like the chat stream. Its text, usage, and interrupts reach the parent.
+- `chat({ stream: false }).text` on the parent is the parent reply only. Child text stays in `chunks` on events that have `subagentRunId`, and in the tool result. It is not part of `text`.
- A very long string in the result (for example a base64 image) reaches the parent model as a short note, `[omitted 5000 characters]`. The full value stays on `SUBAGENT_FINISHED.result`.
​
`produces` says what the agent makes (`'image'`, `'text'`, and more). It does not change how the agent runs.
2 additions and 2 deletionsdocs/reference/functions/streamToText.mdModified
View file
@@ -13,8 +13,8 @@
​
Read a StreamChunk async iterable to the end and return its text and chunks.
​
-`text` joins the deltas of every TEXT_MESSAGE_CONTENT event. `chunks` keeps
-every chunk in order, so tool calls and interrupt outcomes are not lost.
+`text` joins parent TEXT_MESSAGE_CONTENT deltas. A chunk with `subagentRunId`
+is child text: `chunks` keeps it, `text` does not. Tool calls stay in `chunks`.
​
## Parameters