Documentation
¶
Overview ¶
Package acp implements the Agent Client Protocol (ACP) for driving external agent hosts and models such as Google Antigravity.
Index ¶
- Constants
- func NewPipePair() (*PipeTransport, *PipeTransport)
- func NormalizeToolCall(name string, rawArgs json.RawMessage) (string, json.RawMessage)
- type AgentInfo
- type Capabilities
- type Client
- func (c *Client) Call(ctx context.Context, method string, params any, result any) error
- func (c *Client) Cancel(ctx context.Context, sessionID string) error
- func (c *Client) Close() error
- func (c *Client) CreateSession(ctx context.Context, params SessionCreateParams) (*SessionCreateResult, error)
- func (c *Client) Initialize(ctx context.Context, info ClientInfo) (*InitializeResult, error)
- func (c *Client) NewSession(ctx context.Context, params SessionNewParams) (*SessionNewResult, error)
- func (c *Client) Notify(ctx context.Context, method string, params any) error
- func (c *Client) Prompt(ctx context.Context, params SessionPromptParams, onEvent EventHandler) (*SessionPromptResult, error)
- func (c *Client) SetModel(ctx context.Context, sessionID, modelID string) error
- func (c *Client) SetToolHandler(h ToolHandler)
- type ClientInfo
- type ContentBlock
- type EventHandler
- type EventType
- type ID
- type IDEMCPServer
- type InitializeParams
- type InitializeResult
- type Notification
- type PipeTransport
- type PromptContent
- type PromptMessage
- type RPCError
- type Request
- type Response
- type SessionCreateParams
- type SessionCreateResult
- type SessionEvent
- type SessionNewParams
- type SessionNewResult
- type SessionPromptParams
- type SessionPromptResult
- type SetModelParams
- type SocketTransport
- type StdioTransport
- type ToolCall
- type ToolDefinition
- type ToolHandler
- type ToolResult
- type Transport
- type Usage
Constants ¶
const ( CodeParseError = -32700 CodeInvalidRequest = -32600 CodeMethodNotFound = -32601 CodeInvalidParams = -32602 CodeInternalError = -32603 )
JSON-RPC 2.0 error codes.
const ProtocolVersion = 1
ProtocolVersion is the supported ACP version.
Variables ¶
This section is empty.
Functions ¶
func NewPipePair ¶
func NewPipePair() (*PipeTransport, *PipeTransport)
NewPipePair creates a linked pair of PipeTransports for in-memory testing.
func NormalizeToolCall ¶
func NormalizeToolCall(name string, rawArgs json.RawMessage) (string, json.RawMessage)
NormalizeToolCall normalizes tool names and argument casing from Antigravity/ACP hosts to match standard Blitz ADK tool signatures.
Types ¶
type AgentInfo ¶
type AgentInfo struct {
Name string `json:"name"`
Version string `json:"version"`
Description string `json:"description,omitempty"`
Vendor string `json:"vendor,omitempty"`
}
AgentInfo describes the agent or host implementation.
type Capabilities ¶
type Capabilities struct {
Streaming bool `json:"streaming,omitempty"`
Tools bool `json:"tools,omitempty"`
Thinking bool `json:"thinking,omitempty"`
Cancellation bool `json:"cancellation,omitempty"`
}
Capabilities describes the supported features.
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client is a JSON-RPC 2.0 client speaking the Agent Client Protocol (ACP).
func (*Client) CreateSession ¶
func (c *Client) CreateSession(ctx context.Context, params SessionCreateParams) (*SessionCreateResult, error)
CreateSession requests a new session from the ACP host.
func (*Client) Initialize ¶
func (c *Client) Initialize(ctx context.Context, info ClientInfo) (*InitializeResult, error)
Initialize performs the ACP handshake.
func (*Client) NewSession ¶
func (c *Client) NewSession(ctx context.Context, params SessionNewParams) (*SessionNewResult, error)
NewSession requests a new session from the ACP host via session/new (falling back to session/create).
func (*Client) Prompt ¶
func (c *Client) Prompt(ctx context.Context, params SessionPromptParams, onEvent EventHandler) (*SessionPromptResult, error)
Prompt sends a prompt to the ACP host, streaming events to onEvent if provided.
func (*Client) SetModel ¶
SetModel configures the active model for an ACP session via session/set_model.
func (*Client) SetToolHandler ¶
func (c *Client) SetToolHandler(h ToolHandler)
SetToolHandler configures the callback executed when the server issues a tool/call request.
type ClientInfo ¶
ClientInfo describes the client implementation.
type ContentBlock ¶
ContentBlock represents a rich content chunk in an ACP prompt or message.
type EventHandler ¶
type EventHandler func(event SessionEvent)
EventHandler receives streaming session event notifications.
type EventType ¶
type EventType string
EventType defines streaming delta kinds for session/event notifications.
const ( // EventTextDelta is streamed candidate text delta. EventTextDelta EventType = "text_delta" // EventThoughtDelta is streamed reasoning or thinking delta. EventThoughtDelta EventType = "thought_delta" // EventToolCall is a tool execution request event. EventToolCall EventType = "tool_call" // EventUsage reports token usage deltas or totals. EventUsage EventType = "usage" // EventDone marks prompt stream completion. EventDone EventType = "done" // EventError marks prompt stream error. EventError EventType = "error" )
EventType values.
type ID ¶
ID represents a JSON-RPC 2.0 request or response identifier (number or string).
func (ID) MarshalJSON ¶
MarshalJSON encodes the ID as a JSON number or string.
func (*ID) UnmarshalJSON ¶
UnmarshalJSON decodes the ID from a JSON number or string.
type IDEMCPServer ¶
type IDEMCPServer struct {
// contains filtered or unexported fields
}
IDEMCPServer serves tools over Model Context Protocol (MCP) to an external ACP agent host such as Google Antigravity via its --ide-mcp-port flag.
func NewIDEMCPServer ¶
func NewIDEMCPServer() (*IDEMCPServer, error)
NewIDEMCPServer starts a TCP listener on localhost on an ephemeral port serving host tools over MCP to an ACP agent process.
func (*IDEMCPServer) Close ¶
func (s *IDEMCPServer) Close() error
Close closes the listener and terminates all active client connections.
func (*IDEMCPServer) Port ¶
func (s *IDEMCPServer) Port() int
Port returns the TCP port the MCP server is listening on.
func (*IDEMCPServer) SetHandler ¶
func (s *IDEMCPServer) SetHandler(h ToolHandler)
SetHandler configures the delegate for executing tools/call requests.
func (*IDEMCPServer) SetTools ¶
func (s *IDEMCPServer) SetTools(tools []ToolDefinition)
SetTools updates the list of tools advertised to the MCP client.
type InitializeParams ¶
type InitializeParams struct {
ProtocolVersion int `json:"protocolVersion"`
ClientInfo ClientInfo `json:"clientInfo"`
Capabilities Capabilities `json:"capabilities"`
}
InitializeParams are parameters for the initialize method.
type InitializeResult ¶
type InitializeResult struct {
ProtocolVersion int `json:"protocolVersion"`
AgentInfo AgentInfo `json:"agentInfo"`
Capabilities Capabilities `json:"capabilities"`
}
InitializeResult is the result of the initialize method.
type Notification ¶
type Notification struct {
JSONRPC string `json:"jsonrpc"`
Method string `json:"method"`
Params json.RawMessage `json:"params,omitempty"`
}
Notification is a JSON-RPC 2.0 notification message (no ID).
type PipeTransport ¶
type PipeTransport struct {
// contains filtered or unexported fields
}
PipeTransport connects two in-memory pipe endpoints for testing.
type PromptContent ¶
type PromptContent []ContentBlock
PromptContent represents ACP prompt content: always serializes as a JSON array of ContentBlock ([]ContentBlock), satisfying hosts that require []jsontext.Value, but can unmarshal from either a string or []ContentBlock.
func TextContent ¶
func TextContent(text string) PromptContent
TextContent creates a PromptContent slice with a single text block.
func (PromptContent) MarshalJSON ¶
func (p PromptContent) MarshalJSON() ([]byte, error)
MarshalJSON encodes PromptContent as a JSON array of ContentBlock.
func (*PromptContent) UnmarshalJSON ¶
func (p *PromptContent) UnmarshalJSON(b []byte) error
UnmarshalJSON decodes PromptContent from a JSON string or array of ContentBlock.
type PromptMessage ¶
type PromptMessage struct {
Role string `json:"role"`
Content string `json:"content"`
Thought string `json:"thought,omitempty"`
ToolCalls []ToolCall `json:"toolCalls,omitempty"`
ToolResults []ToolResult `json:"toolResults,omitempty"`
}
PromptMessage represents a chat message passed to/from ACP.
type RPCError ¶
type RPCError struct {
Code int `json:"code"`
Message string `json:"message"`
Data any `json:"data,omitempty"`
}
RPCError is a JSON-RPC 2.0 error object.
type Request ¶
type Request struct {
JSONRPC string `json:"jsonrpc"`
ID ID `json:"id"`
Method string `json:"method"`
Params json.RawMessage `json:"params,omitempty"`
}
Request is a JSON-RPC 2.0 request message.
type Response ¶
type Response struct {
JSONRPC string `json:"jsonrpc"`
ID ID `json:"id"`
Result json.RawMessage `json:"result,omitempty"`
Error *RPCError `json:"error,omitempty"`
}
Response is a JSON-RPC 2.0 response message.
type SessionCreateParams ¶
type SessionCreateParams struct {
SessionID string `json:"sessionId"`
Workspace string `json:"workspace,omitempty"`
Model string `json:"model,omitempty"`
SystemPrompt string `json:"systemPrompt,omitempty"`
}
SessionCreateParams are parameters for creating an ACP session.
type SessionCreateResult ¶
type SessionCreateResult struct {
SessionID string `json:"sessionId"`
Status string `json:"status"`
}
SessionCreateResult is the result of session creation.
type SessionEvent ¶
type SessionEvent struct {
SessionID string `json:"sessionId"`
Type EventType `json:"type"`
Text string `json:"text,omitempty"`
Thought string `json:"thought,omitempty"`
ToolCall *ToolCall `json:"toolCall,omitempty"`
Usage *Usage `json:"usage,omitempty"`
Error string `json:"error,omitempty"`
}
SessionEvent is an event notification payload sent while prompt streaming.
type SessionNewParams ¶
type SessionNewParams struct {
SessionID string `json:"sessionId,omitempty"`
Cwd string `json:"cwd,omitempty"`
Workspace string `json:"workspace,omitempty"`
Model string `json:"model,omitempty"`
SystemPrompt string `json:"systemPrompt,omitempty"`
DisableBuiltInTools bool `json:"disableBuiltInTools,omitempty"`
AdditionalDirs []string `json:"additionalDirectories,omitempty"`
}
SessionNewParams are parameters for creating an ACP session via session/new.
type SessionNewResult ¶
type SessionNewResult struct {
SessionID string `json:"sessionId"`
Status string `json:"status,omitempty"`
}
SessionNewResult is the result of session/new.
type SessionPromptParams ¶
type SessionPromptParams struct {
SessionID string `json:"sessionId"`
Prompt PromptContent `json:"prompt"`
Messages []PromptMessage `json:"messages,omitempty"`
Model string `json:"model,omitempty"`
Stream bool `json:"stream,omitempty"`
}
SessionPromptParams are parameters for session/prompt.
type SessionPromptResult ¶
type SessionPromptResult struct {
Message PromptMessage `json:"message,omitempty"`
StopReason string `json:"stopReason,omitempty"`
FinishReason string `json:"finishReason,omitempty"`
Usage *Usage `json:"usage,omitempty"`
}
SessionPromptResult is the result of session/prompt when complete.
type SetModelParams ¶
SetModelParams are parameters for session/set_model.
type SocketTransport ¶
type SocketTransport struct {
// contains filtered or unexported fields
}
SocketTransport communicates over a local Unix domain socket or TCP connection.
func NewSocketTransport ¶
func NewSocketTransport(ctx context.Context, network, address string) (*SocketTransport, error)
NewSocketTransport dials network ("unix" or "tcp") at address.
func (*SocketTransport) Close ¶
func (s *SocketTransport) Close() error
Close closes the underlying socket.
type StdioTransport ¶
type StdioTransport struct {
// contains filtered or unexported fields
}
StdioTransport executes a sub-process and communicates over its stdin and stdout.
func NewStdioTransport ¶
func NewStdioTransport(ctx context.Context, command string, args []string, dir string) (*StdioTransport, error)
NewStdioTransport starts command with args and wraps its standard input/output streams.
func (*StdioTransport) Close ¶
func (t *StdioTransport) Close() error
Close terminates the transport and child process.
type ToolCall ¶
type ToolCall struct {
ID string `json:"id"`
Name string `json:"name"`
Arguments json.RawMessage `json:"arguments"`
}
ToolCall represents a tool invocation requested by the agent.
type ToolDefinition ¶
type ToolDefinition struct {
Name string `json:"name"`
Description string `json:"description,omitempty"`
InputSchema map[string]any `json:"inputSchema"`
}
ToolDefinition describes a tool exposed to the agent host over MCP.
type ToolHandler ¶
type ToolHandler func(ctx context.Context, call ToolCall) (ToolResult, error)
ToolHandler handles tool call requests dispatched from the agent host to the client.
type ToolResult ¶
type ToolResult struct {
CallID string `json:"callId"`
Name string `json:"name"`
Content string `json:"content,omitempty"`
Error string `json:"error,omitempty"`
}
ToolResult represents the outcome of a tool execution.
type Transport ¶
type Transport interface {
Send(ctx context.Context, msg []byte) error
Receive(ctx context.Context) ([]byte, error)
Close() error
}
Transport sends and receives raw protocol messages.
type Usage ¶
type Usage struct {
InputTokens int64 `json:"inputTokens"`
OutputTokens int64 `json:"outputTokens"`
ReasoningTokens int64 `json:"reasoningTokens,omitempty"`
ThoughtTokens int64 `json:"thoughtTokens,omitempty"`
CachedTokens int64 `json:"cachedTokens,omitempty"`
CachedReadTokens int64 `json:"cachedReadTokens,omitempty"`
TotalTokens int64 `json:"totalTokens,omitempty"`
}
Usage reports token counts from ACP prompt execution.