a2a.server.agent_execution package

Submodules

a2a.server.agent_execution.agent_executor module

class a2a.server.agent_execution.agent_executor.AgentExecutor

Bases: ABC

Agent Executor interface.

Implementations of this interface contain the core logic of the agent, executing tasks based on requests and publishing updates to an event queue.

abstractmethod async cancel(context: RequestContext, event_queue: EventQueue) None

Request the agent to cancel an ongoing task.

The agent should attempt to stop the task identified by the task_id in the context and publish a TaskStatusUpdateEvent with state TaskState.canceled to the event_queue.

Parameters:
  • context – The request context containing the task ID to cancel.

  • event_queue – The queue to publish the cancellation status update to.

abstractmethod async execute(context: RequestContext, event_queue: EventQueue) None

Execute the agent’s logic for a given request context.

The agent should read necessary information from the context and publish Task or Message events, or TaskStatusUpdateEvent / TaskArtifactUpdateEvent to the event_queue. This method should return once the agent’s execution for this request is complete or yields control (e.g., enters an input-required state).

Parameters:
  • context – The request context containing the message, task ID, etc.

  • event_queue – The queue to publish events to.

a2a.server.agent_execution.context module

class a2a.server.agent_execution.context.RequestContext(request: MessageSendParams | None = None, task_id: str | None = None, context_id: str | None = None, task: Task | None = None, related_tasks: list[Task] | None = None, call_context: ServerCallContext | None = None)

Bases: object

Request Context.

Holds information about the current request being processed by the server, including the incoming message, task and context identifiers, and related tasks.

add_activated_extension(uri: str) None

Add an extension to the set of activated extensions for this request.

This causes the extension to be indicated back to the client in the response.

Attaches a related task to the context.

This is useful for scenarios like tool execution where a new task might be spawned.

Parameters:

task – The Task object to attach.

property call_context: ServerCallContext | None

The server call context associated with this request.

property configuration: MessageSendConfiguration | None

The MessageSendConfiguration from the request, if available.

property context_id: str | None

The ID of the conversation context associated with this task.

property current_task: Task | None

The current Task object being processed.

get_user_input(delimiter: str = '\n') str

Extracts text content from the user’s message parts.

Parameters:

delimiter – The string to use when joining multiple text parts.

Returns:

A single string containing all text content from the user message, joined by the specified delimiter. Returns an empty string if no user message is present or if it contains no text parts.

property message: Message | None

The incoming Message object from the request, if available.

property metadata: dict[str, Any]

Metadata associated with the request, if available.

property related_tasks: list[Task]

A list of tasks related to the current request.

property requested_extensions: set[str]

Extensions that the client requested to activate.

property task_id: str | None

The ID of the task associated with this context.

a2a.server.agent_execution.request_context_builder module

class a2a.server.agent_execution.request_context_builder.RequestContextBuilder

Bases: ABC

Builds request context to be supplied to agent executor.

abstractmethod async build(params: MessageSendParams | None = None, task_id: str | None = None, context_id: str | None = None, task: Task | None = None, context: ServerCallContext | None = None) RequestContext

a2a.server.agent_execution.simple_request_context_builder module

class a2a.server.agent_execution.simple_request_context_builder.SimpleRequestContextBuilder(should_populate_referred_tasks: bool = False, task_store: TaskStore | None = None)

Bases: RequestContextBuilder

Builds request context and populates referred tasks.

async build(params: MessageSendParams | None = None, task_id: str | None = None, context_id: str | None = None, task: Task | None = None, context: ServerCallContext | None = None) RequestContext

Builds the request context for an agent execution.

This method assembles the RequestContext object. If the builder was initialized with should_populate_referred_tasks=True, it fetches all tasks referenced in params.message.reference_task_ids from the task_store.

Parameters:
  • params – The parameters of the incoming message send request.

  • task_id – The ID of the task being executed.

  • context_id – The ID of the current execution context.

  • task – The primary task object associated with the request.

  • context – The server call context, containing metadata about the call.

Returns:

An instance of RequestContext populated with the provided information and potentially a list of related tasks.

Module contents

Components for executing agent logic within the A2A server.

class a2a.server.agent_execution.AgentExecutor

Bases: ABC

Agent Executor interface.

Implementations of this interface contain the core logic of the agent, executing tasks based on requests and publishing updates to an event queue.

abstractmethod async cancel(context: RequestContext, event_queue: EventQueue) None

Request the agent to cancel an ongoing task.

The agent should attempt to stop the task identified by the task_id in the context and publish a TaskStatusUpdateEvent with state TaskState.canceled to the event_queue.

Parameters:
  • context – The request context containing the task ID to cancel.

  • event_queue – The queue to publish the cancellation status update to.

abstractmethod async execute(context: RequestContext, event_queue: EventQueue) None

Execute the agent’s logic for a given request context.

The agent should read necessary information from the context and publish Task or Message events, or TaskStatusUpdateEvent / TaskArtifactUpdateEvent to the event_queue. This method should return once the agent’s execution for this request is complete or yields control (e.g., enters an input-required state).

Parameters:
  • context – The request context containing the message, task ID, etc.

  • event_queue – The queue to publish events to.

class a2a.server.agent_execution.RequestContext(request: MessageSendParams | None = None, task_id: str | None = None, context_id: str | None = None, task: Task | None = None, related_tasks: list[Task] | None = None, call_context: ServerCallContext | None = None)

Bases: object

Request Context.

Holds information about the current request being processed by the server, including the incoming message, task and context identifiers, and related tasks.

add_activated_extension(uri: str) None

Add an extension to the set of activated extensions for this request.

This causes the extension to be indicated back to the client in the response.

Attaches a related task to the context.

This is useful for scenarios like tool execution where a new task might be spawned.

Parameters:

task – The Task object to attach.

property call_context: ServerCallContext | None

The server call context associated with this request.

property configuration: MessageSendConfiguration | None

The MessageSendConfiguration from the request, if available.

property context_id: str | None

The ID of the conversation context associated with this task.

property current_task: Task | None

The current Task object being processed.

get_user_input(delimiter: str = '\n') str

Extracts text content from the user’s message parts.

Parameters:

delimiter – The string to use when joining multiple text parts.

Returns:

A single string containing all text content from the user message, joined by the specified delimiter. Returns an empty string if no user message is present or if it contains no text parts.

property message: Message | None

The incoming Message object from the request, if available.

property metadata: dict[str, Any]

Metadata associated with the request, if available.

property related_tasks: list[Task]

A list of tasks related to the current request.

property requested_extensions: set[str]

Extensions that the client requested to activate.

property task_id: str | None

The ID of the task associated with this context.

class a2a.server.agent_execution.RequestContextBuilder

Bases: ABC

Builds request context to be supplied to agent executor.

abstractmethod async build(params: MessageSendParams | None = None, task_id: str | None = None, context_id: str | None = None, task: Task | None = None, context: ServerCallContext | None = None) RequestContext
class a2a.server.agent_execution.SimpleRequestContextBuilder(should_populate_referred_tasks: bool = False, task_store: TaskStore | None = None)

Bases: RequestContextBuilder

Builds request context and populates referred tasks.

async build(params: MessageSendParams | None = None, task_id: str | None = None, context_id: str | None = None, task: Task | None = None, context: ServerCallContext | None = None) RequestContext

Builds the request context for an agent execution.

This method assembles the RequestContext object. If the builder was initialized with should_populate_referred_tasks=True, it fetches all tasks referenced in params.message.reference_task_ids from the task_store.

Parameters:
  • params – The parameters of the incoming message send request.

  • task_id – The ID of the task being executed.

  • context_id – The ID of the current execution context.

  • task – The primary task object associated with the request.

  • context – The server call context, containing metadata about the call.

Returns:

An instance of RequestContext populated with the provided information and potentially a list of related tasks.