Serve
The ag2 serve command starts a server that exposes your agent via one of three protocols.
Protocols#
REST API (default)#
Serves a FastAPI application with the following endpoints:
| Endpoint | Method | Description |
|---|---|---|
/chat | POST | Send a message, get a response |
/chat/stream | POST | Streaming response via SSE |
/agents | GET | List available agents |
/health | GET | Health check |
/docs | GET | Swagger UI |
curl -X POST http://localhost:8000/chat \
-H "Content-Type: application/json" \
-d '{"message": "Hello, agent!"}'
MCP Server#
Wraps your agent as an MCP (Model Context Protocol) server, exposing chat and list_agents tools.
A2A Endpoint#
Serves the agent using the A2A protocol with a well-known agent card.
Options#
| Flag | Description |
|---|---|
--protocol | rest (default), mcp, or a2a |
--port | Port to listen on (default: 8000) |
--reload | Hot-reload on file changes |
--ngrok | Expose to internet via ngrok tunnel |