File size: 1,993 Bytes
8a87cbb | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 | import pytest
from aegis.core import Agent, AgentContext, AgentResult, Task
from aegis.core.conductor import Conductor
from aegis.core.registry import AgentNotFoundError, AgentRegistry
class StubAgent(Agent):
def __init__(
self,
name: str,
*,
result_name: str | None = None,
) -> None:
self.name = name
self._result_name = result_name or name
async def run(self, context: AgentContext) -> AgentResult:
return AgentResult(
agent_name=self._result_name,
success=True,
output={"task": context.task.name},
)
@pytest.mark.asyncio
async def test_conductor_executes_registered_agent() -> None:
registry = AgentRegistry([StubAgent("planner")])
conductor = Conductor(registry)
context = AgentContext(
task=Task(
name="Create plan",
description="Build a deterministic execution plan.",
)
)
result = await conductor.execute("planner", context)
assert result.success is True
assert result.output == {"task": "Create plan"}
@pytest.mark.asyncio
async def test_conductor_rejects_missing_agent() -> None:
conductor = Conductor(AgentRegistry())
context = AgentContext(
task=Task(
name="Missing agent",
description="Verify missing-agent behavior.",
)
)
with pytest.raises(AgentNotFoundError):
await conductor.execute("missing", context)
@pytest.mark.asyncio
async def test_conductor_rejects_mismatched_result_name() -> None:
registry = AgentRegistry([StubAgent("planner", result_name="research")])
conductor = Conductor(registry)
context = AgentContext(
task=Task(
name="Validate result",
description="Verify agent identity enforcement.",
)
)
with pytest.raises(
ValueError,
match="Agent result name does not match",
):
await conductor.execute("planner", context)
|