a2a

package
v0.1.0-alpha.4 Latest Latest
Warning

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

Go to latest
Published: Jan 28, 2026 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MethodSendMessage = "message/send"
	MethodGetTask     = "tasks/get"
	MethodListTasks   = "tasks/list"
	MethodCancelTask  = "tasks/cancel"
)

A2A JSON-RPC method names.

View Source
const (
	ParseError     = -32700
	InvalidRequest = -32600
	MethodNotFound = -32601
	InvalidParams  = -32602
	InternalError  = -32603
)

Standard JSON-RPC error codes.

View Source
const (
	ErrTaskNotFound         = -32001
	ErrTaskNotCancellable   = -32002
	ErrUnsupportedOperation = -32003
)

A2A-specific error codes.

View Source
const ProtocolVersion = "1.0"

ProtocolVersion is the A2A protocol version supported by this implementation.

Variables

This section is empty.

Functions

This section is empty.

Types

type A2AAgentStatus

type A2AAgentStatus struct {
	Name        string   `json:"name"`
	Role        string   `json:"role"` // "local" or "remote"
	URL         string   `json:"url,omitempty"`
	Endpoint    string   `json:"endpoint,omitempty"`
	Available   bool     `json:"available"`
	SkillCount  int      `json:"skillCount"`
	Skills      []string `json:"skills"`
	Description string   `json:"description,omitempty"`
}

A2AAgentStatus contains status information for an A2A agent.

type AgentCapabilities

type AgentCapabilities struct {
}

AgentCapabilities describes what the agent supports. Note: Currently empty as streaming, push notifications, and state transition history are not implemented. This struct is retained for A2A protocol compatibility.

type AgentCard

type AgentCard struct {
	Name               string            `json:"name"`
	Description        string            `json:"description,omitempty"`
	URL                string            `json:"url"`
	Version            string            `json:"version,omitempty"`
	Provider           *Provider         `json:"provider,omitempty"`
	DocumentationURL   string            `json:"documentationUrl,omitempty"`
	Capabilities       AgentCapabilities `json:"capabilities"`
	Skills             []Skill           `json:"skills"`
	DefaultInputModes  []string          `json:"defaultInputModes,omitempty"`
	DefaultOutputModes []string          `json:"defaultOutputModes,omitempty"`
}

AgentCard represents the A2A Agent Card for discovery. Served at /.well-known/agent.json

type Artifact

type Artifact struct {
	ID          string `json:"id"`
	Name        string `json:"name,omitempty"`
	Description string `json:"description,omitempty"`
	Parts       []Part `json:"parts"`
	Index       int    `json:"index,omitempty"`
}

Artifact represents task output artifacts.

type CancelTaskParams

type CancelTaskParams struct {
	ID string `json:"id"`
}

CancelTaskParams contains parameters for tasks/cancel request.

type Client

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

Client communicates with a remote A2A agent.

func NewClient

func NewClient(name, endpoint string) *Client

NewClient creates a new A2A client.

func (*Client) AgentCard

func (c *Client) AgentCard() *AgentCard

AgentCard returns the cached agent card.

func (*Client) CancelTask

func (c *Client) CancelTask(ctx context.Context, taskID string) (*Task, error)

CancelTask cancels a running task.

func (*Client) Endpoint

func (c *Client) Endpoint() string

Endpoint returns the agent's endpoint URL.

func (*Client) FetchAgentCard

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

FetchAgentCard retrieves the agent card from /.well-known/agent.json

func (*Client) GetTask

func (c *Client) GetTask(ctx context.Context, taskID string, historyLength int) (*Task, error)

GetTask retrieves task status.

func (*Client) IsAvailable

func (c *Client) IsAvailable() bool

IsAvailable returns true if the agent is reachable.

func (*Client) ListTasks

func (c *Client) ListTasks(ctx context.Context, params ListTasksParams) (*ListTasksResult, error)

ListTasks lists tasks matching the criteria.

func (*Client) Name

func (c *Client) Name() string

Name returns the local name alias for this agent.

func (*Client) Ping

func (c *Client) Ping(ctx context.Context) error

Ping checks if the agent is reachable by fetching its agent card.

func (*Client) SendMessage

func (c *Client) SendMessage(ctx context.Context, params SendMessageParams) (*SendMessageResult, error)

SendMessage sends a message to the remote agent.

func (*Client) SetAuth

func (c *Client) SetAuth(authType, token, headerName string)

SetAuth configures authentication for the client.

type Error

type Error struct {
	Code    int    `json:"code"`
	Message string `json:"message"`
	Data    any    `json:"data,omitempty"`
}

Error represents a JSON-RPC 2.0 error.

type FilePart

type FilePart struct {
	Name     string `json:"name,omitempty"`
	MimeType string `json:"mimeType,omitempty"`
	Bytes    string `json:"bytes,omitempty"` // base64 encoded
	URI      string `json:"uri,omitempty"`
}

FilePart represents file content in a message.

type Gateway

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

Gateway manages A2A agents - both local (server role) and remote (client role).

func NewGateway

func NewGateway(baseURL string) *Gateway

NewGateway creates a new A2A gateway.

func (*Gateway) AggregatedSkills

func (g *Gateway) AggregatedSkills() []Skill

AggregatedSkills returns all skills from all agents (local and remote).

func (*Gateway) GetRemoteAgent

func (g *Gateway) GetRemoteAgent(name string) *Client

GetRemoteAgent returns a remote agent client by name.

func (*Gateway) GetTask

func (g *Gateway) GetTask(ctx context.Context, taskID string) (*Task, error)

GetTask retrieves a task by ID.

func (*Gateway) Handler

func (g *Gateway) Handler() *Handler

Handler returns the HTTP handler for A2A endpoints.

func (*Gateway) ListRemoteAgents

func (g *Gateway) ListRemoteAgents() []*Client

ListRemoteAgents returns all registered remote agents.

func (*Gateway) RegisterLocalAgent

func (g *Gateway) RegisterLocalAgent(name string, card AgentCard, handler TaskHandler)

RegisterLocalAgent registers an agent that this gateway serves (server role).

func (*Gateway) RegisterRemoteAgent

func (g *Gateway) RegisterRemoteAgent(ctx context.Context, name, endpoint string, authType, authToken, authHeader string) error

RegisterRemoteAgent registers an external A2A agent (client role).

func (*Gateway) SendMessage

func (g *Gateway) SendMessage(ctx context.Context, targetAgent string, params SendMessageParams) (*SendMessageResult, error)

SendMessage routes a message to the appropriate agent.

func (*Gateway) Status

func (g *Gateway) Status() []A2AAgentStatus

Status returns status of all A2A agents.

func (*Gateway) UnregisterLocalAgent

func (g *Gateway) UnregisterLocalAgent(name string)

UnregisterLocalAgent removes a local agent.

func (*Gateway) UnregisterRemoteAgent

func (g *Gateway) UnregisterRemoteAgent(name string)

UnregisterRemoteAgent removes a remote agent.

type GetTaskParams

type GetTaskParams struct {
	ID            string `json:"id"`
	HistoryLength int    `json:"historyLength,omitempty"`
}

GetTaskParams contains parameters for tasks/get request.

type Handler

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

Handler provides HTTP handlers for A2A protocol endpoints.

func NewHandler

func NewHandler(baseURL string) *Handler

NewHandler creates a new A2A HTTP handler.

func (*Handler) GetLocalAgent

func (h *Handler) GetLocalAgent(name string) *LocalAgent

GetLocalAgent returns a local agent by name.

func (*Handler) ListLocalAgents

func (h *Handler) ListLocalAgents() []AgentCard

ListLocalAgents returns all registered local agents.

func (*Handler) RegisterLocalAgent

func (h *Handler) RegisterLocalAgent(name string, agent *LocalAgent)

RegisterLocalAgent registers an agent that this gateway serves.

func (*Handler) ServeHTTP

func (h *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP routes A2A HTTP requests.

func (*Handler) UnregisterLocalAgent

func (h *Handler) UnregisterLocalAgent(name string)

UnregisterLocalAgent removes a local agent.

type ListTasksParams

type ListTasksParams struct {
	ContextID string    `json:"contextId,omitempty"`
	Status    TaskState `json:"status,omitempty"`
	PageSize  int       `json:"pageSize,omitempty"`
	PageToken string    `json:"pageToken,omitempty"`
}

ListTasksParams contains parameters for tasks/list request.

type ListTasksResult

type ListTasksResult struct {
	Tasks         []Task `json:"tasks"`
	NextPageToken string `json:"nextPageToken,omitempty"`
}

ListTasksResult is the response to tasks/list.

type LocalAgent

type LocalAgent struct {
	Card    AgentCard
	Handler TaskHandler
}

LocalAgent represents an A2A agent served by this gateway.

type Message

type Message struct {
	ID       string            `json:"messageId"`
	Role     MessageRole       `json:"role"`
	Parts    []Part            `json:"parts"`
	Metadata map[string]string `json:"metadata,omitempty"`
}

Message represents a conversational message in A2A.

func NewTextMessage

func NewTextMessage(role MessageRole, text string) Message

NewTextMessage creates a message with a single text part.

type MessageRole

type MessageRole string

MessageRole indicates the sender of a message.

const (
	RoleUser  MessageRole = "user"
	RoleAgent MessageRole = "agent"
)

type Part

type Part struct {
	Type     PartType          `json:"type"`
	Text     string            `json:"text,omitempty"`
	File     *FilePart         `json:"file,omitempty"`
	Data     json.RawMessage   `json:"data,omitempty"`
	Metadata map[string]string `json:"metadata,omitempty"`
}

Part represents a content part in a message.

func NewTextPart

func NewTextPart(text string) Part

NewTextPart creates a text content part.

type PartType

type PartType string

PartType indicates the type of content in a part.

const (
	PartTypeText PartType = "text"
	PartTypeFile PartType = "file"
	PartTypeData PartType = "data"
)

type Provider

type Provider struct {
	Organization string `json:"organization"`
	URL          string `json:"url,omitempty"`
}

Provider describes the organization providing the agent.

type Request

type Request struct {
	JSONRPC string           `json:"jsonrpc"`
	ID      *json.RawMessage `json:"id,omitempty"`
	Method  string           `json:"method"`
	Params  json.RawMessage  `json:"params,omitempty"`
}

Request represents a JSON-RPC 2.0 request.

type Response

type Response struct {
	JSONRPC string           `json:"jsonrpc"`
	ID      *json.RawMessage `json:"id,omitempty"`
	Result  any              `json:"result,omitempty"`
	Error   *Error           `json:"error,omitempty"`
}

Response represents a JSON-RPC 2.0 response.

func NewErrorResponse

func NewErrorResponse(id *json.RawMessage, code int, message string) Response

NewErrorResponse creates a JSON-RPC error response.

func NewSuccessResponse

func NewSuccessResponse(id *json.RawMessage, result any) Response

NewSuccessResponse creates a JSON-RPC success response.

type SendMessageParams

type SendMessageParams struct {
	Message   Message           `json:"message"`
	ContextID string            `json:"contextId,omitempty"`
	Metadata  map[string]string `json:"metadata,omitempty"`
}

SendMessageParams contains parameters for message/send request.

type SendMessageResult

type SendMessageResult struct {
	Task    *Task    `json:"task,omitempty"`
	Message *Message `json:"message,omitempty"`
}

SendMessageResult is the response to message/send.

type Skill

type Skill struct {
	ID          string   `json:"id"`
	Name        string   `json:"name"`
	Description string   `json:"description,omitempty"`
	Tags        []string `json:"tags,omitempty"`
	Examples    []string `json:"examples,omitempty"`
}

Skill represents a distinct capability the agent exposes.

type Task

type Task struct {
	ID        string            `json:"id"`
	ContextID string            `json:"contextId,omitempty"`
	Status    TaskStatus        `json:"status"`
	Messages  []Message         `json:"messages,omitempty"`
	Artifacts []Artifact        `json:"artifacts,omitempty"`
	Metadata  map[string]string `json:"metadata,omitempty"`
	CreatedAt time.Time         `json:"createdAt"`
	UpdatedAt time.Time         `json:"updatedAt"`
}

Task represents an A2A task.

type TaskHandler

type TaskHandler func(ctx context.Context, task *Task, msg *Message) (*Task, error)

TaskHandler is a function that processes A2A messages for a local agent.

type TaskState

type TaskState string

TaskState represents the current state of a task.

const (
	TaskStateSubmitted     TaskState = "submitted"
	TaskStateWorking       TaskState = "working"
	TaskStateInputRequired TaskState = "input_required"
	TaskStateCompleted     TaskState = "completed"
	TaskStateFailed        TaskState = "failed"
	TaskStateCancelled     TaskState = "cancelled"
	TaskStateRejected      TaskState = "rejected"
)

func (TaskState) IsTerminal

func (s TaskState) IsTerminal() bool

IsTerminal returns true if the state is a terminal state.

type TaskStatus

type TaskStatus struct {
	State   TaskState `json:"state"`
	Message string    `json:"message,omitempty"`
}

TaskStatus represents the status of a task.

Jump to

Keyboard shortcuts

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