a2a

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: Jul 20, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package a2a provides connection registry for A2A communication graphs.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrCircuitOpen is returned when the circuit breaker is open.
	ErrCircuitOpen = fmt.Errorf("circuit breaker open")
	// ErrPayloadTooLarge is returned when the request payload exceeds the limit.
	ErrPayloadTooLarge = fmt.Errorf("payload too large")
)
View Source
var DefaultAwaitTimeout = 60 * time.Second

DefaultAwaitTimeout is the default timeout for DelegationFuture.Await.

Functions

func ResetRegistry

func ResetRegistry()

ResetRegistry clears all entries from the global registry. Used in tests.

func SendStream

func SendStream(ctx context.Context, endpoint string, msg *A2AMessage, authToken string) (<-chan A2AStreamMessage, error)

SendStream sends a message via WebSocket and returns a channel of stream messages.

Types

type A2AClient

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

A2AClient sends A2A messages to remote agents over HTTP.

func NewA2AClient

func NewA2AClient(opts ...A2AClientOption) *A2AClient

NewA2AClient creates a new A2AClient with sensible defaults.

func (*A2AClient) GetStatus

func (c *A2AClient) GetStatus(ctx context.Context, endpoint, fromID, toID string) (*A2AMessage, error)

GetStatus sends a health check request to a remote agent.

func (*A2AClient) ResetCircuit

func (c *A2AClient) ResetCircuit(endpoint string)

ResetCircuit resets the circuit breaker for a given endpoint.

func (*A2AClient) Send

func (c *A2AClient) Send(ctx context.Context, endpoint string, msg *A2AMessage) (*A2AMessage, error)

Send sends an A2A message to the given endpoint and returns the response.

type A2AClientOption

type A2AClientOption func(*A2AClient) //revive:disable-line:exported

A2AClientOption configures an A2AClient.

func WithClientAuthToken

func WithClientAuthToken(token string) A2AClientOption

WithClientAuthToken sets the bearer token for A2A requests.

func WithClientTimeout

func WithClientTimeout(timeout time.Duration) A2AClientOption

WithClientTimeout sets the HTTP client timeout.

func WithMaxRetries

func WithMaxRetries(n int) A2AClientOption

WithMaxRetries sets the maximum number of retry attempts.

type A2AConnection added in v0.6.0

type A2AConnection struct {
	SourceAgentID string    `json:"source_agent_id"`
	TargetAgentID string    `json:"target_agent_id"`
	Protocol      string    `json:"protocol"`
	Status        string    `json:"status"`
	ConnectedAt   time.Time `json:"connected_at"`
}

A2AConnection represents an active communication channel between two agents.

type A2AHandler

type A2AHandler func(ctx context.Context, msg *A2AMessage) (*A2AMessage, error) //revive:disable-line:exported

A2AHandler is a function that processes an A2AMessage and returns a response.

type A2AMessage

type A2AMessage struct {
	ID            string                 `json:"id"`
	From          string                 `json:"from"`
	To            string                 `json:"to"`
	Type          A2AMessageType         `json:"type"`
	Action        string                 `json:"action"`
	Payload       map[string]interface{} `json:"payload,omitempty"`
	CorrelationID string                 `json:"correlation_id,omitempty"`
	TraceID       string                 `json:"trace_id,omitempty"`
	Timestamp     time.Time              `json:"timestamp,omitempty"`
}

A2AMessage is the universal envelope for all A2A communication between agents.

type A2AMessageType

type A2AMessageType string //revive:disable-line:exported

A2AMessageType represents the type of an A2A message.

const (
	A2AMessageTypeRequest  A2AMessageType = "request"
	A2AMessageTypeResponse A2AMessageType = "response"
	A2AMessageTypeEvent    A2AMessageType = "event"
	A2AMessageTypeError    A2AMessageType = "error"
	A2AMessageTypeStream   A2AMessageType = "stream"
)

A2A message type constants for the A2A protocol envelope.

type A2ARouter

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

A2ARouter routes incoming A2A messages by action name.

func NewA2ARouter

func NewA2ARouter() *A2ARouter

NewA2ARouter creates a new A2ARouter.

func (*A2ARouter) Handle

func (r *A2ARouter) Handle(action string, handler A2AHandler)

Handle registers a handler for the given action.

func (*A2ARouter) Route

func (r *A2ARouter) Route(ctx context.Context, msg *A2AMessage) (*A2AMessage, error)

Route dispatches a message to the appropriate handler based on its action.

func (*A2ARouter) SetFallback

func (r *A2ARouter) SetFallback(handler A2AHandler)

SetFallback sets the fallback handler for unknown actions.

type A2AServer

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

A2AServer is an HTTP server that accepts A2A messages.

func NewA2AServer

func NewA2AServer(router *A2ARouter, addr string, opts ...A2AServerOption) *A2AServer

NewA2AServer creates a new A2AServer with the given router and options.

func (*A2AServer) Addr

func (s *A2AServer) Addr() string

Addr returns the server's listening address.

func (*A2AServer) HandleWS

func (s *A2AServer) HandleWS(handler StreamHandler)

HandleWS registers a WebSocket handler at /ws on the server.

func (*A2AServer) Start

func (s *A2AServer) Start() error

Start begins listening for HTTP requests.

func (*A2AServer) Stop

func (s *A2AServer) Stop(ctx context.Context) error

Stop gracefully shuts down the server.

type A2AServerOption

type A2AServerOption func(*A2AServer) //revive:disable-line:exported

A2AServerOption configures an A2AServer.

func WithAuthToken

func WithAuthToken(token string) A2AServerOption

WithAuthToken sets the bearer token required for A2A requests.

type A2AStreamMessage

type A2AStreamMessage struct {
	Type    string          `json:"type"`
	Content string          `json:"content,omitempty"`
	Payload json.RawMessage `json:"payload,omitempty"`
	Done    bool            `json:"done,omitempty"`
	Error   string          `json:"error,omitempty"`
}

A2AStreamMessage represents a streaming token or final response over WS.

type A2ATaskRequest

type A2ATaskRequest struct {
	Description    string                 `json:"description"`
	ExpectedOutput string                 `json:"expected_output,omitempty"`
	Context        string                 `json:"context,omitempty"`
	Priority       int                    `json:"priority,omitempty"`
	Deadline       time.Time              `json:"deadline,omitempty"`
	Metadata       map[string]interface{} `json:"metadata,omitempty"`
}

A2ATaskRequest is the typed payload for delegating a task to an agent.

type A2ATaskResponse

type A2ATaskResponse struct {
	Result  string `json:"result,omitempty"`
	Success bool   `json:"success"`
	Error   string `json:"error,omitempty"`
}

A2ATaskResponse is the typed payload with the task execution result.

type AgentCard

type AgentCard struct {
	ID           string            `json:"id"`
	Name         string            `json:"name"`
	Role         string            `json:"role"`
	Description  string            `json:"description,omitempty"`
	Capabilities []string          `json:"capabilities"`
	Endpoint     string            `json:"endpoint"`
	Version      string            `json:"version,omitempty"`
	Metadata     map[string]string `json:"metadata,omitempty"`
	CreatedAt    time.Time         `json:"created_at"`
}

AgentCard is the public agent identity for discovery via the registry.

type AgentRegistry

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

AgentRegistry provides in-memory agent discovery by ID or capability.

func GlobalA2ARegistry

func GlobalA2ARegistry() *AgentRegistry

GlobalA2ARegistry returns the package-level singleton registry.

func (*AgentRegistry) Count

func (r *AgentRegistry) Count() int

Count returns the number of registered agents.

func (*AgentRegistry) FindByCapability

func (r *AgentRegistry) FindByCapability(capability string) []*AgentCard

FindByCapability returns all agent cards that have the given capability.

func (*AgentRegistry) ListAll

func (r *AgentRegistry) ListAll() []*AgentCard

ListAll returns all registered agent cards.

func (*AgentRegistry) Lookup

func (r *AgentRegistry) Lookup(id string) (*AgentCard, error)

Lookup returns an agent card by ID, or an error if not found.

func (*AgentRegistry) Register

func (r *AgentRegistry) Register(card *AgentCard) error

Register adds an agent card to the registry. Returns an error if the ID already exists.

func (*AgentRegistry) Unregister

func (r *AgentRegistry) Unregister(id string)

Unregister removes an agent card from the registry by ID.

type ConnectionRegistry added in v0.6.0

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

ConnectionRegistry tracks active agent-to-agent communication channels. ConnectionRegistry tracks active agent-to-agent communication channels.

func NewConnectionRegistry added in v0.6.0

func NewConnectionRegistry() *ConnectionRegistry

NewConnectionRegistry creates a new ConnectionRegistry.

func (*ConnectionRegistry) ActiveConnections added in v0.6.0

func (r *ConnectionRegistry) ActiveConnections() []A2AConnection

ActiveConnections returns all active connections.

func (*ConnectionRegistry) AllConnections added in v0.6.0

func (r *ConnectionRegistry) AllConnections() []A2AConnection

AllConnections returns all connections (including closed).

func (*ConnectionRegistry) RegisterConnection added in v0.6.0

func (r *ConnectionRegistry) RegisterConnection(source, target, protocol string)

RegisterConnection adds or updates an active connection.

func (*ConnectionRegistry) UnregisterConnection added in v0.6.0

func (r *ConnectionRegistry) UnregisterConnection(source, target string)

UnregisterConnection marks a connection as closed.

type DelegationFuture

type DelegationFuture struct {
	ReceiverRole string
	Request      string
	ResponseChan chan string
}

DelegationFuture represents an async delegation result.

func (*DelegationFuture) Await

func (f *DelegationFuture) Await(ctx context.Context) (string, error)

Await blocks until the delegation result is available or context expires.

type StreamHandler

type StreamHandler func(ctx context.Context, msg *A2AMessage) (<-chan A2AStreamMessage, error)

StreamHandler is a function that processes an A2AMessage and returns a channel of stream messages.

Jump to

Keyboard shortcuts

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