acp

package module
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Oct 12, 2026 License: MIT Imports: 17 Imported by: 5 modules, 4 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.

README

Agent Client Protocol Go banner

Agent Client Protocol for Go

English | 한국어

Build coding agents and editor clients that communicate through the Agent Client Protocol (ACP). This Go SDK provides typed APIs, streaming session updates, cancellation, and stdio, HTTP, and WebSocket connections.

This is an unofficial implementation. ACP v1 is stable; ACP v2 and the HTTP transport specification are drafts. The protocol is evolving, so support follows the pinned upstream revision. See the official ACP documentation for the protocol itself.

Protocol Schema version
ACP v1 1.25.0
ACP v2 (draft) 2.0.0-alpha.8

Quick start · Packages · Examples · Documentation

Requirements and Installation

Requires Go 1.27+ and uses encoding/json/v2. Run this in your Go module to add the SDK:

go get github.com/ironpark/acp-go

Quick Start

Run an agent and client in the same process, with no API key or external agent required:

git clone https://github.com/ironpark/acp-go.git
cd acp-go
go run ./examples/inprocess

Expected output:

>> hello
<< HELLO
>> same process, no child
<< SAME PROCESS, NO CHILD

The complete example connects both sides with acp1.Pipe. Once connected, the client initializes the agent, creates a session, and sends a prompt. This excerpt shows that flow; agent and ctx are created earlier in the example:

if _, err := agent.Initialize(ctx, &acp1.InitializeRequest{}); err != nil {
    log.Fatal(err)
}
session, err := agent.StartSession(ctx, &acp1.NewSessionRequest{Cwd: "/"})
if err != nil {
    log.Fatal(err)
}
turn, err := session.Prompt(ctx, acp1.TextBlock("hello"))
if err != nil {
    log.Fatal(err)
}
text, _, err := turn.Text()
if err != nil {
    log.Fatal(err)
}
fmt.Println(text) // HELLO

To build your own agent, start with Echo Agent: implement Initialize, NewSession, Prompt, and CancelSession. Optional interfaces add capabilities such as loading sessions.

To build a client, start with Client: use acp1.SpawnAgent to launch a stdio agent and implement SessionUpdate and RequestPermission to handle its updates and permission requests. See the SDK guide for connection setup and capability detection.

Packages

Start with acp1 for ACP v1. Add other packages as your application needs them.

Package When to use it
acp1 Build an agent or client for stable ACP v1.
acp2 Work with draft ACP v2; APIs may change.
acp Configure shared transports, middleware, errors, stores, and typed extensions.
acphttp Connect remote agents over Streamable HTTP or WebSocket (draft).
router Serve both protocol versions, or connect with v2 → v1 fallback.
acpmcp Bridge MCP over ACP (separate module, unstable).
schema/v1 / schema/v2 Access generated wire types and validation rules.

Examples

Choose an example by what you want to build. The examples guide has run commands and setup details.

Goal Example
Try an agent and client in one process In-process
Implement the smallest agent Echo Agent
Add sessions, modes, tools, and permission requests Agent
Interact with a stdio agent Client
Build a model-backed coding agent using OpenRouter Open Agent
Connect over HTTP or WebSocket and reload a session HTTP Agent / HTTP Client
Support both v1 and v2, including fallback Dual Agent / Dual Client
Expose client-provided MCP servers to an agent MCP over ACP

Documentation

Contributing

Issues and pull requests for the Go SDK are welcome. For protocol changes, use the official ACP repository.

Build and test the main module from the repository root:

go build ./...
go test ./...

The MCP bridge and schema generator are separate modules; run their tests from acpmcp/ and internal/cmd/schema/, respectively. See the MCP guide and schema guide for details.

License

See LICENSE for the license terms.

Documentation

Overview

Package acp holds what every Agent Client Protocol version shares: the connection options, the Transport interface and the stdio transport, middleware, error type, session store and turn tracker, and extension methods (CallExt, ExtRouter, ExtMethodHandler). The Streamable HTTP and WebSocket transports are in github.com/ironpark/acp-go/acphttp.

The protocol façades live in versioned sibling packages, each generated from the upstream schema of that version:

github.com/ironpark/acp-go/router serves both versions on one endpoint. The wire types are in github.com/ironpark/acp-go/schema/v1 and github.com/ironpark/acp-go/schema/v2.

See the protocol docs: https://agentclientprotocol.com

Index

Constants

View Source
const (
	ErrorCodeParseError       = jsonrpc.CodeParseError
	ErrorCodeInvalidRequest   = jsonrpc.CodeInvalidRequest
	ErrorCodeMethodNotFound   = jsonrpc.CodeMethodNotFound
	ErrorCodeInvalidParams    = jsonrpc.CodeInvalidParams
	ErrorCodeInternalError    = jsonrpc.CodeInternalError
	ErrorCodeRequestCancelled = jsonrpc.CodeRequestCancelled
	ErrorCodeAuthRequired     = jsonrpc.CodeAuthRequired
	ErrorCodeResourceNotFound = jsonrpc.CodeResourceNotFound
)

Error codes defined by JSON-RPC 2.0 and by ACP.

Variables

View Source
var ErrTurnCancelled = acpconn.ErrTurnCancelled

ErrTurnCancelled is the cause of a turn context cancelled by the client's session/cancel, through TurnTracker.Cancel or before the turn began, which is how an agent tells it apart from other cancellation; TurnCancelled checks for it.

View Source
var ErrTurnInProgress = acpconn.ErrTurnInProgress

ErrTurnInProgress reports a prompt on a session whose turn has not ended. v1 allows one prompt turn per session at a time, so both sides refuse it. It is an invalid-request error, and errors.Is matches it by code and message, so a caller recognizes it after it crossed the wire too.

Functions

func AfterReply

func AfterReply(ctx context.Context, fn func(ctx context.Context)) bool

AfterReply registers fn to run once the request whose handler context ctx derives from has been answered successfully. The connection writes its messages in order, so what fn sends reaches the peer after the response, which is how an agent sends a session update about a session the response creates without the update arriving first:

func (a *myAgent) NewSession(ctx context.Context, params *acp1.NewSessionRequest) (*acp1.NewSessionResponse, error) {
	id := acp1.GenerateSessionID()
	acp.AfterReply(ctx, func(ctx context.Context) {
		acp1.NewSessionStream(a.client, id).SendCommands(ctx, commands)
	})
	return &acp1.NewSessionResponse{SessionID: id}, nil
}

Functions run in the order they were registered, on the request's goroutine, with a context that keeps ctx's values but not its cancellation. They do not run when the handler returns an error or the connection closes first. AfterReply reports false, and fn never runs, when ctx is not a request handler's context or the request has already been answered.

func CallExt

func CallExt[R any](ctx context.Context, conn ExtCaller, method string, params any) (*R, error)

CallExt sends an extension request and decodes its result into an R. A null or empty result decodes to the zero value.

resp, err := acp.CallExt[IndexResponse](ctx, conn, "_zed.dev/index", IndexRequest{Path: dir})

See protocol docs: [Extensibility](https://agentclientprotocol.com/protocol/extensibility)

func GenerateID

func GenerateID(prefix string) string

GenerateID returns a new id of the form "<prefix>_<UUIDv7>", for the ids an agent mints: sessions, messages, tool calls. A version 7 UUID starts with its creation time, so ids sort in the order they were minted, which keeps the index of a database-backed store compact.

func GenerateSessionID

func GenerateSessionID() string

GenerateSessionID returns a new id of the form "session_<UUIDv7>".

func IsCode

func IsCode(err error, code ErrorCode) bool

IsCode reports whether err is, or wraps, a RequestError with the given code:

if acp.IsCode(err, acp.ErrorCodeAuthRequired) {
	// authenticate, then retry
}

func TurnCancelled

func TurnCancelled(ctx context.Context) bool

TurnCancelled reports whether ctx, or the turn context it derives from, was cancelled by the client's session/cancel, as opposed to a deadline, the connection closing or no cancellation at all. The protocol answers such a turn with the cancelled stop reason, whatever the work returned:

if acp.TurnCancelled(ctx) {
	return &acp1.PromptResponse{StopReason: acp1.StopReasonCancelled}, nil
}

func WithoutRequestTimeout

func WithoutRequestTimeout(ctx context.Context) context.Context

WithoutRequestTimeout returns a context whose requests the connection's WithRequestTimeout does not bound, for an extension request that waits for the user; ctx's own deadline still applies.

Types

type Conn

type Conn interface {
	ExtCaller
	// ExtNotification sends a notification outside the spec.
	ExtNotification(ctx context.Context, method string, params any) error
	// Close shuts the connection down, waiting for in-flight handlers.
	Close() error
	// Done is closed once the connection stops.
	Done() <-chan struct{}
}

Conn is what the agent- and client-side connections of every protocol version share, for code that does not depend on the version.

type ErrorCode

type ErrorCode = jsonrpc.ErrorCode

ErrorCode is a JSON-RPC error code.

type ExtCaller

type ExtCaller interface {
	ExtMethod(ctx context.Context, method string, params any) (jsontext.Value, error)
}

ExtCaller sends requests outside the spec. The agent- and client-side connections of every protocol version implement it.

type ExtMethodHandler

type ExtMethodHandler interface {
	ServeExtMethod(ctx context.Context, method string, params jsontext.Value) (any, error)
}

ExtMethodHandler handles methods outside the spec. Prefix custom methods with a unique identifier such as a domain name. Its method has a Serve prefix, like http.Handler's, so an agent or client can embed both a handler, such as ExtRouter, and its connection, whose ExtMethod sends requests. Every protocol version's façade dispatches unknown methods to it.

See protocol docs: [Extensibility](https://agentclientprotocol.com/protocol/extensibility)

type ExtNotificationHandler

type ExtNotificationHandler interface {
	ServeExtNotification(ctx context.Context, method string, params jsontext.Value) error
}

ExtNotificationHandler handles notifications outside the spec.

The connection answers $/cancel_request itself, so it never reaches here.

type ExtRouter

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

ExtRouter serves extension methods and notifications through typed handlers. Embed it in an agent or client to implement ExtMethodHandler and ExtNotificationHandler:

type myAgent struct {
	acp.ExtRouter
	// ...
}

a.HandleExt("_zed.dev/index", a.index)
a.OnExtNotification("_zed.dev/progress", a.progress)

Params that fail to decode are answered with invalid params. An unregistered method is answered with method not found, and an unregistered notification is ignored, as the protocol recommends. Register handlers before the connection starts; the router is not safe for concurrent registration.

See protocol docs: [Extensibility](https://agentclientprotocol.com/protocol/extensibility)

func (*ExtRouter) HandleExt

func (r *ExtRouter) HandleExt[P, R any](method string, fn func(context.Context, *P) (*R, error))

HandleExt registers a typed handler for an extension method. A nil response is sent as an empty object.

func (*ExtRouter) OnExtNotification

func (r *ExtRouter) OnExtNotification[P any](method string, fn func(context.Context, *P) error)

OnExtNotification registers a typed handler for an extension notification.

func (*ExtRouter) ServeExtMethod

func (r *ExtRouter) ServeExtMethod(ctx context.Context, method string, params jsontext.Value) (any, error)

ServeExtMethod dispatches an extension request to its registered handler.

func (*ExtRouter) ServeExtNotification

func (r *ExtRouter) ServeExtNotification(ctx context.Context, method string, params jsontext.Value) error

ServeExtNotification dispatches an extension notification to its registered handler, ignoring notifications nothing is registered for.

type FileStore

type FileStore[ID ~string, T any] struct {
	// contains filtered or unexported fields
}

FileStore keeps sessions in memory like MemoryStore and writes each one to its own JSON file in a directory, so the sessions survive a restart: a new FileStore on the same directory loads them, and session/resume and session/list find them again.

Get and List read the in-memory copy, so they return the same value every time, as MemoryStore does, and session state can be changed in place. Only Set writes to disk: the session manager sets a session when it creates it, so an agent that changes a session afterwards saves it again, typically when a turn ends, which the manager's WithAutoSave option does for it:

if err := manager.Save(ctx, id, session); err != nil { ... }

A session is encoded with encoding/json/v2, which skips unexported fields, so session state with unexported fields implements json.Marshaler and json.Unmarshaler, taking its own lock while it encodes.

Each file is named after the hex-encoded session id, so any id is a safe file name; an id of up to 122 bytes fits common file name limits. A file is written to a temporary name, synced, renamed into place, and the directory synced, so a crash or power loss leaves either the previous version or the new one. Where a directory cannot be synced, as on Windows, the rename is as durable as the file system makes it. One process at a time may use a directory: the store does not see files another process writes.

func NewFileStore

func NewFileStore[ID ~string, T any](dir string) (*FileStore[ID, T], error)

NewFileStore opens a store in dir, creating the directory if needed, and loads every session saved there. A file that does not decode is an error, so a store never starts without sessions it was meant to keep.

func (*FileStore[ID, T]) Delete

func (s *FileStore[ID, T]) Delete(ctx context.Context, id ID) error

func (*FileStore[ID, T]) Get

func (s *FileStore[ID, T]) Get(ctx context.Context, id ID) (T, bool, error)

func (*FileStore[ID, T]) List

func (s *FileStore[ID, T]) List(ctx context.Context) ([]ID, error)

func (*FileStore[ID, T]) Set

func (s *FileStore[ID, T]) Set(ctx context.Context, id ID, session T) error

Set writes the session to its file, then makes it the in-memory copy. When the write fails, the store keeps the previous version in memory and on disk. When only the final directory sync fails, the new version is in place in both, but may not survive a power loss, and Set reports the error.

type MemoryStore

type MemoryStore[ID comparable, T any] struct {
	// contains filtered or unexported fields
}

MemoryStore keeps sessions in memory for the life of the process. The zero value is an empty store ready to use.

func NewMemoryStore

func NewMemoryStore[ID comparable, T any]() *MemoryStore[ID, T]

NewMemoryStore creates an empty in-memory store.

func (*MemoryStore[ID, T]) Delete

func (s *MemoryStore[ID, T]) Delete(_ context.Context, id ID) error

Delete removes the session stored under id, if any.

func (*MemoryStore[ID, T]) Get

func (s *MemoryStore[ID, T]) Get(_ context.Context, id ID) (T, bool, error)

Get returns the session stored under id and whether there is one.

func (*MemoryStore[ID, T]) List

func (s *MemoryStore[ID, T]) List(context.Context) ([]ID, error)

List returns the ids of the stored sessions, in no particular order.

func (*MemoryStore[ID, T]) Set

func (s *MemoryStore[ID, T]) Set(_ context.Context, id ID, session T) error

Set stores session under id, replacing any session stored there.

type Metrics

type Metrics interface {
	ObserveRPC(ctx context.Context, method string, kind RPCKind, duration time.Duration, err error)
}

Metrics observes every message a connection handles, so one hook can feed a metrics backend or start and end tracing spans. The context is the handler's own, so a tracing implementation can annotate the span it derived from it.

It only sees incoming traffic: use MetricsMiddleware on a connection to instrument what the peer sends. Outgoing calls have no shared hook; count them where they are made.

type MetricsFunc

type MetricsFunc func(ctx context.Context, method string, kind RPCKind, duration time.Duration, err error)

MetricsFunc adapts a function to Metrics.

func (MetricsFunc) ObserveRPC

func (f MetricsFunc) ObserveRPC(ctx context.Context, method string, kind RPCKind, duration time.Duration, err error)

ObserveRPC calls f.

type Middleware

type Middleware = jsonrpc.Middleware

Middleware wraps incoming request and/or notification handling. Either field may be nil; the first middleware added is the outermost.

func LoggingMiddleware

func LoggingMiddleware(logger *slog.Logger) Middleware

LoggingMiddleware logs each incoming method to logger with its duration and any error, as structured attributes: "method", "duration", and on failure "error" and, for a RequestError, "code". A request logs at Info and a notification, which session updates make frequent, at Debug; a failure of either logs at Warn. The handler's context is passed to logger.

Passing nil uses slog.Default.

func MethodFilterMiddleware

func MethodFilterMiddleware(filter func(method string) bool, mw Middleware) Middleware

MethodFilterMiddleware applies mw only to methods matching filter, so a policy can target a few methods without wrapping the whole connection.

func MetricsMiddleware

func MetricsMiddleware(m Metrics) Middleware

MetricsMiddleware reports every handled message to m with its method, kind, duration and any error, so one hook covers counters, histograms and tracing:

mw := acp.MetricsMiddleware(acp.MetricsFunc(func(ctx context.Context, method string, kind acp.RPCKind, d time.Duration, err error) {
	rpcCalls.WithLabelValues(method, string(kind)).Inc()
	rpcDuration.WithLabelValues(method).Observe(d.Seconds())
}))
conn := acp1.NewAgentSideConnection(newAgent, transport, acp.WithMiddleware(mw))

A nil m makes the middleware a no-op, and the observation still carries the error a request handler returned, not the RequestError the peer receives.

func TimeoutMiddleware

func TimeoutMiddleware(timeout time.Duration) Middleware

TimeoutMiddleware bounds how long any one handler may run. Handlers should watch ctx and return promptly; a handler that returns after its deadline answers the peer with a cancelled error.

type NotificationHandler

type NotificationHandler = jsonrpc.NotificationHandler

NotificationHandler handles one incoming notification.

type Option

type Option = jsonrpc.Option

Option configures a connection. The same option values configure the v2 façade, so middleware or timeouts set up once serve either version.

func WithErrorHandler

func WithErrorHandler(h func(error)) Option

WithErrorHandler sets a callback for non-fatal errors: undecodable messages, write failures and errors returned by notification handlers.

func WithMiddleware

func WithMiddleware(mw ...Middleware) Option

WithMiddleware adds middleware to the incoming handler chain.

func WithRequestTimeout

func WithRequestTimeout(d time.Duration) Option

WithRequestTimeout bounds outgoing requests whose caller context carries no deadline of its own. Requests that wait for the user are exempt: a v1 session/prompt, which lasts its whole turn, and session/request_permission and elicitation/create; bound those with their context, and mark other such requests with WithoutRequestTimeout. Default: none.

func WithShutdownTimeout

func WithShutdownTimeout(d time.Duration) Option

WithShutdownTimeout bounds how long Close waits for in-flight handlers. Default: wait indefinitely.

func WithWriteQueueSize

func WithWriteQueueSize(size int) Option

WithWriteQueueSize sets the outgoing queue depth. Default: 100.

type RPCKind

type RPCKind string

RPCKind is the kind of incoming message a Metrics observation describes: a request, which expects a response, or a notification.

const (
	// RPCRequest is a request expecting a response.
	RPCRequest RPCKind = "request"
	// RPCNotification is a notification, which has no response.
	RPCNotification RPCKind = "notification"
)

type RequestError

type RequestError = jsonrpc.RequestError

RequestError is a JSON-RPC error carried as a Go error.

Returning one from a handler controls the code, message and data the peer receives; any other error becomes an internal error. Errors from the peer are returned to callers in this same shape, so errors.As recovers the code.

func AuthRequired

func AuthRequired(detail string) *RequestError

AuthRequired reports that the caller must authenticate first (-32000).

Agents return this from NewSession when no credentials are available yet.

func InternalError

func InternalError(detail string) *RequestError

InternalError reports a handler failure (-32603).

func InvalidParams

func InvalidParams(detail string) *RequestError

InvalidParams reports parameters that failed validation (-32602).

func InvalidRequest

func InvalidRequest(detail string) *RequestError

InvalidRequest reports a malformed request object (-32600).

func MethodNotFound

func MethodNotFound(method string) *RequestError

MethodNotFound reports an unknown or unsupported method (-32601).

The connection returns this automatically when an optional method's interface is not implemented.

func ParseError

func ParseError(detail string) *RequestError

ParseError reports invalid JSON (-32700).

func RequestCancelled

func RequestCancelled(detail string) *RequestError

RequestCancelled reports a request abandoned before completion (-32800).

The connection returns this automatically when a handler's context is cancelled, either by the peer's $/cancel_request or by shutdown.

func ResourceNotFound

func ResourceNotFound(detail string) *RequestError

ResourceNotFound reports a missing resource such as a file (-32002).

type RequestHandler

type RequestHandler = jsonrpc.RequestHandler

RequestHandler handles one incoming request and returns the value to encode as its result.

type SessionInfoLister

type SessionInfoLister[Info any] interface {
	ListSessionInfo(ctx context.Context, query SessionListQuery) ([]Info, error)
}

SessionInfoLister is implemented by a SessionStore that can answer session/list itself, such as one backed by a database index. The session manager of each façade uses it instead of reading and describing every stored session for each page, so a page costs the store one query.

ListSessionInfo returns the sessions that match query, in the order SessionListPosition.Compare defines, with each SessionID set. The manager asks for one more session than a page holds and returns the page and next cursor from the result, so a store that stops short of Limit ends the listing.

type SessionListPosition

type SessionListPosition struct {
	// UpdatedAt is the session's last-activity timestamp, compared as a
	// string, so a store must write every timestamp in one format, such as
	// RFC 3339 in UTC. A session without one sorts after every dated session.
	UpdatedAt string
	// SessionID breaks ties between sessions with the same UpdatedAt.
	SessionID string
}

SessionListPosition is a session's place in a session/list result, which lists the most recently updated sessions first and breaks ties by session id ascending.

func (SessionListPosition) Compare

func (p SessionListPosition) Compare(other SessionListPosition) int

Compare orders two positions the way session/list does. A negative result means p is listed before other, a positive one after it.

type SessionListQuery

type SessionListQuery struct {
	// Cwd, when not empty, keeps only the sessions in this working directory.
	Cwd string
	// After, when not nil, keeps only the sessions listed after this
	// position; a nil After starts at the most recently updated session.
	After *SessionListPosition
	// Limit, when positive, is the most sessions to return; zero or less
	// returns every match.
	Limit int
}

SessionListQuery selects one page of sessions for a SessionInfoLister.

type SessionStore

type SessionStore[ID comparable, T any] interface {
	// Get returns the session with the given id, or false if there is none.
	Get(ctx context.Context, id ID) (T, bool, error)
	// Set stores a session, replacing any session with the same id.
	Set(ctx context.Context, id ID, session T) error
	// Delete removes a session. Deleting an unknown id is not an error.
	Delete(ctx context.Context, id ID) error
	// List returns the stored session ids.
	List(ctx context.Context) ([]ID, error)
}

SessionStore keeps per-session state for an agent, keyed by the protocol version's session id type. Implementations must be safe for concurrent use.

Every method takes the context of the request it serves and can fail, so a store backed by a database or a remote cache can report its errors; the session manager returns them to the client.

type Transport

type Transport = jsonrpc.Transport

Transport is a bidirectional message transport. Implement it to carry ACP over something other than stdio; package acphttp provides Streamable HTTP and WebSocket.

func NewStdioTransport

func NewStdioTransport(reader io.Reader, writer io.Writer) Transport

NewStdioTransport carries newline-delimited JSON over a reader/writer pair.

type TurnTracker

type TurnTracker[ID comparable] struct {
	// contains filtered or unexported fields
}

TurnTracker holds a cancellable context for the turn in progress on each session, so a cancel notification can stop the work a prompt started. The zero value is ready to use and it is safe for concurrent use.

A turn started from a session/prompt request's context is also cancelled by a session/cancel that arrived after the prompt but before the turn began, so an agent may do work, such as loading the session, before it starts the turn without losing an early cancel. It also ends when the connection serving that request closes, even when it was started from a context detached from the request, as a v2 turn is; TurnCancelled then reports false.

The two ways to start a turn follow the protocol versions: in v1 a prompt occupies the session until it ends, so TurnTracker.Begin refuses a second one; in v2 a prompt may contribute to foreground work already running, so TurnTracker.Join hands back the running turn, and TurnTracker.Settle lets the work end it only once it has answered every prompt that joined.

func (*TurnTracker[ID]) Begin

func (t *TurnTracker[ID]) Begin(ctx context.Context, id ID) (context.Context, func(), error)

Begin starts a turn on a session and returns its context and a done func to call when the turn ends. It fails with ErrTurnInProgress while the session has a turn running.

func (*TurnTracker[ID]) Cancel

func (t *TurnTracker[ID]) Cancel(id ID) bool

Cancel cancels the session's turn in progress with ErrTurnCancelled and reports whether there was one.

func (*TurnTracker[ID]) Join

func (t *TurnTracker[ID]) Join(ctx context.Context, id ID) (turnCtx context.Context, done func(), joined bool)

Join returns the session's running turn, or starts one when there is none. joined reports which: a joined caller gets a no-op done, since the turn belongs to the caller that started it. A turn that has settled is ending, so Join waits for its done and then starts a new one.

func (*TurnTracker[ID]) Settle

func (t *TurnTracker[ID]) Settle(id ID) bool

Settle reports whether the session's turn may end: false when a caller joined it since it began or since the last Settle, whose prompt the work must answer before trying again. Once it reports true, callers that would join wait for the turn's done and start a new turn instead, so the starter can report the end without a joined prompt going unanswered:

for {
	work(turnCtx) // answers every prompt received so far
	if tracker.Settle(id) {
		break
	}
}
report the end, then done()

Directories

Path Synopsis
Package acp1 implements the Agent Client Protocol (ACP) v1 for Go.
Package acp1 implements the Agent Client Protocol (ACP) v1 for Go.
acp1test
Package acp1test helps test ACP v1 agents: Client is a client that records what an agent sends and answers its permission requests, and Connect runs an agent against it in memory.
Package acp1test helps test ACP v1 agents: Client is a client that records what an agent sends and answers its permission requests, and Connect runs an agent against it in memory.
Package acp2 implements the draft Agent Client Protocol v2 for Go.
Package acp2 implements the draft Agent Client Protocol v2 for Go.
acp2test
Package acp2test helps test ACP v2 agents: Client is a client that records what an agent sends and answers its permission requests, and Connect runs an agent against it in memory.
Package acp2test helps test ACP v2 agents: Client is a client that records what an agent sends and answers its permission requests, and Connect runs an agent against it in memory.
Package acphttp carries ACP over Streamable HTTP and WebSocket, following the draft RFD "Streamable HTTP & WebSocket Transport" that the TypeScript and Python SDKs implement.
Package acphttp carries ACP over Streamable HTTP and WebSocket, following the draft RFD "Streamable HTTP & WebSocket Transport" that the TypeScript and Python SDKs implement.
acpmcp module
examples
agent command
Command agent is a complete ACP agent over stdio.
Command agent is a complete ACP agent over stdio.
client command
Command client is an interactive ACP client for any agent over stdio.
Command client is an interactive ACP client for any agent over stdio.
dual-agent command
Command dual-agent serves the echo agent in both ACP v1 and the draft v2 from one binary.
Command dual-agent serves the echo agent in both ACP v1 and the draft v2 from one binary.
dual-client command
Command dual-client connects to an agent with ACP v2 when the agent supports it and falls back to v1 when it does not, then runs one prompt.
Command dual-client connects to an agent with ACP v2 when the agent supports it and falls back to v1 when it does not, then runs one prompt.
echo command
Command echo is the smallest useful ACP agent: it streams each prompt back to the client as an agent message.
Command echo is the smallest useful ACP agent: it streams each prompt back to the client as an agent message.
http-agent command
Command http-agent serves the echo agent over Streamable HTTP instead of stdio, at http://localhost:8000/acp.
Command http-agent serves the echo agent over Streamable HTTP instead of stdio, at http://localhost:8000/acp.
http-client command
Command http-client connects to the http-agent example over Streamable HTTP, or over WebSocket with -ws, and runs one prompt turn.
Command http-client connects to the http-agent example over Streamable HTTP, or over WebSocket with -ws, and runs one prompt turn.
inprocess command
Command inprocess runs an agent and a client in one process, connected in memory with acp1.Pipe instead of a child process's stdio:
Command inprocess runs an agent and a client in one process, connected in memory with acp1.Pipe instead of a child process's stdio:
open-agent command
Command open-agent is an ACP coding agent backed by a model on OpenRouter.
Command open-agent is an ACP coding agent backed by a model on OpenRouter.
internal
acpconn
Package acpconn holds what the versioned ACP façades share: the agent-side JSON-RPC connection with prompt cancel tracking, generic dispatch, process spawn and in-memory pipes, and client turn buffering.
Package acpconn holds what the versioned ACP façades share: the agent-side JSON-RPC connection with prompt cancel tracking, generic dispatch, process spawn and in-memory pipes, and client turn buffering.
Package router serves ACP v1 and the draft v2 on one endpoint.
Package router serves ACP v1 and the draft v2 on one endpoint.
schema
internal/union
Package union recognizes the alternatives of the generated raw ACP unions (unions that are not discriminated objects).
Package union recognizes the alternatives of the generated raw ACP unions (unions that are not discriminated objects).
internal/zod
Package zod evaluates the statically extracted Zod rules used by the generated ACP schema packages.
Package zod evaluates the statically extracted Zod rules used by the generated ACP schema packages.
internal/zod/zodsnap
Package zodsnap pins what a zod.Registry makes of a corpus of inputs, so a change to the rule evaluator or to how rules are generated can be checked against the results before it.
Package zodsnap pins what a zod.Registry makes of a corpus of inputs, so a change to the rule evaluator or to how rules are generated can be checked against the results before it.
meta
Package meta holds the _meta extension map that every ACP schema version reserves on its requests, responses and notifications.
Package meta holds the _meta extension map that every ACP schema version reserves on its requests, responses and notifications.
optional
Package optional holds Value, a JSON member that tells absent, null and a value apart.
Package optional holds Value, a JSON member that tells absent, null and a value apart.
v1
v2

Jump to

Keyboard shortcuts

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