Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions python/packages/core/agent_framework/_workflows/_edge.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from dataclasses import dataclass, field
from typing import Any, ClassVar, TypeAlias, TypeVar

from .._agents import SupportsAgentRun
from ._const import INTERNAL_SOURCE_ID
from ._executor import Executor
from ._model_utils import DictConvertible, encode_value
Expand Down Expand Up @@ -264,7 +265,7 @@ def __init__(self) -> None:
"""

condition: Callable[[Any], bool]
target: Executor | str
target: Executor | SupportsAgentRun
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

str should also be accepted for executor IDs.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought string names were removed? https://learn.microsoft.com/en-us/agent-framework/support/upgrade/python-2026-significant-changes#-workflow-factory-methods-removed-from-workflowbuilder

Would it not throw an error here:

raise TypeError(
f"WorkflowBuilder expected an Executor or SupportsAgentRun instance; got {type(candidate).__name__}."
)



@dataclass
Expand All @@ -287,7 +288,7 @@ def __init__(self) -> None:
assert fallback.target.id == "dead_letter"
"""

target: Executor | str
target: Executor | SupportsAgentRun


@dataclass(init=False)
Expand Down
25 changes: 25 additions & 0 deletions python/packages/core/tests/workflow/test_workflow_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
AgentResponseUpdate,
AgentSession,
BaseAgent,
Case,
Default,
Executor,
Message,
WorkflowBuilder,
Expand Down Expand Up @@ -193,6 +195,29 @@ def condition_func(msg: MockMessage) -> bool:
assert "Target" in workflow.executors


def test_switch_case_with_agents():
"""Test add_switch_case_edge_group with Case and Default edges using agents."""
router = DummyAgent(id="router_agent", name="router")
handler = DummyAgent(id="handler", name="handler")
fallback = DummyAgent(id="fallback_agent", name="fallback")

workflow = (
WorkflowBuilder(start_executor=router)
.add_switch_case_edge_group(
router,
[
Case(condition=lambda _: True, target=handler),
Default(target=fallback),
],
)
.build()
)

# All three agents should be AgentExecutor wrappers
agent_executors = [e for e in workflow.executors.values() if isinstance(e, AgentExecutor)]
assert len(agent_executors) == 3


# region with_output_from tests


Expand Down
Loading