mirror of
https://github.com/microsoft/agent-framework.git
synced 2026-06-16 21:04:09 +08:00
c8694a8c76
* Workflow init commit * Add samples and clean up * ExecutionContext -> WorkflowContext * Address comments 1 * Fix mypy * flatting folder structure, and rename contexts * Remove add_loop * Add map reduce sample, remove Activation conditions * Add AgentExecutor and allow multiple handlers per executor * Minor improvement * Add RequestInfoExecutor * Add unit tests part 1 * Address comments 2 * Pre-commit update * Add run method and more unit tests * Add xml docs * run_stream -> run_streaming * message_handler -> handler --------- Co-authored-by: Chris <66376200+crickman@users.noreply.github.com> Co-authored-by: Evan Mattson <evan.mattson@microsoft.com>
48 lines
1.3 KiB
Python
48 lines
1.3 KiB
Python
# Copyright (c) Microsoft. All rights reserved.
|
|
|
|
from dataclasses import dataclass
|
|
from typing import Any
|
|
|
|
from agent_framework.workflow import Executor, WorkflowContext, handler
|
|
|
|
from agent_framework_workflow._edge import Edge
|
|
|
|
|
|
@dataclass
|
|
class MockMessage:
|
|
"""A mock message for testing purposes."""
|
|
|
|
data: Any
|
|
|
|
|
|
class MockExecutor(Executor):
|
|
"""A mock executor for testing purposes."""
|
|
|
|
@handler
|
|
async def mock_handler(self, message: MockMessage, ctx: WorkflowContext) -> None:
|
|
"""A mock handler that does nothing."""
|
|
pass
|
|
|
|
|
|
def test_create_edge():
|
|
"""Test creating an edge with a source and target executor."""
|
|
source = MockExecutor(id="source_executor")
|
|
target = MockExecutor(id="target_executor")
|
|
|
|
edge = Edge(source=source, target=target)
|
|
|
|
assert edge.source_id == "source_executor"
|
|
assert edge.target_id == "target_executor"
|
|
assert edge.id == f"{edge.source_id}{Edge.ID_SEPARATOR}{edge.target_id}"
|
|
assert (edge.source_id, edge.target_id) == Edge.source_and_target_from_id(edge.id)
|
|
|
|
|
|
def test_edge_can_handle():
|
|
"""Test creating an edge with a source and target executor."""
|
|
source = MockExecutor(id="source_executor")
|
|
target = MockExecutor(id="target_executor")
|
|
|
|
edge = Edge(source=source, target=target)
|
|
|
|
assert edge.can_handle(MockMessage(data="test"))
|