ag2 serve - AG2

Serve

The ag2 serve command starts a server that exposes your agent via one of three protocols.

ag2 serve <agent_file> [--protocol <protocol>] [--port <port>]

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
ag2 serve my_agent.py --protocol rest --port 8000
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.

ag2 serve my_agent.py --protocol mcp

A2A Endpoint

Serves the agent using the A2A protocol with a well-known agent card.

ag2 serve my_agent.py --protocol a2a --port 8000

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