API Reference¶
Core public entrypoints for building and driving ACP agents and clients. Generated Pydantic schema models live in acp.schema (v1) and acp.experimental.v2.schema (v2).
Core (v1)¶
acp.core.run_agent(agent, input_stream=None, output_stream=None, *, use_unstable_protocol=False, stdio_buffer_limit_bytes=DEFAULT_STDIO_BUFFER_LIMIT_BYTES, **connection_kwargs)
async
¶
Run an ACP agent over the given input/output streams.
This is a convenience function that creates an :class:AgentSideConnection
and starts listening for incoming messages.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
agent
|
Agent
|
The agent implementation to run. |
required |
input_stream
|
Any
|
The (client) input stream to write to (defaults: |
None
|
output_stream
|
Any
|
The (client) output stream to read from (defaults: |
None
|
use_unstable_protocol
|
bool
|
Whether to enable unstable protocol features. |
False
|
**connection_kwargs
|
Any
|
Additional keyword arguments to pass to the
:class: |
{}
|
acp.core.connect_to_agent(client, input_stream, output_stream=None, *, use_unstable_protocol=False, **connection_kwargs)
¶
Create a ClientSideConnection to an ACP agent.
Two forms are supported:
- Byte streams (stdio): pass
input_stream(anasyncio.StreamWriter) andoutput_stream(anasyncio.StreamReader). - Message transport (HTTP/WebSocket): pass a single
:class:
~acp._transport.Transportasinput_streamand leaveoutput_streamasNone.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
client
|
Client
|
The client implementation to use. |
required |
input_stream
|
Any
|
The agent input stream ( |
required |
output_stream
|
Any
|
The agent output stream ( |
None
|
use_unstable_protocol
|
bool
|
Whether to enable unstable protocol features. |
False
|
**connection_kwargs
|
Any
|
Additional keyword arguments to pass to the
:class: |
{}
|
Returns:
| Name | Type | Description |
|---|---|---|
A |
ClientSideConnection
|
class: |
acp.stdio.spawn_agent_process(to_client, command, *args, env=None, cwd=None, transport_kwargs=None, **connection_kwargs)
async
¶
Spawn an ACP agent subprocess and return a ClientSideConnection to it.
acp.stdio.spawn_client_process(to_agent, command, *args, env=None, cwd=None, transport_kwargs=None, **connection_kwargs)
async
¶
Spawn an ACP client subprocess and return an AgentSideConnection to it.
acp.agent.connection.AgentSideConnection
¶
Agent-side connection wrapper that dispatches JSON-RPC messages to a Client implementation. The agent can use this connection to communicate with the Client so it behaves like a Client.
__init__(to_agent, input_stream, output_stream=None, listening=True, *, use_unstable_protocol=False, **connection_kwargs)
¶
listen()
async
¶
Start listening for incoming messages.
session_update(session_id, update, **kwargs)
async
¶
request_permission(session_id, tool_call, options, **kwargs)
async
¶
ext_method(method, params)
async
¶
ext_notification(method, params)
async
¶
close()
async
¶
acp.client.connection.ClientSideConnection
¶
Client-side connection wrapper that dispatches JSON-RPC messages to an Agent implementation. The client can use this connection to communicate with the Agent so it behaves like an Agent.
__init__(to_client, input_stream, output_stream=None, *, use_unstable_protocol=False, listening=True, **connection_kwargs)
¶
initialize(protocol_version, client_capabilities=None, client_info=None, **kwargs)
async
¶
new_session(cwd, additional_directories=None, mcp_servers=None, system_prompt=None, config_options=None, **kwargs)
async
¶
load_session(cwd, session_id, mcp_servers=None, additional_directories=None, system_prompt=None, config_options=None, **kwargs)
async
¶
resume_session(session_id, cwd, additional_directories=None, mcp_servers=None, system_prompt=None, config_options=None, **kwargs)
async
¶
prompt(session_id, prompt, **kwargs)
async
¶
cancel(session_id, **kwargs)
async
¶
ext_method(method, params)
async
¶
ext_notification(method, params)
async
¶
close()
async
¶
Protocol v2 (Preview) & Negotiation¶
acp.experimental.negotiation.AgentProtocolRouter
¶
acp.experimental.v2.agent.run_agent(agent, input_stream=None, output_stream=None, *, stdio_buffer_limit_bytes=50 * 1024 * 1024, **connection_kwargs)
async
¶
acp.experimental.v2.client.connect_to_agent(client, input_stream, output_stream=None, **connection_kwargs)
¶
Web Transport ([http])¶
acp.http.client.create_http_stream(url, *, client=None, headers=None)
¶
Create a Streamable HTTP client :class:Transport.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
url
|
str
|
The ACP endpoint URL (e.g. |
required |
client
|
AsyncClient | None
|
An optional pre-configured |
None
|
headers
|
dict[str, str] | None
|
Extra headers sent on every request. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
A |
Transport
|
class: |
acp.http.asgi.create_asgi_app(agent_factory, *, path=ACP_ENDPOINT_PATH)
¶
Create a Starlette app with one agent instance per connection.
The app handles POST/GET/DELETE and WebSocket at path (default: /acp).
The path is relative to any parent mount. When mounting the app, enter its
lifespan from the parent lifespan too.
acp.ws.client.create_websocket_stream(url, *, headers=None, cookie_store=None)
async
¶
Connect a WebSocket and return a :class:Transport.
Per the RFD, clients MUST accept, store, and return cookies on all HTTP-based
transports (including WebSocket) so servers can rely on cookies for session
affinity (e.g. sticky sessions behind a load balancer). A single WebSocket is
one long-lived connection, so cookie support matters across reconnects:
pass a caller-owned cookie_store reused between fresh streams. Any cookies
already in the store are sent as a Cookie header on the handshake, and any
Set-Cookie headers on the upgrade response are captured back into it.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
url
|
str
|
The ACP WebSocket endpoint (e.g. |
required |
headers
|
dict[str, str] | None
|
Extra headers sent during the handshake. |
None
|
cookie_store
|
MemoryAcpCookieStore | None
|
Optional caller-owned affinity cookie store to reuse across reconnects. If omitted, an ephemeral per-stream store is used. |
None
|
Returns:
| Type | Description |
|---|---|
Transport
|
A connected :class: |
Contrib Utilities¶
acp.contrib.session_state.SessionAccumulator
¶
Merge :class:acp.schema.SessionNotification objects into a session snapshot.
The accumulator focuses on the common requirements observed in the Toad UI:
- Always expose the latest merged tool call state (even if updates arrive
without a matching
tool_callstart). - Track the agent plan, available commands, and current mode id.
- Record the raw stream of user/agent message chunks for UI rendering.
This helper is experimental: APIs may change while we gather feedback.
apply(notification)
¶
Merge a new session notification into the current snapshot.
snapshot()
¶
Return an immutable snapshot of the current state.
subscribe(callback)
¶
Register a callback that receives every new snapshot.
The callback is invoked immediately after :meth:apply finishes. The
function returns an unsubscribe callable.
reset()
¶
Clear all accumulated state.
acp.contrib.tool_calls.ToolCallTracker
¶
Utility for generating ACP tool call updates on the server side.
start(external_id, *, title, name=None, kind=None, status='in_progress', content=None, locations=None, raw_input=None, raw_output=None)
¶
Register a new tool call and return the tool_call notification.
progress(external_id, *, title=UNSET, name=UNSET, kind=UNSET, status=UNSET, content=UNSET, locations=UNSET, raw_input=UNSET, raw_output=UNSET)
¶
Produce a tool_call_update message and merge it into the tracker.
append_stream_text(external_id, text, *, title=UNSET, status=UNSET)
¶
Append text to the tool call arguments/content and emit an update.
view(external_id)
¶
Return an immutable view of the current tool call state.
tool_call_model(external_id)
¶
Return a deep copy of the tool call suitable for permission requests.
forget(external_id)
¶
Remove a tracked tool call (e.g. after completion).