ACP API Reference¶
Auto-generated API documentation for the ACP module.
acp
¶
ACP (Agent Client Protocol) -- Zero-dependency Python implementation.
Part of zerodep: https://github.com/Oaklight/zerodep Copyright (c) 2026 Peng Ding. MIT License.
The Agent Client Protocol standardizes communication between code editors (Clients) and AI coding agents (Agents). It uses JSON-RPC 2.0 over stdio (newline-delimited JSON), similar to how the Language Server Protocol (LSP) standardized language-server integration.
This single-file module provides:
-
JSONRPCTransport -- async read/write of newline-delimited JSON-RPC 2.0 messages over arbitrary
asyncio.StreamReader/asyncio.StreamWriterpairs (typically stdin/stdout of a subprocess). -
Protocol data types -- pure-dataclass representations of every message and structure defined by the ACP specification (protocol version 1).
-
ACPClient -- high-level async helper that spawns an agent subprocess, performs the
initializehandshake, creates sessions, sends prompts, and yieldssession/updatenotifications as an async iterator. -
ACPAgent -- abstract base class for implementing an ACP-compatible agent. Subclass it and override the
on_*handler methods; callagent.run()to start the stdio event loop.
Requires Python >= 3.10. No third-party packages are needed -- only the
standard library (asyncio, json, dataclasses, enum, typing,
sys, abc, uuid, logging).
Quickstart -- Client side::
async def main():
client = ACPClient(["python", "-m", "my_agent"])
await client.start()
init = await client.initialize()
session = await client.new_session("/home/user/project")
async for update in client.prompt(session.session_id, "Hello!"):
print(update)
await client.stop()
Quickstart -- Agent side::
class EchoAgent(ACPAgent):
async def on_initialize(self, params):
return InitializeResult(protocol_version=1)
async def on_new_session(self, params):
return NewSessionResult(session_id="sess_1")
async def on_prompt(self, params):
text = ""
for block in params.prompt:
if isinstance(block, TextContent):
text = block.text
await self.send_update(params.session_id,
AgentMessageChunkUpdate(
content=TextContent(text=f"Echo: {text}")))
return PromptResult(stop_reason=StopReason.END_TURN)
if __name__ == "__main__":
asyncio.run(EchoAgent().run())
JSONRPCError
dataclass
¶
A JSON-RPC 2.0 error object.
Attributes:
| Name | Type | Description |
|---|---|---|
code |
int
|
Numeric error code. |
message |
str
|
Human-readable error message. |
data |
Any
|
Optional additional error data. |
Source code in jsonrpc/jsonrpc.py
JSONRPCException
¶
Bases: Exception
Exception wrapper around a JSONRPCError data object.
Attributes:
| Name | Type | Description |
|---|---|---|
error |
The underlying |
Source code in jsonrpc/jsonrpc.py
JSONRPCTransport
¶
Async JSON-RPC 2.0 transport over newline-delimited JSON streams.
Each message is a single JSON object terminated by \n.
Messages must not contain embedded newlines.
Attributes:
| Name | Type | Description |
|---|---|---|
reader |
Async stream to read incoming messages from. |
|
writer |
Async stream to write outgoing messages to. |
Source code in jsonrpc/jsonrpc.py
356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 | |
is_closed
property
¶
Whether the writer has been closed.
read_message()
async
¶
Read the next JSON-RPC message.
Returns:
| Type | Description |
|---|---|
dict[str, Any] | None
|
Parsed JSON object, or |
Source code in jsonrpc/jsonrpc.py
write_message(msg)
async
¶
Write a JSON-RPC message followed by a newline.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
msg
|
dict[str, Any]
|
JSON-serializable dictionary to send. |
required |
Source code in jsonrpc/jsonrpc.py
send_request(method, params=None, req_id=None)
async
¶
Build and send a JSON-RPC request.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
method
|
str
|
The RPC method name. |
required |
params
|
Any
|
Parameters for the method. |
None
|
req_id
|
Union[int, str, None]
|
Optional explicit request id. |
None
|
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
The message dictionary that was sent. |
Source code in jsonrpc/jsonrpc.py
send_notification(method, params=None)
async
¶
Build and send a JSON-RPC notification (no id).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
method
|
str
|
The RPC method name. |
required |
params
|
Any
|
Parameters for the notification. |
None
|
Source code in jsonrpc/jsonrpc.py
send_result(req_id, result)
async
¶
Send a JSON-RPC success response.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
req_id
|
Union[int, str]
|
The id of the original request. |
required |
result
|
Any
|
The result payload. |
required |
Source code in jsonrpc/jsonrpc.py
send_error(req_id, error)
async
¶
Send a JSON-RPC error response.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
req_id
|
Union[int, str, None]
|
The id of the original request (may be |
required |
error
|
JSONRPCError
|
The error object. |
required |
Source code in jsonrpc/jsonrpc.py
StopReason
¶
Bases: str, Enum
Reason an agent stopped a prompt turn.
Source code in acp/acp.py
ToolKind
¶
Bases: str, Enum
Category of a tool being invoked.
Source code in acp/acp.py
ToolCallStatus
¶
PermissionOptionKind
¶
Bases: str, Enum
Kind of permission option presented to the user.
Source code in acp/acp.py
PlanEntryPriority
¶
PlanEntryStatus
¶
TextContent
dataclass
¶
Plain text content block.
Attributes:
| Name | Type | Description |
|---|---|---|
text |
str
|
The text payload. |
type |
str
|
Discriminator (always |
Source code in acp/acp.py
ImageContent
dataclass
¶
Base64-encoded image content block.
Attributes:
| Name | Type | Description |
|---|---|---|
data |
str
|
Base64-encoded image data. |
mime_type |
str
|
MIME type such as |
type |
str
|
Discriminator (always |
Source code in acp/acp.py
AudioContent
dataclass
¶
Base64-encoded audio content block.
Attributes:
| Name | Type | Description |
|---|---|---|
data |
str
|
Base64-encoded audio data. |
mime_type |
str
|
MIME type such as |
type |
str
|
Discriminator (always |
Source code in acp/acp.py
ResourceContent
dataclass
¶
Embedded resource content block.
Attributes:
| Name | Type | Description |
|---|---|---|
resource |
_TextResource
|
The embedded resource (text or blob). |
type |
str
|
Discriminator (always |
Source code in acp/acp.py
ResourceLinkContent
dataclass
¶
Reference to an external resource.
Attributes:
| Name | Type | Description |
|---|---|---|
uri |
str
|
URI of the resource. |
name |
str
|
Human-readable resource name. |
mime_type |
str | None
|
Optional MIME type. |
title |
str | None
|
Optional display title. |
description |
str | None
|
Optional description. |
size |
int | None
|
Optional size in bytes. |
type |
str
|
Discriminator (always |
Source code in acp/acp.py
ImplementationInfo
dataclass
¶
Information about a client or agent implementation.
Attributes:
| Name | Type | Description |
|---|---|---|
name |
str
|
Programmatic identifier. |
version |
str
|
Version string. |
title |
str | None
|
Human-readable display name. |
Source code in acp/acp.py
FsCapabilities
dataclass
¶
Client file-system capabilities.
Attributes:
| Name | Type | Description |
|---|---|---|
read_text_file |
bool
|
Whether |
write_text_file |
bool
|
Whether |
Source code in acp/acp.py
ClientCapabilities
dataclass
¶
Capabilities supported by the client.
Attributes:
| Name | Type | Description |
|---|---|---|
fs |
FsCapabilities | None
|
File-system method availability. |
terminal |
bool
|
Whether all |
Source code in acp/acp.py
PromptCapabilities
dataclass
¶
Content types the agent supports in prompts.
Attributes:
| Name | Type | Description |
|---|---|---|
image |
bool
|
Whether image content is supported. |
audio |
bool
|
Whether audio content is supported. |
embedded_context |
bool
|
Whether embedded resource content is supported. |
Source code in acp/acp.py
McpCapabilities
dataclass
¶
MCP transport capabilities.
Attributes:
| Name | Type | Description |
|---|---|---|
http |
bool
|
Whether HTTP MCP transport is supported. |
sse |
bool
|
Whether SSE MCP transport is supported. |
Source code in acp/acp.py
SessionListCapability
dataclass
¶
SessionCapabilities
dataclass
¶
Session-level capabilities.
Attributes:
| Name | Type | Description |
|---|---|---|
list |
SessionListCapability | None
|
If present, |
Source code in acp/acp.py
AgentCapabilities
dataclass
¶
Capabilities supported by the agent.
Attributes:
| Name | Type | Description |
|---|---|---|
load_session |
bool
|
Whether |
prompt_capabilities |
PromptCapabilities | None
|
Supported content types in prompts. |
mcp_capabilities |
McpCapabilities | None
|
Supported MCP transports. |
session_capabilities |
SessionCapabilities | None
|
Session-level capabilities. |
Source code in acp/acp.py
AuthMethod
dataclass
¶
An authentication method advertised by the agent.
Attributes:
| Name | Type | Description |
|---|---|---|
id |
str
|
Unique identifier for this auth method. |
name |
str
|
Human-readable name. |
description |
str | None
|
Optional description. |
Source code in acp/acp.py
InitializeParams
dataclass
¶
Parameters for the initialize request.
Attributes:
| Name | Type | Description |
|---|---|---|
protocol_version |
int
|
Latest protocol version the client supports. |
client_capabilities |
ClientCapabilities | None
|
Capabilities the client supports. |
client_info |
ImplementationInfo | None
|
Information about the client implementation. |
Source code in acp/acp.py
InitializeResult
dataclass
¶
Result of the initialize request.
Attributes:
| Name | Type | Description |
|---|---|---|
protocol_version |
int
|
Negotiated protocol version. |
agent_capabilities |
AgentCapabilities | None
|
Capabilities the agent supports. |
agent_info |
ImplementationInfo | None
|
Information about the agent implementation. |
auth_methods |
list[AuthMethod] | None
|
Available authentication methods. |
Source code in acp/acp.py
EnvVariable
dataclass
¶
An environment variable.
Attributes:
| Name | Type | Description |
|---|---|---|
name |
str
|
Variable name. |
value |
str
|
Variable value. |
Source code in acp/acp.py
McpServerStdio
dataclass
¶
Stdio MCP server specification.
Attributes:
| Name | Type | Description |
|---|---|---|
name |
str
|
Human-readable server name. |
command |
str
|
Path to the MCP server executable. |
args |
list[str]
|
Command-line arguments. |
env |
list[EnvVariable] | None
|
Environment variables. |
Source code in acp/acp.py
HttpHeader
dataclass
¶
McpServerHttp
dataclass
¶
HTTP MCP server specification.
Attributes:
| Name | Type | Description |
|---|---|---|
name |
str
|
Human-readable server name. |
url |
str
|
URL of the MCP server. |
headers |
list[HttpHeader]
|
HTTP headers. |
type |
str
|
Transport type ( |
Source code in acp/acp.py
NewSessionParams
dataclass
¶
Parameters for session/new.
Attributes:
| Name | Type | Description |
|---|---|---|
cwd |
str
|
Absolute path to the working directory. |
mcp_servers |
list[dict[str, Any]] | None
|
MCP servers to connect to. |
Source code in acp/acp.py
SessionMode
dataclass
¶
An operating mode for the agent.
Attributes:
| Name | Type | Description |
|---|---|---|
id |
str
|
Unique mode identifier. |
name |
str
|
Human-readable mode name. |
description |
str | None
|
Optional description. |
Source code in acp/acp.py
SessionModeState
dataclass
¶
Current mode state for a session.
Attributes:
| Name | Type | Description |
|---|---|---|
current_mode_id |
str
|
The currently active mode. |
available_modes |
list[SessionMode]
|
All available modes. |
Source code in acp/acp.py
ConfigOptionValue
dataclass
¶
A possible value for a configuration option.
Attributes:
| Name | Type | Description |
|---|---|---|
value |
str
|
Value identifier. |
name |
str
|
Human-readable name. |
description |
str | None
|
Optional description. |
Source code in acp/acp.py
ConfigOption
dataclass
¶
A session configuration option.
Attributes:
| Name | Type | Description |
|---|---|---|
id |
str
|
Unique option identifier. |
name |
str
|
Human-readable label. |
type |
str
|
Input control type (currently only |
current_value |
str
|
Currently selected value. |
options |
list[ConfigOptionValue]
|
Available values. |
description |
str | None
|
Optional description. |
category |
str | None
|
Optional semantic category. |
Source code in acp/acp.py
NewSessionResult
dataclass
¶
Result of session/new.
Attributes:
| Name | Type | Description |
|---|---|---|
session_id |
str
|
Unique identifier for the created session. |
modes |
SessionModeState | None
|
Optional mode state. |
config_options |
list[ConfigOption] | None
|
Optional configuration options. |
Source code in acp/acp.py
LoadSessionParams
dataclass
¶
Parameters for session/load.
Attributes:
| Name | Type | Description |
|---|---|---|
session_id |
str
|
Session to resume. |
cwd |
str
|
Working directory. |
mcp_servers |
list[dict[str, Any]] | None
|
MCP servers to connect to. |
Source code in acp/acp.py
PromptParams
dataclass
¶
Parameters for session/prompt.
Attributes:
| Name | Type | Description |
|---|---|---|
session_id |
str
|
Target session. |
prompt |
list[ContentBlock]
|
Content blocks forming the user message. |
Source code in acp/acp.py
PromptResult
dataclass
¶
Result of session/prompt.
Attributes:
| Name | Type | Description |
|---|---|---|
stop_reason |
StopReason
|
Why the agent stopped. |
Source code in acp/acp.py
CancelParams
dataclass
¶
Parameters for session/cancel notification.
Attributes:
| Name | Type | Description |
|---|---|---|
session_id |
str
|
Session to cancel. |
Source code in acp/acp.py
SetModeParams
dataclass
¶
Parameters for session/set_mode.
Attributes:
| Name | Type | Description |
|---|---|---|
session_id |
str
|
Target session. |
mode_id |
str
|
Mode to switch to. |
Source code in acp/acp.py
SetConfigOptionParams
dataclass
¶
Parameters for session/set_config_option.
Attributes:
| Name | Type | Description |
|---|---|---|
session_id |
str
|
Target session. |
config_id |
str
|
Configuration option id. |
value |
str
|
New value. |
Source code in acp/acp.py
SetConfigOptionResult
dataclass
¶
Result of session/set_config_option.
Attributes:
| Name | Type | Description |
|---|---|---|
config_options |
list[ConfigOption]
|
Complete list of config options with current values. |
Source code in acp/acp.py
ListSessionsParams
dataclass
¶
Parameters for session/list.
Attributes:
| Name | Type | Description |
|---|---|---|
cwd |
str | None
|
Optional directory filter. |
cursor |
str | None
|
Optional pagination cursor. |
Source code in acp/acp.py
SessionInfo
dataclass
¶
Metadata about an existing session.
Attributes:
| Name | Type | Description |
|---|---|---|
session_id |
str
|
Unique session identifier. |
cwd |
str
|
Working directory. |
title |
str | None
|
Optional human-readable title. |
updated_at |
str | None
|
Optional ISO 8601 timestamp. |
Source code in acp/acp.py
ListSessionsResult
dataclass
¶
Result of session/list.
Attributes:
| Name | Type | Description |
|---|---|---|
sessions |
list[SessionInfo]
|
List of session metadata. |
next_cursor |
str | None
|
Pagination cursor for the next page. |
Source code in acp/acp.py
ToolCallLocation
dataclass
¶
File location affected by a tool call.
Attributes:
| Name | Type | Description |
|---|---|---|
path |
str
|
Absolute file path. |
line |
int | None
|
Optional line number (1-based). |
Source code in acp/acp.py
DiffContent
dataclass
¶
A file diff produced by a tool call.
Attributes:
| Name | Type | Description |
|---|---|---|
path |
str
|
Absolute path of the file being modified. |
new_text |
str
|
New content after modification. |
old_text |
str | None
|
Original content ( |
type |
str
|
Discriminator (always |
Source code in acp/acp.py
TerminalContent
dataclass
¶
Reference to terminal output embedded in a tool call.
Attributes:
| Name | Type | Description |
|---|---|---|
terminal_id |
str
|
Id of the terminal created with |
type |
str
|
Discriminator (always |
Source code in acp/acp.py
ToolCallContentItem
dataclass
¶
A content item within a tool call (wraps a ContentBlock).
Attributes:
| Name | Type | Description |
|---|---|---|
content |
ContentBlock
|
The wrapped content block. |
type |
str
|
Discriminator (always |
Source code in acp/acp.py
PermissionOption
dataclass
¶
A permission option presented to the user.
Attributes:
| Name | Type | Description |
|---|---|---|
option_id |
str
|
Unique option identifier. |
name |
str
|
Human-readable label. |
kind |
PermissionOptionKind
|
Permission kind hint. |
Source code in acp/acp.py
PermissionOutcome
dataclass
¶
Outcome of a permission request.
Attributes:
| Name | Type | Description |
|---|---|---|
outcome |
str
|
|
option_id |
str | None
|
The selected option id (if |
Source code in acp/acp.py
RequestPermissionParams
dataclass
¶
Parameters for session/request_permission (agent -> client).
Attributes:
| Name | Type | Description |
|---|---|---|
session_id |
str
|
Target session. |
tool_call |
dict[str, Any]
|
Tool call update with details about the operation. |
options |
list[PermissionOption]
|
Available permission options. |
Source code in acp/acp.py
RequestPermissionResult
dataclass
¶
Result of session/request_permission.
Attributes:
| Name | Type | Description |
|---|---|---|
outcome |
PermissionOutcome
|
The user's decision. |
Source code in acp/acp.py
PlanEntry
dataclass
¶
A single entry in an agent's execution plan.
Attributes:
| Name | Type | Description |
|---|---|---|
content |
str
|
Human-readable task description. |
priority |
PlanEntryPriority
|
Relative importance. |
status |
PlanEntryStatus
|
Current execution status. |
Source code in acp/acp.py
AvailableCommandInput
dataclass
¶
Input specification for a slash command.
Attributes:
| Name | Type | Description |
|---|---|---|
hint |
str
|
Placeholder text shown when no input has been provided. |
Source code in acp/acp.py
AvailableCommand
dataclass
¶
A slash command advertised by the agent.
Attributes:
| Name | Type | Description |
|---|---|---|
name |
str
|
Command name (e.g. |
description |
str
|
Human-readable description. |
input |
AvailableCommandInput | None
|
Optional input specification. |
Source code in acp/acp.py
ReadTextFileParams
dataclass
¶
Parameters for fs/read_text_file (agent -> client).
Attributes:
| Name | Type | Description |
|---|---|---|
session_id |
str
|
Target session. |
path |
str
|
Absolute file path. |
line |
int | None
|
Optional start line (1-based). |
limit |
int | None
|
Optional max number of lines. |
Source code in acp/acp.py
ReadTextFileResult
dataclass
¶
WriteTextFileParams
dataclass
¶
Parameters for fs/write_text_file (agent -> client).
Attributes:
| Name | Type | Description |
|---|---|---|
session_id |
str
|
Target session. |
path |
str
|
Absolute file path. |
content |
str
|
Text content to write. |
Source code in acp/acp.py
CreateTerminalParams
dataclass
¶
Parameters for terminal/create (agent -> client).
Attributes:
| Name | Type | Description |
|---|---|---|
session_id |
str
|
Target session. |
command |
str
|
Command to execute. |
args |
list[str] | None
|
Command arguments. |
env |
list[EnvVariable] | None
|
Environment variables. |
cwd |
str | None
|
Working directory (absolute path). |
output_byte_limit |
int | None
|
Max bytes of output to retain. |
Source code in acp/acp.py
CreateTerminalResult
dataclass
¶
Result of terminal/create.
Attributes:
| Name | Type | Description |
|---|---|---|
terminal_id |
str
|
Unique terminal identifier. |
Source code in acp/acp.py
TerminalOutputParams
dataclass
¶
Parameters for terminal/output.
Attributes:
| Name | Type | Description |
|---|---|---|
session_id |
str
|
Target session. |
terminal_id |
str
|
Terminal to query. |
Source code in acp/acp.py
TerminalExitStatus
dataclass
¶
Terminal process exit status.
Attributes:
| Name | Type | Description |
|---|---|---|
exit_code |
int | None
|
Process exit code (may be |
signal |
str | None
|
Termination signal (may be |
Source code in acp/acp.py
TerminalOutputResult
dataclass
¶
Result of terminal/output.
Attributes:
| Name | Type | Description |
|---|---|---|
output |
str
|
Captured terminal output. |
truncated |
bool
|
Whether output was truncated. |
exit_status |
TerminalExitStatus | None
|
Present only if the command has exited. |
Source code in acp/acp.py
WaitForExitParams
dataclass
¶
Parameters for terminal/wait_for_exit.
Attributes:
| Name | Type | Description |
|---|---|---|
session_id |
str
|
Target session. |
terminal_id |
str
|
Terminal to wait on. |
Source code in acp/acp.py
KillTerminalParams
dataclass
¶
Parameters for terminal/kill.
Attributes:
| Name | Type | Description |
|---|---|---|
session_id |
str
|
Target session. |
terminal_id |
str
|
Terminal to kill. |
Source code in acp/acp.py
ReleaseTerminalParams
dataclass
¶
Parameters for terminal/release.
Attributes:
| Name | Type | Description |
|---|---|---|
session_id |
str
|
Target session. |
terminal_id |
str
|
Terminal to release. |
Source code in acp/acp.py
AgentMessageChunkUpdate
dataclass
¶
Agent text output chunk.
Attributes:
| Name | Type | Description |
|---|---|---|
content |
ContentBlock
|
The content block. |
session_update |
str
|
Discriminator. |
Source code in acp/acp.py
UserMessageChunkUpdate
dataclass
¶
Replayed user message chunk (used in session/load).
Attributes:
| Name | Type | Description |
|---|---|---|
content |
ContentBlock
|
The content block. |
session_update |
str
|
Discriminator. |
Source code in acp/acp.py
ThoughtMessageChunkUpdate
dataclass
¶
Agent internal reasoning chunk.
Attributes:
| Name | Type | Description |
|---|---|---|
content |
ContentBlock
|
The content block. |
session_update |
str
|
Discriminator. |
Source code in acp/acp.py
ToolCallUpdate
dataclass
¶
Initial tool call notification.
Attributes:
| Name | Type | Description |
|---|---|---|
tool_call_id |
str
|
Unique tool call identifier. |
title |
str
|
Human-readable description. |
kind |
ToolKind
|
Tool category. |
status |
ToolCallStatus
|
Current execution status. |
content |
list[ToolCallContent] | None
|
Tool call content items. |
locations |
list[ToolCallLocation] | None
|
File locations affected. |
raw_input |
dict[str, Any] | None
|
Raw input parameters. |
raw_output |
dict[str, Any] | None
|
Raw output. |
session_update |
str
|
Discriminator. |
Source code in acp/acp.py
ToolCallStatusUpdate
dataclass
¶
Tool call progress/result update.
Attributes:
| Name | Type | Description |
|---|---|---|
tool_call_id |
str
|
The tool call being updated. |
status |
ToolCallStatus | None
|
New status. |
content |
list[ToolCallContent] | None
|
Optional new content. |
title |
str | None
|
Optional updated title. |
locations |
list[ToolCallLocation] | None
|
Optional updated locations. |
session_update |
str
|
Discriminator. |
Source code in acp/acp.py
PlanUpdate
dataclass
¶
Agent execution plan.
Attributes:
| Name | Type | Description |
|---|---|---|
entries |
list[PlanEntry]
|
Plan entries. |
session_update |
str
|
Discriminator. |
Source code in acp/acp.py
AvailableCommandsUpdate
dataclass
¶
Update to available slash commands.
Attributes:
| Name | Type | Description |
|---|---|---|
available_commands |
list[AvailableCommand]
|
Current list of commands. |
session_update |
str
|
Discriminator. |
Source code in acp/acp.py
CurrentModeUpdate
dataclass
¶
Notification that the agent changed its mode.
Attributes:
| Name | Type | Description |
|---|---|---|
mode_id |
str
|
New mode identifier. |
session_update |
str
|
Discriminator. |
Source code in acp/acp.py
ConfigOptionUpdate
dataclass
¶
Notification that config options changed.
Attributes:
| Name | Type | Description |
|---|---|---|
config_options |
list[ConfigOption]
|
Complete configuration state. |
session_update |
str
|
Discriminator. |
Source code in acp/acp.py
SessionInfoUpdate
dataclass
¶
Update to session metadata.
Attributes:
| Name | Type | Description |
|---|---|---|
title |
str | None
|
Updated session title. |
updated_at |
str | None
|
Updated timestamp. |
session_update |
str
|
Discriminator. |
Source code in acp/acp.py
ACPClient
¶
High-level async client for communicating with an ACP agent subprocess.
Usage::
client = ACPClient(["python", "-m", "my_agent"])
await client.start()
init = await client.initialize()
session = await client.new_session("/project")
async for update in client.prompt(session.session_id, "Hello"):
print(update)
await client.stop()
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
command
|
list[str]
|
Command and arguments to spawn the agent process. |
required |
env
|
dict[str, str] | None
|
Optional environment variables for the subprocess. |
None
|
Source code in acp/acp.py
1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 | |
start()
async
¶
Launch the agent subprocess and begin reading messages.
Source code in acp/acp.py
stop()
async
¶
Terminate the agent subprocess and clean up.
Source code in acp/acp.py
set_request_handler(handler)
¶
Register a handler for incoming requests from the agent.
This is used for requests like session/request_permission,
fs/read_text_file, etc.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
handler
|
Callable[[str, dict[str, Any]], Any]
|
Async callable |
required |
Source code in acp/acp.py
initialize(params=None)
async
¶
Perform the initialize handshake with the agent.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
params
|
InitializeParams | None
|
Initialization parameters (defaults provided if |
None
|
Returns:
| Type | Description |
|---|---|
InitializeResult
|
The agent's initialization result. |
Source code in acp/acp.py
new_session(cwd, mcp_servers=None)
async
¶
Create a new conversation session.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cwd
|
str
|
Absolute path to the working directory. |
required |
mcp_servers
|
list[dict[str, Any]] | None
|
Optional MCP server configurations. |
None
|
Returns:
| Type | Description |
|---|---|
NewSessionResult
|
The session creation result including the session id. |
Source code in acp/acp.py
load_session(session_id, cwd, mcp_servers=None)
async
¶
Load (resume) an existing session.
The agent will replay conversation history as session/update
notifications before responding.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
session_id
|
str
|
Session to resume. |
required |
cwd
|
str
|
Working directory. |
required |
mcp_servers
|
list[dict[str, Any]] | None
|
Optional MCP server configurations. |
None
|
Source code in acp/acp.py
prompt(session_id, text, extra_content=None)
async
¶
Send a prompt and yield session/update notifications.
This is an async generator. It yields each raw update dictionary
until the session/prompt response is received.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
session_id
|
str
|
Target session. |
required |
text
|
str
|
User message text. |
required |
extra_content
|
list[ContentBlock] | None
|
Additional content blocks to include. |
None
|
Yields:
| Type | Description |
|---|---|
AsyncIterator[dict[str, Any]]
|
Raw |
Source code in acp/acp.py
prompt_simple(session_id, text)
async
¶
Send a prompt and collect all updates, returning them with the result.
A simpler alternative to the async-generator prompt() method.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
session_id
|
str
|
Target session. |
required |
text
|
str
|
User message text. |
required |
Returns:
| Type | Description |
|---|---|
tuple[list[dict[str, Any]], PromptResult]
|
Tuple of (list of update dicts, PromptResult). |
Source code in acp/acp.py
cancel(session_id)
async
¶
Cancel the current prompt turn.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
session_id
|
str
|
Session to cancel. |
required |
Source code in acp/acp.py
set_mode(session_id, mode_id)
async
¶
Switch the agent operating mode.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
session_id
|
str
|
Target session. |
required |
mode_id
|
str
|
Mode to switch to. |
required |
Source code in acp/acp.py
list_sessions(cwd=None, cursor=None)
async
¶
List sessions known to the agent.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cwd
|
str | None
|
Optional working-directory filter. |
None
|
cursor
|
str | None
|
Optional pagination cursor. |
None
|
Returns:
| Type | Description |
|---|---|
ListSessionsResult
|
List of session metadata. |
Source code in acp/acp.py
ACPAgent
¶
Bases: ABC
Abstract base class for implementing an ACP-compatible agent.
Subclass this and override the on_* methods. Call await agent.run()
to start the stdio event loop.
Example::
class MyAgent(ACPAgent):
async def on_initialize(self, params):
return InitializeResult(protocol_version=1)
async def on_new_session(self, params):
return NewSessionResult(session_id=str(uuid.uuid4()))
async def on_prompt(self, params):
await self.send_update(params.session_id,
AgentMessageChunkUpdate(content=TextContent(text="Hi!")))
return PromptResult(stop_reason=StopReason.END_TURN)
Source code in acp/acp.py
1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 | |
on_initialize(params)
abstractmethod
async
¶
Handle the initialize request.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
params
|
InitializeParams
|
Initialization parameters from the client. |
required |
Returns:
| Type | Description |
|---|---|
InitializeResult
|
Initialization result with agent capabilities. |
Source code in acp/acp.py
on_new_session(params)
abstractmethod
async
¶
Handle session/new.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
params
|
NewSessionParams
|
Session creation parameters. |
required |
Returns:
| Type | Description |
|---|---|
NewSessionResult
|
Result containing the new session id. |
on_prompt(params)
abstractmethod
async
¶
Handle session/prompt.
Use self.send_update() to stream updates back to the client
before returning the final result.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
params
|
PromptParams
|
Prompt parameters including user message. |
required |
Returns:
| Type | Description |
|---|---|
PromptResult
|
Result with the stop reason. |
Source code in acp/acp.py
on_load_session(params)
async
¶
Handle session/load. Override to support session resumption.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
params
|
LoadSessionParams
|
Session load parameters. |
required |
Source code in acp/acp.py
on_cancel(params)
async
¶
Handle session/cancel notification.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
params
|
CancelParams
|
Cancel parameters. |
required |
on_set_mode(params)
async
¶
Handle session/set_mode.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
params
|
SetModeParams
|
Mode change parameters. |
required |
on_set_config_option(params)
async
¶
Handle session/set_config_option.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
params
|
SetConfigOptionParams
|
Config option change parameters. |
required |
Returns:
| Type | Description |
|---|---|
SetConfigOptionResult
|
Complete configuration state. |
Source code in acp/acp.py
on_list_sessions(params)
async
¶
Handle session/list.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
params
|
ListSessionsParams
|
List sessions parameters. |
required |
Returns:
| Type | Description |
|---|---|
ListSessionsResult
|
List of session metadata. |
send_update(session_id, update)
async
¶
Send a session/update notification to the client.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
session_id
|
str
|
Target session. |
required |
update
|
SessionUpdate
|
The update payload. |
required |
Source code in acp/acp.py
request_permission(session_id, tool_call, options)
async
¶
Request permission from the client for a tool call.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
session_id
|
str
|
Target session. |
required |
tool_call
|
dict[str, Any]
|
Tool call details. |
required |
options
|
list[PermissionOption]
|
Available permission options. |
required |
Returns:
| Type | Description |
|---|---|
PermissionOutcome
|
The user's decision. |
Raises:
| Type | Description |
|---|---|
JSONRPCException
|
If the client returns an error. |
Source code in acp/acp.py
read_text_file(session_id, path, *, line=None, limit=None)
async
¶
Read a text file via the client's fs/read_text_file method.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
session_id
|
str
|
Target session. |
required |
path
|
str
|
Absolute file path. |
required |
line
|
int | None
|
Optional start line (1-based). |
None
|
limit
|
int | None
|
Optional max lines. |
None
|
Returns:
| Type | Description |
|---|---|
str
|
File text content. |
Source code in acp/acp.py
write_text_file(session_id, path, content)
async
¶
Write a text file via the client's fs/write_text_file method.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
session_id
|
str
|
Target session. |
required |
path
|
str
|
Absolute file path. |
required |
content
|
str
|
Text content to write. |
required |
Source code in acp/acp.py
create_terminal(session_id, command, *, args=None, cwd=None)
async
¶
Create a terminal via the client's terminal/create method.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
session_id
|
str
|
Target session. |
required |
command
|
str
|
Command to execute. |
required |
args
|
list[str] | None
|
Command arguments. |
None
|
cwd
|
str | None
|
Working directory. |
None
|
Returns:
| Type | Description |
|---|---|
str
|
Terminal id. |
Source code in acp/acp.py
run()
async
¶
Run the agent, reading from stdin and writing to stdout.
This blocks until the client closes the connection (EOF on stdin).
Source code in acp/acp.py
to_dict(obj)
¶
Recursively convert a dataclass instance to a JSON-friendly dict.
Nonevalues and empty collections are omitted.- Snake-case field names are converted to camelCase per the ACP spec.
- Enum values are serialized as their
.value.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
obj
|
Any
|
A dataclass instance, dict, list, or primitive. |
required |
Returns:
| Type | Description |
|---|---|
Any
|
A JSON-serializable value. |
Source code in acp/acp.py
from_raw(raw)
¶
Convert camelCase keys in raw to snake_case.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
raw
|
dict[str, Any]
|
A dictionary with camelCase keys. |
required |
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
A new dictionary with snake_case keys. |