fix: filter **kwargs and *args from tool call schema generation#2619
Open
Ricardo-M-L wants to merge 2 commits intoag2ai:mainfrom
Open
fix: filter **kwargs and *args from tool call schema generation#2619Ricardo-M-L wants to merge 2 commits intoag2ai:mainfrom
Ricardo-M-L wants to merge 2 commits intoag2ai:mainfrom
Conversation
When a function has `**kwargs` or `*args`, the tool schema generation incorrectly treats them as regular parameters. This causes LLMs to nest all arguments inside a `kwargs` field, leading to Pydantic validation failures. Filter VAR_KEYWORD and VAR_POSITIONAL parameter kinds in all five functions that iterate over inspect.Signature.parameters: - get_typed_signature() - get_param_annotations() - get_required_params() - get_default_values() - get_missing_annotations() Fixes ag2ai#1790 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
10bcc92 to
3e25c69
Compare
Codecov Report✅ All modified and coverable lines are covered by tests.
... and 64 files with indirect coverage changes 🚀 New features to boost your workflow:
|
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
VAR_KEYWORD(**kwargs) andVAR_POSITIONAL(*args) parameter kinds from tool schema generation inautogen/tools/function_utils.pyinspect.Signature.parameters:get_typed_signature(),get_param_annotations(),get_required_params(),get_default_values(),get_missing_annotations()Why
When a function has
**kwargs, AG2's tool schema generation treatskwargsas a regular required parameter. The LLM sees it in the schema and nests all arguments inside akwargsfield, causing Pydantic validation failure. See the issue for a detailed reproduction.Fixes #1790
Test plan
test_get_typed_signature_filters_var_keyword,test_get_typed_signature_filters_var_positional,test_get_typed_signature_filters_both_var_positional_and_keyword,test_get_param_annotations_excludes_kwargs,test_get_required_params_excludes_kwargs,test_get_required_params_excludes_args,test_get_default_values_excludes_kwargs,test_get_missing_annotations_excludes_var_params,test_get_function_schema_with_kwargs_only,test_get_function_schema_with_regular_params_and_kwargs,test_get_function_schema_with_args_and_kwargs,test_get_function_schema_no_kwargs_regression)pytest-asyncio— pre-existing, unrelated)hello_world_v3(arg1, arg2, **kwargs)now generates a schema withoutkwargsin properties or required🤖 Generated with Claude Code