Skip to content

Open a conversation whose tool result is a list of parts - #2874

Draft
davidmckayv wants to merge 2 commits into
mainfrom
fix/tool-result-parts
Draft

davidmckayv wants to merge 2 commits into
mainfrom
fix/tool-result-parts

Conversation

@davidmckayv

@davidmckayv davidmckayv commented Dec 3, 2026 •

Copy link
Copy Markdown
Contributor

What changed and why

A conversation with a connected Bot blanked the whole page with TypeError: e.trim is not a function when one of the Bot's tool results was a list of content parts instead of a string. AG-UI 1.0 allows both (ToolMessageSchema, ToolCallResultEvent), and the stock ag_ui_claude_sdk adapter sends a list whenever a Claude tool result is anything but one plain text block: Read on a picture or a PDF, or an MCP tool that answered in several parts. The transcript read every result as a string. The throw was in ChatTranscript's own render (dropRepeatedAppCards -> cardApp -> asText), outside every row's ToolRenderBoundary. The page went blank live, and a conversation holding one could not be opened again.

  • chat-messages.ts: a tool message's content is turned into text once, where results are gathered, so every reader downstream gets a string. A string stays exactly as it came, so refusal markers and JSON envelopes read the same. A list becomes its text parts, a paragraph each, with a short line for anything else ("Returned an image.", "Returned a document.", "Returned an audio clip.", "Returned a video.", "Returned a file."). Any other value is shown as JSON.
  • tool-result.ts: asText and the readers built on it (refusalOf, forDisplay, flaggedFailure, browserCallFailed, cutOffStep, unofferedTool, toolResultFailed, and the envelope helpers) take any value.
  • gallery-tools.tsx, sandboxed-tools.tsx: the stored-refusal check called props.result?.startsWith. It now reads the result as text first. coding-tools.tsx already goes through codingOutcome -> cutOffStep/asText, so the change above covers it. CopilotKit 1.88 itself flattens toolMessage.content with contentToText before a renderer sees it.
  • shared/tool-steps.ts: settled no longer calls .trim() on a result that is not a string.
  • Backstop: toVisibleChatItems projects each message on its own, and cardApp reads each step on its own. One that still throws is logged and costs that row alone, so the rest of the conversation shows.

App only: no API or database change.

Red / green

app/tests/tool-result-parts.test.tsx uses the tool message the real ag_ui_claude_sdk 0.2.4 produces. It was printed by running the adapter's own build_agui_tool_message and handle_tool_result_block on the ToolResultBlock Claude Code hands it. Each case goes through readableTurns, toVisibleChatItems, dropRepeatedAppCards and a rendered ChatTranscript:

  • a stored Read of a picture opens and draws the Read step, model2.png, "Returned an image." and the reply
  • a result in two text parts draws each part as its own paragraph
  • a live result that is a JSON object is drawn as JSON
  • the result readers take a list of parts
  • one message whose projection throws leaves the rest of the conversation

On main (b086b40): 0 pass, 5 fail. Each fails with TypeError: text.trim is not a function from asText via cardApp, or, for the backstop, with the throw escaping ChatTranscript. On this branch: 5 pass, 0 fail.

End to end

The real product on a fresh test machine, in Chrome (Chromium) and Safari (WebKit). Each browser connected a Bot from New Bot > Bring your own agent > An agent you already run. The agent was a stand-in that knows nothing about OpenBot. It answers every run with the events ag_ui_claude_sdk 0.2.4 streams for that turn, in the adapter's order: RUN_STARTED, the tool call, TOOL_CALL_RESULT, the answer, MESSAGES_SNAPSHOT, RUN_FINISHED. The TOOL_CALL_RESULT and the snapshot's tool message are the ones the adapter's own code prints, byte for byte.

Two turns per browser: a Read of a picture (one image part), and an MCP tool that answered in two text parts. For each turn, the answer arrives live with no page error, and the stored events keep the result as the list the agent sent. The conversation then opens again, the step opens, and the result shows. Screenshots were taken at 1440 and 390 px, light and dark, with nothing scrolling sideways.

  • main (b086b40): both browsers fail at the first turn. The page shows "This page couldn't be shown" with TypeError: text.trim is not a function.
  • This branch (413cdcc): 9 of 9 pass in both browsers.

The first green run turned up one layout bug, which the second commit fixes. Two text parts ran together into one line ("Found 2 pages Ribbon diagrams Protein folds"), because the result is drawn as markdown. Each part is now its own paragraph, and the run was repeated on the fixed head.

Before (main) After (this branch)
Chrome, a Read of a picture Chrome on main: This page couldn't be shown, TypeError: text.trim is not a function Chrome on this branch: the conversation opened again, Read model2.png opened to Returned an image., and the answer
Safari, a Read of a picture Safari on main: This page couldn't be shown, TypeError: text.trim is not a function Safari on this branch: the conversation opened again with the Read step and the answer
Chrome, two text parts (did not get this far) Chrome on this branch: Search Docs opened to two paragraphs, Found 2 pages and Ribbon diagrams Protein folds
Safari, two text parts (did not get this far) Safari on this branch: Search Docs opened to two paragraphs
Phone width, dark, and the live turn
Chrome, Read, live Chrome, Read, 390 dark Safari, Read, 390 dark Safari, two parts, 390 dark
Chrome, the live turn Chrome, Read step at 390 px, dark Safari, Read step at 390 px, dark Safari, two parts at 390 px, dark

Changelog

Conversations.

  • A conversation no longer goes blank when a connected Bot's tool answers with a picture, a document or several parts (a Claude Agent SDK Bot reading an image, for one). Conversations that already hold such a step open again and show it.

AG-UI 1.0 lets a tool result be a string or a list of content parts, and the
stock ag_ui_claude_sdk adapter sends a list whenever a Claude tool result is
anything but one plain text block: Read on a picture or a PDF, or an MCP tool
that answered in several parts. The transcript read every result as a string,
so the first .trim() on a list threw inside ChatTranscript's render and blanked
the page, and a stored history holding one could not be opened again.

The transcript projection now turns a tool message's content into text once,
for every reader: a string as it came, a list as its text parts with a short
line for a picture, document or other part, anything else as JSON. The result
readers in tool-result.ts and the gallery and sandboxed renderers take any
value. One message or step that still cannot be read now costs that row alone,
not the conversation.
The result is drawn as markdown, which runs single lines together, so two text parts read as one sentence (Found 2 pages Ribbon diagrams Protein folds). Found by the end-to-end run.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant