.NET: Python: [Bug]: Two switch-case branches cannot route to the same executor (EdgeDuplicationError)
维护者通常 1 天内回复
评估
调研方向
从 agent_framework/_workflows/_edge.py 中的 SwitchCaseEdgeGroup.__init__ 开始,issue 指出相同目标重复出现时会产生重复的 edge。阅读 edge 组的实现和 workflow edge 验证,然后检查 switch-case 路由的回归测试。完成标准是多个 case,或一个 case 与 default,可以共享同一目标,workflow 能够构建,且路由行为保持正确。
由索引模型根据 Issue 内容生成。
描述
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
- Add a switch-case edge group where two
Caseentries have the sametarget. - 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
环境准备
在浏览器里用你自己的 GitHub 账号启动这个项目的开发容器。
- 没有 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
microsoft/agent-framework 的其他 Issue
-
Python: [Bug]: Out-of-range Cosmos memory search parameters silently disable retrieval可能已有人在做 @eavanvalkenburg 于 1 天前认领。 未关闭python
难度 2/5 1-3 小时 新手友好度 78/100
microsoft/agent-framework#9317 · 已指派 1 人 ·
维护者通常 1 天内回复
-
Python: [Bug]: A non-positive MCP request timeout silently disables the timeout可能已有人在做 @jpalvarezl 于 1 天前认领。 未关闭python
难度 2/5 1-3 小时 新手友好度 82/100
microsoft/agent-framework#9313 · 已指派 1 人 ·
维护者通常 1 天内回复
-
Python: [Bug]: Content.from_dict leaves the nested content of image generation and MCP server tool results as plain dicts可能已有人在做 @eavanvalkenburg 于 1 天前认领。 未关闭python
难度 2/5 1-3 小时 新手友好度 77/100
microsoft/agent-framework#9303 · 已指派 1 人 ·
维护者通常 1 天内回复
-
.NET python triage
难度 1/5 1 小时以内 新手友好度 85/100
microsoft/agent-framework#9092 · 1 条评论 ·
维护者通常 1 天内回复
-
Python: raw-data content mappings lose annotations and attachment metadata可能已有人在做 @moonbox3 于 15 天前认领。 未关闭python triage
难度 2/5 1-3 小时 新手友好度 78/100
microsoft/agent-framework#8632 · 2 条评论 ·
维护者通常 1 天内回复
查看 microsoft/agent-framework 的全部 Issue
相似的 Issue
-
good first issue
难度 2/5 1-3 小时 新手友好度 85/100
btclib-org/btclib-node#1955 ·
维护者通常 1 天内回复
-
documentation v0.9.2
难度 2/5 半天 新手友好度 72/100
khuisman/mcp-gee-sweet#1033 ·
维护者通常 1 天内回复
-
bug
难度 2/5 1-3 小时 新手友好度 76/100
ossf/cve-bin-tool#5966 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 62/100
维护者通常 2 天内回复
-
write_iceberg ignores the table's write.parquet.compression-codec property可能已有人在做 @YuangGao 今天认领。 未关闭
难度 2/5 1-3 小时 新手友好度 82/100
Eventual-Inc/Daft#7606 ·
维护者通常 1 天内回复