Hacktoberfest 2026: los issues que los mantenedores marcaron para octubre, abiertos y aptos para principiantes. Explorar issues de Hacktoberfest

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

Cerrado Apto para principiantes
#9,297 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 1 día

@shanto462 ya está trabajando en esto.

Desde el 12/10/2026.

  • #9300 de @shanto462 — abierto

Evaluación

Dificultad
2/5
Tiempo estimado
1-3 horas
Aptitud para principiantes
78/100
Tipo de issue
Error
Claridad
Bien especificado
Estado de actividad
Activo
Stack tecnológico
python
Área
backend

Línea de trabajo

Empieza en agent_framework/_workflows/_edge.py, en SwitchCaseEdgeGroup.__init__, donde el issue señala edges duplicadas para destinos repetidos. Lee la implementación del grupo de edges y la validación de edges del workflow; después, revisa las pruebas de regresión del enrutamiento switch-case. El trabajo estará terminado cuando varios cases, o un case y el default, puedan compartir un destino, el workflow se construya y el comportamiento del enrutamiento siga siendo correcto.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

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

Lenguaje dominante
Python
Estrellas
14k
Forks
2.5k
Merge medio
2 d 4 h
PR fusionados (30 d)
403

Preparar el entorno

Abrir en Codespaces

Inicia el contenedor de desarrollo del proyecto en tu navegador, con tu propia cuenta de GitHub.

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de microsoft/agent-framework

Todos los issues de microsoft/agent-framework

Issues similares

Más issues de Python

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.