Skip to content

Python: Workflow.AsAIAgent returns intermediate agent text instead of designated workflow output #6211

@ssccinng

Description

@ssccinng

Description

In the .NET workflow host, Workflow.AsAIAgent().RunAsync(...) currently merges intermediate agent response updates into the outer AgentResponse.Text even when the workflow explicitly designates a terminal output executor via WithOutputFrom(...).

This makes .NET differ from the Python workflow agent behavior: Python surfaces the designated workflow output as the final agent response, while .NET can return the concatenated text of upstream agents and ignore a terminal non-chat executor output such as string.

Repro shape

ExecutorBinding first = firstAgent.BindAsExecutor(new AIAgentHostOptions { ForwardIncomingMessages = false });
ExecutorBinding second = secondAgent.BindAsExecutor(new AIAgentHostOptions { ForwardIncomingMessages = false });
UppercaseStringExecutor uppercase = new();

Workflow workflow = new WorkflowBuilder(first)
    .AddEdge(first, second)
    .AddEdge(second, uppercase)
    .WithOutputFrom(uppercase)
    .Build();

AgentResponse response = await workflow
    .AsAIAgent("WorkflowAgent")
    .RunAsync(new ChatMessage(ChatRole.User, "hello"));

Expected

The outer agent response should be produced from the designated terminal workflow output, e.g. SECOND ANSWER.

Actual

The outer response can be formed from intermediate agent updates, e.g. first answer\nsecond answer, while the terminal string output is not represented as the final agent response.

Notes

I have a PR that adds a regression test and changes the .NET host response aggregation so terminal workflow outputs win when present, while preserving legacy streaming updates for observers.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    Status

    No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions