a2a

package
v1.1.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 7, 2026 License: Apache-2.0 Imports: 20 Imported by: 0

Documentation

Overview

Package a2a provides thin, host-oriented client primitives for remote A2A agents.

The package deliberately stays protocol-shaped:

  • it fetches, validates, and caches Agent Cards
  • it exposes Send, SendStream, Subscribe, GetTask, and CancelTask
  • it preserves task IDs, context IDs, status, artifacts, raw protocol payloads, and protocol errors in stable agent-adaptor-owned DTOs
  • it surfaces typed protocol errors without pretending remote traffic has local process Result semantics

The implementation delegates discovery and wire transports to the official github.com/a2aproject/a2a-go/v2 SDK.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrInvalidAgentCard identifies invalid or incomplete discovery documents.
	ErrInvalidAgentCard = errors.New("a2a client: invalid agent card")
	// ErrProtocol identifies malformed or unexpected A2A protocol data.
	ErrProtocol = errors.New("a2a client: protocol error")
	// ErrUnauthorized identifies authentication or authorization failures.
	ErrUnauthorized = errors.New("a2a client: unauthorized")
	// ErrNotFound identifies a remote task that does not exist.
	ErrNotFound = errors.New("a2a client: task not found")
	// ErrUnsupported identifies an operation the remote endpoint cannot perform.
	ErrUnsupported = errors.New("a2a client: unsupported operation")
	// ErrUntrustedOrigin identifies an endpoint that is not allowed to receive credentials.
	ErrUntrustedOrigin = errors.New("a2a client: untrusted origin")
)

Functions

This section is empty.

Types

type AgentCard

type AgentCard struct {
	// Name is the agent's display name.
	Name string
	// Description explains the agent's purpose.
	Description string
	// URL is the preferred endpoint advertised by the agent.
	URL string
	// Version is the agent implementation version.
	Version string
	// DocumentationURL points to human-readable agent documentation.
	DocumentationURL string
	// IconURL points to the agent's display icon.
	IconURL string
	// Provider identifies the organization operating the agent, when declared.
	Provider *Provider
	// Capabilities describes optional protocol behavior.
	Capabilities Capabilities
	// DefaultInputModes lists accepted input media types.
	DefaultInputModes []string
	// DefaultOutputModes lists produced output media types.
	DefaultOutputModes []string
	// Skills describes the operations advertised by the agent.
	Skills []Skill
	// SupportedInterfaces lists usable protocol endpoints.
	SupportedInterfaces []AgentInterface
	// Fingerprint is a deterministic digest of the validated discovery document.
	Fingerprint string
	// Raw preserves the normalized discovery payload.
	Raw map[string]any
}

AgentCard is the validated discovery document returned by AgentCard.

type AgentInterface

type AgentInterface struct {
	// URL is the absolute endpoint URL.
	URL string
	// ProtocolBinding identifies the endpoint's transport binding.
	ProtocolBinding TransportProtocol
	// Tenant is the endpoint's optional tenant selector.
	Tenant string
	// ProtocolVersion is the A2A protocol version implemented by the endpoint.
	ProtocolVersion string
}

AgentInterface describes one protocol endpoint advertised by an agent.

type Artifact

type Artifact struct {
	// ID is the artifact identifier.
	ID string
	// Name is the artifact's display name.
	Name string
	// Description explains the artifact contents.
	Description string
	// Parts contains the ordered artifact content.
	Parts []Part
	// Extensions lists extension URIs used by the artifact.
	Extensions []string
	// Metadata preserves application-defined artifact metadata.
	Metadata map[string]any
	// Raw preserves the normalized protocol artifact.
	Raw map[string]any
}

Artifact is one output produced by an A2A task.

type Auth

type Auth interface {
	Wrap(base http.RoundTripper) http.RoundTripper
	Headers() map[string]string
}

Auth attaches client-owned credentials to discovery and protocol requests.

func BearerToken

func BearerToken(token string) Auth

BearerToken returns authentication that sends token as an HTTP bearer credential to trusted A2A origins. An empty token sends no credential.

func BearerTokenFromEnv

func BearerTokenFromEnv(name string) Auth

BearerTokenFromEnv reads name immediately and returns bearer authentication for the resulting value. An unset or empty variable sends no credential.

type CancelTaskRequest

type CancelTaskRequest struct {
	// TaskID identifies the task to cancel.
	TaskID string
	// Tenant selects the remote tenant when supported.
	Tenant string
	// Metadata contains application-defined cancellation metadata.
	Metadata map[string]any
}

CancelTaskRequest identifies a task to cancel.

type Capabilities

type Capabilities struct {
	// Streaming reports support for streaming message execution.
	Streaming bool
	// PushNotifications reports support for push notification configuration.
	PushNotifications bool
	// ExtendedAgentCard reports support for authenticated extended discovery.
	ExtendedAgentCard bool
	// Extensions lists additional advertised protocol features.
	Extensions []Extension
}

Capabilities describes optional behavior advertised by an A2A agent.

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client discovers an A2A agent and invokes its task protocol. A Client is safe for concurrent use.

func New

func New(opts Options) *Client

New constructs a lazy Client. Discovery and protocol validation occur on the first operation that contacts the remote agent.

func (*Client) AgentCard

func (c *Client) AgentCard(ctx context.Context) (AgentCard, error)

AgentCard returns the validated and normalized discovery document.

func (*Client) CancelTask

func (c *Client) CancelTask(ctx context.Context, req CancelTaskRequest) (Task, error)

CancelTask requests cancellation and returns the remote task state reported by the server.

func (*Client) Close

func (c *Client) Close() error

Close releases transports owned by the underlying A2A client. It is safe to call before the client has performed discovery.

func (*Client) GetTask

func (c *Client) GetTask(ctx context.Context, req GetTaskRequest) (Task, error)

GetTask retrieves the current state of one remote task.

func (*Client) Send

func (c *Client) Send(ctx context.Context, req SendRequest) (Task, error)

Send sends one message and waits for the remote operation's immediate protocol result.

func (*Client) SendStream

func (c *Client) SendStream(ctx context.Context, req SendRequest) (*Stream, error)

SendStream sends one message and returns its ordered stream of A2A events.

func (*Client) Subscribe

func (c *Client) Subscribe(ctx context.Context, req SubscribeRequest) (*Stream, error)

Subscribe returns a stream of subsequent events for an existing task.

type Event

type Event struct {
	// Kind identifies the event payload and lifecycle meaning.
	Kind EventKind
	// Task contains a full task snapshot for task events.
	Task *Task
	// Message contains a message event payload.
	Message *Message
	// Status contains a status update payload.
	Status *TaskStatus
	// Artifact contains an artifact update payload.
	Artifact *Artifact
	// TaskID identifies the affected task.
	TaskID string
	// ContextID identifies the affected conversation context.
	ContextID string
	// Append reports that artifact content appends to earlier content.
	Append bool
	// LastChunk reports that an artifact update is complete.
	LastChunk bool
	// RecoveredState reports that the terminal event was reconstructed with GetTask.
	RecoveredState bool
	// Raw preserves the normalized protocol event.
	Raw map[string]any
}

Event is one ordered A2A stream/subscription update.

type EventKind

type EventKind string

EventKind identifies the normalized payload carried by an Event.

const (
	// EventTask carries a full task snapshot.
	EventTask EventKind = "task"
	// EventMessage carries a standalone message.
	EventMessage EventKind = "message"
	// EventStatus carries a task status update.
	EventStatus EventKind = "status"
	// EventArtifact carries an artifact update.
	EventArtifact EventKind = "artifact"
	// EventTerminal carries the final recovered or observed task state.
	EventTerminal EventKind = "terminal"
)

type Extension

type Extension struct {
	// URI uniquely identifies the extension contract.
	URI string
	// Description explains the extension's behavior.
	Description string
	// Required reports whether clients must understand the extension.
	Required bool
	// Params preserves extension-specific parameters.
	Params map[string]any
}

Extension is one optional protocol feature declared by an agent.

type GetTaskRequest

type GetTaskRequest struct {
	// TaskID identifies the task to retrieve.
	TaskID string
	// Tenant selects the remote tenant when supported.
	Tenant string
	// HistoryLength limits message history returned with the task.
	HistoryLength *int
}

GetTaskRequest identifies a task snapshot to retrieve.

type Message

type Message struct {
	// ID is the message identifier assigned by its producer.
	ID string
	// Role identifies the message author role.
	Role string
	// TaskID associates the message with a task, when available.
	TaskID string
	// ContextID associates the message with a remote conversation context.
	ContextID string
	// Parts contains the ordered message content.
	Parts []Part
	// ReferenceTasks lists tasks referenced by this message.
	ReferenceTasks []string
	// Extensions lists extension URIs used by this message.
	Extensions []string
	// Metadata preserves application-defined message metadata.
	Metadata map[string]any
	// Raw preserves the normalized protocol message.
	Raw map[string]any
}

Message is an A2A message projected into a stable local shape.

type Options

type Options struct {
	// AgentCardURL is the absolute URL used to discover the remote agent.
	AgentCardURL string
	// AgentCardPath overrides the discovery path derived from AgentCardURL.
	AgentCardPath string
	// Auth supplies credentials for trusted discovery and agent endpoints.
	Auth Auth
	// HTTPClient supplies transport settings. A nil value uses http.DefaultClient.
	HTTPClient *http.Client
	// TrustedAuthOrigins are additional absolute origins allowed to receive Auth.
	TrustedAuthOrigins []string
	// AcceptedOutputModes restrict the media types accepted from the agent.
	AcceptedOutputModes []string
	// PreferredTransports orders the protocol bindings considered by discovery.
	PreferredTransports []TransportProtocol
}

Options configures discovery, authentication, and protocol negotiation for a Client.

type Part

type Part struct {
	// Kind identifies which content field is populated.
	Kind PartKind
	// Text contains text content.
	Text string
	// Raw contains inline binary content.
	Raw []byte
	// Data contains structured data content.
	Data any
	// URL identifies remotely hosted content.
	URL string
	// MediaType is the content MIME type.
	MediaType string
	// Filename is the suggested content filename.
	Filename string
	// Metadata preserves application-defined part metadata.
	Metadata map[string]any
}

Part is one typed content part in an A2A message or artifact.

type PartKind

type PartKind string

PartKind identifies the representation used by a Part.

const (
	// PartText identifies UTF-8 text content.
	PartText PartKind = "text"
	// PartRaw identifies inline binary content.
	PartRaw PartKind = "raw"
	// PartData identifies structured data content.
	PartData PartKind = "data"
	// PartURL identifies content referenced by URL.
	PartURL PartKind = "url"
)

type ProtocolError

type ProtocolError struct {
	// Op is the protocol operation that failed.
	Op string
	// Reason is the remote or validation error description.
	Reason string
	// Cause supports errors.Is and errors.As classification.
	Cause error
	// Raw preserves structured error details when the transport provides them.
	Raw map[string]any
}

ProtocolError records the A2A operation, normalized reason, causal error, and any structured protocol details observed for a failed request.

func (*ProtocolError) Error

func (e *ProtocolError) Error() string

func (*ProtocolError) Unwrap

func (e *ProtocolError) Unwrap() error

type Provider

type Provider struct {
	// Organization is the provider's display name.
	Organization string
	// URL is the provider's public URL.
	URL string
}

Provider identifies the organization responsible for an A2A agent.

type SendRequest

type SendRequest struct {
	// Message is the message to send.
	Message Message
	// ContextID continues a remote conversation context when non-empty.
	ContextID string
	// TaskID associates the message with an existing task when non-empty.
	TaskID string
	// Tenant selects the remote tenant when supported.
	Tenant string
	// AcceptedOutputModes restricts acceptable response media types.
	AcceptedOutputModes []string
	// ReturnImmediately requests an immediate protocol response.
	ReturnImmediately bool
	// HistoryLength limits task history returned with the result.
	HistoryLength *int
	// Metadata contains application-defined request metadata.
	Metadata map[string]any
}

SendRequest configures one Send or SendStream operation.

type Skill

type Skill struct {
	// ID is the stable protocol identifier for the skill.
	ID string
	// Name is the skill's display name.
	Name string
	// Description explains the skill's behavior.
	Description string
	// Tags provide discovery keywords.
	Tags []string
	// Examples contain representative requests.
	Examples []string
	// InputModes lists accepted media types for the skill.
	InputModes []string
	// OutputModes lists media types the skill may produce.
	OutputModes []string
}

Skill describes one operation advertised in an AgentCard.

type Stream

type Stream struct {
	// contains filtered or unexported fields
}

Stream is an ordered remote A2A event stream.

func (*Stream) Close

func (s *Stream) Close() error

Close cancels the stream and waits until its event producer has stopped.

func (*Stream) Recv

func (s *Stream) Recv() (Event, error)

Recv waits for the next event. It returns io.EOF after the stream closes.

func (*Stream) RecvContext

func (s *Stream) RecvContext(ctx context.Context) (Event, error)

RecvContext waits for the next stream event or context cancellation.

type StreamRecoveryError

type StreamRecoveryError struct {
	// TaskID is the last task identifier observed before disconnection.
	TaskID string
	// Cause is the transport or protocol error that ended the stream.
	Cause error
}

StreamRecoveryError reports a disconnected stream whose terminal task state could not be recovered.

func (*StreamRecoveryError) Error

func (e *StreamRecoveryError) Error() string

func (*StreamRecoveryError) Unwrap

func (e *StreamRecoveryError) Unwrap() error

type SubscribeRequest

type SubscribeRequest struct {
	// TaskID identifies the task to subscribe to.
	TaskID string
	// Tenant selects the remote tenant when supported.
	Tenant string
	// Since is rejected when set. A2A 1.0 SubscribeToTask has no cursor replay
	// field, and the client refuses to pretend host-side replay cursors are
	// supported by the remote protocol.
	Since string
}

SubscribeRequest identifies an existing task to observe.

type Task

type Task struct {
	// ID is the remote task identifier.
	ID string
	// ContextID is the remote conversation context identifier.
	ContextID string
	// Status is the task's current execution state.
	Status TaskStatus
	// Messages contains task conversation history returned by the server.
	Messages []Message
	// Artifacts contains outputs produced by the task.
	Artifacts []Artifact
	// Metadata preserves application-defined task metadata.
	Metadata map[string]any
	// Raw preserves the normalized protocol task.
	Raw map[string]any
}

Task is a normalized snapshot of one remote A2A task.

type TaskState

type TaskState string

TaskState identifies an A2A task lifecycle state.

const (
	// TaskStateUnspecified means no task state was reported.
	TaskStateUnspecified TaskState = ""
	// TaskStateSubmitted means the task has been accepted but not started.
	TaskStateSubmitted TaskState = "TASK_STATE_SUBMITTED"
	// TaskStateWorking means the task is executing.
	TaskStateWorking TaskState = "TASK_STATE_WORKING"
	// TaskStateCompleted means the task completed successfully.
	TaskStateCompleted TaskState = "TASK_STATE_COMPLETED"
	// TaskStateFailed means the task terminated with failure.
	TaskStateFailed TaskState = "TASK_STATE_FAILED"
	// TaskStateCanceled means the task was canceled.
	TaskStateCanceled TaskState = "TASK_STATE_CANCELED"
	// TaskStateInputRequired means the task is waiting for user input.
	TaskStateInputRequired TaskState = "TASK_STATE_INPUT_REQUIRED"
	// TaskStateRejected means the task was rejected.
	TaskStateRejected TaskState = "TASK_STATE_REJECTED"
	// TaskStateAuthRequired means the task is waiting for authentication.
	TaskStateAuthRequired TaskState = "TASK_STATE_AUTH_REQUIRED"
)

func (TaskState) Terminal

func (s TaskState) Terminal() bool

Terminal reports whether s represents a final task state.

type TaskStatus

type TaskStatus struct {
	// State is the normalized task lifecycle state.
	State TaskState
	// Message provides status detail when supplied by the server.
	Message *Message
	// Timestamp is the server-reported status time.
	Timestamp *time.Time
}

TaskStatus describes the current state and optional status message of a task.

type TransportProtocol

type TransportProtocol string

TransportProtocol names an A2A transport binding.

const (
	// TransportJSONRPC selects the A2A JSON-RPC transport binding.
	TransportJSONRPC TransportProtocol = "JSONRPC"
	// TransportHTTPJSON selects the A2A HTTP+JSON transport binding.
	TransportHTTPJSON TransportProtocol = "HTTP+JSON"
)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL