acp

package
v1.3.7 Latest Latest
Warning

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

Go to latest
Published: Nov 29, 2026 License: Apache-2.0 Imports: 12 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package acp implements the Agent Client Protocol (ACP) for driving external agent hosts and models such as Google Antigravity.

Index

Constants

View Source
const (
	CodeParseError     = -32700
	CodeInvalidRequest = -32600
	CodeMethodNotFound = -32601
	CodeInvalidParams  = -32602
	CodeInternalError  = -32603
)

JSON-RPC 2.0 error codes.

View Source
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 NewClient

func NewClient(transport Transport) *Client

NewClient creates an ACP client connected through transport.

func (*Client) Call

func (c *Client) Call(ctx context.Context, method string, params any, result any) error

Call performs a synchronous JSON-RPC request and unmarshals result.

func (*Client) Cancel

func (c *Client) Cancel(ctx context.Context, sessionID string) error

Cancel sends a cancellation notification for a running session prompt.

func (*Client) Close

func (c *Client) Close() error

Close terminates the client and transport.

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) Notify

func (c *Client) Notify(ctx context.Context, method string, params any) error

Notify sends a one-way JSON-RPC notification.

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

func (c *Client) SetModel(ctx context.Context, sessionID, modelID string) error

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

type ClientInfo struct {
	Name    string `json:"name"`
	Version string `json:"version"`
}

ClientInfo describes the client implementation.

type ContentBlock

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

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

type ID struct {
	Num   int64
	Str   string
	IsStr bool
}

ID represents a JSON-RPC 2.0 request or response identifier (number or string).

func (ID) MarshalJSON

func (id ID) MarshalJSON() ([]byte, error)

MarshalJSON encodes the ID as a JSON number or string.

func (ID) String

func (id ID) String() string

String returns the string representation of the ID.

func (*ID) UnmarshalJSON

func (id *ID) UnmarshalJSON(b []byte) error

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.

func (*PipeTransport) Close

func (p *PipeTransport) Close() error

Close closes both pipe ends.

func (*PipeTransport) Receive

func (p *PipeTransport) Receive(_ context.Context) ([]byte, error)

Receive reads the next message from the pipe.

func (*PipeTransport) Send

func (p *PipeTransport) Send(_ context.Context, msg []byte) error

Send writes msg to the pipe.

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.

func (*RPCError) Error

func (e *RPCError) Error() string

Error implements the error interface.

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

type SetModelParams struct {
	SessionID string `json:"sessionId"`
	ModelID   string `json:"modelId"`
}

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.

func (*SocketTransport) Receive

func (s *SocketTransport) Receive(_ context.Context) ([]byte, error)

Receive reads the next message from the socket.

func (*SocketTransport) Send

func (s *SocketTransport) Send(_ context.Context, msg []byte) error

Send sends msg over the socket connection.

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.

func (*StdioTransport) Receive

func (t *StdioTransport) Receive(_ context.Context) ([]byte, error)

Receive reads the next newline-delimited message.

func (*StdioTransport) Send

func (t *StdioTransport) Send(_ context.Context, msg []byte) error

Send sends msg terminated by a newline.

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.

Jump to

Keyboard shortcuts

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