Skip to content

feat: stream tool-call arguments as incremental AG-UI deltas - #781

Merged
blove merged 3 commits into
mainfrom
blove/stream-tool-call-args
Sep 22, 2026
Merged

blove merged 3 commits into
mainfrom
blove/stream-tool-call-args

Conversation

@blove

@blove blove commented Sep 22, 2026

Copy link
Copy Markdown
Contributor

Summary

Tool-call arguments now reach the AG-UI wire as they are generated: TOOL_CALL_START, one or more TOOL_CALL_ARGS deltas, then TOOL_CALL_END, under the call's logical id. A client that renders from a tool call's arguments can paint progressively, as it already does for assistant text.

  • @b4run/langchain: the agent adapter projects the tool_call_chunks fragments a provider streams on on_chat_model_stream into a new tool_call_args chunk, correlated by model run and fragment index. The on_chat_model_end announce and its guards are unchanged, so identity across interrupt/resume and the resume-replay path behave exactly as before. Subagent models and the two orchestration tools (writeTodos, task) never stream.
  • Byte identity: a new canonical-json-stream re-serializes the raw provider JSON token by token into exactly what JSON.stringify(args) produces, so the concatenated deltas match today's single delta byte for byte. Duplicate or array-index-like keys, which cannot be canonicalized before their object closes, fall to raw passthrough that still parses to the same object.
  • @b4run/ag-ui: the first fragment opens the call, each fragment is one delta, the announce emits any uncovered tail and then TOOL_CALL_END. A tool_call with no preceding fragments takes today's three-frame path unchanged (the silent fallback for providers that yield no fragments). Open streamed calls are ended on done, interrupt, error and exhausted streams.
  • @b4run/cli: the middleware after hook treats a fragment as proof a held message was not final; the live tail renders nothing for fragments.

Design: docs/superpowers/specs/2026-09-21-stream-tool-call-args-design.md.

Test plan

  • Transcoder: randomized fragmentation of serialized objects concatenates to JSON.stringify of the parse; whitespace, escapes, surrogates and number forms canonicalize; hazard shapes fall to passthrough that parses identically.
  • Adapter: multi-fragment turn, fragment-less turn identical to today, two interleaved calls by index, orchestration names, subagent models, interrupt then resume announces once.
  • Mapper: deltas concatenate to today's payload, tail emission, terminal-path closing; conformance test runs a streamed call through @ag-ui/client verifyEvents.
  • Wire: CLI AG-UI endpoint test asserts several TOOL_CALL_ARGS frames on the SSE stream.
  • Live against OpenAI gpt-5-mini: 61 deltas over ~5 s, concatenation identical to the announce. Anthropic not verified (no API credit on the local key).
  • turbo run lint typecheck test for langchain, ag-ui and cli; node scripts/check-docs.mjs passes.

🤖 Generated with Claude Code

@vercel

vercel Bot commented Sep 22, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
b4-run Ready Ready Preview Sep 22, 2026 4:49am UTC

Request Review

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Automated approval: this PR received an intelligent (AI) code review. See the review comments on this PR.

@blove
blove merged commit 1cadde8 into main Sep 22, 2026
30 of 31 checks passed
@blove
blove deleted the blove/stream-tool-call-args branch September 22, 2026 05:10
blove added a commit to liveloveapp/hashbrown that referenced this pull request Sep 22, 2026
## Summary

Bumps the invoicing server's seven `@b4run/*` pins from 0.9.0 to 0.10.0
and refreshes the root lockfile. 0.10.0 ships
[cacheplane/b4run#781](cacheplane/b4run#781),
which streams a tool call's arguments as several `TOOL_CALL_ARGS` deltas
instead of one; the hashbrown client already parses partial arguments
incrementally, so generative UI in the example now paints while the
model is still writing the component tree. No code changes were needed
in the example.

The lockfile diff is the B4 package set plus two nested duplicates
(`commander`, `typescript`) that now dedupe to the root.

## Test plan

- [x] `nx run-many -t build test lint --projects
invoicing-server,invoicing-contracts,invoicing-react` passes (server 213
tests, contracts 65, react 8).
- [x] Every `@b4run/*` entry in the lockfile resolves to 0.10.0.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-authored-by: Claude Fable 5.1 <[email protected]>

This branch was successfully deployed

1 active and 1 inactive deployments
vercel-preview — 323af546 Deployed Sep 22, 2026 by blove via vercel-native #2176
Preview — 323af546 Deployed Sep 22, 2026 by vercel[bot]
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