5. Starting the Server
With an Agent Card and an Agent Executor in place, you can set up and start the A2A server.
The Python SDK provides a route factory and helper functions (create_agent_card_routes, create_jsonrpc_routes, create_rest_routes) that create routes for the A2A server’s services. These routes attach natively to popular frameworks such as Starlette
and FastAPI
, which give you better control over authentication, logging, and other features. This tutorial uses Starlette with Uvicorn
.
Server setup in Helloworld
Look at __main__.py again to see how the server is initialized and started.
First, create the request handler:
# The RequestHandler processes incoming requests and manages tasks
request_handler = DefaultRequestHandler(
# Agent executor handles the execution of the client requests
agent_executor=HelloWorldAgentExecutor(),
# The task_store is used to store and manage tasks
task_store=InMemoryTaskStore(),
# Public agent card for unauthenticated users
agent_card=public_agent_card,
# Extended agent card for authenticated users
extended_agent_card=extended_agent_card,
)Then create the routes, build the app, and run it:
# Creating the routes for the A2A server
# These routes handle the incoming requests from the clients
# and the outgoing responses to the clients
routes = []
# Create routes for the agent card
routes.extend(create_agent_card_routes(public_agent_card))
# Create routes for the JSONRPC protocol
# Alternatively, you can choose GRPC or HTTP_JSON as protocol bindings
# based on your requirements
routes.extend(create_jsonrpc_routes(request_handler, '/'))
# Create a web app with the defined routes
# Here we are using Starlette, a lightweight ASGI web framework to serve the agent
# Alternatively, you can choose FastAPI or other ASGI frameworks
app = Starlette(routes=routes)
# Run the app
# Uvicorn is a production-ready ASGI HTTP server
uvicorn.run(app, host='127.0.0.1', port=9999)Taking it piece by piece:
1. DefaultRequestHandler
- The SDK provides
DefaultRequestHandler. It takes yourAgentExecutorimplementation (HelloWorldAgentExecutor), aTaskStore(InMemoryTaskStore), and the public and extendedAgentCardobjects. - It routes incoming A2A RPC calls to the appropriate methods on your executor (such as
executeorcancel). - The
TaskStoreis used byDefaultRequestHandlerto manage the lifecycle of tasks, especially for stateful interactions, streaming, and resubscription. Even if your agent executor is simple, the handler needs a task store. agent_cardis passed to the handler so it can verify the agent’s declared capabilities when processing requests. For example, it checks whether streaming or push notifications are supported before handling those request types.extended_agent_cardis passed so the handler can serve it through theGetExtendedAgentCardmethod to authenticated clients.
2. create_agent_card_routes and create_jsonrpc_routes
create_agent_card_routes(public_agent_card)returns Starlette routes that expose the Agent Card at the/.well-known/agent-card.jsonendpoint for public discovery.create_jsonrpc_routes(request_handler, '/')returns Starlette routes that handle all incoming A2A JSON-RPC method calls by delegating to therequest_handler.- These route lists are combined and passed to a standard
Starletteapplication.
3. uvicorn.run(app, ...)
- The constructed
Starletteapp is run withuvicorn.run(), making your agent accessible over HTTP. host='127.0.0.1'makes the server accessible only from your local machine.port=9999specifies the port to listen on. It matches the endpoint defined in theAgentCard’ssupported_interfaces.
Running the Helloworld server
All run commands in this tutorial assume two things: your terminal is at the root of the a2a-samples checkout (the directory containing samples/), and the virtual environment from Setup
is activated. Open a terminal in that state and run:
# from the a2a-samples directory
python samples/python/agents/helloworld/__main__.pyYou should see output similar to this, indicating that the server is running:
INFO: Started server process [xxxxx]
INFO: Waiting for application startup.
INFO: Application startup complete.
INFO: Uvicorn running on http://127.0.0.1:9999 (Press CTRL+C to quit)
Before you go further, two practical notes — one about the port, one about stopping:
- Port 9999 already in use. If another server (for example a previous run of this one) still holds the port, startup logs
error while attempting to bind on address ('127.0.0.1', 9999): address already in useand the process exits — stop the other process first. - Stopping the server. Pressing Ctrl+C in the terminal running
__main__.pyis the normal way to stop the server: Uvicorn shuts the application down and the process exits cleanly.
The Helloworld server is now listening for requests.
Check the served Agent Card
Before talking to the server, fetch the card it actually serves and check the interface it advertises. The tutorial’s environment already has everything needed — this uses only the Python standard library. In a second terminal (same checkout root, same activated environment):
python -c "import json, urllib.request; card = json.load(urllib.request.urlopen('http://127.0.0.1:9999/.well-known/agent-card.json', timeout=5)); interface = card['supportedInterfaces'][0]; print(interface['protocolBinding'], interface['protocolVersion'], interface['url'])"For the pinned helloworld sample this prints:
JSONRPC 1.0 http://127.0.0.1:9999
That single line confirms the three facts that matter for the next step: the binding is JSONRPC, the protocol version is 1.0, and the advertised URL is the loopback endpoint the server listens on.
If the command times out or answers with an HTTP error, the card was not fetched: do not assume the server is up. Go back to the server terminal and confirm the Uvicorn startup lines are there, and check that the URL you used carries the exact path /.well-known/agent-card.json on 127.0.0.1:9999.
Optionally, for the full three-assertion check (release version, compatible interface, endpoint URL against the selected entry), you can reuse the checker shipped with the Agent Card pre-flight section
: save the served card with curl -fsSL http://127.0.0.1:9999/.well-known/agent-card.json -o helloworld-card.json (on Windows use curl.exe), download check_agent_card_release.py from the same section
, and run it with --binding JSONRPC --protocol 1.0 --expect-version 0.0.1 --expect-url http://127.0.0.1:9999 helloworld-card.json. Both the standard-library line and the optional checker were run against the live helloworld server on 2026-11-14 and passed with the pinned versions.
In the next step, you will interact with the server .
Separate startup, discovery, and task durability
If the process exits before listening, check the virtual environment, dependency versions, imports, and whether port 9999 is already in use. Once it listens, run the card check above ; an HTML error page at that address is a routing problem, not a failure of the agent’s greeting logic.
Next, compare the returned card’s JSON-RPC URL with the registered JSON-RPC route. Use that advertised endpoint for messages; do not send a JSON-RPC envelope to the Agent Card URL. When moving behind a reverse proxy, update the externally reachable interface URL as well as routing and authentication. Keep this local tutorial bound to loopback while developing it.
InMemoryTaskStore keeps tasks only in the running process. A restart loses them, and separate worker processes do not share that memory. It is useful for the greeting exercise but does not establish durable recovery. Before accepting long-lived or valuable work, choose persistent task storage and coordinate worker ownership and backend idempotency. The recovery guide
explains why persisting task state alone is insufficient.