Skip to content

Add multi-agent coordination test scenarios#780

Merged
Bryan-Roe merged 2 commits intomainfrom
codex/create-test-scenarios-for-multi-agent-coordination
Aug 3, 2025
Merged

Add multi-agent coordination test scenarios#780
Bryan-Roe merged 2 commits intomainfrom
codex/create-test-scenarios-for-multi-agent-coordination

Conversation

@Bryan-Roe
Copy link
Collaborator

@Bryan-Roe Bryan-Roe commented Jul 27, 2025

Summary

  • add new test_multi_agent_coordination.py with simple multi-agent tests

Testing

  • python test_multi_agent_coordination.py
  • python -m py_compile test_multi_agent_coordination.py

https://chatgpt.com/codex/tasks/task_e_6886a78e34888322b63530ddffc9b600

Summary by Sourcery

Add a new asynchronous test suite for basic multi-agent coordination scenarios

New Features:

  • Introduce DummyAgent class for async message passing between agents
  • Introduce MultiAgentCoordinator class to orchestrate ping-pong, broadcast, and chain interactions

Tests:

  • Add test_multi_agent_coordination.py with ping-pong, broadcast, and chain coordination scenarios

Copilot AI review requested due to automatic review settings July 27, 2025 22:45
@sourcery-ai
Copy link

sourcery-ai bot commented Jul 27, 2025

Reviewer's Guide

Introduces a new asynchronous test suite to validate basic multi-agent coordination patterns using a DummyAgent and a central MultiAgentCoordinator.

File-Level Changes

Change Details Files
Introduce async multi-agent coordination test suite
  • Define DummyAgent with send and receive methods
  • Implement MultiAgentCoordinator methods: ping_pong, broadcast, chain
  • Add main async function to run scenarios and assert outcomes
  • Configure logging and entry point execution
test_multi_agent_coordination.py

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

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):

Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

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>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Comment on lines 40 to 47
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"
Copy link

Choose a reason for hiding this comment

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

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, 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.

Comment on lines +56 to +59
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")
Copy link

Choose a reason for hiding this comment

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

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>
@Bryan-Roe Bryan-Roe merged commit 89f51a6 into main Aug 3, 2025
6 of 10 checks passed
@Bryan-Roe Bryan-Roe deleted the codex/create-test-scenarios-for-multi-agent-coordination branch August 3, 2025 08:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant