Skip to content

fasta2a

Storage

Bases: ABC, Generic[ContextT]

A storage to retrieve and save tasks, as well as retrieve and save context.

The storage serves two purposes:

  1. Task storage: Stores tasks in A2A protocol format with their status, artifacts, and message history
  2. Context storage: Stores conversation context in a format optimized for the specific agent implementation

Methods

load_task

@abstractmethod

@async

def load_task(task_id: str, history_length: int | None = None) -> Task | None

Load a task from storage.

If the task is not found, return None.

Returns

Task | None

submit_task

@abstractmethod

@async

def submit_task(context_id: str, message: Message) -> Task

Submit a task to storage.

Returns

Task

update_task

@abstractmethod

@async

def update_task(
    task_id: str,
    state: TaskState,
    new_artifacts: list[Artifact] | None = None,
    new_messages: list[Message] | None = None,
) -> Task

Update the state of a task. Appends artifacts and messages, if specified.

Returns

Task

load_context

@abstractmethod

@async

def load_context(context_id: str) -> ContextT | None

Retrieve the stored context given the context_id.

Returns

ContextT | None

update_context

@abstractmethod

@async

def update_context(context_id: str, context: ContextT) -> None

Updates the context for a context_id.

Implementing agent can decide what to store in context.

Returns

None

Broker

Bases: ABC

The broker class is in charge of scheduling the tasks.

The HTTP server uses the broker to schedule tasks.

The simple implementation is the InMemoryBroker, which is the broker that runs the tasks in the same process as the HTTP server. That said, this class can be extended to support remote workers.

Methods

run_task

@abstractmethod

@async

def run_task(params: TaskSendParams) -> None

Send a task to be executed by the worker.

Returns

None

cancel_task

@abstractmethod

@async

def cancel_task(params: TaskIdParams) -> None

Cancel a task.

Returns

None

receive_task_operations

@abstractmethod

def receive_task_operations() -> AsyncIterator[TaskOperation]

Receive task operations from the broker.

On a multi-worker setup, the broker will need to round-robin the task operations between the workers.

Returns

AsyncIterator[TaskOperation]

Worker

Bases: ABC, Generic[ContextT]

A worker is responsible for executing tasks.

Methods

run

@async

def run() -> AsyncIterator[None]

Run the worker.

It connects to the broker, and it makes itself available to receive commands.

Returns

AsyncIterator[None]

FastA2A

Bases: Starlette

The main class for the FastA2A library.

Skill

Bases: TypedDict

Skills are a unit of capability that an agent can perform.

Attributes

id

A unique identifier for the skill.

Type: str

name

Human readable name of the skill.

Type: str

description

A human-readable description of the skill.

It will be used by the client or a human as a hint to understand the skill.

Type: str

tags

Set of tag-words describing classes of capabilities for this specific skill.

Examples: “cooking”, “customer support”, “billing”.

Type: list[str]

examples

The set of example scenarios that the skill can perform.

Will be used by the client as a hint to understand how the skill can be used. (e.g. “I need a recipe for bread”)

Type: NotRequired[list[str]]

input_modes

Supported mime types for input data.

Type: list[str]

output_modes

Supported mime types for output data.

Type: list[str]

This module contains the schema for the agent card.

AgentCard

Bases: TypedDict

The card that describes an agent.

Attributes

name

Human readable name of the agent e.g. “Recipe Agent”.

Type: str

description

A human-readable description of the agent.

Used to assist users and other agents in understanding what the agent can do. (e.g. “Agent that helps users with recipes and cooking.”)

Type: str

url

A URL to the address the agent is hosted at.

Type: str

version

The version of the agent - format is up to the provider. (e.g. “1.0.0”)

Type: str

protocol_version

The version of the A2A protocol this agent supports.

Type: str

provider

The service provider of the agent.

Type: NotRequired[AgentProvider]

documentation_url

A URL to documentation for the agent.

Type: NotRequired[str]

icon_url

A URL to an icon for the agent.

Type: NotRequired[str]

preferred_transport

The transport of the preferred endpoint. If empty, defaults to JSONRPC.

Type: NotRequired[str]

additional_interfaces

Announcement of additional supported transports.

Type: NotRequired[list[AgentInterface]]

capabilities

The capabilities of the agent.

Type: AgentCapabilities

security

Security requirements for contacting the agent.

Type: NotRequired[list[dict[str, list[str]]]]

security_schemes

Security scheme definitions.

Type: NotRequired[dict[str, SecurityScheme]]

default_input_modes

Supported mime types for input data.

Type: list[str]

default_output_modes

Supported mime types for output data.

Type: list[str]

skills

The set of skills, or distinct capabilities, that the agent can perform.

Type: list[Skill]

AgentProvider

Bases: TypedDict

The service provider of the agent.

Attributes

organization

The name of the agent provider’s organization.

Type: str

url

A URL for the agent provider’s website or relevant documentation.

Type: str

AgentCapabilities

Bases: TypedDict

The capabilities of the agent.

Attributes

streaming

Whether the agent supports streaming.

Type: NotRequired[bool]

push_notifications

Whether the agent can notify updates to client.

Type: NotRequired[bool]

state_transition_history

Whether the agent exposes status change history for tasks.

Type: NotRequired[bool]

HttpSecurityScheme

Bases: TypedDict

HTTP security scheme.

Attributes

type

The type of the security scheme. Must be ‘http’.

Type: Literal[‘http’]

scheme

The name of the HTTP Authorization scheme.

Type: str

bearer_format

A hint to the client to identify how the bearer token is formatted.

Type: NotRequired[str]

description

Description of this security scheme.

Type: NotRequired[str]

ApiKeySecurityScheme

Bases: TypedDict

API Key security scheme.

Attributes

type

The type of the security scheme. Must be ‘apiKey’.

Type: Literal[‘apiKey’]

name

The name of the header, query or cookie parameter to be used.

Type: str

in_

The location of the API key.

Type: Literal[‘query’, ‘header’, ‘cookie’]

description

Description of this security scheme.

Type: NotRequired[str]

OAuth2SecurityScheme

Bases: TypedDict

OAuth2 security scheme.

Attributes

type

The type of the security scheme. Must be ‘oauth2’.

Type: Literal[‘oauth2’]

flows

An object containing configuration information for the flow types supported.

Type: dict[str, Any]

description

Description of this security scheme.

Type: NotRequired[str]

OpenIdConnectSecurityScheme

Bases: TypedDict

OpenID Connect security scheme.

Attributes

type

The type of the security scheme. Must be ‘openIdConnect’.

Type: Literal[‘openIdConnect’]

open_id_connect_url

OpenId Connect URL to discover OAuth2 configuration values.

Type: str

description

Description of this security scheme.

Type: NotRequired[str]

AgentInterface

Bases: TypedDict

An interface that the agent supports.

Attributes

transport

The transport protocol (e.g., ‘jsonrpc’, ‘websocket’).

Type: str

url

The URL endpoint for this transport.

Type: str

description

Description of this interface.

Type: NotRequired[str]

AgentExtension

Bases: TypedDict

A declaration of an extension supported by an Agent.

Attributes

uri

The URI of the extension.

Type: str

description

A description of how this agent uses this extension.

Type: NotRequired[str]

required

Whether the client must follow specific requirements of the extension.

Type: NotRequired[bool]

params

Optional configuration for the extension.

Type: NotRequired[dict[str, Any]]

Skill

Bases: TypedDict

Skills are a unit of capability that an agent can perform.

Attributes

id

A unique identifier for the skill.

Type: str

name

Human readable name of the skill.

Type: str

description

A human-readable description of the skill.

It will be used by the client or a human as a hint to understand the skill.

Type: str

tags

Set of tag-words describing classes of capabilities for this specific skill.

Examples: “cooking”, “customer support”, “billing”.

Type: list[str]

examples

The set of example scenarios that the skill can perform.

Will be used by the client as a hint to understand how the skill can be used. (e.g. “I need a recipe for bread”)

Type: NotRequired[list[str]]

input_modes

Supported mime types for input data.

Type: list[str]

output_modes

Supported mime types for output data.

Type: list[str]

Artifact

Bases: TypedDict

Agents generate Artifacts as an end result of a Task.

Artifacts are immutable, can be named, and can have multiple parts. A streaming response can append parts to existing Artifacts.

A single Task can generate many Artifacts. For example, “create a webpage” could create separate HTML and image Artifacts.

Attributes

artifact_id

Unique identifier for the artifact.

Type: str

name

The name of the artifact.

Type: NotRequired[str]

description

A description of the artifact.

Type: NotRequired[str]

parts

The parts that make up the artifact.

Type: list[Part]

metadata

Metadata about the artifact.

Type: NotRequired[dict[str, Any]]

extensions

Array of extensions.

Type: NotRequired[list[str]]

append

Whether to append this artifact to an existing one.

Type: NotRequired[bool]

last_chunk

Whether this is the last chunk of the artifact.

Type: NotRequired[bool]

PushNotificationConfig

Bases: TypedDict

Configuration for push notifications.

A2A supports a secure notification mechanism whereby an agent can notify a client of an update outside a connected session via a PushNotificationService. Within and across enterprises, it is critical that the agent verifies the identity of the notification service, authenticates itself with the service, and presents an identifier that ties the notification to the executing Task.

The target server of the PushNotificationService should be considered a separate service, and is not guaranteed (or even expected) to be the client directly. This PushNotificationService is responsible for authenticating and authorizing the agent and for proxying the verified notification to the appropriate endpoint (which could be anything from a pub/sub queue, to an email inbox or other service, etc.).

For contrived scenarios with isolated client-agent pairs (e.g. local service mesh in a contained VPC, etc.) or isolated environments without enterprise security concerns, the client may choose to simply open a port and act as its own PushNotificationService. Any enterprise implementation will likely have a centralized service that authenticates the remote agents with trusted notification credentials and can handle online/offline scenarios. (This should be thought of similarly to a mobile Push Notification Service).

Attributes

id

Server-assigned identifier.

Type: NotRequired[str]

url

The URL to send push notifications to.

Type: str

token

Token unique to this task/session.

Type: NotRequired[str]

authentication

Authentication details for push notifications.

Type: NotRequired[SecurityScheme]

TaskPushNotificationConfig

Bases: TypedDict

Configuration for task push notifications.

Attributes

id

The task id.

Type: str

push_notification_config

The push notification configuration.

Type: PushNotificationConfig

Message

Bases: TypedDict

A Message contains any content that is not an Artifact.

This can include things like agent thoughts, user context, instructions, errors, status, or metadata.

All content from a client comes in the form of a Message. Agents send Messages to communicate status or to provide instructions (whereas generated results are sent as Artifacts).

A Message can have multiple parts to denote different pieces of content. For example, a user request could include a textual description from a user and then multiple files used as context from the client.

Attributes

role

The role of the message.

Type: Literal[‘user’, ‘agent’]

parts

The parts of the message.

Type: list[Part]

kind

Event type.

Type: Literal[‘message’]

metadata

Metadata about the message.

Type: NotRequired[dict[str, Any]]

message_id

Identifier created by the message creator.

Type: str

context_id

The context the message is associated with.

Type: NotRequired[str]

task_id

Identifier of task the message is related to.

Type: NotRequired[str]

reference_task_ids

Array of task IDs this message references.

Type: NotRequired[list[str]]

extensions

Array of extensions.

Type: NotRequired[list[str]]

TextPart

Bases: _BasePart

A part that contains text.

Attributes

kind

The kind of the part.

Type: Literal[‘text’]

text

The text of the part.

Type: str

FileWithBytes

Bases: TypedDict

File with base64 encoded data.

Attributes

bytes

The base64 encoded content of the file.

Type: str

mime_type

Optional mime type for the file.

Type: NotRequired[str]

FileWithUri

Bases: TypedDict

File with URI reference.

Attributes

uri

The URI of the file.

Type: str

mime_type

The mime type of the file.

Type: NotRequired[str]

FilePart

Bases: _BasePart

A part that contains a file.

Attributes

kind

The kind of the part.

Type: Literal[‘file’]

file

The file content - either bytes or URI.

Type: FileWithBytes | FileWithUri

DataPart

Bases: _BasePart

A part that contains structured data.

Attributes

kind

The kind of the part.

Type: Literal[‘data’]

data

The data of the part.

Type: dict[str, Any]

TaskStatus

Bases: TypedDict

Status and accompanying message for a task.

Attributes

state

The current state of the task.

Type: TaskState

message

Additional status updates for client.

Type: NotRequired[Message]

timestamp

ISO datetime value of when the status was updated.

Type: NotRequired[str]

Task

Bases: TypedDict

A Task is a stateful entity that allows Clients and Remote Agents to achieve a specific outcome.

Clients and Remote Agents exchange Messages within a Task. Remote Agents generate results as Artifacts. A Task is always created by a Client and the status is always determined by the Remote Agent.

Attributes

id

Unique identifier for the task.

Type: str

context_id

The context the task is associated with.

Type: str

kind

Event type.

Type: Literal[‘task’]

status

Current status of the task.

Type: TaskStatus

history

Optional history of messages.

Type: NotRequired[list[Message]]

artifacts

Collection of artifacts created by the agent.

Type: NotRequired[list[Artifact]]

metadata

Extension metadata.

Type: NotRequired[dict[str, Any]]

TaskStatusUpdateEvent

Bases: TypedDict

Sent by server during message/stream requests.

Attributes

task_id

The id of the task.

Type: str

context_id

The context the task is associated with.

Type: str

kind

Event type.

Type: Literal[‘status-update’]

status

The status of the task.

Type: TaskStatus

final

Indicates the end of the event stream.

Type: bool

metadata

Extension metadata.

Type: NotRequired[dict[str, Any]]

TaskArtifactUpdateEvent

Bases: TypedDict

Sent by server during message/stream requests.

Attributes

task_id

The id of the task.

Type: str

context_id

The context the task is associated with.

Type: str

kind

Event type identification.

Type: Literal[‘artifact-update’]

artifact

The artifact that was updated.

Type: Artifact

append

Whether to append to existing artifact (true) or replace (false).

Type: NotRequired[bool]

last_chunk

Indicates this is the final chunk of the artifact.

Type: NotRequired[bool]

metadata

Extension metadata.

Type: NotRequired[dict[str, Any]]

TaskIdParams

Bases: TypedDict

Parameters for a task id.

Attributes

id

The unique identifier for the task.

Type: str

metadata

Optional metadata associated with the request.

Type: NotRequired[dict[str, Any]]

TaskQueryParams

Bases: TaskIdParams

Query parameters for a task.

Attributes

history_length

Number of recent messages to be retrieved.

Type: NotRequired[int]

MessageSendConfiguration

Bases: TypedDict

Configuration for the send message request.

Attributes

accepted_output_modes

Accepted output modalities by the client.

Type: list[str]

blocking

If the server should treat the client as a blocking request.

Type: NotRequired[bool]

history_length

Number of recent messages to be retrieved.

Type: NotRequired[int]

push_notification_config

Where the server should send notifications when disconnected.

Type: NotRequired[PushNotificationConfig]

MessageSendParams

Bases: TypedDict

Parameters for message/send method.

Attributes

configuration

Send message configuration.

Type: NotRequired[MessageSendConfiguration]

message

The message being sent to the server.

Type: Message

metadata

Extension metadata.

Type: NotRequired[dict[str, Any]]

TaskSendParams

Bases: TypedDict

Internal parameters for task execution within the framework.

Note: This is not part of the A2A protocol - it’s used internally for broker/worker communication.

Attributes

id

The id of the task.

Type: str

context_id

The context id for the task.

Type: str

message

The message to process.

Type: Message

history_length

Number of recent messages to be retrieved.

Type: NotRequired[int]

metadata

Extension metadata.

Type: NotRequired[dict[str, Any]]

ListTaskPushNotificationConfigParams

Bases: TypedDict

Parameters for getting list of pushNotificationConfigurations associated with a Task.

Attributes

id

Task id.

Type: str

metadata

Extension metadata.

Type: NotRequired[dict[str, Any]]

DeleteTaskPushNotificationConfigParams

Bases: TypedDict

Parameters for removing pushNotificationConfiguration associated with a Task.

Attributes

id

Task id.

Type: str

push_notification_config_id

The push notification config id to delete.

Type: str

metadata

Extension metadata.

Type: NotRequired[dict[str, Any]]

JSONRPCMessage

Bases: TypedDict

A JSON RPC message.

Attributes

jsonrpc

The JSON RPC version.

Type: Literal[‘2.0’]

id

The request id.

Type: int | str | None

JSONRPCRequest

Bases: JSONRPCMessage, Generic[Method, Params]

A JSON RPC request.

Attributes

method

The method to call.

Type: Method

params

The parameters to pass to the method.

Type: Params

JSONRPCError

Bases: TypedDict, Generic[CodeT, MessageT]

A JSON RPC error.

Attributes

code

A number that indicates the error type that occurred.

Type: CodeT

message

A string providing a short description of the error.

Type: MessageT

data

A primitive or structured value containing additional information about the error.

Type: NotRequired[Any]

JSONRPCResponse

Bases: JSONRPCMessage, Generic[ResultT, ErrorT]

A JSON RPC response.

SecurityScheme

A security scheme for authentication.

Default: Annotated[Union[HttpSecurityScheme, ApiKeySecurityScheme, OAuth2SecurityScheme, OpenIdConnectSecurityScheme], pydantic.Field(discriminator='type')]

Part

A fully formed piece of content exchanged between a client and a remote agent as part of a Message or an Artifact.

Each Part has its own content type and metadata.

Default: Annotated[Union[TextPart, FilePart, DataPart], pydantic.Field(discriminator='kind')]

TaskState

The possible states of a task.

Type: TypeAlias Default: Literal['submitted', 'working', 'input-required', 'completed', 'canceled', 'failed', 'rejected', 'auth-required', 'unknown']

JSONParseError

A JSON RPC error for a parse error.

Default: JSONRPCError[Literal[-32700], Literal['Invalid JSON payload']]

InvalidRequestError

A JSON RPC error for an invalid request.

Default: JSONRPCError[Literal[-32600], Literal['Request payload validation error']]

MethodNotFoundError

A JSON RPC error for a method not found.

Default: JSONRPCError[Literal[-32601], Literal['Method not found']]

InvalidParamsError

A JSON RPC error for invalid parameters.

Default: JSONRPCError[Literal[-32602], Literal['Invalid parameters']]

InternalError

A JSON RPC error for an internal error.

Default: JSONRPCError[Literal[-32603], Literal['Internal error']]

TaskNotFoundError

A JSON RPC error for a task not found.

Default: JSONRPCError[Literal[-32001], Literal['Task not found']]

TaskNotCancelableError

A JSON RPC error for a task not cancelable.

Default: JSONRPCError[Literal[-32002], Literal['Task not cancelable']]

PushNotificationNotSupportedError

A JSON RPC error for a push notification not supported.

Default: JSONRPCError[Literal[-32003], Literal['Push notification not supported']]

UnsupportedOperationError

A JSON RPC error for an unsupported operation.

Default: JSONRPCError[Literal[-32004], Literal['This operation is not supported']]

ContentTypeNotSupportedError

A JSON RPC error for incompatible content types.

Default: JSONRPCError[Literal[-32005], Literal['Incompatible content types']]

InvalidAgentResponseError

A JSON RPC error for invalid agent response.

Default: JSONRPCError[Literal[-32006], Literal['Invalid agent response']]

SendMessageRequest

A JSON RPC request to send a message.

Default: JSONRPCRequest[Literal['message/send'], MessageSendParams]

SendMessageResponse

A JSON RPC response to send a message.

Default: JSONRPCResponse[Union[Task, Message], JSONRPCError[Any, Any]]

StreamMessageRequest

A JSON RPC request to stream a message.

Default: JSONRPCRequest[Literal['message/stream'], MessageSendParams]

StreamMessageResponse

A JSON RPC response to a StreamMessageRequest.

Default: JSONRPCResponse[Union[Task, Message, TaskStatusUpdateEvent, TaskArtifactUpdateEvent], JSONRPCError[Any, Any]]

GetTaskRequest

A JSON RPC request to get a task.

Default: JSONRPCRequest[Literal['tasks/get'], TaskQueryParams]

GetTaskResponse

A JSON RPC response to get a task.

Default: JSONRPCResponse[Task, TaskNotFoundError]

CancelTaskRequest

A JSON RPC request to cancel a task.

Default: JSONRPCRequest[Literal['tasks/cancel'], TaskIdParams]

CancelTaskResponse

A JSON RPC response to cancel a task.

Default: JSONRPCResponse[Task, Union[TaskNotCancelableError, TaskNotFoundError]]

SetTaskPushNotificationRequest

A JSON RPC request to set a task push notification.

Default: JSONRPCRequest[Literal['tasks/pushNotification/set'], TaskPushNotificationConfig]

SetTaskPushNotificationResponse

A JSON RPC response to set a task push notification.

Default: JSONRPCResponse[TaskPushNotificationConfig, PushNotificationNotSupportedError]

GetTaskPushNotificationRequest

A JSON RPC request to get a task push notification.

Default: JSONRPCRequest[Literal['tasks/pushNotification/get'], TaskIdParams]

GetTaskPushNotificationResponse

A JSON RPC response to get a task push notification.

Default: JSONRPCResponse[TaskPushNotificationConfig, PushNotificationNotSupportedError]

ResubscribeTaskRequest

A JSON RPC request to resubscribe to a task.

Default: JSONRPCRequest[Literal['tasks/resubscribe'], TaskIdParams]

ListTaskPushNotificationConfigRequest

A JSON RPC request to list task push notification configs.

Default: JSONRPCRequest[Literal['tasks/pushNotificationConfig/list'], ListTaskPushNotificationConfigParams]

DeleteTaskPushNotificationConfigRequest

A JSON RPC request to delete a task push notification config.

Default: JSONRPCRequest[Literal['tasks/pushNotificationConfig/delete'], DeleteTaskPushNotificationConfigParams]

A2ARequest

A JSON RPC request to the A2A server.

Default: Annotated[Union[SendMessageRequest, StreamMessageRequest, GetTaskRequest, CancelTaskRequest, SetTaskPushNotificationRequest, GetTaskPushNotificationRequest, ResubscribeTaskRequest, ListTaskPushNotificationConfigRequest, DeleteTaskPushNotificationConfigRequest], Discriminator('method')]

A2AResponse

A JSON RPC response from the A2A server.

Type: TypeAlias Default: Union[SendMessageResponse, StreamMessageResponse, GetTaskResponse, CancelTaskResponse, SetTaskPushNotificationResponse, GetTaskPushNotificationResponse]

A2AClient

A client for the A2A protocol.

Methods

send_message

@async

def send_message(
    message: Message,
    metadata: dict[str, Any] | None = None,
    configuration: MessageSendConfiguration | None = None,
) -> SendMessageResponse

Send a message using the A2A protocol.

Returns a JSON-RPC response containing either a result (Task) or an error.

Returns

SendMessageResponse

UnexpectedResponseError

Bases: Exception

An error raised when an unexpected response is received from the server.