-
Notifications
You must be signed in to change notification settings - Fork 183
Update @tool to return an AgentTool that also acts as a function #258
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
Conversation
Right now when you decorate a function you get back another function that mimics the behavior of a python module. Going forward, we're discussing adding helper/utility methods for AgentTool and in anticipatation of those changes return an AgentTool implementation that also acts like the original function.
To preserve backwards compatibility, allow passing tool_use into `__call__` for now with a warning on usage. In a future release, we can remove
Removing the need for an overload
This commit caused a problem. Previously, we can add multiple tools with different parameters, but now it can not, it report build error |
@yimuniao thanks for reaching out - do you have an example code of what broke? |
Discussed offline; the crux of the issue was that the inferred types of tools changed @tool
def example1(value: str): ...
@tool
def example2(value: str): ...
# Previously would have been typed more generically
tools = [example1]
# And this would have worked
tools.extend([example2]) Now, assigning tools requires typing it more generally: tools: list[AgentTool] = [example1]
# or
tools: list[any] = [example1] This is primarily a problem if someone is using implicitly typed lists and type-checking using |
Description
Update tools decorated with
@tool
to be subclasses ofAgentTool
instead of callable that look similar to python modules.This means that the following:
my_tool
is actually an implementation of AgentTool (specificallyDecoratedFunctionTool
).If you call
my_tool()
directly it acts just like a function call. But it also has the methods and properties of anAgentTool
:This would allow us to include a helper utility in the future that act on AgentTool(s) without needing to special case decorated functions.
One such example is a
bind
utility which would use a constant value for a tool:though this is just an example of how unification benefits
Behavior Change:
We no longer allow passing
ToolUse
directly into the decorated functions (we do allow this right now for backwards compatibility but emit a warning - in the future we will not allow this):This was previously allowed because the tool decorator didn't differentiate between calls that were going to the function and calls that were being done as "tool"; instead this is now implemented via
invoke
like other AgentToolsImplementation Notes:
DecoratedFunctionTool
in a way that typed it as both the original function and an AgentTool@tool()
and@tool
but was also typed correctlyFunctionTool
around for backwards compatibly with the idea that we'll remove it in the future. This is up for debate, but let me know if you disagreeRelated Issues
N/A
Documentation PR
n/A
Type of Change
Refactor
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 prepare
Checklist
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.