Hacktoberfest 2026: những issue maintainer đã đánh dấu cho tháng Mười, đang mở và phù hợp người mới. Xem issue Hacktoberfest

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

Đã đóng Phù hợp với người mới
#9,297 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

@shanto462 đang làm issue này rồi.

Từ ngày 12/10/2026.

  • #9300 của @shanto462 — đang mở

Đánh giá

Độ khó
2/5
Thời gian dự kiến
1-3 giờ
Mức phù hợp với người mới
78/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
python
Lĩnh vực
backend

Hướng nghiên cứu

Bắt đầu tại agent_framework/_workflows/_edge.py, ở SwitchCaseEdgeGroup.__init__, nơi issue xác định các edge bị trùng khi có nhiều trường hợp cùng đích. Đọc phần triển khai nhóm edge và xác thực edge của workflow, sau đó kiểm tra các bài kiểm thử hồi quy cho định tuyến switch-case. Hoàn tất khi nhiều case, hoặc một case và default, có thể dùng chung một đích, workflow được xây dựng và hành vi định tuyến vẫn chính xác.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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

Ngôn ngữ chính
Python
Star
14k
Fork
2.5k
Merge trung bình
2 ngày 9 giờ
Pull request đã merge (30 ngày)
434

Chuẩn bị môi trường

Mở trong Codespaces

Khởi chạy dev container của dự án ngay trên trình duyệt, bằng tài khoản GitHub của bạn.

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của microsoft/agent-framework

Tất cả issue của microsoft/agent-framework

Issue tương tự

Thêm issue về Python

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.