Documentation
¶
Overview ¶
Package protocol A2A Agent Card. Current version: 0.2.2
Index ¶
- Constants
- type AgentCapabilities
- type AgentCard
- func (c *AgentCard) AddSkill(_, name, description string) *AgentCard
- func (c *AgentCard) WithCapabilities(capabilities AgentCapabilities) *AgentCard
- func (c *AgentCard) WithDefaultInputModes(modes []string) *AgentCard
- func (c *AgentCard) WithDefaultOutputModes(modes []string) *AgentCard
- func (c *AgentCard) WithDescription(desc string) *AgentCard
- func (c *AgentCard) WithDocumentationURL(url string) *AgentCard
- func (c *AgentCard) WithName(name string) *AgentCard
- func (c *AgentCard) WithProvider(provider AgentProvider) *AgentCard
- func (c *AgentCard) WithSkills(skills []AgentSkill) *AgentCard
- func (c *AgentCard) WithURL(url string) *AgentCard
- func (c *AgentCard) WithVersion(version string) *AgentCard
- type AgentExtension
- type AgentProvider
- type AgentSkill
- type Artifact
- type Client
- type DataPart
- type FilePart
- type FileWithBytes
- type FileWithURI
- type Handler
- type JSONRPCError
- type JSONRPCRequest
- type JSONRPCResponse
- type Kind
- type Message
- func (m *Message) AddExtensions(ext ...string) *Message
- func (m *Message) AddMetadata(key string, value any) *Message
- func (m *Message) AddPart(part Part) *Message
- func (m *Message) AddReferenceTaskIDs(ids ...string) *Message
- func (m *Message) WithContextID(contextID string) *Message
- func (m *Message) WithMessageID(id string) *Message
- func (m *Message) WithRole(role string) *Message
- func (m *Message) WithTaskID(taskID string) *Message
- type MessageSendConfiguration
- type MessageSendParams
- type MsgHandler
- type Part
- type PartBase
- type PartKind
- type Parts
- type PushNotificationAuthenticationInfo
- type PushNotificationConfig
- type Server
- type Task
- type TaskPushNotificationConfig
- type TaskState
- type TaskStatus
- type TextPart
Constants ¶
const ( // -32700: Invalid JSON payload ErrCodeParseError = -32700 // -32600: Invalid JSON-RPC Request ErrCodeInvalidRequest = -32600 // -32601: Method not found ErrCodeMethodNotFound = -32601 // -32602: Invalid method parameters ErrCodeInvalidParams = -32602 // -32603: Internal server error ErrCodeInternalError = -32603 // -32000 to -32099: Reserved for server-defined errors (A2A-specific) ErrCodeServerErrorStart = -32099 ErrCodeServerErrorEnd = -32000 )
JSON-RPC 2.0 standard error codes (per A2A specification)
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AgentCapabilities ¶
type AgentCapabilities struct {
Streaming *bool `json:"streaming,omitempty"`
PushNotifications *bool `json:"pushNotifications,omitempty"`
StateTransitionHistory *bool `json:"stateTransitionHistory,omitempty"`
Extensions []AgentExtension `json:"extensions,omitempty"`
}
AgentCapabilities defines the capabilities of the agent as per the A2A specification.
type AgentCard ¶
type AgentCard struct {
Name string `json:"name"`
Description string `json:"description"`
URL string `json:"url"`
IconURL *string `json:"iconUrl,omitempty"`
Provider *AgentProvider `json:"provider,omitempty"`
Version string `json:"version"`
DocumentationURL *string `json:"documentationUrl,omitempty"`
Capabilities AgentCapabilities `json:"capabilities"`
SecuritySchemes map[string]string `json:"securitySchemes,omitempty"`
Security []map[string][]string `json:"security,omitempty"`
DefaultInputModes []string `json:"defaultInputModes"`
DefaultOutputModes []string `json:"defaultOutputModes"`
Skills []AgentSkill `json:"skills"`
SupportsAuthenticatedExtendedCard *bool `json:"supportsAuthenticatedExtendedCard,omitempty"`
}
AgentCard represents the A2A Agent Card as defined in the A2A specification. SecurityScheme isn't implemented yet, but should be defined as per the A2A spec. Check docs for it: https://google-a2a.github.io/A2A/latest/specification/#553-securityscheme-object
func NewAgentCard ¶ added in v0.2.1
func NewAgentCard() *AgentCard
NewAgentCard creates and returns a new AgentCard with default values.
func (*AgentCard) AddSkill ¶ added in v0.2.1
AddSkill appends a single skill to the agent's skill list.
func (*AgentCard) WithCapabilities ¶ added in v0.2.1
func (c *AgentCard) WithCapabilities(capabilities AgentCapabilities) *AgentCard
WithCapabilities sets the agent's declared capabilities.
func (*AgentCard) WithDefaultInputModes ¶ added in v0.2.1
WithDefaultInputModes sets the default input modes supported by the agent.
func (*AgentCard) WithDefaultOutputModes ¶ added in v0.2.1
WithDefaultOutputModes sets the default output modes supported by the agent.
func (*AgentCard) WithDescription ¶ added in v0.2.1
WithDescription sets the description of the agent card.
func (*AgentCard) WithDocumentationURL ¶ added in v0.2.1
WithDocumentationURL sets the optional documentation URL for the agent.
func (*AgentCard) WithProvider ¶ added in v0.2.1
func (c *AgentCard) WithProvider(provider AgentProvider) *AgentCard
WithProvider sets the provider information of the agent.
func (*AgentCard) WithSkills ¶ added in v0.2.1
func (c *AgentCard) WithSkills(skills []AgentSkill) *AgentCard
WithSkills sets the list of skills for the agent.
func (*AgentCard) WithVersion ¶ added in v0.2.1
WithVersion sets the version string of the agent.
type AgentExtension ¶
type AgentExtension struct {
URI string `json:"uri"`
Description *string `json:"description,omitempty"`
Required *bool `json:"required,omitempty"`
Params map[string]any `json:"params,omitempty"`
}
AgentExtension represents an extension that can be used by the agent.
type AgentProvider ¶
AgentProvider represents the organization and URL of the agent provider.
type AgentSkill ¶
type AgentSkill struct {
ID string `json:"id"`
Name string `json:"name"`
Description string `json:"description"`
Tags []string `json:"tags"`
Examples []string `json:"examples,omitempty"`
InputModes []string `json:"inputModes,omitempty"`
OutputModes []string `json:"outputModes,omitempty"`
}
AgentSkill represents a skill that the agent can perform.
type Artifact ¶
type Artifact struct {
ArtifactID string `json:"artifactId"` // Required: unique identifier
Name *string `json:"name,omitempty"` // Optional: human-readable name
Description *string `json:"description,omitempty"` // Optional: human-readable description
Parts []map[string]any `json:"parts"` // Required: parts (can be refined later)
Metadata map[string]any `json:"metadata,omitempty"` // Optional: extension metadata
Extensions []string `json:"extensions,omitempty"` // Optional: contributed extension URIs
}
Artifact represents an object with various attributes and metadata.
type Client ¶
type Client interface {
SendMessage(question *MessageSendParams) (*JSONRPCResponse, error)
StreamMessage()
GetTask()
CancelTask()
}
Client represents the interface for a protocol client.
type DataPart ¶
type DataPart struct {
Kind PartKind `json:"kind"` // Must be "data"
Data map[string]any `json:"data"` // Required structured content
PartBase
}
DataPart represents a data part in a message.
type FilePart ¶
type FilePart struct {
Kind PartKind `json:"kind"` // Must be "file"
File any `json:"file"` // Can be FileWithBytes or FileWithUri
PartBase
}
FilePart represents a file part in a message.
func NewFileBytes ¶
NewFileBytes creates a new FilePart with file content as bytes.
func NewFileURI ¶
NewFileURI creates a new FilePart with a file URI.
func (*FilePart) UnmarshalJSON ¶
UnmarshalJSON unmarshals a JSON representation of FilePart, detecting its file type.
type FileWithBytes ¶
type FileWithBytes struct {
Bytes string `json:"bytes"` // Required: base64-encoded content
}
FileWithBytes represents a file with its content encoded in base64.
type FileWithURI ¶
type FileWithURI struct {
URI string `json:"uri"` // Required: URI to the file
}
FileWithURI represents a file referenced by its URI.
type Handler ¶ added in v0.2.0
type Handler func(next Handler, r *JSONRPCRequest) (*JSONRPCResponse, error)
Handler handles all incoming requests on JSONRPC level
type JSONRPCError ¶
type JSONRPCError struct {
Code int `json:"code"` // Error code indicating the type of error
Message string `json:"message"` // Short description of the error
Data any `json:"data,omitempty"` // Optional additional information (any type)
}
JSONRPCError represents an error in a JSON-RPC response.
type JSONRPCRequest ¶
type JSONRPCRequest struct {
JSONRPC string `json:"jsonrpc"` // MUST be "2.0"
Method string `json:"method"` // e.g., "message/send"
Params any `json:"params,omitempty"` // Can be any structured value (typically an object)
ID any `json:"id,omitempty"` // string, number (int), or nil
}
JSONRPCRequest represents a request in the JSON-RPC protocol.
type JSONRPCResponse ¶
type JSONRPCResponse struct {
JSONRPC string `json:"jsonrpc"` // MUST be "2.0"
ID any `json:"id"` // Same type as in request (string, int, or null)
Result any `json:"result,omitempty"` // Present only on success
Error *JSONRPCError `json:"error,omitempty"` // Present only on failure
}
JSONRPCResponse represents a response to a JSON-RPC request.
func (*JSONRPCResponse) String ¶ added in v0.2.1
func (r *JSONRPCResponse) String() string
func (*JSONRPCResponse) UnmarshalJSON ¶
func (r *JSONRPCResponse) UnmarshalJSON(data []byte) error
UnmarshalJSON implements custom unmarshalling for JSON-RPC responses.
type Kind ¶
type Kind string
Kind represents the type of a protocol entity, such as a task or a message.
type Message ¶
type Message struct {
Role string `json:"role"`
Parts Parts `json:"parts"`
Metadata map[string]any `json:"metadata,omitempty"`
Extensions []string `json:"extensions,omitempty"`
ReferenceTaskIDs []string `json:"referenceTaskIds,omitempty"`
MessageID string `json:"messageId"`
TaskID *string `json:"taskId,omitempty"`
ContextID *string `json:"contextId,omitempty"`
Kind Kind `json:"kind"`
}
Message represents a communication unit between a user and an agent.
func NewMessage ¶ added in v0.2.1
func NewMessage() *Message
NewMessage creates and returns a new Message instance with Kind set to KindMessage.
func (*Message) AddExtensions ¶ added in v0.2.1
AddExtensions appends one or more extensions to the Extensions slice of the Message and returns the updated Message instance.
func (*Message) AddMetadata ¶ added in v0.2.1
AddMetadata adds a key-value pair to the Metadata map of the Message and returns the updated Message instance.
func (*Message) AddPart ¶ added in v0.2.1
AddPart appends a Part to the Parts slice in the Message and returns the updated Message instance.
func (*Message) AddReferenceTaskIDs ¶ added in v0.2.1
AddReferenceTaskIDs appends one or more task IDs to the ReferenceTaskIDs slice of the Message and returns the updated Message instance.
func (*Message) WithContextID ¶ added in v0.2.1
WithContextID sets the ContextID field of the Message and returns the updated Message instance.
func (*Message) WithMessageID ¶ added in v0.2.1
WithMessageID sets the MessageID field of the Message and returns the updated Message instance.
func (*Message) WithRole ¶ added in v0.2.1
WithRole sets the Role field of the Message and returns the updated Message instance.
func (*Message) WithTaskID ¶ added in v0.2.1
WithTaskID sets the TaskID field of the Message and returns the updated Message instance.
type MessageSendConfiguration ¶
type MessageSendConfiguration struct {
AcceptedOutputModes []string `json:"acceptedOutputModes"` // Required
HistoryLength *int `json:"historyLength,omitempty"` // Optional
PushNotificationConfig *PushNotificationConfig `json:"pushNotificationConfig,omitempty"` // Optional
Blocking *bool `json:"blocking,omitempty"` // Optional
}
MessageSendConfiguration defines the configuration for sending a message.
type MessageSendParams ¶
type MessageSendParams struct {
Message *Message `json:"message"` // Required
Configuration *MessageSendConfiguration `json:"configuration,omitempty"` // Optional
Metadata map[string]any `json:"metadata,omitempty"` // Optional key-value extension metadata
}
MessageSendParams defines the parameters for sending a message to an agent.
func NewMessageSendParams ¶ added in v0.2.1
func NewMessageSendParams() *MessageSendParams
NewMessageSendParams creates a new instance of MessageSendParams for building.
func (*MessageSendParams) WithConfiguration ¶ added in v0.2.1
func (p *MessageSendParams) WithConfiguration(cfg *MessageSendConfiguration) *MessageSendParams
WithConfiguration sets the configuration for sending the message in the MessageSendParams.
func (*MessageSendParams) WithMessage ¶ added in v0.2.1
func (p *MessageSendParams) WithMessage(msg *Message) *MessageSendParams
WithMessage sets the message to be sent in the MessageSendParams.
func (*MessageSendParams) WithMetadata ¶ added in v0.2.1
func (p *MessageSendParams) WithMetadata(meta map[string]any) *MessageSendParams
WithMetadata sets the metadata for the message in the MessageSendParams.
type MsgHandler ¶ added in v0.2.0
MsgHandler handles messages received from the A2A server on Message level
type PartBase ¶ added in v0.2.1
PartBase represents the base structure for a part, containing common metadata.
type Parts ¶
type Parts []Part
Parts represents a collection of Part interfaces.
func (*Parts) UnmarshalJSON ¶
UnmarshalJSON implements the json.Unmarshaler interface for Parts.
type PushNotificationAuthenticationInfo ¶
type PushNotificationAuthenticationInfo struct {
Schemes []string `json:"schemes"`
Credentials *string `json:"credentials,omitempty"`
}
PushNotificationAuthenticationInfo provides authentication details used in push notification requests.
type PushNotificationConfig ¶
type PushNotificationConfig struct {
ID *string `json:"id,omitempty"`
URL string `json:"url"`
Token *string `json:"token,omitempty"`
Authentication *PushNotificationAuthenticationInfo `json:"authentication,omitempty"`
}
PushNotificationConfig defines configuration for sending push notifications to an external URL.
type Server ¶
type Server interface {
// ListenAndServe starts the server and listens on the specified port, while signaling readiness.
ListenAndServe() error
// MsgHandler sets the message handler for the server.
MsgHandler(handler MsgHandler)
// Handler sets the handler function for processing requests.
Handler(handler Handler)
// Shutdown stops the server gracefully.
Shutdown() error
// Ready returns a channel that signals when the server is ready to accept requests.
Ready() <-chan bool
}
Server defines the interface for a server that can handle incoming A2A messages
type Task ¶
type Task struct {
ID string `json:"id"` // Required: task ID
ContextID string `json:"contextId"` // Required: contextual alignment
Status TaskStatus `json:"status"` // Required: current status
History []Message `json:"history,omitempty"` // Optional: message history
Artifacts []Artifact `json:"artifacts,omitempty"` // Optional: artifacts created
Metadata map[string]any `json:"metadata,omitempty"` // Optional: extension metadata
Kind Kind `json:"kind"` // Required: must be "task"
}
Task represents a task in the A2A protocol.
type TaskPushNotificationConfig ¶
type TaskPushNotificationConfig struct {
TaskID string `json:"taskId"`
PushNotificationConfig PushNotificationConfig `json:"pushNotificationConfig"`
}
TaskPushNotificationConfig links a task with its push notification configuration.
type TaskState ¶
type TaskState string
TaskState represents the lifecycle state of a task.
const ( // TaskStateSubmitted indicates the task was received by the server and acknowledged, // but processing has not yet started. TaskStateSubmitted TaskState = "submitted" // TaskStateWorking indicates the task is actively being processed by the agent. // The client may expect further updates or a terminal state. TaskStateWorking TaskState = "working" // TaskStateInputRequired indicates the agent requires additional input from the client // or user to proceed. The task is effectively paused. TaskStateInputRequired TaskState = "input-required" // TaskStateCompleted indicates the task finished successfully. // Results are typically available in Task.artifacts or TaskStatus.message. TaskStateCompleted TaskState = "completed" // TaskStateCanceled indicates the task was canceled, for example by a tasks/cancel request // or a server-side policy. TaskStateCanceled TaskState = "canceled" // TaskStateFailed indicates the task terminated due to an error during processing. // TaskStatus.message may contain error details. TaskStateFailed TaskState = "failed" // TaskStateRejected indicates the task was rejected by the remote agent. // TaskStatus.message may contain error details. TaskStateRejected TaskState = "rejected" // TaskStateAuthRequired indicates the agent requires additional authentication to proceed. // The task is effectively paused. TaskStateAuthRequired TaskState = "auth-required" // TaskStateUnknown indicates the state of the task cannot be determined. // This may occur if the task ID is invalid, unknown, or expired. TaskStateUnknown TaskState = "unknown" )
type TaskStatus ¶
type TaskStatus struct {
State TaskState `json:"state"` // Required
Message *Message `json:"message,omitempty"` // Optional: additional status message
Timestamp *string `json:"timestamp,omitempty"` // Optional: ISO 8601 datetime string
}
TaskStatus represents the state of a task in the A2A protocol.
type TextPart ¶
type TextPart struct {
Kind PartKind `json:"kind"` // Must be "text"
Text string `json:"text"` // Required text content
PartBase
}
TextPart represents a text part in a message.