Skip to content

aisdk: fix OpenAI streamed tool calls and Anthropic no-arg tools - #616

Merged
mikeland73 merged 3 commits into
mainfrom
claude/admiring-hamilton-rpyrh3-aisdk
Nov 11, 2026
Merged

mikeland73 merged 3 commits into
mainfrom
claude/admiring-hamilton-rpyrh3-aisdk

Conversation

@mikeland73

Copy link
Copy Markdown
Contributor

Summary

Fixes P0 bugs #7 and #8 from specs/bug-scan.md.

  • Use a different copybara action to see if that works better #7 – StreamToResponse failed on every OpenAI function call (aisdk/ai/builder/builder.go): the OpenAI Responses stream sends ToolCallDeltaEvents and then a final ToolCallEvent with the same ID. addToolCall rejected that final event as a "duplicate tool call ID". The builder now records which IDs have received a complete ToolCallEvent. When a final event arrives for a block that was built from deltas, it finalizes that block and takes the full args from the final event. Two complete ToolCallEvents with the same ID are still rejected as duplicates.
  • Rename copybara workflow to 'default' #8 – Anthropic panicked on no-argument tools (aisdk/ai/provider/anthropic/codec/jsonschema.go): FunctionTool.InputSchema is optional, but encodeInputSchema read schema.Type without a nil check. A nil schema is now encoded as {"type":"object","properties":{}}.

How was it tested?

  • builder_test.go:
    • New case that replays the OpenAI event sequence: deltas, then a final event with the same ID. It fails on main with duplicate tool call ID: call_1 and passes with this change.
    • New test that two complete ToolCallEvents with the same ID still error.
  • encode_tools_test.go: new case for &api.FunctionTool{Name: "now"} with no input schema.
  • go vet and go test ./... pass in aisdk/ai.

Community Contribution License

All community contributions in this pull request are licensed to the project maintainers under the terms of the Apache 2 License.

By creating this pull request I represent that I have the right to license the contributions to the project maintainers under the Apache 2 License as stated in the Community Contribution License.


Generated by Claude Code

Fixes bug-scan P0 #7 and #8 from specs/bug-scan.md.

- #7: The OpenAI stream emits ToolCallDeltaEvents for a function call and
  then a final ToolCallEvent with the same ID. ResponseBuilder rejected that
  final event as a duplicate, so builder.StreamToResponse failed on every
  OpenAI stream containing a function call. The builder now finalizes the
  existing block (taking the complete args from the final event) and only
  errors when two complete ToolCallEvents share an ID.
- #8: encodeInputSchema dereferenced a nil schema, so a FunctionTool with
  no InputSchema panicked when sent to Anthropic. A nil schema is now
  encoded as an empty object schema.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Bqy92pq662Fgv5A4GoaUD2
Adds the status as its own line under the matching "Suggested fix order"
item so it doesn't conflict with the other P0 fix PRs.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Bqy92pq662Fgv5A4GoaUD2
@greptile-apps

greptile-apps Bot commented Nov 11, 2026 •

Copy link
Copy Markdown

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The PR appears safe to merge.

Summary

Fixes OpenAI streamed tool calls and Anthropic tools without an input schema.

  • OpenAI streamed tool calls now finish as one complete response block.
  • Anthropic accepts function tools with no input schema.

No new actionable issues were found in the changes since the previous review. Tests were inspected, not run.

Reviews (2) · Last reviewed commit: "aisdk/builder: test that final ToolCallE..." · Reviewed by Greptile

Comment thread aisdk/ai/builder/builder_test.go Resolved
@mikeland73
mikeland73 merged commit 436b4bc into main Nov 11, 2026
10 checks passed
@mikeland73
mikeland73 deleted the claude/admiring-hamilton-rpyrh3-aisdk branch November 11, 2026 05:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants