Skip to content

feat: emit ToolCallStart and ToolResult stream chunks#97

Merged
ishaksebsib merged 30 commits into
lazy-hq:mainfrom
razorback16:feat/tool-call-stream-chunks
Mar 23, 2026
Merged

feat: emit ToolCallStart and ToolResult stream chunks#97
ishaksebsib merged 30 commits into
lazy-hq:mainfrom
razorback16:feat/tool-call-stream-chunks

Conversation

@razorback16

@razorback16 razorback16 commented Mar 1, 2026

Copy link
Copy Markdown
Contributor

aisdkdemo

Summary

  • Fixes bug: Vercel UI stream emits hardcoded "unknown" for tool_call_id and tool_name #103, bug: Tool calls are swallowed in stream_text() #102.
  • Replaces ToolCall(String) streaming chunk with structured ToolCallDelta { tool_call_id, tool_name, delta }.
  • Emits ToolCallDelta in provider streaming paths for Anthropic, Google, and OpenAI.
  • Adds missing OpenAI Responses SSE handling for function-call streaming events:
    • response.output_item.added
    • response.output_item.done
    • response.function_call_arguments.delta
    • response.function_call_arguments.done
  • This specifically fixes the previous OpenAI gap where tool-call argument deltas were not surfaced during streaming.
  • Updates Vercel UI stream integration to emit real tool-call-start / tool-call-delta / tool-call-end with real tool ids/names (no hardcoded unknown path in normal flows).
  • Adds examples/stream_tool_probe.rs for provider-level real-world streaming verification.

Test plan

  • cargo test --all
  • cargo clippy --all -- -D warnings
  • cargo fmt --all -- --check
  • Real-world probe: cargo run --example stream_tool_probe --features "openai" -- openai both
  • Real-world probe: cargo run --example stream_tool_probe --features "google" -- google both
  • Real-world probe: cargo run --example stream_tool_probe --features "anthropic" -- anthropic both

Real-world verification notes

  • OpenAI now emits ToolCallDelta chunks in streaming (core + Vercel UI path), which was previously missing.
  • Anthropic and Google continue to emit expected tool-call delta/start/end behavior.

@rijkvanzanten rijkvanzanten 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.

LGTM! Ideally we add the toolcall to the delta as well so we get streaming arguments for tool calls, but I'm happy to do that as a follow-up PR if that's easier

Comment thread src/core/language_model/stream_text.rs Outdated
@surafelfikru

surafelfikru commented Mar 3, 2026

Copy link
Copy Markdown
Member

@razorback16, Wanted to push some changes (related to adding more variants) to this PR but I was getting this error. was wondering if there are any collaborator settings to configure on your side.

@razorback16 razorback16 force-pushed the feat/tool-call-stream-chunks branch 2 times, most recently from c787be7 to f0a3725 Compare March 3, 2026 20:00
@razorback16

razorback16 commented Mar 3, 2026

Copy link
Copy Markdown
Contributor Author

I have finished the pull request. Please have a look @surafelfikru @rijkvanzanten

razorback16 and others added 15 commits March 18, 2026 11:21
Add two new LanguageModelStreamChunkType variants that are emitted
around tool execution in stream_text: ToolCallStart (before) carries
ToolCallInfo with the tool name and input, ToolResult (after) carries
ToolResultInfo with the output. This allows consumers to display tool
calls and results in real time without workarounds.
- replace legacy ToolCall(String) chunk with structured ToolCallDelta
- emit tool-call deltas in OpenAI/Anthropic/Google streaming paths
- wire OpenAI Responses SSE function-call argument delta/done events
- propagate real tool ids/names in Vercel UI stream mapping
- add stream_tool_probe example and fix its warning output
Replace deprecated Start/Text variant references in mock stream tests
with the renamed TextStart/TextDelta variants across openai, anthropic,
and google provider test suites.
@surafelfikru surafelfikru force-pushed the feat/tool-call-stream-chunks branch from ff74243 to 5e840e9 Compare March 18, 2026 08:27
…s NotSupported chunks

reqwest_eventsource fires Event::Open on connection before any data events.
All three provider clients mapped this to NotSupported("{}"), which leaked
into the stream channel as the first item and caused mock tests to panic on
the TextDelta assertion.

Filter Event::Open before parse_stream_sse in the shared send_and_stream,
fixing all six failing stream tests. Update openai_chat_completions tests
whose first-item assertion was an artifact of the now-removed Open event.
@surafelfikru surafelfikru requested review from ishaksebsib and removed request for rijkvanzanten March 18, 2026 08:57
@razorback16

Copy link
Copy Markdown
Contributor Author

@surafelfikru @ishaksebsib any update on merging this pull request?

@ishaksebsib ishaksebsib merged commit f6fe525 into lazy-hq:main Mar 23, 2026
6 checks passed
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.

bug: Vercel UI stream emits hardcoded "unknown" for tool_call_id and tool_name

4 participants