-
Notifications
You must be signed in to change notification settings - Fork 466
feat(tools): Support string descriptions in Annotated parameters #1089
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
|
The unit tests seems to be failing but they pass on my end, is it due to the logic written in decorator file init method @dbschmigelski |
They are failing when I run locally. I think there are some small bugs related to truthiness. I also am not seeing proper handling of the required case. I think there is an issue when it comes to defaulting when we have Field within Annotated with Field does not have a default so it is incorrectly still in required, If we did it would pass though So we have to address the failing tests and probably add a test with this inner-default |
|
It seems to be failing again @dbschmigelski , I added a new commit again to fix the default handling. For Annotated params with Field, I copy the Field (preserving constraints) then override the default from function signature. For non-Annotated params, I pass the default directly to Field constructor. |
|
I can check again regarding the branch protection. I think there are some interesting things going on for the test failures For this is the default issue I mentioned, where when default is present INSIDE the Field it is respected. But, if we have an Annotation, with a Field, and the Annotation has the default then we unexpectedly are not respecting the default. For It looks like when the Field does not have any description, even when we do |
No I figured out the branch protection happens cause I opened the PR from my fork, I should be opening it from the main repo itself. So its my fault, if you want I can create a new PR immediately with the same changes. |
|
Actually we only allow PRs from forks, so you're definitely doing it right, may just be a problem with my git locally |
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
|
Looks like we have one failing test @Ratish1, are you unable to run |
No i can run it, it passes for me locally @dbschmigelski . Idk why this is failing, I think I found a fix, pushing the changes now. |
Strange, I had thought hatch would prevent issues |
I normally just do pre commit check all command. I tried hatch and it passes for me, dont know if this is a me problem. Anyway hopefully it works now. |
|
It seems to still fail @dbschmigelski . I think get_type_hints() behaves differently for complex Annotated types in older Python versions so I removed it and switched to use param.annotation directly. |
|
The tests pass now @dbschmigelski, I also updated the description of the PR. Lmk if you need more changes, thanks. |
Made some minor changes to avoid making breaking changes to the FunctionToolMetadata class. It is highly unlikely, but technically someone could have depended on self.type_hints and the old behavior of self.param_descriptions |
Oh ok got it, thanks for the help. |
Description
This PR adds support for using typing.Annotated to define argument descriptions directly in the type hints of @tool decorated functions. This provides a cleaner and more maintainable way to document tool parameters.To ensure a robust and maintainable implementation, this feature is currently focused on string-based descriptions. Support for
pydantic.Fieldconstraints withinAnnotatedis deferred to a future enhancement, and aNotImplementedErroris raised to guide developers.Key changes
Annotatedtype hints and uses it as the parameter's description, prioritizing it over docstrings.param.annotationfor type inspection to ensure consistent behavior across all supported Python versions, including Python 3.10.NotImplementedErrorifpydantic.Fieldis used within anAnnotatedtype.value handling, and correct priority.NotImplementedErrorcase.Related Issues
#511
Documentation PR
N/AType of Change
New feature
Testing
How have you tested the change? Verify that the changes do not break functionality or introduce warnings in consuming repositories: agents-docs, agents-tools, agents-cli
hatch run prepareChecklist
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.