-
Notifications
You must be signed in to change notification settings - Fork 238
fix(agent): prevent JSON serialization errors with non-serializable direct tool parameters #498
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
Merged
cagataycali
merged 2 commits into
strands-agents:main
from
cagataycali:fix/non-serializable-tool-parameters
Jul 18, 2025
Merged
fix(agent): prevent JSON serialization errors with non-serializable direct tool parameters #498
cagataycali
merged 2 commits into
strands-agents:main
from
cagataycali:fix/non-serializable-tool-parameters
Jul 18, 2025
Conversation
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
…ool parameters Fixes issue where passing non-serializable objects (Agent instances, custom classes, functions, etc.) as tool parameters would cause JSON serialization errors during tool call recording. Changes: - Add parameter filtering in _record_tool_execution() to test each parameter with json.dumps() and replace non-serializable objects with descriptive strings like '<non-serializable: TypeName>' - Remove unused 'messages' parameter from _record_tool_execution method - Fix message format consistency (agent.tool.{name} vs agent.{name}) - Add comprehensive test coverage for various non-serializable object types including Agent instances, custom classes, functions, sets, complex numbers - Add edge case testing for nested structures and None values - Add regression testing for normal serializable parameters - Add testing for disabled recording scenarios The fix maintains full functionality while preventing crashes, providing clear error indicators instead of cryptic JSON serialization errors. Closes strands-agents#350
yakshpradippatel
previously approved these changes
Jul 18, 2025
mkmeral
reviewed
Jul 18, 2025
- Replace manual serialization loop with json.dumps default parameter - Use __qualname__ for better type representation - Change format from <non-serializable> to <<non-serializable>> - Update tests to match new serialization format - Addresses PR feedback to simplify serialization approach
JackYPCOnline
approved these changes
Jul 18, 2025
dbschmigelski
pushed a commit
to Ketansuhaas/sdk-python
that referenced
this pull request
Jul 24, 2025
…irect tool parameters (strands-agents#498) * fix(agent): prevent JSON serialization errors with non-serializable tool parameters Fixes issue where passing non-serializable objects (Agent instances, custom classes, functions, etc.) as tool parameters would cause JSON serialization errors during tool call recording. Changes: - Add parameter filtering in _record_tool_execution() to test each parameter with json.dumps() and replace non-serializable objects with descriptive strings like '<non-serializable: TypeName>' - Remove unused 'messages' parameter from _record_tool_execution method - Fix message format consistency (agent.tool.{name} vs agent.{name}) - Add comprehensive test coverage for various non-serializable object types including Agent instances, custom classes, functions, sets, complex numbers - Add edge case testing for nested structures and None values - Add regression testing for normal serializable parameters - Add testing for disabled recording scenarios The fix maintains full functionality while preventing crashes, providing clear error indicators instead of cryptic JSON serialization errors. Closes strands-agents#350 * refactor: use json.dumps default parameter for non-serializable objects - Replace manual serialization loop with json.dumps default parameter - Use __qualname__ for better type representation - Change format from <non-serializable> to <<non-serializable>> - Update tests to match new serialization format - Addresses PR feedback to simplify serialization approach
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.
Description
This PR fixes a critical issue where passing non-serializable objects as tool parameters would cause JSON serialization errors during tool call recording, leading to crashes when agents tried to record their tool usage.
The Problem
When agents passed complex objects like Agent instances, custom classes, functions, or other non-JSON-serializable objects as tool parameters, the
_record_tool_execution()
method would fail with cryptic JSON serialization errors, breaking the entire tool execution flow.The Solution
json.dumps()
before recording<non-serializable: TypeName>
Key Changes
_record_tool_execution()
to handle non-serializable objectsmessages
parameter from method signatureagent.tool.{name}
vsagent.{name}
)Related Issues
Closes #350
Documentation PR
No documentation changes needed - this is an internal bug fix that maintains existing API.
Type of Change
Bug fix
Testing
Comprehensive test suite added covering:
hatch run prepare
- all pre-commit hooks passedTest Results
All existing tests pass, and 5 new test functions added:
test_agent_tool_non_serializable_parameter_filtering
test_agent_tool_multiple_non_serializable_types
test_agent_tool_serialization_edge_cases
test_agent_tool_no_non_serializable_parameters
test_agent_tool_record_direct_tool_call_disabled_with_non_serializable
Checklist
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.