Principle:A2aproject A2a java Agent Executor Pattern
| Knowledge Sources | |
|---|---|
| Domains | Software_Architecture, Inversion_of_Control |
| Last Updated | 2026-10-29 00:00 GMT |
Overview
An architectural pattern that decouples A2A protocol handling from agent business logic by defining a single functional interface through which all agent behavior is executed.
Description
The Agent Executor Pattern separates the concerns of protocol management (request routing, task persistence, event queuing, transport handling) from business logic (LLM calls, data processing, external API integration). The framework provides the infrastructure; the developer implements a single `AgentExecutor` interface with an `execute()` method.
This addresses the problem of protocol boilerplate: without this separation, every agent implementation would need to handle JSON-RPC parsing, task lifecycle management, event queue interaction, and error mapping — all before any business logic can run. The executor pattern lets agent developers focus solely on what the agent does, while the framework handles how messages get there and back.
In the broader software architecture landscape, this is an instance of the Inversion of Control pattern (also known as the Hollywood Principle: "Don't call us, we'll call you"). The framework calls the executor; the executor never calls the framework's transport layer directly. It is also related to the Command Pattern — each message invocation is a command executed asynchronously.
The `AgentEmitter` companion provides a simplified API for the executor to communicate results back to the client: sending messages, streaming artifacts, and managing task state transitions. The executor enqueues events; the framework handles delivery.
Usage
Use this principle when:
- Building any A2A-compatible agent — implementing `AgentExecutor` is the minimum requirement
- You want to keep business logic testable in isolation from protocol concerns
- You need asynchronous, background-thread execution of agent logic
- You want streaming results (LLM token streaming, progressive artifact delivery)
Theoretical Basis
The pattern follows Inversion of Control with an event-driven output channel:
// Framework calls executor — never the reverse
interface AgentExecutor {
void execute(RequestContext context, AgentEmitter emitter)
default void cancel(RequestContext context, AgentEmitter emitter)
}
// Executor communicates back via emitter (event queue)
emitter → enqueue events → EventQueue → transport → client
The threading model is critical:
Client request → Transport handler → DefaultRequestHandler
→ spawns background thread → AgentExecutor.execute()
→ executor enqueues events via AgentEmitter
→ EventQueue delivers to client transport (Vert.x worker threads)
Key constraint: executor must not block waiting for events to be consumed.
Enqueue and return — the queue handles backpressure.
The executor is a `@FunctionalInterface`, enabling lambda-based implementations for simple agents.
Practical Guide
To implement an agent executor:
- Create a CDI producer class annotated with `@ApplicationScoped`
- Produce an `AgentExecutor` via `@Produces` method
- In `execute()`, use `AgentEmitter` to send messages or manage task lifecycle
- Optionally implement `cancel()` for cancellation support (default throws `TaskNotCancelableError`)
Related Pages
Implemented By
- Implementation:A2aproject_A2a_java_AgentExecutor
- Implementation:A2aproject_A2a_java_AgentEmitter
- Implementation:A2aproject_A2a_java_DefaultRequestHandler
- Implementation:A2aproject_A2a_java_Quarkus_Dev_Server
- Implementation:A2aproject_A2a_java_RequestContext
- Implementation:A2aproject_A2a_java_ServerCallContext
- Implementation:A2aproject_A2a_java_RequestHandler_SPI
- Implementation:A2aproject_A2a_java_Server_Config_and_ThreadPool
- Implementation:A2aproject_A2a_java_MicroProfileConfigProvider