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 ¶
- func AgentListConfigPath() string
- func ConfigPath() string
- func HandleAgentCard(card *AgentCard) http.HandlerFunc
- func InitA2AConfig(force bool) (string, error)
- func InitA2AMasterConfig(force bool) (string, error)
- func ProjectAgentListConfigPath() string
- func ProjectConfigPath() string
- func Run(cfg *Config, version string, executor AgentExecutor) error
- func SaveAgentList(path string, cfg *AgentListConfig) error
- func SaveConfig(path string, cfg *Config) error
- type A2AManager
- type AgentCard
- type AgentCardCfg
- type AgentEntry
- type AgentExecutor
- type AgentFactory
- type AgentListConfig
- type Artifact
- type Capabilities
- type Client
- func (c *Client) CancelTask(ctx context.Context, taskID string) (*Task, error)
- func (c *Client) GetAgentCard(ctx context.Context) (*AgentCard, error)
- func (c *Client) GetTask(ctx context.Context, taskID string) (*Task, error)
- func (c *Client) SendMessage(ctx context.Context, taskID string, msg *Message) (*Task, error)
- func (c *Client) SendMessageStream(ctx context.Context, taskID string, msg *Message) (<-chan TaskEvent, error)
- type Config
- type DefaultExecutor
- type Handler
- func (h *Handler) GetTaskStore() *TaskStore
- func (h *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request)
- func (h *Handler) Subscribe(taskID string) chan TaskEvent
- func (h *Handler) SubscribeSSE(w http.ResponseWriter, r *http.Request)
- func (h *Handler) Unsubscribe(taskID string, ch chan TaskEvent)
- type JSONRPCError
- type JSONRPCRequest
- type JSONRPCResponse
- type Message
- type MessagePart
- type SendMessageParams
- type Server
- type Skill
- type Task
- type TaskError
- type TaskEvent
- type TaskState
- type TaskStore
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 HandleAgentCard ¶
func HandleAgentCard(card *AgentCard) http.HandlerFunc
HandleAgentCard serves the Agent Card at /.well-known/agent.json.
func InitA2AConfig ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 (*Client) CancelTask ¶
CancelTask cancels a running task.
func (*Client) GetAgentCard ¶
GetAgentCard retrieves the Agent Card from the server.
func (*Client) SendMessage ¶
SendMessage sends a message to an A2A server (sync response).
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 (*Config) GetListenAddr ¶
GetListenAddr returns the listen address.
func (*Config) GetWorkDir ¶
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 ¶
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) SubscribeSSE ¶
func (h *Handler) SubscribeSSE(w http.ResponseWriter, r *http.Request)
SubscribeSSE handles SSE subscription for task events at /a2a/events.
func (*Handler) Unsubscribe ¶
Unsubscribe removes an SSE subscriber.
type JSONRPCError ¶
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 ¶
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) GetHandler ¶
GetHandler returns the A2A handler (for integration mode).
func (*Server) RegisterRoutes ¶
RegisterRoutes registers A2A routes on an external mux (for integration mode).
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.
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.