Skip to content

.NET: Workflow.AsAIAgent drops a terminal executor's ChatMessage output unless includeWorkflowOutputsInResponse is set #9704

Open

Description

@tzdevelopteam

Description

When a workflow is hosted with Workflow.AsAIAgent(...) and includeWorkflowOutputsInResponse is left at its default (false), an executor designated with WithOutputFrom(...) reaches the agent response only if its output is a string or AIContent. The same executor yielding a ChatMessage or IEnumerable<ChatMessage> produces no update at all: the stream carries only an observability update for the WorkflowOutputEvent.

In WorkflowSession.cs (1.25.0, unchanged on main as of 2026-10-26), the WorkflowOutputEvent case computes includeTerminalOutput = this._workflow.IsTerminalOutput(output.ExecutorId) and then:

  • forwards updateContents when _includeWorkflowOutputsInResponse || includeTerminalOutput;
  • forwards updateMessages only when _includeWorkflowOutputsInResponse.

The comment above that block says response-compatible payloads are forwarded "when the host requests all workflow outputs, or when this executor is an explicit output source for the workflow", so the two branches disagree with it. The same gap was pointed out in an automated review comment on #6212, which introduced the terminal-output path.

Since #8020 the hosted AddAsAIAgent() sets includeWorkflowOutputsInResponse: true, so this shows up only when Workflow.AsAIAgent is called directly, for example to pass an execution environment (#9370).

Steps to reproduce

File-based app (dotnet run repro.cs), Microsoft.Agents.AI.Workflows 1.25.0. The same terminal executor is bound twice, once returning List<ChatMessage> and once returning string, each marked with WithOutputFrom:

#:package Microsoft.Agents.AI.Workflows@1.25.0
#pragma warning disable MAAIW001, MAAI001
using Microsoft.Agents.AI;
using Microsoft.Agents.AI.Workflows;
using Microsoft.Extensions.AI;

static string Last(List<ChatMessage> m) => m.LastOrDefault(x => x.Role == ChatRole.User)?.Text ?? "";

Func<List<ChatMessage>, List<ChatMessage>> asMessages = m => [new(ChatRole.Assistant, $"echo: {Last(m)}")];
Func<List<ChatMessage>, string> asString = m => $"echo: {Last(m)}";

foreach (var (label, answer) in new (string, ExecutorBinding)[]
{
    ("List<ChatMessage>", asMessages.BindAsExecutor("Answer", threadsafe: true)),
    ("string", asString.BindAsExecutor("Answer", threadsafe: true)),
})
{
    ExecutorBinding start = new Start();
    var workflow = new WorkflowBuilder(start).AddEdge(start, answer).WithOutputFrom(answer).Build();
    var agent = workflow.AsAIAgent(name: "repro");
    var text = "";
    await foreach (var u in agent.RunStreamingAsync("hi")) text += u.Text;
    Console.WriteLine($"{label,-18} streamed text: \"{text}\"");
}

sealed class Start() : ChatProtocolExecutor("Start", new ChatProtocolExecutorOptions { AutoSendTurnToken = false })
{
    protected override ValueTask TakeTurnAsync(List<ChatMessage> messages, IWorkflowContext context, bool? emitEvents, CancellationToken cancellationToken = default)
        => context.SendMessageAsync(messages, cancellationToken);
}

Actual behavior

List<ChatMessage>  streamed text: ""
string             streamed text: "echo: hi"

In our app (behind the AG-UI server) a branch that answered with a List<ChatMessage> reached the client as RUN_STARTED followed directly by RUN_FINISHED, with no text message, so the user saw an empty reply.

Expected behavior

An executor designated with WithOutputFrom(...) reaches the agent response whatever its payload type, a ChatMessage or a list of them included, as its string and AIContent outputs already do.

Versions

  • Microsoft.Agents.AI.Workflows 1.25.0 (.NET 10)
  • Same code path on main (commit at time of writing)

Activity

  1. added
    .NETUsage: [Issues, PRs], Target: .Net
    triageUsage: [Issues], Target: All issues that still need to be triaged
    on Oct 26, 2026
  2. sunny-kavixo commented on Oct 26, 2026

    @sunny-kavixo
    Contributor

    Hi Microsoft Agent Framework maintainers,

    I'd like to contribute a fix for Issue #9704, and I've started investigating the reported Workflow.AsAIAgent terminal-output handling.

    My investigation is focused on:

    1. Reproducing the missing ChatMessage and IEnumerable<ChatMessage> responses from executors explicitly marked with WithOutputFrom(...).
    2. Tracing the WorkflowOutputEvent handling in WorkflowSession.cs to identify the precise cause.
    3. Preparing a minimal, backward-compatible fix that preserves existing output-inclusion behavior.
    4. Adding regression tests for terminal and non-terminal outputs, including streaming scenarios.
    5. Running the relevant .NET tests and validation checks before submitting a focused PR.

    I'll also check for overlapping contributions to avoid duplicating work.

    If this issue is available for contribution, I'd appreciate confirmation that I can take ownership and submit a PR.

    Thank you for your time and consideration.

    Best regards,
    Putluru Sandeep
    GitHub: Putluru Sandeep (@sunny-kavixo)

  3. sunny-kavixo commented on Oct 26, 2026

    @sunny-kavixo
    Contributor

    I would like to implement this focused .NET fix and regression coverage. My proposed direction is to make terminal ChatMessage/IEnumerable<ChatMessage> outputs selected by WithOutputFrom(...) follow the same terminal-output inclusion path as string/AIContent, while preserving exclusion of non-terminal workflow outputs and existing includeWorkflowOutputsInResponse: true behavior. I plan to cover streaming and non-streaming responses plus the relevant output shapes. Could a maintainer please confirm the direction with ready-for-implementation and assign this issue to Putluru Sandeep (@sunny-kavixo)?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    .NETUsage: [Issues, PRs], Target: .NettriageUsage: [Issues], Target: All issues that still need to be triaged

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions