a2a

package
v1.1.57 Latest Latest
Warning

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

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

Documentation

Overview

Package a2a implements the A2A (Agent-to-Agent) protocol server. It provides a JSON-RPC 2.0 endpoint for other agents to send tasks to VibeCoding. Supports both standalone mode (vibecoding a2a start) and integration mode (hermes + a2a.enabled).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AgentListConfigPath

func AgentListConfigPath() string

AgentListConfigPath returns the path to the global a2a-list.json.

func ConfigPath

func ConfigPath() string

ConfigPath returns the path to the global a2a.json.

func HandleAgentCard

func HandleAgentCard(card *AgentCard) http.HandlerFunc

HandleAgentCard serves the Agent Card at /.well-known/agent.json.

func InitA2AConfig

func InitA2AConfig(force bool) (string, error)

InitA2AConfig creates the a2a.json template at the default location. Returns the file path. If force is false and the file already exists, returns an error.

func InitA2AMasterConfig

func InitA2AMasterConfig(force bool) (string, error)

InitA2AMasterConfig creates a sample a2a-list.json at the default location. Returns the file path. If force is false and the file already exists, returns an error.

func ProjectAgentListConfigPath

func ProjectAgentListConfigPath() string

ProjectAgentListConfigPath returns the path to the project-level .vibe/a2a-list.json.

func ProjectConfigPath

func ProjectConfigPath() string

ProjectConfigPath returns the path to the project-level .vibe/a2a.json.

func Run

func Run(cfg *Config, version string, executor AgentExecutor) error

Run starts the A2A server in standalone mode with signal handling.

func SaveAgentList

func SaveAgentList(path string, cfg *AgentListConfig) error

SaveAgentList writes the agent list config to a JSON file.

func SaveConfig

func SaveConfig(path string, cfg *Config) error

SaveConfig writes the config to a JSON file.

Types

type A2AManager

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

A2AManager manages a list of remote A2A agents and provides dispatch methods.

func NewA2AManager

func NewA2AManager(cfg *AgentListConfig) *A2AManager

NewA2AManager creates a new A2A manager from a config.

func (*A2AManager) Dispatch

func (m *A2AManager) Dispatch(ctx context.Context, name, message string) (string, error)

Dispatch sends a message to the named remote A2A agent and returns the response text.

func (*A2AManager) Get

func (m *A2AManager) Get(name string) (*AgentEntry, bool)

Get returns an agent entry by name.

func (*A2AManager) List

func (m *A2AManager) List() []*AgentEntry

List returns all registered agent entries in order.

type AgentCard

type AgentCard struct {
	Name         string       `json:"name"`
	Description  string       `json:"description"`
	URL          string       `json:"url"`
	Version      string       `json:"version"`
	Capabilities Capabilities `json:"capabilities"`
	Skills       []Skill      `json:"skills"`
}

AgentCard represents the A2A Agent Card (/.well-known/agent.json).

func DefaultAgentCard

func DefaultAgentCard(version, serverURL string) *AgentCard

DefaultAgentCard returns the default Agent Card for VibeCoding.

type AgentCardCfg

type AgentCardCfg struct {
	Name        string `json:"name,omitempty"`
	Description string `json:"description,omitempty"`
	Version     string `json:"version,omitempty"`
}

AgentCardCfg holds customizable Agent Card fields.

type AgentEntry

type AgentEntry struct {
	Name      string `json:"name"`
	URL       string `json:"url"`
	AuthToken string `json:"auth_token,omitempty"`
}

AgentEntry describes a remote A2A agent in a2a-list.json.

type AgentExecutor

type AgentExecutor interface {
	ExecuteTask(ctx context.Context, task *Task, msg *Message) (<-chan TaskEvent, error)
}

AgentExecutor processes A2A tasks by running them through the agent loop.

type AgentFactory

type AgentFactory interface {
	CreateForA2A(workDir string, mode string) (*agent.Agent, error)
}

AgentFactory creates agent instances for A2A task execution.

type AgentListConfig

type AgentListConfig struct {
	Agents []AgentEntry `json:"agents"`
}

AgentListConfig is the top-level structure of a2a-list.json.

func LoadAgentList

func LoadAgentList(path string) (*AgentListConfig, error)

LoadAgentList loads a2a-list.json from the given path.

type Artifact

type Artifact struct {
	Name        string         `json:"name,omitempty"`
	Description string         `json:"description,omitempty"`
	Parts       []MessagePart  `json:"parts"`
	Metadata    map[string]any `json:"metadata,omitempty"`
}

Artifact represents output produced by an agent task.

type Capabilities

type Capabilities struct {
	Streaming         bool `json:"streaming"`
	PushNotifications bool `json:"pushNotifications"`
}

Capabilities describes what the agent can do.

type Client

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

Client is an A2A protocol client for sending tasks to other A2A servers.

func NewClient

func NewClient(baseURL, authToken string) *Client

NewClient creates a new A2A client.

func (*Client) CancelTask

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

CancelTask cancels a running task.

func (*Client) GetAgentCard

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

GetAgentCard retrieves the Agent Card from the server.

func (*Client) GetTask

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

GetTask gets the current state of a task.

func (*Client) SendMessage

func (c *Client) SendMessage(ctx context.Context, taskID string, msg *Message) (*Task, error)

SendMessage sends a message to an A2A server (sync response).

func (*Client) SendMessageStream

func (c *Client) SendMessageStream(ctx context.Context, taskID string, msg *Message) (<-chan TaskEvent, error)

SendMessageStream sends a message and returns SSE events via channel.

type Config

type Config struct {
	Enabled   bool          `json:"enabled"`
	Port      int           `json:"port"`
	Host      string        `json:"host"`
	AuthToken string        `json:"auth_token,omitempty"`
	WorkDir   string        `json:"work_dir,omitempty"`
	AgentCard *AgentCardCfg `json:"agent_card,omitempty"`
}

Config holds A2A server configuration.

func DefaultConfig

func DefaultConfig() *Config

DefaultConfig returns default A2A configuration.

func (*Config) GetListenAddr

func (c *Config) GetListenAddr() string

GetListenAddr returns the listen address.

func (*Config) GetWorkDir

func (c *Config) GetWorkDir() string

GetWorkDir returns the resolved working directory.

type DefaultExecutor

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

DefaultExecutor implements AgentExecutor by running tasks through the agent loop.

func NewDefaultExecutor

func NewDefaultExecutor(factory AgentFactory) *DefaultExecutor

NewDefaultExecutor creates a new default executor.

func (*DefaultExecutor) ExecuteTask

func (e *DefaultExecutor) ExecuteTask(ctx context.Context, task *Task, msg *Message) (<-chan TaskEvent, error)

ExecuteTask runs an A2A task through the agent loop.

type Handler

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

Handler handles A2A JSON-RPC requests.

func NewHandler

func NewHandler(executor AgentExecutor) *Handler

NewHandler creates a new A2A handler.

func (*Handler) GetTaskStore

func (h *Handler) GetTaskStore() *TaskStore

GetTaskStore returns the task store.

func (*Handler) ServeHTTP

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

ServeHTTP handles A2A JSON-RPC requests at /a2a.

func (*Handler) Subscribe

func (h *Handler) Subscribe(taskID string) chan TaskEvent

Subscribe adds an SSE subscriber for task events.

func (*Handler) SubscribeSSE

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

SubscribeSSE handles SSE subscription for task events at /a2a/events.

func (*Handler) Unsubscribe

func (h *Handler) Unsubscribe(taskID string, ch chan TaskEvent)

Unsubscribe removes an SSE subscriber.

type JSONRPCError

type JSONRPCError struct {
	Code    int    `json:"code"`
	Message string `json:"message"`
}

JSONRPCError represents a JSON-RPC 2.0 error.

type JSONRPCRequest

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

JSONRPCRequest represents a JSON-RPC 2.0 request.

type JSONRPCResponse

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

JSONRPCResponse represents a JSON-RPC 2.0 response.

type Message

type Message struct {
	Role     string         `json:"role"` // "user" or "agent"
	Parts    []MessagePart  `json:"parts"`
	Metadata map[string]any `json:"metadata,omitempty"`
}

Message represents an A2A message (text or structured).

type MessagePart

type MessagePart struct {
	Type string `json:"type"` // "text"
	Text string `json:"text,omitempty"`
}

MessagePart is a part of a message.

type SendMessageParams

type SendMessageParams struct {
	TaskID  string   `json:"task_id,omitempty"`
	Message *Message `json:"message"`
}

SendMessageParams represents the params for message/send.

type Server

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

Server is the A2A HTTP server.

func NewServer

func NewServer(cfg *Config, version string, executor AgentExecutor) *Server

NewServer creates a new A2A server.

func (*Server) GetCard

func (s *Server) GetCard() *AgentCard

GetCard returns the Agent Card.

func (*Server) GetHandler

func (s *Server) GetHandler() *Handler

GetHandler returns the A2A handler (for integration mode).

func (*Server) RegisterRoutes

func (s *Server) RegisterRoutes(mux *http.ServeMux)

RegisterRoutes registers A2A routes on an external mux (for integration mode).

func (*Server) Start

func (s *Server) Start() error

Start starts the A2A server in standalone mode. Blocks until stopped.

func (*Server) Stop

func (s *Server) Stop(timeout time.Duration) error

Stop gracefully shuts down the server.

type Skill

type Skill struct {
	ID          string `json:"id"`
	Name        string `json:"name"`
	Description string `json:"description"`
}

Skill describes a specific capability.

type Task

type Task struct {
	ID        string         `json:"id"`
	State     TaskState      `json:"state"`
	Message   *Message       `json:"message,omitempty"`
	Artifacts []Artifact     `json:"artifacts,omitempty"`
	Error     *TaskError     `json:"error,omitempty"`
	Metadata  map[string]any `json:"metadata,omitempty"`
	CreatedAt time.Time      `json:"created_at"`
	UpdatedAt time.Time      `json:"updated_at"`
}

Task represents an A2A task.

func (*Task) Clone

func (t *Task) Clone() *Task

Clone returns a deep copy of the task value.

type TaskError

type TaskError struct {
	Code    int    `json:"code"`
	Message string `json:"message"`
}

TaskError represents an error in task processing.

type TaskEvent

type TaskEvent struct {
	TaskID    string     `json:"task_id"`
	State     TaskState  `json:"state"`
	Message   *Message   `json:"message,omitempty"`
	Artifact  *Artifact  `json:"artifact,omitempty"`
	Error     *TaskError `json:"error,omitempty"`
	Timestamp time.Time  `json:"timestamp"`
}

TaskEvent is sent via SSE for streaming task updates.

type TaskState

type TaskState string

TaskState represents the state of an A2A task.

const (
	TaskStateSubmitted TaskState = "submitted"
	TaskStateWorking   TaskState = "working"
	TaskStateCompleted TaskState = "completed"
	TaskStateFailed    TaskState = "failed"
	TaskStateCanceled  TaskState = "canceled"
)

type TaskStore

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

TaskStore manages task storage.

func NewTaskStore

func NewTaskStore() *TaskStore

NewTaskStore creates a new task store.

func (*TaskStore) Create

func (s *TaskStore) Create(id string) *Task

Create creates a new task.

func (*TaskStore) Get

func (s *TaskStore) Get(id string) *Task

Get returns a task by ID.

func (*TaskStore) SetState

func (s *TaskStore) SetState(id string, state TaskState)

SetState updates the task state.

func (*TaskStore) Update

func (s *TaskStore) Update(task *Task)

Update updates a task.

Jump to

Keyboard shortcuts

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