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

.NET: Python: [Bug]: Two switch-case branches cannot route to the same executor (EdgeDuplicationError)

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

维护者通常 1 天内回复

@shanto462 已经在做这个了。

开始于 2026年10月12日。

  • #9300 来自 @shanto462 —— 未关闭

评估

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

调研方向

从 agent_framework/_workflows/_edge.py 中的 SwitchCaseEdgeGroup.__init__ 开始,issue 指出相同目标重复出现时会产生重复的 edge。阅读 edge 组的实现和 workflow edge 验证,然后检查 switch-case 路由的回归测试。完成标准是多个 case,或一个 case 与 default,可以共享同一目标,workflow 能够构建,且路由行为保持正确。

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

描述

.NET python triage
Observed Behavior

WorkflowBuilder.add_switch_case_edge_group fails at build() with EdgeDuplicationError when two Case entries target the same executor. This is a common shape: several conditions lead to one handler, for example "refund" and "return" requests both go to a refunds executor. A Case and the Default that share a target fail the same way.

The only workaround is to merge the conditions into one Case.

Expected Behavior

The workflow builds, and each message is routed by the first matching case as usual. The .NET SwitchBuilder allows several cases with the same target.

Steps to Reproduce
  1. Add a switch-case edge group where two Case entries have the same target.
  2. Call build().
Minimal Reproduction
from agent_framework import Case, Default, Executor, WorkflowBuilder, WorkflowContext, handler


class Router(Executor):
    @handler
    async def route(self, message: str, ctx: WorkflowContext[str]) -> None:
        await ctx.send_message(message)


class Handler(Executor):
    @handler
    async def handle(self, message: str, ctx: WorkflowContext[str, str]) -> None:
        await ctx.yield_output(f"{self.id}: {message}")


router = Router(id="router")
refunds = Handler(id="refunds")
general = Handler(id="general")

workflow = (
    WorkflowBuilder(start_executor=router)
    .add_switch_case_edge_group(
        router,
        [
            Case(condition=lambda m: m.startswith("refund"), target=refunds),
            Case(condition=lambda m: m.startswith("return"), target=refunds),
            Default(target=general),
        ],
    )
    .build()  # raises EdgeDuplicationError
)

The cause is in agent_framework/_workflows/_edge.py: SwitchCaseEdgeGroup.__init__ creates one Edge per case, so two cases with the same target create the edge router->refunds twice, and workflow validation rejects duplicate edges. Routing only needs one edge per target, because the case conditions decide which target gets the message.

Error Messages and Stack Traces
  File ".../agent_framework/_workflows/_validation.py", line 195, in _validate_edge_duplication
    raise EdgeDuplicationError(edge_id)
agent_framework._workflows._validation.EdgeDuplicationError: [EDGE_DUPLICATION] Duplicate edge detected: router->refunds. Each edge in the workflow must be unique.
Package Versions

agent-framework-core: 1.21.0 (main at a75e803ef)

Python Version

Python 3.12

Additional Context

I'd like to fix this. The change is one line in SwitchCaseEdgeGroup.__init__ (one edge per distinct target, in order of first appearance) plus regression tests.

AI assistance: I used an AI coding assistant for the analysis and to draft this report. I reproduced and verified the behavior myself.

主要语言
Python
星标
14k
派生
2.5k
平均合并
2 天 7 小时
30 天内合并 PR
416

环境准备

在 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 摘要。