Skip to content

Return last text parts on empty message #1408

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

Merged
merged 1 commit into from
Apr 17, 2025
Merged

Return last text parts on empty message #1408

merged 1 commit into from
Apr 17, 2025

Conversation

samuelcolvin
Copy link
Member

We sometimes get an empty response with anthropic (and perhaps other models) when the model has already returned text alongside tool calls in this scenario, if text responses are allowed, we return text from the most recent model response, if any.

Copy link

github-actions bot commented Apr 8, 2025

Docs Preview

commit: cde9fd8
Preview URL: https://767168b7-pydantic-ai-previews.pydantic.workers.dev

@Kludex
Copy link
Member

Kludex commented Apr 8, 2025

Maybe this PR solves #1292

@Kludex
Copy link
Member

Kludex commented Apr 8, 2025

There's a similar PR I think? #1294

Copy link
Contributor

@dmontagu dmontagu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is kind of an opinionated approach to how the graph should behave if you get an empty response, but I think it's a reasonable opinion. I feel like we might want to refactor this in the future but even if we do I suspect any change would be backwards compatible, and this is clearly an improvement over the current behavior, so I think let's go with it.

However, I'll note that I think it would be nice to provide a way for a tool to indicate that its result should not be used to continue the conversation. I have some ideas about this but they are mostly opinionated and probably we don't need to start with that complexity.

For this specific case, I think if you wanted to avoid having the conversation continue just because there was text and tools, you could add an output tool with a single text field (or even do something like OutputTool(str) from the result->output PR), and that would make it possible for the model to decide precisely when it's agentic run was finished (in particular, not needing to receive a request with the result of any non-output tools called alongside an output tool).

Either way, I'm in favor of merging this as is.

@samuelcolvin samuelcolvin merged commit aae9022 into main Apr 17, 2025
18 checks passed
@samuelcolvin samuelcolvin deleted the last-text-parts branch April 17, 2025 13:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants