What is ACP?
The Agent Client Protocol (ACP) is a standardized communication protocol that enables code editors and AI-powered coding agents to work together seamlessly. It defines how these two participants exchange messages, manage sessions, execute tool calls, and handle real-time updates.ACP is designed to be editor-agnostic and agent-agnostic, allowing any compliant client to work with any compliant agent.
Protocol Architecture
ACP follows a client-server architecture where:Communication Layer
ACP uses JSON-RPC 2.0 over NDJSON (newline-delimited JSON) for bidirectional communication. This design enables:- Request/Response: Synchronous operations with expected replies
- Notifications: Fire-and-forget messages for streaming updates
- Stream-based: Efficient communication over stdin/stdout
Protocol Flow
A typical ACP interaction follows this sequence:1. Initialization
The client and agent negotiate capabilities and protocol version:2. Session Creation
The client creates a new conversation session:3. Prompt Processing
The client sends user prompts and receives streaming updates:session/update notifications:
- Message chunks (text, thoughts)
- Tool calls and their execution status
- Execution plans
- Mode changes
4. Tool Execution & Permissions
When the agent needs to perform sensitive operations, it requests permission:Key Protocol Features
Type Safety
The Dart SDK provides full type safety with:- Sealed union types for exhaustive pattern matching
- JSON serialization via
json_serializable - Null safety throughout
- Comprehensive error types
Error Handling
ACP uses standard JSON-RPC error codes with additional domain-specific codes:| Code | Error | Description |
|---|---|---|
| -32700 | Parse error | Invalid JSON |
| -32600 | Invalid request | Malformed request |
| -32601 | Method not found | Unknown method |
| -32602 | Invalid params | Parameter validation failed |
| -32603 | Internal error | Unexpected runtime error |
| -32000 | Auth required | Authentication needed |
| -32002 | Resource not found | File/resource missing |
| -32800 | Cancelled | Request was cancelled |
Request Cancellation
ACP supports protocol-level cancellation via the$/cancel_request notification:
Cancellation is best-effort. The peer may still complete the request if it’s already in progress.
Extension Methods
Both clients and agents can implement custom extension methods prefixed with_:
Protocol Versions
Stable Features (v0.1.0)
The current stable protocol includes:- Core lifecycle:
initialize,authenticate - Session management:
session/new,session/load,session/prompt - Session control:
session/cancel,session/set_mode,session/set_config_option - File operations:
fs/read_text_file,fs/write_text_file - Terminal operations:
terminal/create,terminal/output,terminal/wait_for_exit,terminal/kill,terminal/release - Updates: All core session update types
- Cancellation:
$/cancel_request
Unstable Features
The SDK also supports unstable features that may change:session/list- List existing sessionssession/fork- Fork a session to create a branchsession/resume- Resume without replaying historysession/set_model- Change the AI model
Unstable features are marked with the
unstable prefix in method names and may be removed or changed in future versions.Stream Behavior
ThendJsonStream() function handles malformed messages gracefully:
- Invalid JSON lines are skipped
- Valid messages continue to be processed
- Parse errors can be logged via the
onParseErrorcallback
Next Steps
Agents
Learn how to implement an ACP agent
Clients
Learn how to implement an ACP client
Sessions
Understand session management
Connections
Deep dive into connection handling