From a0a734729a7575c72c321602c41fc0159eefeb6a Mon Sep 17 00:00:00 2001 From: Bryan <74067792+Bryan-Roe@users.noreply.github.com> Date: Sun, 27 Jul 2025 15:45:15 -0700 Subject: [PATCH 1/2] Add multi-agent coordination test scenarios --- test_multi_agent_coordination.py | 94 ++++++++++++++++++++++++++++++++ 1 file changed, 94 insertions(+) create mode 100644 test_multi_agent_coordination.py diff --git a/test_multi_agent_coordination.py b/test_multi_agent_coordination.py new file mode 100644 index 000000000000..9f9b44feaea0 --- /dev/null +++ b/test_multi_agent_coordination.py @@ -0,0 +1,94 @@ +#!/usr/bin/env python3 +""" +Test scenarios for multi-agent coordination. + +This module defines simple asynchronous tests that demonstrate how agents can +coordinate through a central orchestrator. The goal is to verify basic message +passing and coordination patterns between agents. +""" + +import asyncio +import logging +from typing import List + +logging.basicConfig(level=logging.INFO) +logger = logging.getLogger(__name__) + + +class DummyAgent: + """A minimal agent that can send and receive messages.""" + + def __init__(self, name: str) -> None: + self.name = name + self.received: List[str] = [] + + async def send(self, message: str, recipient: "DummyAgent") -> None: + logger.info("%s sending to %s: %s", self.name, recipient.name, message) + await recipient.receive(f"{self.name}: {message}") + + async def receive(self, message: str) -> None: + logger.info("%s received: %s", self.name, message) + self.received.append(message) + + +class MultiAgentCoordinator: + """Coordinates interactions between a group of agents.""" + + def __init__(self, *agents: DummyAgent) -> None: + self.agents = list(agents) + + async def ping_pong(self) -> bool: + """Simple ping-pong between two agents.""" + if len(self.agents) < 2: + raise ValueError("Ping-pong requires at least two agents") + a, b = self.agents[0], self.agents[1] + await a.send("ping", b) + await b.send("pong", a) + return a.received[-1] == "B: pong" and b.received[-1] == "A: ping" + + async def broadcast(self, message: str, sender: DummyAgent) -> bool: + """Broadcast a message from one agent to all others.""" + tasks = [sender.send(message, agent) for agent in self.agents if agent is not sender] + await asyncio.gather(*tasks) + return all(agent.received and agent.received[-1] == f"{sender.name}: {message}" + for agent in self.agents if agent is not sender) + + async def chain(self, messages: List[str]) -> List[str]: + """Pass messages through the agents in a round-robin fashion.""" + if not messages or len(messages) != len(self.agents): + raise ValueError("Messages list must match number of agents") + + count = len(self.agents) + for i in range(count): + sender = self.agents[i] + recipient = self.agents[(i + 1) % count] + await sender.send(messages[i], recipient) + + return [agent.received[-1] for agent in self.agents] + + +async def main() -> None: + agent_a = DummyAgent("A") + agent_b = DummyAgent("B") + agent_c = DummyAgent("C") + + coordinator = MultiAgentCoordinator(agent_a, agent_b, agent_c) + + logger.info("Running ping-pong scenario...") + ping_pong_ok = await coordinator.ping_pong() + assert ping_pong_ok, "Ping-pong scenario failed" + + logger.info("Running broadcast scenario...") + broadcast_ok = await coordinator.broadcast("hello", sender=agent_a) + assert broadcast_ok, "Broadcast scenario failed" + + logger.info("Running chain scenario...") + chain_results = await coordinator.chain(["step1", "step2", "final"]) + expected = ["C: final", "A: step1", "B: step2"] + assert chain_results == expected, f"Chain scenario failed: {chain_results}" + + print("\n✅ Multi-agent coordination scenarios passed") + + +if __name__ == "__main__": + asyncio.run(main()) From bb21821ba5f0a5332dd6bd59d06b3aae22ef6840 Mon Sep 17 00:00:00 2001 From: Bryan <74067792+Bryan-Roe@users.noreply.github.com> Date: Sun, 3 Aug 2025 01:36:21 -0700 Subject: [PATCH 2/2] Update test_multi_agent_coordination.py Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Signed-off-by: Bryan <74067792+Bryan-Roe@users.noreply.github.com> --- test_multi_agent_coordination.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test_multi_agent_coordination.py b/test_multi_agent_coordination.py index 9f9b44feaea0..5f74c0944f69 100644 --- a/test_multi_agent_coordination.py +++ b/test_multi_agent_coordination.py @@ -44,7 +44,7 @@ async def ping_pong(self) -> bool: a, b = self.agents[0], self.agents[1] await a.send("ping", b) await b.send("pong", a) - return a.received[-1] == "B: pong" and b.received[-1] == "A: ping" + return a.received[-1] == f"{b.name}: pong" and b.received[-1] == f"{a.name}: ping" async def broadcast(self, message: str, sender: DummyAgent) -> bool: """Broadcast a message from one agent to all others."""