Documentation
¶
Overview ¶
Package acp is the agent side of the Agent Client Protocol (https://agentclientprotocol.com), protocol version 1: newline-delimited JSON-RPC 2.0 over stdio. It implements the baseline methods (initialize, authenticate, session/new, session/prompt, session/cancel) and the session/update notifications tinyagent sends; the turns themselves run in a Session the caller provides.
Index ¶
- Constants
- type ContentBlock
- type EnvVariable
- type Error
- type Image
- type MCPServer
- type NewSessionFunc
- type PlanEntry
- type Prompt
- type Resource
- type Server
- type Session
- type Updates
- func (u *Updates) Message(text string)
- func (u *Updates) Plan(entries []PlanEntry)
- func (u *Updates) Request(ctx context.Context, method string, params any) (json.RawMessage, error)
- func (u *Updates) Send(update any)
- func (u *Updates) ToolCall(id, title, kind string, locations []string, rawInput any)
- func (u *Updates) ToolCallStatus(id, status, text string)
- func (u *Updates) Usage(used, size int, costUSD float64)
Constants ¶
const ( CodeParseError = -32700 CodeInvalidRequest = -32600 CodeMethodNotFound = -32601 CodeInvalidParams = -32602 CodeInternalError = -32603 )
JSON-RPC 2.0 error codes.
const ( StopEndTurn = "end_turn" StopMaxTokens = "max_tokens" StopMaxTurnRequests = "max_turn_requests" StopCancelled = "cancelled" )
Stop reasons of a prompt turn.
const ProtocolVersion = 1
ProtocolVersion is the ACP version spoken.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ContentBlock ¶
type ContentBlock struct {
Type string `json:"type"`
Text string `json:"text,omitempty"`
MimeType string `json:"mimeType,omitempty"`
Data string `json:"data,omitempty"`
URI string `json:"uri,omitempty"`
Name string `json:"name,omitempty"`
Resource *Resource `json:"resource,omitempty"`
}
ContentBlock is an ACP content block. Only the fields tinyagent reads are decoded.
type EnvVariable ¶
EnvVariable is one environment variable of a client's MCP server.
type Error ¶
Error is a JSON-RPC error. A Session returns one to pick the code; any other error is reported as an internal error with its message.
func InvalidParams ¶
InvalidParams returns an invalid-params error with a formatted message.
type MCPServer ¶
type MCPServer struct {
Type string `json:"type,omitempty"`
Name string `json:"name"`
Command string `json:"command,omitempty"`
Args []string `json:"args,omitempty"`
Env []EnvVariable `json:"env,omitempty"`
URL string `json:"url,omitempty"`
}
MCPServer is one MCP server a client sends with session/new. Type is "" or "stdio" for a local command, "http" or "sse" for a remote one.
type NewSessionFunc ¶
type NewSessionFunc func(ctx context.Context, id, cwd string, mcpServers []MCPServer) (Session, error)
NewSessionFunc creates a session for session/new. cwd is absolute; id is the new session's id.
type PlanEntry ¶
type PlanEntry struct {
Content string `json:"content"`
Priority string `json:"priority"`
Status string `json:"status"`
}
PlanEntry is one entry of a plan update; Status is pending, in_progress or completed.
type Prompt ¶
Prompt is a session/prompt's content: the task text and the attached images, in order.
func ParsePrompt ¶
func ParsePrompt(blocks []ContentBlock) (Prompt, error)
ParsePrompt turns prompt blocks into task text and images. Text blocks are joined; a text resource becomes quoted context naming its URI; a resource link becomes a reference line (it is not fetched). Images are decoded. Other blocks (audio, binary resources) and a prompt without any text are invalid params.
type Resource ¶
type Resource struct {
URI string `json:"uri"`
MimeType string `json:"mimeType,omitempty"`
Text *string `json:"text,omitempty"`
Blob string `json:"blob,omitempty"`
}
Resource is the resource of an embedded-context block: text or a base64 blob.
type Server ¶
type Server struct {
Name, Version string
NewSession NewSessionFunc
// Log receives protocol problems; nil discards them.
Log io.Writer
// contains filtered or unexported fields
}
Server answers ACP requests read from a client.
func (*Server) Request ¶ added in v0.8.0
Request sends a JSON-RPC request to the client and waits for its response. It is called from a turn goroutine (for session/request_permission); Serve's read loop routes the response back through deliverResponse. A cancelled ctx returns ctx's error.
type Session ¶
type Session interface {
// Prompt runs one turn, streaming progress through u, and returns its
// stop reason. When ctx is cancelled (session/cancel) the reply is
// "cancelled" whatever Prompt returns.
Prompt(ctx context.Context, p Prompt, u *Updates) (string, error)
// Close releases the session's resources; it runs after its last turn.
Close()
}
Session runs one ACP session's prompt turns, one at a time.
type Updates ¶
type Updates struct {
// contains filtered or unexported fields
}
Updates sends one session's session/update notifications.
func (*Updates) Request ¶ added in v0.8.0
Request sends a request to the client and waits for its response (used for session/request_permission).
func (*Updates) ToolCallStatus ¶
ToolCallStatus updates a tool call's status, with optional result text.