a2a

package module
v0.0.0-...-02a9dc6 Latest Latest
Warning

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

Go to latest
Published: May 5, 2026 License: MIT Imports: 4 Imported by: 0

README ΒΆ

A2A Protocol - Go Implementation

The official Go implementation of the Agent2Agent (A2A) communication protocol for building distributed agent systems with seamless inter-agent communication.

πŸš€ Quick Start

Installation
go get github.com/A2AGateway/a2a-protocol
Basic Usage
package main

import (
    "context"
    "fmt"
    "log"
    
    "github.com/A2AGateway/a2a-protocol"
)

func main() {
    // Create agent card
    agent := &a2aprotocol.AgentCard{
        Name:        "My Agent",
        Description: "A helpful AI agent",
        URL:         "http://localhost:8080",
        Version:     "1.0.0",
        Capabilities: a2aprotocol.AgentCapabilities{
            Streaming:               true,
            PushNotifications:       true,
            StateTransitionHistory:  true,
        },
    }

    // Create protocol handler
    handler := a2aprotocol.NewProtocolHandler(agent)

    // Handle incoming A2A messages
    handler.HandleTaskSend(func(ctx context.Context, params *a2aprotocol.TaskSendParams) (*a2aprotocol.Task, error) {
        // Process the task
        task := &a2aprotocol.Task{
            ID:     params.ID,
            Status: a2aprotocol.TaskStatus{
                State:     "completed",
                Timestamp: time.Now(),
            },
        }
        return task, nil
    })

    // Start A2A server
    log.Fatal(handler.ListenAndServe(":8080"))
}

πŸ”Œ Agent Communication

Sending Messages to Other Agents
package main

import (
    "context"
    "github.com/A2AGateway/a2a-protocol"
)

func sendMessageToAgent() {
    client := a2aprotocol.NewClient()
    
    // Create message
    message := &a2aprotocol.Message{
        Role: "user",
        Parts: []a2aprotocol.Part{
            &a2aprotocol.TextPart{
                Type: "text",
                Text: "Hello from another agent!",
            },
        },
    }
    
    // Send to agent
    task, err := client.SendTask(context.Background(), &a2aprotocol.TaskSendParams{
        ID:      "task-123",
        Message: message,
    }, "http://target-agent:8080")
    
    if err != nil {
        log.Fatal(err)
    }
    
    fmt.Printf("Task sent: %s, Status: %s\n", task.ID, task.Status.State)
}

πŸ“‹ Core Features

  • JSON-RPC 2.0 - Standardized message transport
  • Task Management - Complete task lifecycle support
  • Agent Discovery - Dynamic agent registration and lookup
  • Streaming Support - Real-time response streaming
  • Push Notifications - Event-driven communication
  • Type Safety - Comprehensive Go type definitions
  • Error Handling - Robust error propagation
  • Testing Tools - Built-in testing utilities

πŸ§ͺ Testing

# Run all tests
go test ./...

# Run with coverage
go test -coverprofile=coverage.out ./...
go tool cover -html=coverage.out

# Run benchmarks
go test -bench=. ./...

πŸ”§ Advanced Configuration

// Custom server configuration
config := &a2aprotocol.ServerConfig{
    Host:           "0.0.0.0",
    Port:           8080,
    ReadTimeout:    30 * time.Second,
    WriteTimeout:   30 * time.Second,
    MaxMessageSize: 10 * 1024 * 1024, // 10MB
    EnableCORS:     true,
}

server := a2aprotocol.NewServer(config, handler)

🀝 Contributing

We welcome contributions! Please see our Contributing Guide.

πŸ“„ License

MIT License - see LICENSE file for details.

πŸ†˜ Support


Built with ❀️ by the A2AGateway team

Documentation ΒΆ

Overview ΒΆ

Package a2a implements the A2A protocol operations and data structures This file implements the agent card functionality as defined in the A2A schema

Package a2a implements the A2A protocol operations and data structures This file implements the Artifact structure as defined in the A2A schema

Package a2a implements the A2A protocol operations and data structures This file implements the specific error types defined in the A2A schema

Package a2a implements the A2A protocol operations and data structures This file implements the base JSON-RPC 2.0 request/response structures as defined in the A2A schema

Package a2a implements the A2A protocol operations and data structures This file defines message structures used for communication between agents according to the A2A protocol

Package a2a implements the A2A protocol operations and data structures This file implements the different part types (TextPart, FilePart, DataPart) as defined in the A2A schema

Package a2a implements the A2A protocol operations and data structures This package implements the specification defined in a2a.json schema

Package a2a implements the A2A protocol operations and data structures This file implements push notification functionality as defined in the A2A schema

Package a2a implements the A2A protocol operations and data structures This file defines task structures and operations according to the A2A protocol

Index ΒΆ

Constants ΒΆ

View Source
const (
	ErrCodeParseError                   = -32700
	ErrCodeInvalidRequest               = -32600
	ErrCodeMethodNotFound               = -32601
	ErrCodeInvalidParams                = -32602
	ErrCodeInternalError                = -32603
	ErrCodeTaskNotFound                 = -32001
	ErrCodeTaskNotCancelable            = -32002
	ErrCodePushNotificationNotSupported = -32003
	ErrCodeUnsupportedOperation         = -32004
)

Error codes as defined in the A2A schema

View Source
const JSONRPCVersion = "2.0"

JSONRPCVersion is the version of JSON-RPC used

Variables ΒΆ

This section is empty.

Functions ΒΆ

func ValidateFileContent ΒΆ

func ValidateFileContent(file FileContent) bool

ValidateFileContent validates that the FileContent follows the constraints (either 'bytes' or 'uri' must be provided, but not both)

Types ΒΆ

type AgentAuthentication ΒΆ

type AgentAuthentication struct {
	Schemes     []string `json:"schemes"`
	Credentials *string  `json:"credentials,omitempty"`
}

AgentAuthentication represents the authentication requirements of an agent

type AgentCapabilities ΒΆ

type AgentCapabilities struct {
	Streaming              bool `json:"streaming,omitempty"`
	PushNotifications      bool `json:"pushNotifications,omitempty"`
	StateTransitionHistory bool `json:"stateTransitionHistory,omitempty"`
}

AgentCapabilities represents the capabilities of an agent

type AgentCard ΒΆ

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

AgentCard represents an agent's capabilities according to the A2A protocol

func FromJSON ΒΆ

func FromJSON(data []byte) (*AgentCard, error)

FromJSON parses JSON into an agent card

func NewAgentCard ΒΆ

func NewAgentCard(name, url, version string, capabilities AgentCapabilities, skills []AgentSkill) *AgentCard

NewAgentCard creates a new agent card with required fields

func (*AgentCard) ToJSON ΒΆ

func (a *AgentCard) ToJSON() ([]byte, error)

ToJSON converts the agent card to JSON

func (*AgentCard) Validate ΒΆ

func (a *AgentCard) Validate() bool

Validate checks if the agent card is valid according to the A2A schema

func (*AgentCard) WithDescription ΒΆ

func (a *AgentCard) WithDescription(description string) *AgentCard

WithDescription adds a description to the agent card

func (*AgentCard) WithProvider ΒΆ

func (a *AgentCard) WithProvider(organization string, url *string) *AgentCard

WithProvider adds provider information to the agent card

type AgentProvider ΒΆ

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

AgentProvider represents the provider of an agent

type AgentSkill ΒΆ

type AgentSkill struct {
	ID          string   `json:"id"`
	Name        string   `json:"name"`
	Description *string  `json:"description,omitempty"`
	Tags        []string `json:"tags,omitempty"`
	Examples    []string `json:"examples,omitempty"`
	InputModes  []string `json:"inputModes,omitempty"`
	OutputModes []string `json:"outputModes,omitempty"`
}

AgentSkill represents a skill that an agent can perform

type Artifact ΒΆ

type Artifact struct {
	Name        *string                `json:"name,omitempty"`
	Description *string                `json:"description,omitempty"`
	Parts       []Part                 `json:"parts"`
	Index       int                    `json:"index,omitempty"`
	Append      *bool                  `json:"append,omitempty"`
	LastChunk   *bool                  `json:"lastChunk,omitempty"`
	Metadata    map[string]interface{} `json:"metadata,omitempty"`
}

Artifact represents a task artifact in the A2A protocol This corresponds to the Artifact definition in the schema

func ArtifactFromJSON ΒΆ

func ArtifactFromJSON(data []byte) (*Artifact, error)

ArtifactFromJSON parses JSON into an artifact

func NewArtifact ΒΆ

func NewArtifact(parts []Part) *Artifact

NewArtifact creates a new artifact with the given parts

func (*Artifact) ToJSON ΒΆ

func (a *Artifact) ToJSON() ([]byte, error)

ToJSON converts the artifact to JSON

func (*Artifact) WithAppend ΒΆ

func (a *Artifact) WithAppend(append bool) *Artifact

WithAppend sets the append flag of the artifact

func (*Artifact) WithDescription ΒΆ

func (a *Artifact) WithDescription(description string) *Artifact

WithDescription adds a description to the artifact

func (*Artifact) WithIndex ΒΆ

func (a *Artifact) WithIndex(index int) *Artifact

WithIndex sets the index of the artifact

func (*Artifact) WithLastChunk ΒΆ

func (a *Artifact) WithLastChunk(lastChunk bool) *Artifact

WithLastChunk sets the lastChunk flag of the artifact

func (*Artifact) WithMetadata ΒΆ

func (a *Artifact) WithMetadata(metadata map[string]interface{}) *Artifact

WithMetadata adds metadata to the artifact

func (*Artifact) WithName ΒΆ

func (a *Artifact) WithName(name string) *Artifact

WithName adds a name to the artifact

type AuthenticationInfo ΒΆ

type AuthenticationInfo struct {
	Schemes     []string `json:"schemes"`
	Credentials *string  `json:"credentials,omitempty"`
}

AuthenticationInfo represents authentication information in the A2A protocol

func NewAuthenticationInfo ΒΆ

func NewAuthenticationInfo(schemes []string) *AuthenticationInfo

NewAuthenticationInfo creates new authentication information

func (*AuthenticationInfo) WithCredentials ΒΆ

func (a *AuthenticationInfo) WithCredentials(credentials string) *AuthenticationInfo

WithCredentials adds credentials to the authentication information

type CancelTaskRequest ΒΆ

type CancelTaskRequest struct {
	JSONRPC string       `json:"jsonrpc"`
	ID      interface{}  `json:"id,omitempty"`
	Method  string       `json:"method"`
	Params  TaskIdParams `json:"params"`
}

CancelTaskRequest represents a JSON-RPC request for the tasks/cancel method

type CancelTaskResponse ΒΆ

type CancelTaskResponse struct {
	JSONRPC string        `json:"jsonrpc"`
	ID      interface{}   `json:"id,omitempty"`
	Result  *Task         `json:"result,omitempty"`
	Error   *JSONRPCError `json:"error,omitempty"`
}

CancelTaskResponse represents a JSON-RPC response for the tasks/cancel method

type DataPart ΒΆ

type DataPart struct {
	Type     string                 `json:"type"`
	Data     map[string]interface{} `json:"data"`
	Metadata map[string]interface{} `json:"metadata,omitempty"`
}

DataPart represents a data part

func NewDataPart ΒΆ

func NewDataPart(data map[string]interface{}) DataPart

NewDataPart creates a new data part

func (DataPart) GetMetadata ΒΆ

func (d DataPart) GetMetadata() map[string]interface{}

GetMetadata returns the part metadata

func (DataPart) GetType ΒΆ

func (d DataPart) GetType() string

GetType returns the part type

func (DataPart) WithMetadata ΒΆ

func (d DataPart) WithMetadata(metadata map[string]interface{}) DataPart

WithMetadata adds metadata to the data part

type FileContent ΒΆ

type FileContent struct {
	Name     string `json:"name,omitempty"`
	MimeType string `json:"mimeType,omitempty"`
	Bytes    string `json:"bytes,omitempty"`
	URI      string `json:"uri,omitempty"`
}

FileContent represents the content of a file, either as base64 encoded bytes or a URI. Either 'bytes' or 'uri' must be provided, but not both.

func NewFileContentWithBytes ΒΆ

func NewFileContentWithBytes(name, mimeType, bytes string) FileContent

NewFileContentWithBytes creates a new FileContent with base64 encoded data

func NewFileContentWithURI ΒΆ

func NewFileContentWithURI(name, mimeType, uri string) FileContent

NewFileContentWithURI creates a new FileContent with a URI reference

type FilePart ΒΆ

type FilePart struct {
	Type     string                 `json:"type"`
	File     FileContent            `json:"file"`
	Metadata map[string]interface{} `json:"metadata,omitempty"`
}

FilePart represents a file part

func NewFilePart ΒΆ

func NewFilePart(file FileContent) FilePart

NewFilePart creates a new file part

func (FilePart) GetMetadata ΒΆ

func (f FilePart) GetMetadata() map[string]interface{}

GetMetadata returns the part metadata

func (FilePart) GetType ΒΆ

func (f FilePart) GetType() string

GetType returns the part type

func (FilePart) WithMetadata ΒΆ

func (f FilePart) WithMetadata(metadata map[string]interface{}) FilePart

WithMetadata adds metadata to the file part

type GetTaskPushNotificationRequest ΒΆ

type GetTaskPushNotificationRequest struct {
	JSONRPC string       `json:"jsonrpc"`
	ID      interface{}  `json:"id,omitempty"`
	Method  string       `json:"method"`
	Params  TaskIdParams `json:"params"`
}

GetTaskPushNotificationRequest represents a JSON-RPC request for the tasks/pushNotification/get method

type GetTaskPushNotificationResponse ΒΆ

type GetTaskPushNotificationResponse struct {
	JSONRPC string                      `json:"jsonrpc"`
	ID      interface{}                 `json:"id,omitempty"`
	Result  *TaskPushNotificationConfig `json:"result,omitempty"`
	Error   *JSONRPCError               `json:"error,omitempty"`
}

GetTaskPushNotificationResponse represents a JSON-RPC response for the tasks/pushNotification/get method

type GetTaskRequest ΒΆ

type GetTaskRequest struct {
	JSONRPC string          `json:"jsonrpc"`
	ID      interface{}     `json:"id,omitempty"`
	Method  string          `json:"method"`
	Params  TaskQueryParams `json:"params"`
}

GetTaskRequest represents a JSON-RPC request for the tasks/get method

type GetTaskResponse ΒΆ

type GetTaskResponse struct {
	JSONRPC string        `json:"jsonrpc"`
	ID      interface{}   `json:"id,omitempty"`
	Result  *Task         `json:"result,omitempty"`
	Error   *JSONRPCError `json:"error,omitempty"`
}

GetTaskResponse represents a JSON-RPC response for the tasks/get method

type JSONRPCError ΒΆ

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

JSONRPCError represents a JSON-RPC 2.0 error

func InternalError ΒΆ

func InternalError() *JSONRPCError

InternalError creates an internal error

func InvalidParamsError ΒΆ

func InvalidParamsError() *JSONRPCError

InvalidParamsError creates an invalid parameters error

func InvalidRequestError ΒΆ

func InvalidRequestError() *JSONRPCError

InvalidRequestError creates an invalid request error

func JSONParseError ΒΆ

func JSONParseError() *JSONRPCError

JSONParseError creates a JSON parse error

func MethodNotFoundError ΒΆ

func MethodNotFoundError() *JSONRPCError

MethodNotFoundError creates a method not found error

func NewJSONRPCError ΒΆ

func NewJSONRPCError(code int, message string) *JSONRPCError

NewJSONRPCError creates a new JSON-RPC error

func PushNotificationNotSupportedError ΒΆ

func PushNotificationNotSupportedError() *JSONRPCError

PushNotificationNotSupportedError creates a push notification not supported error

func TaskNotCancelableError ΒΆ

func TaskNotCancelableError() *JSONRPCError

TaskNotCancelableError creates a task not cancelable error

func TaskNotFoundError ΒΆ

func TaskNotFoundError() *JSONRPCError

TaskNotFoundError creates a task not found error

func UnsupportedOperationError ΒΆ

func UnsupportedOperationError() *JSONRPCError

UnsupportedOperationError creates an unsupported operation error

func (*JSONRPCError) WithData ΒΆ

func (e *JSONRPCError) WithData(data interface{}) *JSONRPCError

WithData adds data to the error

type JSONRPCMessage ΒΆ

type JSONRPCMessage struct {
	JSONRPC string      `json:"jsonrpc"`
	ID      interface{} `json:"id,omitempty"`
}

JSONRPCMessage represents a JSON-RPC 2.0 message

func NewJSONRPCMessage ΒΆ

func NewJSONRPCMessage(id interface{}) *JSONRPCMessage

NewJSONRPCMessage creates a new JSON-RPC message

type JSONRPCRequest ΒΆ

type JSONRPCRequest struct {
	JSONRPC string      `json:"jsonrpc"`
	ID      interface{} `json:"id,omitempty"`
	Method  string      `json:"method"`
	Params  interface{} `json:"params,omitempty"`
}

JSONRPCRequest represents a JSON-RPC 2.0 request

func NewJSONRPCRequest ΒΆ

func NewJSONRPCRequest(id interface{}, method string, params interface{}) *JSONRPCRequest

NewJSONRPCRequest creates a new JSON-RPC request

func RequestFromJSON ΒΆ

func RequestFromJSON(data []byte) (*JSONRPCRequest, error)

RequestFromJSON parses JSON into a request

func (*JSONRPCRequest) ToJSON ΒΆ

func (r *JSONRPCRequest) ToJSON() ([]byte, error)

ToJSON converts the request to JSON

type JSONRPCResponse ΒΆ

type JSONRPCResponse struct {
	JSONRPC string        `json:"jsonrpc"`
	ID      interface{}   `json:"id,omitempty"`
	Result  interface{}   `json:"result,omitempty"`
	Error   *JSONRPCError `json:"error,omitempty"`
}

JSONRPCResponse represents a JSON-RPC 2.0 response

func NewJSONRPCErrorResponse ΒΆ

func NewJSONRPCErrorResponse(id interface{}, error *JSONRPCError) *JSONRPCResponse

NewJSONRPCErrorResponse creates a new JSON-RPC error response

func NewJSONRPCResponse ΒΆ

func NewJSONRPCResponse(id interface{}, result interface{}) *JSONRPCResponse

NewJSONRPCResponse creates a new JSON-RPC response

func ResponseFromJSON ΒΆ

func ResponseFromJSON(data []byte) (*JSONRPCResponse, error)

ResponseFromJSON parses JSON into a response

func (*JSONRPCResponse) IsError ΒΆ

func (r *JSONRPCResponse) IsError() bool

IsError checks if the response is an error

func (*JSONRPCResponse) ToJSON ΒΆ

func (r *JSONRPCResponse) ToJSON() ([]byte, error)

ToJSON converts the response to JSON

type Message ΒΆ

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

Message represents a communication between agents according to A2A protocol

func MessageFromJSON ΒΆ

func MessageFromJSON(data []byte) (*Message, error)

MessageFromJSON parses JSON into a message

func NewMessage ΒΆ

func NewMessage(role MessageRole, parts []Part) *Message

NewMessage creates a new message

func (*Message) MarshalJSON ΒΆ

func (m *Message) MarshalJSON() ([]byte, error)

MarshalJSON serializes the message, preserving the concrete Part types.

func (*Message) ToJSON ΒΆ

func (m *Message) ToJSON() ([]byte, error)

ToJSON converts the message to JSON

func (*Message) UnmarshalJSON ΒΆ

func (m *Message) UnmarshalJSON(data []byte) error

UnmarshalJSON deserializes the message, dispatching each part to its concrete type (TextPart, FilePart, DataPart) based on the "type" field.

func (*Message) WithMetadata ΒΆ

func (m *Message) WithMetadata(metadata map[string]interface{}) *Message

WithMetadata adds metadata to the message

type MessageRole ΒΆ

type MessageRole string

MessageRole defines the sender role

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

type Part ΒΆ

type Part interface {
	GetType() string
	GetMetadata() map[string]interface{}
}

Part represents a content part in a message or artifact

type Protocol ΒΆ

type Protocol struct {
}

Protocol implements the A2A protocol

func NewProtocol ΒΆ

func NewProtocol() *Protocol

NewProtocol creates a new A2A protocol instance

func (*Protocol) CreateCancelTaskRequest ΒΆ

func (p *Protocol) CreateCancelTaskRequest(id interface{}, params TaskIdParams) *CancelTaskRequest

CreateCancelTaskRequest creates a JSON-RPC request for tasks/cancel

func (*Protocol) CreateGetTaskPushNotificationRequest ΒΆ

func (p *Protocol) CreateGetTaskPushNotificationRequest(id interface{}, params TaskIdParams) *GetTaskPushNotificationRequest

CreateGetTaskPushNotificationRequest creates a JSON-RPC request for tasks/pushNotification/get

func (*Protocol) CreateGetTaskRequest ΒΆ

func (p *Protocol) CreateGetTaskRequest(id interface{}, params TaskQueryParams) *GetTaskRequest

CreateGetTaskRequest creates a JSON-RPC request for tasks/get

func (*Protocol) CreateSendTaskRequest ΒΆ

func (p *Protocol) CreateSendTaskRequest(id interface{}, params TaskSendParams) *SendTaskRequest

CreateSendTaskRequest creates a JSON-RPC request for tasks/send

func (*Protocol) CreateSetTaskPushNotificationRequest ΒΆ

func (p *Protocol) CreateSetTaskPushNotificationRequest(id interface{}, params TaskPushNotificationConfig) *SetTaskPushNotificationRequest

CreateSetTaskPushNotificationRequest creates a JSON-RPC request for tasks/pushNotification/set

func (*Protocol) CreateTaskResubscriptionRequest ΒΆ

func (p *Protocol) CreateTaskResubscriptionRequest(id interface{}, params TaskQueryParams) *TaskResubscriptionRequest

CreateTaskResubscriptionRequest creates a JSON-RPC request for tasks/resubscribe

func (*Protocol) CreateTaskStreamingRequest ΒΆ

func (p *Protocol) CreateTaskStreamingRequest(id interface{}, params TaskSendParams) *SendTaskStreamingRequest

CreateTaskStreamingRequest creates a JSON-RPC request for tasks/sendSubscribe

func (*Protocol) ParseCancelTaskResponse ΒΆ

func (p *Protocol) ParseCancelTaskResponse(data []byte) (*CancelTaskResponse, error)

ParseCancelTaskResponse parses a CancelTaskResponse from JSON

func (*Protocol) ParseGetTaskPushNotificationResponse ΒΆ

func (p *Protocol) ParseGetTaskPushNotificationResponse(data []byte) (*GetTaskPushNotificationResponse, error)

ParseGetTaskPushNotificationResponse parses a GetTaskPushNotificationResponse from JSON

func (*Protocol) ParseGetTaskResponse ΒΆ

func (p *Protocol) ParseGetTaskResponse(data []byte) (*GetTaskResponse, error)

ParseGetTaskResponse parses a GetTaskResponse from JSON

func (*Protocol) ParseResponse ΒΆ

func (p *Protocol) ParseResponse(data []byte) (*JSONRPCResponse, error)

ParseResponse parses a JSON-RPC response

func (*Protocol) ParseSendTaskResponse ΒΆ

func (p *Protocol) ParseSendTaskResponse(data []byte) (*SendTaskResponse, error)

ParseSendTaskResponse parses a SendTaskResponse from JSON

func (*Protocol) ParseSetTaskPushNotificationResponse ΒΆ

func (p *Protocol) ParseSetTaskPushNotificationResponse(data []byte) (*SetTaskPushNotificationResponse, error)

ParseSetTaskPushNotificationResponse parses a SetTaskPushNotificationResponse from JSON

func (*Protocol) ParseStreamingResponse ΒΆ

func (p *Protocol) ParseStreamingResponse(data []byte) (*SendTaskStreamingResponse, error)

ParseStreamingResponse parses a SendTaskStreamingResponse from JSON

func (*Protocol) ParseTask ΒΆ

func (p *Protocol) ParseTask(response *JSONRPCResponse) (*Task, error)

ParseTask parses a Task from a JSON-RPC response

func (*Protocol) ParseTaskArtifactUpdate ΒΆ

func (p *Protocol) ParseTaskArtifactUpdate(response *SendTaskStreamingResponse) (*TaskArtifactUpdateEvent, error)

ParseTaskArtifactUpdate parses a TaskArtifactUpdateEvent from a streaming response

func (*Protocol) ParseTaskStatusUpdate ΒΆ

func (p *Protocol) ParseTaskStatusUpdate(response *SendTaskStreamingResponse) (*TaskStatusUpdateEvent, error)

ParseTaskStatusUpdate parses a TaskStatusUpdateEvent from a streaming response

type PushNotificationConfig ΒΆ

type PushNotificationConfig struct {
	URL            string              `json:"url"`
	Token          *string             `json:"token,omitempty"`
	Authentication *AuthenticationInfo `json:"authentication,omitempty"`
}

PushNotificationConfig represents push notification configuration in the A2A protocol

func NewPushNotificationConfig ΒΆ

func NewPushNotificationConfig(url string) *PushNotificationConfig

NewPushNotificationConfig creates a new push notification configuration

func (*PushNotificationConfig) WithAuthentication ΒΆ

WithAuthentication adds authentication information to the push notification configuration

func (*PushNotificationConfig) WithToken ΒΆ

WithToken adds a token to the push notification configuration

type SendTaskRequest ΒΆ

type SendTaskRequest struct {
	JSONRPC string         `json:"jsonrpc"`
	ID      interface{}    `json:"id,omitempty"`
	Method  string         `json:"method"`
	Params  TaskSendParams `json:"params"`
}

SendTaskRequest represents a JSON-RPC request for the tasks/send method

type SendTaskResponse ΒΆ

type SendTaskResponse struct {
	JSONRPC string        `json:"jsonrpc"`
	ID      interface{}   `json:"id,omitempty"`
	Result  *Task         `json:"result,omitempty"`
	Error   *JSONRPCError `json:"error,omitempty"`
}

SendTaskResponse represents a JSON-RPC response for the tasks/send method

type SendTaskStreamingRequest ΒΆ

type SendTaskStreamingRequest struct {
	JSONRPC string         `json:"jsonrpc"`
	ID      interface{}    `json:"id,omitempty"`
	Method  string         `json:"method"`
	Params  TaskSendParams `json:"params"`
}

SendTaskStreamingRequest represents a JSON-RPC request for the tasks/sendSubscribe method

type SendTaskStreamingResponse ΒΆ

type SendTaskStreamingResponse struct {
	JSONRPC string        `json:"jsonrpc"`
	ID      interface{}   `json:"id,omitempty"`
	Result  interface{}   `json:"result,omitempty"`
	Error   *JSONRPCError `json:"error,omitempty"`
}

SendTaskStreamingResponse represents a JSON-RPC response for the tasks/sendSubscribe method

type SetTaskPushNotificationRequest ΒΆ

type SetTaskPushNotificationRequest struct {
	JSONRPC string                     `json:"jsonrpc"`
	ID      interface{}                `json:"id,omitempty"`
	Method  string                     `json:"method"`
	Params  TaskPushNotificationConfig `json:"params"`
}

SetTaskPushNotificationRequest represents a JSON-RPC request for the tasks/pushNotification/set method

type SetTaskPushNotificationResponse ΒΆ

type SetTaskPushNotificationResponse struct {
	JSONRPC string                      `json:"jsonrpc"`
	ID      interface{}                 `json:"id,omitempty"`
	Result  *TaskPushNotificationConfig `json:"result,omitempty"`
	Error   *JSONRPCError               `json:"error,omitempty"`
}

SetTaskPushNotificationResponse represents a JSON-RPC response for the tasks/pushNotification/set method

type Task ΒΆ

type Task struct {
	ID        string                 `json:"id"`
	SessionID *string                `json:"sessionId,omitempty"`
	Status    TaskStatus             `json:"status"`
	Artifacts []Artifact             `json:"artifacts,omitempty"`
	History   []Message              `json:"history,omitempty"`
	Metadata  map[string]interface{} `json:"metadata,omitempty"`
}

Task represents a task in the A2A protocol

func NewTask ΒΆ

func NewTask(id string, state TaskState) *Task

NewTask creates a new task

func TaskFromJSON ΒΆ

func TaskFromJSON(data []byte) (*Task, error)

TaskFromJSON parses JSON into a task

func (*Task) AddArtifact ΒΆ

func (t *Task) AddArtifact(artifact Artifact) *Task

AddArtifact adds an artifact to the task

func (*Task) AddToHistory ΒΆ

func (t *Task) AddToHistory(message Message) *Task

AddToHistory adds a message to the task history

func (*Task) ToJSON ΒΆ

func (t *Task) ToJSON() ([]byte, error)

ToJSON converts the task to JSON

func (*Task) WithMessage ΒΆ

func (t *Task) WithMessage(message *Message) *Task

WithMessage adds a message to the task status

func (*Task) WithSessionID ΒΆ

func (t *Task) WithSessionID(sessionID string) *Task

WithSessionID adds a session ID to the task

type TaskArtifactUpdateEvent ΒΆ

type TaskArtifactUpdateEvent struct {
	ID       string                 `json:"id"`
	Artifact Artifact               `json:"artifact"`
	Metadata map[string]interface{} `json:"metadata,omitempty"`
}

TaskArtifactUpdateEvent represents a task artifact update event

type TaskIdParams ΒΆ

type TaskIdParams struct {
	ID       string                 `json:"id"`
	Metadata map[string]interface{} `json:"metadata,omitempty"`
}

TaskIdParams represents parameters for methods requiring only a task ID

type TaskPushNotificationConfig ΒΆ

type TaskPushNotificationConfig struct {
	ID                     string                 `json:"id"`
	PushNotificationConfig PushNotificationConfig `json:"pushNotificationConfig"`
}

TaskPushNotificationConfig represents task push notification configuration

func NewTaskPushNotificationConfig ΒΆ

func NewTaskPushNotificationConfig(id string, config PushNotificationConfig) *TaskPushNotificationConfig

NewTaskPushNotificationConfig creates a new task push notification configuration

type TaskQueryParams ΒΆ

type TaskQueryParams struct {
	ID            string                 `json:"id"`
	HistoryLength *int                   `json:"historyLength,omitempty"`
	Metadata      map[string]interface{} `json:"metadata,omitempty"`
}

TaskQueryParams represents parameters for tasks/get method

type TaskResubscriptionRequest ΒΆ

type TaskResubscriptionRequest struct {
	JSONRPC string          `json:"jsonrpc"`
	ID      interface{}     `json:"id,omitempty"`
	Method  string          `json:"method"`
	Params  TaskQueryParams `json:"params"`
}

TaskResubscriptionRequest represents a JSON-RPC request for the tasks/resubscribe method

type TaskSendParams ΒΆ

type TaskSendParams struct {
	ID               string                  `json:"id"`
	SessionID        string                  `json:"sessionId,omitempty"`
	Message          Message                 `json:"message"`
	PushNotification *PushNotificationConfig `json:"pushNotification,omitempty"`
	HistoryLength    *int                    `json:"historyLength,omitempty"`
	Metadata         map[string]interface{}  `json:"metadata,omitempty"`
}

TaskSendParams represents parameters for tasks/send method

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"
	TaskStateCanceled      TaskState = "canceled"
	TaskStateFailed        TaskState = "failed"
	TaskStateUnknown       TaskState = "unknown"
)

type TaskStatus ΒΆ

type TaskStatus struct {
	State     TaskState `json:"state"`
	Message   *Message  `json:"message,omitempty"`
	Timestamp time.Time `json:"timestamp"`
}

TaskStatus represents the status of a task

type TaskStatusUpdateEvent ΒΆ

type TaskStatusUpdateEvent struct {
	ID       string                 `json:"id"`
	Status   TaskStatus             `json:"status"`
	Final    bool                   `json:"final,omitempty"`
	Metadata map[string]interface{} `json:"metadata,omitempty"`
}

TaskStatusUpdateEvent represents a task status update event

type TextPart ΒΆ

type TextPart struct {
	Type     string                 `json:"type"`
	Text     string                 `json:"text"`
	Metadata map[string]interface{} `json:"metadata,omitempty"`
}

TextPart represents a text part

func NewTextPart ΒΆ

func NewTextPart(text string) TextPart

NewTextPart creates a new text part

func (TextPart) GetMetadata ΒΆ

func (t TextPart) GetMetadata() map[string]interface{}

GetMetadata returns the part metadata

func (TextPart) GetType ΒΆ

func (t TextPart) GetType() string

GetType returns the part type

func (TextPart) WithMetadata ΒΆ

func (t TextPart) WithMetadata(metadata map[string]interface{}) TextPart

WithMetadata adds metadata to the text part

Jump to

Keyboard shortcuts

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