-
Notifications
You must be signed in to change notification settings - Fork 242
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
How can one simply return the response of the tool, instead of routing the response to a final result handler? #127
Comments
I don't really understand the question I'm afraid. Result tools are not required - if the return type is And there aren't any LLM calls after the result is returned. |
@pedroallenrevez I've implemented one idea @samuelcolvin and I discussed for addressing this in #142. I think it works and makes it possible for tool calls to be the "result tool", and makes it possible to disable the default schema-based result tool. But I don't love the approach. Repeating what I wrote at the end of the PR body:
Do you have any reactions to either of these proposals? In principle we could support both but I suspect @samuelcolvin might not want two different ways to override the default behavior. While I think the @jlowin — @samuelcolvin mentioned you had some ideas/thoughts on this issue, feedback on either of the proposals above is very much welcome. |
Thanks @dmontagu for the thoughtful proposals. We had a chance to discuss offline, so I will try to summarize here -- I think we can distill or reframe the core issue and solution: The fundamental problem is that using a user-supplied tool in Pydantic AI currently requires two LLM calls: one to use the tool and another to generate the final response. We want to enable single-call workflows if the user knows that a single call satisfies their objective, while maintaining strong typing. Rather than embedding termination logic within tools via
For users who need dynamic termination logic, they can achieve this by giving their agent both regular and result tools, letting the agent itself make the choice of which to call. This keeps the architecture clean while supporting all needed use cases. The ultimate consequence of all of this is that the user is supplying the terminal tool(s) instead of having PydanticAI auto-generate one. I think this aligns well with Pydantic AI's focus on composable, strongly-typed LLM invocations! |
Even though I just mildly understand Just a small observation:
I feel this is the key-point to achieve natural intuiteveness when building agents. Thanks people :) |
There is a question of how to perform validation when registering multiple response tools. Presumably a single validation function still works but the pattern of using @result_tool
def f(x:list[int]) → list[int]:
... # validate and return
@result_tool
def g(x: list[int]) → list[int]:
... # validate and return (maybe this is obvious and falls out of the design but just in case) |
I'm assuming a
result_tool
is always needed.In this case I want the tool to be another agent, and I just want the response from that agent, without any other LLM call.
The text was updated successfully, but these errors were encountered: