Hacktoberfest 2026:メンテナが10月に向けて印を付けた、オープンで初心者向けの issue。 Hacktoberfest の issue を見る

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

クローズ 初心者向け
#9,297 コメント 0 件 リアクション 0 件 担当者 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日 4時間
マージ済み PR(30日)
403

環境構築

Codespaces で開く

このプロジェクトの開発コンテナを、あなたの GitHub アカウントでブラウザ上に起動します。

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

microsoft/agent-framework のほかの issue

microsoft/agent-framework の issue をすべて見る

似ている issue

Python の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。