Repository navigation
.NET: Workflow.AsAIAgent drops a terminal executor's ChatMessage output unless includeWorkflowOutputsInResponse is set #9704
Description
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
updateContentswhen_includeWorkflowOutputsInResponse || includeTerminalOutput; - forwards
updateMessagesonly 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)
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsNo status
Activity
sunny-kavixo commentedon Oct 26, 2026
Hi Microsoft Agent Framework maintainers,
I'd like to contribute a fix for Issue #9704, and I've started investigating the reported
Workflow.AsAIAgentterminal-output handling.My investigation is focused on:
ChatMessageandIEnumerable<ChatMessage>responses from executors explicitly marked withWithOutputFrom(...).WorkflowOutputEventhandling inWorkflowSession.csto identify the precise cause.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)
sunny-kavixo commentedon Oct 26, 2026
I would like to implement this focused .NET fix and regression coverage. My proposed direction is to make terminal
ChatMessage/IEnumerable<ChatMessage>outputs selected byWithOutputFrom(...)follow the same terminal-output inclusion path asstring/AIContent, while preserving exclusion of non-terminal workflow outputs and existingincludeWorkflowOutputsInResponse: truebehavior. I plan to cover streaming and non-streaming responses plus the relevant output shapes. Could a maintainer please confirm the direction withready-for-implementationand assign this issue to Putluru Sandeep (@sunny-kavixo)?