acp

package
v0.4.2 Latest Latest
Warning

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

Go to latest
Published: May 25, 2026 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ProtocolVersion = "1.0"
	JSONRPCVersion  = "2.0"
)

Protocol version constants

View Source
const (
	ErrCodeParseError       = -32700
	ErrCodeInvalidRequest   = -32600
	ErrCodeMethodNotFound   = -32601
	ErrCodeInvalidParams    = -32602
	ErrCodeInternalError    = -32603
	ErrCodeServerError      = -32000
	ErrCodeUnauthorized     = -32001
	ErrCodeConnectionFailed = -32002
)

Error codes for ACP

Variables

This section is empty.

Functions

func BuiltinTools

func BuiltinTools() []map[string]interface{}

BuiltinTools returns the list of built-in ACP tools

func GenerateRequestID

func GenerateRequestID() string

GenerateRequestID generates a new request ID

func ParseSkillCall

func ParseSkillCall(params json.RawMessage) (string, string, map[string]interface{}, error)

ParseSkillCall parses a skill call request

func ToolSchemaToMap

func ToolSchemaToMap(tool map[string]interface{}) map[string]interface{}

ToolSchemaToMap converts a tool schema to map format used by agent

Types

type AgentInfo

type AgentInfo struct {
	ID           string            `json:"id"`
	Name         string            `json:"name"`
	Version      string            `json:"version"`
	Capabilities []string          `json:"capabilities"`
	Metadata     map[string]string `json:"metadata,omitempty"`
}

AgentInfo represents information about an agent

type Client

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

Client represents an ACP client for connecting to other agents

func NewClient

func NewClient(agentID string, transport Transport) *Client

NewClient creates a new ACP client

func NewClientWithTimeout

func NewClientWithTimeout(agentID string, transport Transport, timeout time.Duration) *Client

NewClientWithTimeout creates a new ACP client with custom timeout

func (*Client) CallSkill

func (c *Client) CallSkill(ctx context.Context, skillName string, params map[string]interface{}) (interface{}, error)

CallSkill calls a skill on the connected agent

func (*Client) Connect

func (c *Client) Connect(ctx context.Context) (*AgentInfo, error)

Connect connects to an ACP server and performs handshake

func (*Client) Disconnect

func (c *Client) Disconnect() error

Disconnect disconnects from the ACP server

func (*Client) GetAgentInfo

func (c *Client) GetAgentInfo(ctx context.Context) (*AgentInfo, error)

GetAgentInfo returns information about the connected agent

func (*Client) GetSkills

func (c *Client) GetSkills() map[string]Skill

GetSkills returns a copy of the known skills

func (*Client) IsConnected

func (c *Client) IsConnected() bool

IsConnected returns whether the client is connected

func (*Client) ListSkills

func (c *Client) ListSkills(ctx context.Context) ([]Skill, error)

ListSkills lists all available skills from the connected agent

func (*Client) Ping

func (c *Client) Ping(ctx context.Context) error

Ping sends a ping to check connection

func (*Client) SendMessage

func (c *Client) SendMessage(ctx context.Context, targetAgent string, content string) error

SendMessage sends a message to another agent (via connected agent)

func (*Client) ShareMemory

func (c *Client) ShareMemory(ctx context.Context, item MemoryItem) error

ShareMemory shares a memory item with the connected agent

type ConnectionRequest

type ConnectionRequest struct {
	AgentID      string    `json:"agentId"`
	AgentInfo    AgentInfo `json:"agentInfo"`
	Capabilities []string  `json:"capabilities"`
	Skills       []Skill   `json:"skills"`
}

ConnectionRequest is sent when connecting to an agent

type ConnectionResponse

type ConnectionResponse struct {
	Success      bool      `json:"success"`
	AgentInfo    AgentInfo `json:"agentInfo,omitempty"`
	Capabilities []string  `json:"capabilities,omitempty"`
	Skills       []Skill   `json:"skills,omitempty"`
	Error        string    `json:"error,omitempty"`
}

ConnectionResponse is returned after a successful connection

type HTTPTransport

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

HTTPTransport implements ACP transport over HTTP

func NewHTTPTransport

func NewHTTPTransport(baseURL string, headers map[string]string) *HTTPTransport

NewHTTPTransport creates a new HTTP transport

func (*HTTPTransport) Close

func (t *HTTPTransport) Close() error

Close closes the HTTP transport (no-op)

func (*HTTPTransport) Receive

func (t *HTTPTransport) Receive(ctx context.Context) (*JSONRPCRequest, error)

Receive receives a JSON-RPC request (not applicable for HTTP)

func (*HTTPTransport) Respond

func (t *HTTPTransport) Respond(ctx context.Context, resp *JSONRPCResponse) error

Respond sends a JSON-RPC response (no-op for HTTP transport)

func (*HTTPTransport) Send

Send sends a JSON-RPC request and returns the response

type Handler

type Handler = HandlerFunc

HandlerFunc is the function signature for ACP method handlers (documented in server.go)

type HandlerFunc

type HandlerFunc func(ctx context.Context, params json.RawMessage) (interface{}, error)

HandlerFunc is the function signature for ACP method handlers

type JSONRPCError

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

JSONRPCError represents a JSON-RPC 2.0 error

func (*JSONRPCError) Error

func (e *JSONRPCError) Error() string

Error implements the error interface

type JSONRPCRequest

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

JSONRPCRequest represents a JSON-RPC 2.0 request

func NewJSONRPCRequest

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

NewJSONRPCRequest creates a new JSON-RPC request

type JSONRPCResponse

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

JSONRPCResponse represents a JSON-RPC 2.0 response

func NewJSONRPCError

func NewJSONRPCError(id interface{}, code int, message string) *JSONRPCResponse

NewJSONRPCError creates a new JSON-RPC error response

func NewJSONRPCResponse

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

NewJSONRPCResponse creates a new JSON-RPC response

type ListResponse

type ListResponse struct {
	Items []interface{} `json:"items"`
	Count int           `json:"count"`
}

ListResponse wraps a list result

type Manager

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

Manager manages multiple ACP connections (servers and clients)

func NewManager

func NewManager() *Manager

NewManager creates a new ACP manager

func (*Manager) CallSkill

func (m *Manager) CallSkill(ctx context.Context, agentName string, skillName string, params map[string]interface{}) (interface{}, error)

CallSkill calls a skill on a connected agent

func (*Manager) Close

func (m *Manager) Close() error

Close closes all connections and servers

func (*Manager) Connect

func (m *Manager) Connect(name string, agentID string, transport Transport) error

Connect connects using a pre-configured transport

func (*Manager) ConnectHTTP

func (m *Manager) ConnectHTTP(name string, agentID string, baseURL string, headers map[string]string) error

ConnectHTTP connects to an ACP agent using HTTP transport

func (*Manager) ConnectSSE

func (m *Manager) ConnectSSE(name string, agentID string, url string, headers map[string]string) error

ConnectSSE connects to an ACP agent using SSE transport

func (*Manager) ConnectStdio

func (m *Manager) ConnectStdio(name string, agentID string, command string, args, env []string) error

ConnectStdio connects to an ACP agent using stdio transport

func (*Manager) Disconnect

func (m *Manager) Disconnect(name string) error

Disconnect disconnects from an ACP agent

func (*Manager) GetClient

func (m *Manager) GetClient(name string) (*Client, error)

GetClient gets a client by name

func (*Manager) GetServer

func (m *Manager) GetServer(name string) (*Server, error)

GetServer gets a server by name

func (*Manager) HealthCheck

func (m *Manager) HealthCheck() map[string]bool

HealthCheck checks health of all connections

func (*Manager) ListAllSkills

func (m *Manager) ListAllSkills() []Skill

ListAllSkills lists all skills from all connected agents

func (*Manager) ListConnected

func (m *Manager) ListConnected() []string

ListConnected lists all connected agent names

func (*Manager) ListConnectedAgents

func (m *Manager) ListConnectedAgents() []AgentInfo

ListConnectedAgents returns detailed info about all connected agents

func (*Manager) ListServers

func (m *Manager) ListServers() []string

ListServers lists all running servers

func (*Manager) Ping

func (m *Manager) Ping(ctx context.Context, name string) error

Ping checks connectivity to an agent

func (*Manager) StartServer

func (m *Manager) StartServer(name string, agentID string, info AgentInfo, transport Transport) (*Server, error)

StartServer starts an ACP server

func (*Manager) StopServer

func (m *Manager) StopServer(name string) error

StopServer stops an ACP server

type MemoryItem

type MemoryItem struct {
	ID       string                 `json:"id"`
	Content  string                 `json:"content"`
	Type     string                 `json:"type"`
	Metadata map[string]interface{} `json:"metadata,omitempty"`
}

MemoryItem represents a shared memory entry

type MemoryProvider

type MemoryProvider interface {
	GetMemory(ctx context.Context, query string) ([]MemoryItem, error)
	ShareMemory(ctx context.Context, item MemoryItem) error
}

MemoryProvider interface for providing memory to other agents

type MemoryProviderInterface

type MemoryProviderInterface = MemoryProvider

MemoryProvider is the interface for memory providers (documented in server.go)

type Message

type Message struct {
	ID        string                 `json:"id"`
	From      string                 `json:"from"`
	To        string                 `json:"to"`
	Content   string                 `json:"content"`
	Type      string                 `json:"type"`
	Timestamp int64                  `json:"timestamp"`
	Metadata  map[string]interface{} `json:"metadata,omitempty"`
}

Message represents a message between agents

type SSETransport

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

SSETransport implements ACP transport over Server-Sent Events

func NewSSETransport

func NewSSETransport(url string, headers map[string]string) (*SSETransport, error)

NewSSETransport creates a new SSE transport

func (*SSETransport) Close

func (t *SSETransport) Close() error

Close closes the SSE transport

func (*SSETransport) Receive

func (t *SSETransport) Receive(ctx context.Context) (*JSONRPCRequest, error)

Receive receives a JSON-RPC request via SSE (for inbound requests)

func (*SSETransport) Respond

func (t *SSETransport) Respond(ctx context.Context, resp *JSONRPCResponse) error

Respond sends a JSON-RPC response (no-op for SSE transport)

func (*SSETransport) Send

Send sends a JSON-RPC request and returns the response

type Server

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

Server represents an ACP server that exposes agent capabilities

func NewACPServer

func NewACPServer(agentID string, info AgentInfo) *Server

NewServer creates a new ACP server (alias for backward compatibility)

func NewServer

func NewServer(agentID string, info AgentInfo) *Server

NewServer creates a new ACP server

func NewServerWithTransport

func NewServerWithTransport(agentID string, info AgentInfo, transport Transport) *Server

NewServerWithTransport creates a new ACP server with a specific transport

func (*Server) GetAgentInfo

func (s *Server) GetAgentInfo() AgentInfo

GetAgentInfo returns the agent info

func (*Server) IsRunning

func (s *Server) IsRunning() bool

IsRunning returns whether the server is running

func (*Server) ListSkills

func (s *Server) ListSkills() []Skill

ListSkills returns all registered skills

func (*Server) RegisterHandler

func (s *Server) RegisterHandler(method string, handler HandlerFunc)

RegisterHandler registers a custom method handler

func (*Server) RegisterSkill

func (s *Server) RegisterSkill(skill Skill, handler HandlerFunc)

RegisterSkill registers a skill with the server

func (*Server) Start

func (s *Server) Start(ctx context.Context) error

Start starts the ACP server

func (*Server) Stop

func (s *Server) Stop() error

Stop stops the ACP server

type ServerStub

type ServerStub = Server

Server represents an ACP server (alias for backward compatibility)

type Skill

type Skill struct {
	Name        string                 `json:"name"`
	Description string                 `json:"description"`
	InputSchema map[string]interface{} `json:"inputSchema"`
	Source      string                 `json:"source,omitempty"`
}

Skill represents an agent skill/capability

type SkillCallRequest

type SkillCallRequest struct {
	SkillName string                 `json:"skillName"`
	Params    map[string]interface{} `json:"params,omitempty"`
}

SkillCallRequest represents a request to call a skill

type SkillCallResponse

type SkillCallResponse struct {
	Success bool                   `json:"success"`
	Result  json.RawMessage        `json:"result,omitempty"`
	Error   string                 `json:"error,omitempty"`
	Output  map[string]interface{} `json:"output,omitempty"`
}

SkillCallResponse represents the result of a skill call

type StdioTransport

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

StdioTransport implements ACP transport over stdio

func NewStdioTransport

func NewStdioTransport(command string, args, env []string) (*StdioTransport, error)

NewStdioTransport creates a new stdio transport

func NewStdioTransportFromProcess

func NewStdioTransportFromProcess(cmd *exec.Cmd) (*StdioTransport, error)

NewStdioTransportFromProcess creates a stdio transport from an existing process

func (*StdioTransport) Close

func (t *StdioTransport) Close() error

Close closes the stdio transport

func (*StdioTransport) Receive

func (t *StdioTransport) Receive(ctx context.Context) (*JSONRPCRequest, error)

Receive receives a JSON-RPC request (blocking)

func (*StdioTransport) Respond

func (t *StdioTransport) Respond(ctx context.Context, resp *JSONRPCResponse) error

Respond sends a JSON-RPC response (for server-side use)

func (*StdioTransport) Send

Send sends a JSON-RPC response

type TCPTransport

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

TCPTransport implements ACP transport over TCP

func NewTCPTransport

func NewTCPTransport(address string) (*TCPTransport, error)

NewTCPTransport creates a new TCP transport client

func NewTCPTransportAsServer

func NewTCPTransportAsServer(address string) (*TCPTransport, error)

NewTCPTransportAsServer creates a new TCP transport server

func (*TCPTransport) Close

func (t *TCPTransport) Close() error

Close closes the TCP connection

func (*TCPTransport) Connect

func (t *TCPTransport) Connect(ctx context.Context) error

Connect establishes the TCP connection

func (*TCPTransport) IsConnected

func (t *TCPTransport) IsConnected() bool

IsConnected checks if the TCP connection is alive

func (*TCPTransport) Listen

func (t *TCPTransport) Listen(ctx context.Context) error

Listen starts the TCP server

func (*TCPTransport) Receive

func (t *TCPTransport) Receive(ctx context.Context) (*JSONRPCRequest, error)

Receive receives a JSON-RPC request

func (*TCPTransport) Send

Send sends a JSON-RPC request

type ToolAdapter

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

ToolAdapter adapts ACP client operations to tool interface

func NewToolAdapter

func NewToolAdapter(manager *Manager) *ToolAdapter

NewToolAdapter creates a new tool adapter for ACP

func (*ToolAdapter) Execute

func (t *ToolAdapter) Execute(ctx context.Context, name string, args map[string]interface{}) (interface{}, error)

Execute executes an ACP tool

type Transport

type Transport interface {
	Send(ctx context.Context, req *JSONRPCRequest) (*JSONRPCResponse, error)
	Receive(ctx context.Context) (*JSONRPCRequest, error)
	Respond(ctx context.Context, resp *JSONRPCResponse) error
	Close() error
}

Transport interface for ACP transport layers

type TransportConfig

type TransportConfig struct {
	Type    TransportType     `json:"type"`
	Address string            `json:"address,omitempty"`
	Command string            `json:"command,omitempty"`
	Args    []string          `json:"args,omitempty"`
	Env     []string          `json:"env,omitempty"`
	BaseURL string            `json:"baseURL,omitempty"`
	Headers map[string]string `json:"headers,omitempty"`
}

TransportConfig holds transport configuration

type TransportType

type TransportType string

TransportType represents the type of transport

const (
	TransportStdio TransportType = "stdio"
	TransportHTTP  TransportType = "http"
	TransportSSE   TransportType = "sse"
	TransportTCP   TransportType = "tcp"
)

Jump to

Keyboard shortcuts

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