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

[Bug]: @ag-ui/claude-agent-sdk: tool results with multiple content blocks are truncated to the first block

Open
#2,632 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
15.9k
Forks
1.4k
Avg merge
1d 17h
Merged PRs (30d)
163

Description

### Pre-flight Checklist

- [x] I have searched existing issues and this hasn't been reported yet.
- [x] I am using the **latest** version of AG-UI.

### Describe the Bug

`buildAguiToolMessage` in `@ag-ui/claude-agent-sdk` reads only the first content
block of a tool result:

```ts
const firstBlock = content[0] as Record;
if (firstBlock?.type === "text") { ... }
```

Any tool returning multiple content blocks silently loses everything after the
first — there is no warning and no error, the data is just dropped.

Separately, text that happens to parse as JSON is round-tripped through
`JSON.stringify(JSON.parse(text))`, which rewrites its formatting. The Python
sibling adapter does the same round-trip deliberately (`_normalize_text`, with a
comment that it helps the frontend read fields), so that part may be intentional
for cross-language consistency.

### Steps to Reproduce

1. Have a tool return a result whose `content` is an array of multiple blocks
(e.g. two text blocks, or a text block plus an image block).
2. Run it through `ClaudeAgentAdapter` and inspect the emitted ag-ui tool message.
3. Only `content[0]` is represented; every later block is missing.

### Expected Behavior

All content blocks are preserved rather than truncated to the first (at minimum
behind an opt-in, to avoid changing existing behavior for callers who rely on the
current shape).

### Environment

```text
AG-UI package(s): @ag-ui/claude-agent-sdk (reproduced on main / 0.0.3, also 0.0.2)
Runtime: Node.js
```

### Additional Context

Proposed fix: add a `concatenateToolResultBlocks` config option (default
`false`) that iterates all blocks; the default preserves today's single-block
behavior exactly, so the change is additive and backwards-compatible. A PR is
opened alongside this issue; it raises as an open question whether to also drop
the JSON round-trip (the Python sibling keeps it).

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.