fix(openai): yield tool calls with invalid JSON instead of silently dropping#223
Open
mkaaad wants to merge 1 commit intocharmbracelet:mainfrom
Open
fix(openai): yield tool calls with invalid JSON instead of silently dropping#223mkaaad wants to merge 1 commit intocharmbracelet:mainfrom
mkaaad wants to merge 1 commit intocharmbracelet:mainfrom
Conversation
…ropping Previously, tool calls with invalid JSON arguments were silently dropped in the stream, preventing the agent from reporting the error back to the model. Now all tool calls are yielded regardless of argument validity, and the agent handles validation via its existing repair/error flow. Additionally, track hasYieldedToolCall to map finishReason correctly: use tool_calls only when a tool call was actually yielded, and fall back to stop when no tool call was yielded despite the API saying tool_calls.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
• Yield tool calls with invalid JSON arguments instead of silently dropping them, so the
agent can report errors back to the model
After the Agent fails the validation in validateAndRepairToolCall, it marks Invalid = true and returns the validation error to the model in the form of a tool result message, allowing the model to correct it automatically.
• Add test coverage for invalid JSON tool call handling
Test plan
[✓] Existing tests pass ( go test ./providers/openai/... )
[✓] New test "should drop tool calls with invalid JSON arguments" validates that
invalid JSON tool calls are yielded with correct deltas and finish reason