A Go implementation of the Agent Client Protocol (ACP), which standardizes communication between code editors (interactive programs for viewing and editing source code) and coding agents (programs that use generative AI to autonomously modify code).
This is an unofficial implementation of the ACP specification in Go. The official protocol specification and reference implementations can be found at the official repository.
Note
The Agent Client Protocol is under active development. This implementation may lag behind the latest specification changes. Please refer to the official repository for the most up-to-date protocol specification.
Learn more about the protocol at agentclientprotocol.com.
go get github.com/ironpark/go-acpSee the docs/example directory for complete working examples:
- Agent Example - Agent implementation with SessionStream, middleware, and permission requests
- Client Example - Client implementation using SpawnAgent and MatchSessionUpdate
This implementation provides a clean, modern architecture with bidirectional JSON-RPC 2.0 communication:
Connection: Unified bidirectional transport layer with concurrent request/response correlationTransport: Pluggable transport interface (stdio, HTTP+SSE) for flexible deploymentAgentSideConnection: High-level ACP interface for implementing agentsClientSideConnection: High-level ACP interface for implementing clientsSessionStream: Convenience wrapper for sending session updates with minimal boilerplateMiddleware: Composable request/response processing chain for cross-cutting concernsTerminalHandle: Resource management wrapper for terminal sessions- Generated Types: Complete type-safe Go structs generated from the official ACP JSON schema
agent := &MyAgent{} conn := acp.NewAgentSideConnection(agent, os.Stdin, os.Stdout, acp.WithMiddleware(acp.RecoveryMiddleware()), acp.WithMiddleware(acp.LoggingMiddleware(nil)), ) conn.Start(context.Background())client := &MyClient{} conn, _ := acp.SpawnAgent(ctx, client, "my-agent") go conn.Start(ctx) conn.Initialize(ctx, &acp.InitializeRequest{...}) conn.Prompt(ctx, &acp.PromptRequest{...})The SDK supports pluggable transports via the Transport interface:
// Default: stdio (newline-delimited JSON) conn := acp.NewConnection(handler, os.Stdin, os.Stdout) // HTTP+SSE transport for web deployments transport := acp.NewHTTPServerTransport() conn := acp.NewConnection(handler, nil, nil, acp.WithTransport(transport)) http.Handle("/", transport.Handler())Add cross-cutting concerns to the connection handler chain:
conn := acp.NewAgentSideConnection(agent, reader, writer, acp.WithMiddleware( acp.RecoveryMiddleware(), // catch panics acp.LoggingMiddleware(log.Printf), // log method calls acp.TimeoutMiddleware(30 * time.Second), // per-request timeout ), )Custom middleware follows the standard pattern:
func authMiddleware(next acp.MethodHandler) acp.MethodHandler { return func(ctx context.Context, method string, params json.RawMessage) (any, error) { if method != "initialize" && !isAuthenticated(ctx) { return nil, acp.ErrAuthRequired(nil) } return next(ctx, method, params) } }Reduce boilerplate when sending session updates from agents:
stream := acp.NewSessionStream(client, sessionID) // Stream text stream.SendText(ctx, "Hello!") stream.SendThought(ctx, "thinking...") // Tool call lifecycle stream.StartToolCall(ctx, toolID, "Reading file", acp.ToolKindRead) stream.CompleteToolCall(ctx, toolID, content...) stream.FailToolCall(ctx, toolID) // Other updates stream.SendPlan(ctx, entries) stream.SendModeUpdate(ctx, modeID) stream.SendSessionInfo(ctx, title, updatedAt)Exhaustive pattern matching for discriminated union types:
acp.MatchSessionUpdate(&update, acp.SessionUpdateMatcher[string]{ AgentMessageChunk: func(v acp.SessionUpdateAgentMessageChunk) string { return acp.MatchContentBlock(&v.Content, acp.ContentBlockMatcher[string]{ Text: func(t acp.ContentBlockText) string { return t.Text }, Default: func() string { return "[non-text]" }, }) }, ToolCall: func(v acp.SessionUpdateToolCall) string { return v.Title }, Default: func() string { return "" }, })Matchers are available for all union types: SessionUpdate, ContentBlock, ToolCallContent, RequestPermissionOutcome, MCPServer.
acp.NewConnection(handler, reader, writer, acp.WithWriteQueueSize(500), // configurable write queue acp.WithRequestTimeout(30 * time.Second), // default request timeout acp.WithShutdownTimeout(10 * time.Second), // graceful shutdown timeout acp.WithErrorHandler(func(err error) { ... }), // error callback )This implementation supports ACP Protocol Version 1 with the following features:
initialize- Initialize the agent and negotiate capabilitiesauthenticate- Authenticate with the agent (optional)session/new- Create a new conversation sessionsession/load- Load an existing session (if supported)session/list- List available sessionssession/set_mode- Change session modesession/set_config_option- Update session configurationsession/prompt- Send user prompt to agentsession/cancel- Cancel ongoing operations
session/update- Send session updates (notifications)session/request_permission- Request user permission for operationsfs/read_text_file- Read text file from client filesystemfs/write_text_file- Write text file to client filesystem- Terminal Support (unstable):
terminal/create- Create terminal sessionterminal/output- Get terminal outputterminal/wait_for_exit- Wait for terminal exitterminal/kill- Kill terminal processterminal/release- Release terminal handle
session/fork- Fork a session (viaSessionForkerinterface)session/resume- Resume a session (viaSessionResumerinterface)session/close- Close a session (viaSessionCloserinterface)session/set_model- Set model (viaModelSetterinterface)
This is an unofficial implementation. For protocol specification changes, please contribute to the official repository.
For Go implementation issues and improvements, please open an issue or pull request.
This implementation follows the same license as the official ACP specification.
- Official ACP Repository: zed-industries/agent-client-protocol
- Rust Implementation: Part of the official repository
- Protocol Documentation: agentclientprotocol.com
- Zed
- neovim through the CodeCompanion plugin
- yetone/avante.nvim: A Neovim plugin designed to emulate the behaviour of the Cursor AI IDE
