-
Notifications
You must be signed in to change notification settings - Fork 140
Fix tool call argument serialization issue #39
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix tool call argument serialization issue #39
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR fixes a tool call argument serialization issue where JSON strings were being incorrectly wrapped in a query field instead of being parsed and used directly. The fix enhances argument processing to first attempt JSON parsing of string arguments, using the parsed object directly if it's a dict/list, while preserving backwards compatibility for plain strings.
Key Changes:
- Enhanced string argument processing to parse JSON before wrapping in query field
- Applied the fix to both web search call processing and function call output processing
- Maintained backwards compatibility for plain string arguments
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
|
Amazing good job. Thanks for the PR! |
|
Just tested this locally, fix works as advertised.
I simulated a few SSE events to reproduce. PR branch passes, main fails the JSON‑string case. LGTM. |
|
Quick update: I opened a small stacked PR with follow ups so the diff stays focused:
Stacked PR: phawrylak#1 |
Thats fair, wouldn't be accepting tests in this PR, but later on please do propose a PR for tests. Could definitely be beneficial so we don't have these issues. |
I honestly do not feel these changes are needed for this simple bug fix, and personally find the code slightly less legible (for _serialize_tool_args). PR LGTM |
Thanks for the quick review - keeping #39 focused makes sense. One thing I re-checked on the current branch:
Happy to proceed however you prefer:
|
* Tool calling arguments JSON fix * Extracted duplicated code to helper function * Update utils.py --------- Co-authored-by: Game_Time <108236317+RayBytes@users.noreply.github.com>
Fix tool call argument serialization issue
Problem Description
Tool call arguments were being incorrectly serialized when passed as JSON strings, causing them to be wrapped in an unnecessary
queryfield instead of being parsed and used directly.Before (Broken):
{ "query": "{\"operation\":\"write\",\"todoList\":[{\"id\":1,\"title\":\"test\"}]}" }After (Fixed):
{ "operation": "write", "todoList": [ { "id": 1, "title": "test" } ] }Root Cause
The issue was in the
sse_translate_chatfunction in utils.py at two locations:The original logic treated all string arguments the same way:
This caused valid JSON strings to be double-wrapped instead of being parsed and used directly.
Solution
Enhanced the argument serialization logic to:
queryfieldNew Logic:
Changes Made
Testing
The fix handles multiple scenarios correctly:
queryfield for compatibilityImpact
This fix resolves tool call argument serialization issues for VS Code extensions and other clients that pass structured data as JSON strings, ensuring proper parameter passing without breaking existing functionality for simple string queries.