Pirate Agent A2A is an autonomous agent designed to simulate conversations with a pirate using the A2A (Agent-to-Agent) protocol. It's built with the A2A server framework and uses Google ADK with LiteLLM for AI interactions.
pirate-agent-a2a/
├── pirate_agent_a2a/
│ ├── __init__.py
│ ├── main.py # Entry point, runs A2A server
│ └── agent.py # Pirate agent definition using Google ADK
├── agent.yaml # A2A server configuration
├── run.sh # Launch script
├── pyproject.toml # Python project configuration
├── Dockerfile # Container configuration
└── README.md # This file
- Main Server:
pirate_agent_a2a/main.py- Loads environment and runs A2A server - Agent Definition:
pirate_agent_a2a/agent.py- Defines the pirate agent using Google ADK with enhanced personality - Configuration:
agent.yaml- Server settings, Google ADK handler config, and detailed agent card metadata - Dependencies: Uses
a2a-server>=0.1.0,google-adk>=0.2.0,litellm>=1.67.0,python-dotenv>=1.1.0
- Pirate-speak: Transforms text into authentic pirate lingo
- A2A Protocol: Compatible with A2A agent communication standard
- Streaming: Supports real-time streaming responses
- REST API: Exposes agent via HTTP endpoints
- Clone the repository:
git clone https://github.com/yourusername/pirate-agent-a2a.git
cd pirate-agent-a2a- Install dependencies:
uv sync --reinstallalternatively:
pip install -r requirements.txt- Set up environment variables (create
.envfile):
# Required for LiteLLM - Add your OpenAI API key
OPENAI_API_KEY=your_openai_api_key_here
# Optional: Override default model (currently uses openai/gpt-4o-mini)
# AGENT_MODEL=openai/gpt-4o
# Optional: Server configuration
# PORT=8000
# LOG_LEVEL=debugThe agent is configured through multiple files:
agent.yaml: A2A server configuration, agent cards, and handler settingspirate_agent_a2a/agent.py: Agent personality, model selection, and instructions.env: Environment variables for API keys and runtime settings
- Model: Currently uses
openai/gpt-4o-mini(configurable inagent.py:5) - Port: Defaults to 8000 (configurable in
agent.yaml:3) - Agent Personality: Defined in instruction field in
agent.py:11
docker build --load -t pirate-agent:latest .docker images ls- Get the image id that was pushed
- Now run the image (on local podman)
podman run --rm -it pirate-agent:latestIn this example, agentic is your icr NAMESPACE and a2a is your REPOSITORY name. Replace RESOURCE_GROUP with the name of the resource group where you want the container registry.
# Log docker into the IBM Clouf container registry at icr.io
ibmcloud cr login
ibmcloud cr namespace-add -g RESOURCE_GROUP agentic
# Build the image and push it to the container registry in the 'agentic' namespace and 'a2a' repository.
docker build -f Dockerfile --push -t icr.io/agentic/a2a .
-
Navigate to Containers/Serverless/Projects
-
Create a project, eg. “A2A-play”
-
Navigate to “Applications”
-
Create application Name: pirate-agent-a2a Code repo URL: https://github.com/ccmitchellusa/pirate-agent-a2a
-
Navigate to "Optional settings" Image start options Listening port: 8000
-
Scroll back up to Code section.
-
Select “Specify build details” > Next > Next >.
-
Select a container registry namespace
-
Select Done
Start the agent:
./run.shThe server will start on port 8000. Access endpoints:
- Agent card: http://localhost:8000/agent-card.json
- Health check: http://localhost:8000/health
Once running, the agent exposes these A2A-compliant endpoints:
- GET
/agent-card.json- Agent metadata and capabilities - POST
/chat- Send messages to the pirate agent - POST
/chat/stream- Streaming chat responses - GET
/health- Server health status
# Get agent information
curl http://localhost:8000/agent-card.json
# Send a message to the pirate
curl -X POST http://localhost:8000/chat \
-H "Content-Type: application/json" \
-d '{"message": "Hello there!"}'
# Expected response:
# {"response": "Ahoy there, matey! Welcome aboard me ship!"}This agent implements the A2A (Agent-to-Agent) protocol, making it compatible with:
- A2A CLI clients
- Other A2A-compliant agents
- A2A orchestration platforms
To connect with Chris Hay's A2A CLI client (Localhost):
uvx a2a-cli --server http://localhost:8000 chat
# Expected: Interactive chat session with pirate responses
# Example conversation:
# You: Hello!
# Pirate: Ahoy there, matey! Jolly Chris at yer service!Connect a2a-cli to agent running on Code Engine:
- In the IBM Cloud console> Code Engine > Application page, click "Test Application" in upper right corner. Copy the app's url.
- Replace the url in the following snippet with the actual app's url from step 1:
uvx a2a-cli --log-level DEBUG --server https://application-42.1uo9xqkaspg3.us-east.codeengine.appdomain.cloud chat
# DEBUG mode shows detailed request/response information
# Useful for troubleshooting connection issues# Install dependencies
uv sync --reinstall
# Run locally with debug logging
uv run -m pirate_agent_a2a.main --config agent.yaml --log-level debug
# Alternative: use the run script
./run.sh- Code Structure: Main agent logic in
pirate_agent_a2a/agent.py - Configuration: Modify
agent.yamlfor server settings, agent cards - Environment: Use
.envfile for API keys and secrets - Dependencies: Managed via
pyproject.tomlanduv.lock
# Test agent card endpoint
curl http://localhost:8000/agent-card.json | jq
# Test basic chat functionality
curl -X POST http://localhost:8000/chat \
-H "Content-Type: application/json" \
-d '{"message": "Ahoy!"}'
# Test with A2A CLI
uvx a2a-cli --server http://localhost:8000 chat- Use
--log-level debugfor verbose output - Add
--list-routesto see all available endpoints - Use
--enable-flow-diagnosisfor detailed request tracing - Check logs for LiteLLM API calls and responses
# Complete setup from scratch
git clone <repo-url> && cd pirate-agent-a2a
echo "OPENAI_API_KEY=your_key_here" > .env
uv sync --reinstall
./run.sh
# Check if running
curl -s http://localhost:8000/health# Start with different log levels
uv run -m pirate_agent_a2a.main --config agent.yaml --log-level info
uv run -m pirate_agent_a2a.main --config agent.yaml --log-level debug
# List all available routes
uv run -m pirate_agent_a2a.main --config agent.yaml --list-routes
# Test agent functionality
curl -X POST http://localhost:8000/chat -H "Content-Type: application/json" -d '{"message": "Test message"}'- Agent personality/instructions:
pirate_agent_a2a/agent.py:19-37 - Model configuration:
pirate_agent_a2a/agent.py:17and environment variableMODEL - Server port:
agent.yaml:4 - Agent metadata:
agent.yaml:15-77 - Dependencies:
pyproject.toml:7-12 - Handler type:
agent.yaml:11(currently using GoogleADKHandler)
# Build and run with Docker
docker build -t pirate-agent:latest .
docker run --rm -p 8000:8000 pirate-agent:latest
# Quick container test
docker run --rm -p 8000:8000 pirate-agent:latest &
sleep 5 && curl http://localhost:8000/agent-card.jsonContributions are welcome! Please follow these steps:
- Fork the repository.
- Create a new branch for your feature or bug fix.
- Submit a pull request with a detailed description of your changes.
This project is licensed under the MIT License.
Special thanks to Chris Hayuk and the open-source community for providing tools and inspiration for this project.