4. Agent executor

4. Agent executor

The core logic of how an A2A agent processes requests and produces responses/events is implemented in an Agent Executor.

In the A2A Python SDK, you typically implement an AgentExecutor interface with two primary responsibilities:

  • execute(...): handle incoming requests (both single-response and streaming), read user input from the request context, and emit results/events through an event queue.
  • cancel(...): handle task cancellation requests (if your agent supports cancellation).

What the executor does

Conceptually, the executor is the bridge between:

  • Protocol plumbing (request handler, HTTP server, task store), and
  • Your business logic (your agent’s reasoning, tool calls, and output generation).

Reference implementation

If you’re following along with the official examples, the simplest place to see an executor is the HelloWorld agent in the a2a-samples repository:

  • Executor: samples/python/agents/helloworld/agent_executor.py
  • Server entrypoint: samples/python/agents/helloworld/__main__.py
  • Client: samples/python/agents/helloworld/test_client.py

Read through the executor and identify:

  • where it extracts the user message/parts from the context,
  • where it creates an agent response message,
  • where it enqueues the response (for non-streaming and streaming).

In the next chapter you’ll wire the executor into an HTTP server.