A remote template for agent-starter-pack that creates an AG2 agent deployed on Google Cloud Run with A2A protocol support.
uvx agent-starter-pack create my-agent \
-a https://github.com/ag2ai/build-with-ag2/tree/main/gcp-agent-starter-pack/templates/ag2
ConversableAgent with Google Gemini (Vertex AI or API key)A2aAgentServerThis template uses custom_a2a as its base_template, which provides the “bring your own framework” A2A infrastructure. AG2’s native A2A support (A2aAgentServer) handles the protocol implementation.
| File | Purpose |
|---|---|
app/agent.py |
AG2 ConversableAgent with tools |
app/fast_api_app.py |
FastAPI + AG2 A2aAgentServer |
deployment/ |
Terraform for Cloud Run (from base template) |
Set up a Google Gemini API key for AG2 to use Google Gemini models:
export GOOGLE_GEMINI_API_KEY="your-api-key"
Documentation for using Google Vertex AI with AG2 agents.
After generating your project:
cd my-agent
make install # Install dependencies
make run # Run locally on port 8000
make test # Run tests
make playground # Interactive testing
Or run directly:
uvicorn app.fast_api_app:app --host 0.0.0.0 --port 8000
Edit app/agent.py to modify your agent:
@agent.register_for_llm and @agent.register_for_executionSee AG2 documentation for advanced patterns.
The agent is served via the A2A protocol, enabling:
# Check agent card
curl http://localhost:8000/a2a/app/.well-known/agent-card.json
# Send a message
curl -X POST http://localhost:8000/a2a/app/ \
-H "Content-Type: application/json" \
-d '{
"jsonrpc": "2.0",
"method": "message/send",
"id": "1",
"params": {
"message": {
"messageId": "msg-1",
"role": "user",
"parts": [{"kind": "text", "text": "What is the weather in San Francisco?"}]
}
}
}'
import asyncio
from autogen.a2a import A2aRemoteAgent
async def main():
remote = A2aRemoteAgent(name="client", url="http://localhost:8000")
response = await remote.a_run(message="What's the weather in SF?")
# Consume events to populate messages
async for event in response.events:
pass
# Access the response messages
if response.messages:
print(response.messages[-1].get("content"))
asyncio.run(main())