Add multi-agent coordination test scenarios#780
Conversation
Reviewer's GuideIntroduces a new asynchronous test suite to validate basic multi-agent coordination patterns using a DummyAgent and a central MultiAgentCoordinator. File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Pull Request Overview
This PR adds a new test module for multi-agent coordination scenarios that demonstrates basic message passing and coordination patterns between agents using async/await patterns.
- Implements DummyAgent class for basic message sending/receiving functionality
- Adds MultiAgentCoordinator class with ping-pong, broadcast, and chain coordination patterns
- Includes executable test scenarios with assertions to verify coordination behavior
Comments suppressed due to low confidence (2)
test_multi_agent_coordination.py:42
- The error condition when fewer than 2 agents are provided is not tested. Consider adding a test case that verifies the ValueError is raised with an appropriate message.
if len(self.agents) < 2:
test_multi_agent_coordination.py:58
- The error conditions in the chain method (empty messages or length mismatch) are not tested. Consider adding test cases that verify these ValueError conditions are properly raised.
if not messages or len(messages) != len(self.agents):
There was a problem hiding this comment.
Hey @Bryan-Roe - I've reviewed your changes and they look great!
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location> `test_multi_agent_coordination.py:40` </location>
<code_context>
+ 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:
</code_context>
<issue_to_address>
No test for error condition when less than two agents are present in ping_pong.
Please add a test to confirm that ValueError is raised when ping_pong is called with fewer than two agents.
Suggested implementation:
```python
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")
import pytest
import asyncio
@pytest.mark.asyncio
async def test_ping_pong_raises_value_error_with_less_than_two_agents():
from your_module import MultiAgentCoordinator, DummyAgent # adjust import as needed
coordinator = MultiAgentCoordinator(DummyAgent("A"))
with pytest.raises(ValueError, match="Ping-pong requires at least two agents"):
await coordinator.ping_pong()
```
- Replace `from your_module import MultiAgentCoordinator, DummyAgent` with the correct import path for your project.
- If `pytest.mark.asyncio` is not available, ensure your test runner supports async tests or use an equivalent.
- If `DummyAgent` requires additional arguments or setup, adjust accordingly.
</issue_to_address>
### Comment 2
<location> `test_multi_agent_coordination.py:56` </location>
<code_context>
+ 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)
</code_context>
<issue_to_address>
Missing test for chain method's ValueError on invalid input.
Add a test to verify that chain raises ValueError when given an empty messages list or when the list length differs from the number of agents.
</issue_to_address>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
test_multi_agent_coordination.py
Outdated
| 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" |
There was a problem hiding this comment.
suggestion (testing): No test for error condition when less than two agents are present in ping_pong.
Please add a test to confirm that ValueError is raised when ping_pong is called with fewer than two agents.
Suggested implementation:
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")
import pytest
import asyncio
@pytest.mark.asyncio
async def test_ping_pong_raises_value_error_with_less_than_two_agents():
from your_module import MultiAgentCoordinator, DummyAgent # adjust import as needed
coordinator = MultiAgentCoordinator(DummyAgent("A"))
with pytest.raises(ValueError, match="Ping-pong requires at least two agents"):
await coordinator.ping_pong()- Replace
from your_module import MultiAgentCoordinator, DummyAgentwith the correct import path for your project. - If
pytest.mark.asynciois not available, ensure your test runner supports async tests or use an equivalent. - If
DummyAgentrequires additional arguments or setup, adjust accordingly.
| 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") |
There was a problem hiding this comment.
suggestion (testing): Missing test for chain method's ValueError on invalid input.
Add a test to verify that chain raises ValueError when given an empty messages list or when the list length differs from the number of agents.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Signed-off-by: Bryan <74067792+Bryan-Roe@users.noreply.github.com>
Summary
test_multi_agent_coordination.pywith simple multi-agent testsTesting
python test_multi_agent_coordination.pypython -m py_compile test_multi_agent_coordination.pyhttps://chatgpt.com/codex/tasks/task_e_6886a78e34888322b63530ddffc9b600
Summary by Sourcery
Add a new asynchronous test suite for basic multi-agent coordination scenarios
New Features:
Tests: