How google-a2a/a2a-samples works
Project type and purpose
• This is a Python “multi-agent” sample demonstrating the Agent2Agent (A2A) Protocol, specifically the A2A Multi-Agent Coordination Pattern (MCP) example.
• It shows how multiple agents (defined by JSON “agent_cards”) coordinate via an MCP server and client, persisting state in a SQLite DB (travel_agency.db).
File structure under samples/python/agents/a2a_mcp
• agent_cards/
• Static JSON files defining each agent’s capabilities, prompts, and metadata.
• src/a2a_mcp/
• common/ – shared utilities, types, base classes (agent_executor, runner, workflow).
• mcp/client.py – the client library for agents to register, send tasks, and receive responses.
• mcp/server.py – the MCP server orchestrating requests between agents and persisting history.
• agents/ – entry points for each agent (adk_travel_agent.py, orchestrator_agent.py, planner_agent.py).
• travel_agency.db
• SQLite database used by the MCP server to store task history, agent state, and routing information.
README for additional insights
• The sample is meant to run without extra frameworks: you launch the MCP server, then run each agent’s __main__ which uses the MCP client to register and communicate.
Main components and interactions (to appear
a. agent_cards
– JSON definitions loaded by each agent at startup.
b. Agents (Python processes)
– Orchestrator Agent
– Planner Agent
– ADK Travel Agent
They each:
• Load their card
• Use the MCP client to register with the server
• Send/receive tasks (via JSON-RPC over HTTP or in-memory transport)
c. MCP Client (embedded in each agent)
– Provides send_task(), get_task(), subscribe() interfaces.
d. MCP Server
– Listens for JSON-RPC requests from clients
– Routes messages between agents according to the protocol
– Persists messages and task state in travel_agency.db
e. SQLite DB travel_agency.db
– Tables for task_queue, agent_registry, history
f. common utilities
– Shared code for serializing messages, managing workflows, caching, etc.
Relationships and data flow
• Agent process → (loads JSON card) → MCP Client
• MCP Client ↔ (JSON-RPC / HTTP / in-memory) ↔ MCP Server
• MCP Server → (reads/writes) → travel_agency.db
• MCP Server → (routes requests) → target Agent process via its MCP Client
• common modules are imported by both server and clients for shared logic (types, serialization)
Architectural patterns and design principles
• Microservice-style: each agent is an independent process, communicating over a protocol.
• Pub/Sub / request-response mix: agents subscribe to task updates.
• Persistence layer clearly separated (SQLite).
• Clear separation of concerns: agents (business logic), client (protocol implementation), server (orchestration), common (utilities).