Skip to content

[Bug]: FunctionAgent.structured_output_fn is ignored when executed via AgentWorkflow #22159

Description

@opsbrown

Bug Description

Summary
When a FunctionAgent is executed directly using agent.run(), its structured_output_fn is invoked as expected.

However, when the same agent is executed through an AgentWorkflow using workflow.run(), the agent's structured_output_fn is never called. Instead, only AgentWorkflow.structured_output_fn is consulted.

This behaviour is inconsistent because FunctionAgent exposes a structured_output_fn parameter that appears to be supported, but it is silently ignored when the agent is used inside an AgentWorkflow.

Version

0.14.22

Steps to Reproduce

Minimal Reproduction

async def structured_output_fn(messages):
    print("Structured output callback invoked")
    return None

agent = FunctionAgent(
    name="ProfileCollector",
    tools=[tool],
    llm=llm,
    structured_output_fn=structured_output_fn,
)

workflow = AgentWorkflow(
    agents=[agent],
    root_agent="ProfileCollector",
)

await workflow.run(user_msg="My name is Charlie")

Expected Behaviour
The callback assigned to the FunctionAgent should be executed after the agent completes, just as it is when calling await agent.run(...)

Actual Behaviour
The callback is never executed.

If the exact same callback is instead attached to the workflow:

workflow = AgentWorkflow(
    agents=[agent],
    root_agent="ProfileCollector",
    structured_output_fn=structured_output_fn,
)

then it executes correctly.

Questions
Is this intentional?

Relevant Logs/Tracebacks

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingtriageIssue needs to be triaged/prioritized

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions