Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

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

Chiusa Adatta ai principianti
#9,297 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

@shanto462 ci sta già lavorando.

Dal 12/10/2026.

  • #9300 di @shanto462 — aperta

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
78/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
python
Ambito
backend

Direzione di ricerca

Inizia in agent_framework/_workflows/_edge.py, in corrispondenza di SwitchCaseEdgeGroup.__init__, dove l’issue segnala edge duplicate per destinazioni ripetute. Leggi l’implementazione del gruppo di edge e la validazione delle edge del workflow, poi controlla i test di regressione per il routing switch-case. Il lavoro è completato quando più cases, oppure un case e il default, possono condividere una destinazione, il workflow viene costruito e il comportamento del routing rimane corretto.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

.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.

Lingua principale
Python
Stelle
14k
Fork
2.5k
Merge medio
2g 4h
PR unite (30g)
403

Preparare l'ambiente

Apri in Codespaces

Avvia il container di sviluppo del progetto nel browser, con il tuo account GitHub.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di microsoft/agent-framework

Tutte le issue di microsoft/agent-framework

Issue simili

Altre issue su Python

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.