Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

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

未关闭 适合新手
#9,704 2 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

难度
2/5
预计耗时
1-3 小时
新手友好度
66/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
技术栈
csharp

调研方向

从 WorkflowSession.cs 中的 WorkflowOutputEvent 分支开始,比较终端输出的 updateContents 和 updateMessages 是如何转发的。使用提供的基于文件的 .NET 1.25.0 应用复现问题,然后检查返回 List<ChatMessage> 的终端执行器在 includeWorkflowOutputsInResponse 为 false 时是否会流式传输回复,正如字符串情况已经做到的那样。

由索引模型根据 Issue 内容生成。

描述

.NET triage
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 [email protected]
#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)
主要语言
Python
星标
14.3k
派生
2.5k
平均合并
2 天 19 小时
30 天内合并 PR
382

环境准备

在 Codespaces 中打开

在浏览器里用你自己的 GitHub 账号启动这个项目的开发容器。

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

microsoft/agent-framework 的其他 Issue

查看 microsoft/agent-framework 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。