Skip to content

Hipótesis: El uso del protocolo Agent2Agent facilita una coordinación más eficiente y autónoma entre agentes en escenarios prácticos, en comparación con implementaciones ad-hoc de comunicación entre agentes.

Notifications You must be signed in to change notification settings

theam/multi-agent-a2a-demo

Repository files navigation

Multi-Agent A2A Protocol Demo

Project Objective

This project demonstrates and validates the hypothesis:

"The use of the Agent2Agent (A2A) protocol enables more efficient and autonomous coordination between agents in practical scenarios, compared to ad-hoc agent communication implementations."

We implement a multi-agent system for code review and PR management, where each agent has a specialized role and coordination is handled via the A2A protocol.


Project Structure

src/
├── agents/           # SPADE agent implementations
├── coordinator/      # Coordinator logic
├── tasks/            # Task and artifact utilities
├── utils/            # Helper utilities
└── main.py           # Entry point

Prerequisites

  • Docker (for Prosody XMPP server)
  • Python 3.8+ (recommended: 3.10+)
  • pip

Setup Instructions

1. Clone the repository and enter the folder

git clone <repo-url>
cd <repo-folder>

2. Start Prosody XMPP server with Docker

docker run -d --name prosody -p 5222:5222 -p 5280:5280 prosody/prosody

3. Allow unencrypted connections (for local development only)

docker exec -it prosody sh
# Inside the container:
echo 'c2s_require_encryption = false' >> /etc/prosody/prosody.cfg.lua
exit

4. Restart Prosody

docker restart prosody

5. Create agent users

docker exec -it prosody prosodyctl adduser pr@localhost
# (set password, e.g. prpassword)
docker exec -it prosody prosodyctl adduser best@localhost
# (set password, e.g. bestpassword)
docker exec -it prosody prosodyctl adduser vuln@localhost
# (set password, e.g. vulnpassword)
docker exec -it prosody prosodyctl adduser merge@localhost
# (set password, e.g. mergepassword)

6. Create and activate a Python virtual environment

python3 -m venv venv
source venv/bin/activate

7. Install dependencies

pip install -r requirements.txt

8. Configure agent credentials (if needed)

Edit src/coordinator/coordinator.py and ensure the agent JIDs and passwords match those you set above.

9. Run the system

python3 src/main.py

10. View the results

  • The final combined report is saved as a2a_report.json in the project root.
  • You can open this file with any text editor or JSON viewer.

How it works

  • PullRequestAgent: Simulates PR creation.
  • BestPracticesAgent: Reviews code style and best practices.
  • VulnerabilityAgent: Scans for security issues.
  • MergeAgent: Attempts to merge if all checks pass.
  • Coordinator: Orchestrates the workflow using the A2A protocol.

All communication and task assignment between agents follows the A2A protocol, with structured JSON messages, agent cards, and task artifacts.


Validating the Hypothesis: A2A vs. Ad-hoc

To validate the hypothesis, you can:

  1. Run this project (A2A protocol) and measure:

    • Time to complete the workflow
    • Number of lines of code for coordination
    • Autonomy (no hardcoded agent logic, agents are discoverable and tasks are structured)
    • Robustness (easy to add new agents or change workflow)
  2. Run the ad-hoc version (agents communicate via direct function calls, global variables, or unstructured messages) and compare:

    • Code complexity and maintainability
    • Flexibility to add/replace agents
    • Error handling and extensibility
    • How easy it is to change the workflow

Expected result:

  • The A2A protocol version will be more modular, easier to extend, and require less manual intervention for agent coordination, validating the hypothesis.

Workflow Comparison: A2A vs Ad-hoc

How to run both workflows

  1. A2A (SPADE/XMPP):

    python3 src/main.py

    This will generate the file a2a_report.json.

  2. Ad-hoc:

    python3 src/main_adhoc.py

    This will generate the file adhoc_report.json.

How to compare results

  1. Run the comparison script:
    python3 compare_reports.py
    This will display a summary table and a bar chart comparing the execution times of each workflow stage.

Requirements for the Comparison Script

To use the comparison and visualization script (compare_reports.py), you need to install two additional Python packages:

  1. Activate your virtual environment (if not already active):
    source venv/bin/activate
  2. Install the required packages:
    pip install tabulate matplotlib

Now you can run the comparison script as described above:

python3 compare_reports.py

This will display a summary table and a bar chart comparing the execution times of each workflow stage.

How to interpret the results

  • Analysis results: Both workflows should produce the same linting and vulnerability reports if they use the same input.
  • Timing: The ad-hoc version is usually faster, but the A2A version is more modular and extensible.
  • Modularity and autonomy: The A2A approach allows for independent agents and structured communication, ideal for distributed or scalable scenarios.

Suggested conclusions

  • Use A2A if you need autonomy, extensibility, or distributed agents.
  • Use ad-hoc if you only care about speed and simplicity in a controlled environment.

References


For any issues or questions, open an issue or contact the maintainer.

About

Hipótesis: El uso del protocolo Agent2Agent facilita una coordinación más eficiente y autónoma entre agentes en escenarios prácticos, en comparación con implementaciones ad-hoc de comunicación entre agentes.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages