Skip to content

Conversation

@Danipulok
Copy link
Contributor

Fixes #3636

`run_stream()` behaves differently from `run()` and `run_sync()` when choosing the final result:

- **`run_stream()`**: The first called tool that **can** produce a final result (output or deferred) becomes the final result
- **`run()` / `run_sync()`**: The first **output** tool becomes the final result. If none are called, all **deferred** tools become the final result as `DeferredToolRequests`
Copy link
Contributor Author

Choose a reason for hiding this comment

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

If none are called

The wording is like this, since we get an UnexpectedModelBehavior if both output and deferred tools are called, but none output tools are validated

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If I understand correctly, the deferred tools args are not validated

I guess it means we could check that if any deferred tools calls are present and tool_call_results is None, we can skip ignore invalid output tool calls, as we do in here:

yield _messages.FunctionToolCallEvent(call)
output_parts.append(e.tool_retry)
yield _messages.FunctionToolResultEvent(e.tool_retry)

But I'm not sure about it...
And IMHO, if do this at all, then it should be done in a separate PR

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.

Inconsistency in result.output for agent.run_sync and agent.run_stream when both OutputTool and DeferredTool are called

1 participant