fix: honor agent structured_output_fn/output_cls inside AgentWorkflow#22162
Open
anneheartrecord wants to merge 1 commit into
Open
fix: honor agent structured_output_fn/output_cls inside AgentWorkflow#22162anneheartrecord wants to merge 1 commit into
anneheartrecord wants to merge 1 commit into
Conversation
When a FunctionAgent with its own structured_output_fn (or output_cls) runs inside an AgentWorkflow, the agent's structured output config was ignored: aggregate_tool_results only consulted the workflow-level structured_output_fn / output_cls. The agent's callback fired with agent.run() but not workflow.run(). Fall back to the running agent's structured_output_fn / output_cls when the workflow defines none, keeping workflow-level config as the precedence winner.
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.
Description
Fixes #22159
A
FunctionAgentconfigured with its ownstructured_output_fn(oroutput_cls) produced structured output when run directly viaagent.run(), but the same agent silently ignored that config when executed through anAgentWorkflow.The cause is in
AgentWorkflow.parse_agent_output: on agent completion it only consulted the workflow-levelself.structured_output_fn/self.output_cls, never the running agent's. The single-agent path (BaseWorkflowAgent.parse_agent_output) reads the agent's own config, hence the inconsistency.The fix falls back to the running agent's
structured_output_fn/output_clswhen the workflow defines none. Workflow-level config still takes precedence, so existing behavior is unchanged when it's set.Scope note: this targets the normal completion path (the one in the reported repro). The
return_directshort-circuit inaggregate_tool_resultsdoesn't generate structured output, but that's already symmetric with the standalone agent path (BaseWorkflowAgentdoesn't either), so it's left as-is to avoid introducing a new inconsistency.Type of Change
How Has This Been Tested?
Added to
tests/agent/workflow/test_agent_with_structured_output.py:output_clshonored viaAgentWorkflowstructured_output_fnhonored viaAgentWorkflowstructured_output_fnhonored viaAgentWorkflowstructured_output_fnstill overrides the agent'sAll structured-output tests pass locally (
uv run pytest tests/agent/workflow/test_agent_with_structured_output.py -k "not openai").Suggested Checklist: