Support tool calling when a structured result is provided - #184
Merged
Merged
Conversation
Deploying pydantic-ai with
|
| Latest commit: |
d3a01f1
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://08121d92.pydantic-ai.pages.dev |
| Branch Preview URL: | https://multiple-tools.pydantic-ai.pages.dev |
jlowin
commented
Dec 9, 2024
jlowin
marked this pull request as ready for review
December 9, 2024 21:57
samuelcolvin
left a comment
Member
There was a problem hiding this comment.
otherwise this looks great.
I'm happy to help or take over if my feedback is too annoying.
Contributor
Author
|
All good feedback. Will clean up today or tomorrow as time allows. |
Co-authored-by: Samuel Colvin <s@muelcolvin.com>
Co-authored-by: Samuel Colvin <s@muelcolvin.com>
Contributor
Author
|
@samuelcolvin I think this is all cleaned up now |
thiagohora
pushed a commit
to thiagohora/pydantic-ai
that referenced
this pull request
Feb 10, 2026
Co-authored-by: Samuel Colvin <s@muelcolvin.com>
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.
This PR addresses behavior when an agent requests multiple tool calls, one of which is a "final" result call. I believe it closes #161 and follows #179.
In this PR:
end_strategyparameter that can be either "early" or "correct".Earlymeans that the presence of a "final" result short-circuits all other tool calls, and they are not made. Passing "correct" will call all tools, even if a final result was provided.correctis the default value.end_strategyis, a ToolResult message is always generated for every tool call. This ensures that messages from the agent call can safely be used as the input to another call._handle_model_responsemethod was very complicated, so I split it into a few straightforward method calls. If that's not desirable, it's easy to recombine.Note: this PR does not address the streaming case, as that is more complexing pending conversation with @samuelcolvin .