Skip to content

Conversation

@anton-tw
Copy link
Contributor

@anton-tw anton-tw commented Dec 1, 2025

Summary

  • Fixes an issue where some providers (e.g., Bedrock) return an initial empty {} followed by actual arguments when streaming tool calls, resulting in malformed {}{...} JSON
  • Detects and strips the leading {} prefix while preserving legitimate empty {} arguments

Test plan

  • Added test for stripping {} prefix when followed by real arguments
  • Added test to verify legitimate empty {} arguments are preserved

When streaming, some models return an initial empty `{}` followed by the
actual arguments, resulting in `{}{...}`. This fix detects and strips
the leading `{}` prefix while preserving legitimate empty arguments.
@changeset-bot
Copy link

changeset-bot bot commented Dec 1, 2025

🦋 Changeset detected

Latest commit: acc60c2

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 2 packages
Name Type
@openai/agents-openai Patch
@openai/agents Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@anton-tw
Copy link
Contributor Author

anton-tw commented Dec 1, 2025

@seratch We ran into an issue when using Bedrock as the provider - during streaming, tool call arguments would arrive as {} in the first chunk, followed by the actual arguments in subsequent chunks. This resulted in malformed JSON like {}{\"key\":\"value\"} which breaks parsing.

This PR adds a small fix that detects and strips the leading {} when it's followed by real arguments, while still preserving legitimate empty {} arguments for tools that don't require parameters.

Would appreciate your thoughts on this approach!

@seratch seratch added this to the 0.3.x milestone Dec 2, 2025
@seratch seratch enabled auto-merge (squash) December 2, 2025 06:32
@seratch seratch changed the title fix: strip leading {} from streaming tool call arguments fix: strip leading {} from streaming tool call arguments (Bedrock) Dec 2, 2025
@seratch seratch disabled auto-merge December 2, 2025 06:32
@seratch seratch enabled auto-merge (squash) December 2, 2025 06:32
@seratch seratch merged commit d552b50 into openai:main Dec 2, 2025
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants