-
Notifications
You must be signed in to change notification settings - Fork 2k
Support pydantic schemas in tools #1660
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
base: main
Are you sure you want to change the base?
Conversation
# Return primitive values as-is | ||
return obj | ||
|
||
def convert_anyof_to_nullable(obj): |
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.
@albertvillanova a big part of the logic in there is to handle our "nullable" parameter with Pydantic models that follow a different json schema spec.
Maybe it would be wise in a follow-up PR to handle json schemas directly rather than converting their logic to our nullable fomat
Handling json shcemas directly could use either of the solutions below:
Solution 1:
Just add a completely new validation logic, with a tool.input_schema parameter that follows the pydantic schema : each tool init could either (exclusive OR) use tool.inputs or tool.input_schema, depending on what was use for initialization.
Then after some time, tool.inputs could be deprecated to only follow the new version.
Solution 2:
Let tool.inputs be either our legacy way of describing inputs, or a json schema. This is detected dynamically, then either logic is used for validation.
@duguyue100 to my understanding, this PR might be a comprehensive solution to your issue described in #1708 and grll/mcpadapt#68 |
@chahn Does this have anything to do with how MCPAdapt creates smolagents tools? I couldn't see it. |
@albertvillanova do you have some time for a review? |
Tools can use pydantic models as their input schemas!
Builds on #1643, fixes #699
Features:
ToolCallingAgent
, where the model can only output a dictionary)Discussion points:
structured_output
arg to agent initialization, this would be for an upcoming PR