Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Use this page as the quick orientation for the Python SDK repo. It mirrors the t
| Path | Why it exists |
| --- | --- |
| `src/acp/` | Runtime package: agent/client bases, transports, helpers, schema bindings, contrib utilities |
| `src/acp/http/`, `src/acp/ws/` | Experimental remote transports (Streamable HTTP + WebSocket), client + server; opt-in via the `[http]` extra |
| `src/acp/http/`, `src/acp/ws/` | Remote transports (Streamable HTTP + WebSocket), client + server; opt-in via the `[http]` extra |
| `schema/` | Upstream JSON schema sources (regenerate with `make gen-all`) |
| `examples/` | Runnable scripts such as `echo_agent.py`, `client.py`, `gemini.py`, `duet.py` |
| `tests/` | Pytest suite, including optional Gemini smoke tests in `tests/test_gemini_example.py` |
Expand Down
13 changes: 8 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@

Python SDK for building [Agent Client Protocol (ACP)](https://agentclientprotocol.com/) agents and clients, with generated Pydantic models and asyncio transports over stdio, Streamable HTTP, and WebSocket.

> **ACP v2 is in Preview:** "Preview is the same stage our RFDs go through before we complete them. The work is implemented and ready for broad review. For v2, that means we think the design is settled enough to build on. If you were waiting for the Draft to stop moving before you started, this is the time to start." — [ACP v2 is available in Preview](https://agentclientprotocol.com/announcements/acp-v2-preview) · See the [Protocol v2 (Preview) guide](https://agentclientprotocol.github.io/python-sdk/experimental-v2/).

## Installation

```bash
Expand All @@ -19,7 +21,7 @@ pip install agent-client-protocol
uv add agent-client-protocol
```

For experimental HTTP/WebSocket transports, install the `http` extra (`pip install "agent-client-protocol[http]"`). Requires Python 3.10–3.15.
For Streamable HTTP and WebSocket transports, install the `http` extra (`pip install "agent-client-protocol[http]"`). Requires Python 3.10–3.15.

## Quick example

Expand Down Expand Up @@ -87,11 +89,12 @@ asyncio.run(main())

## Documentation

- [Quickstart](https://agentclientprotocol.github.io/python-sdk/quickstart/) — Connect your agent to Zed, Toad, Lody, or T3 Code, or drive agents programmatically.
- [Protocol Features](https://agentclientprotocol.github.io/python-sdk/protocol-features/) — Unstable opt-in methods, session notices, stateless MCP-over-ACP, cancellation, and extensions (`schema-v1.35.0`).
- [Quickstart](https://agentclientprotocol.github.io/python-sdk/quickstart/) — Connect an agent to Zed, Toad, Lody, or T3 Code, or drive agents from Python.
- [Protocol Features (v1)](https://agentclientprotocol.github.io/python-sdk/protocol-features/) — Unstable opt-in methods, session notices, stateless MCP-over-ACP, cancellation, and extensions.
- [Web Transport](https://agentclientprotocol.github.io/python-sdk/web-transport/) — Serve and consume ACP over Streamable HTTP and WebSocket (`[http]`).
- [Experimental Protocol v2](https://agentclientprotocol.github.io/python-sdk/experimental-v2/) — Preview v2 runtime (`schema-v2.0.0-beta.4`) and dual-stack `AgentProtocolRouter`.
- [Examples](https://github.com/agentclientprotocol/python-sdk/tree/main/examples) · [Contrib](https://agentclientprotocol.github.io/python-sdk/contrib/) · [Use Cases](https://agentclientprotocol.github.io/python-sdk/use-cases/) · [Testing](https://agentclientprotocol.github.io/python-sdk/testing/)
- [Protocol v2 (Preview)](https://agentclientprotocol.github.io/python-sdk/experimental-v2/) — Preview v2 runtime and dual-stack `AgentProtocolRouter`.
- [API Reference](https://agentclientprotocol.github.io/python-sdk/api-reference/) — Core entrypoints, connection classes, transports, and contrib helpers.
- [Examples](https://github.com/agentclientprotocol/python-sdk/tree/main/examples) · [Contrib](https://agentclientprotocol.github.io/python-sdk/contrib/) · [Use Cases](https://agentclientprotocol.github.io/python-sdk/use-cases/) · [Testing](https://agentclientprotocol.github.io/python-sdk/testing/) · [Migration Guides](https://agentclientprotocol.github.io/python-sdk/migration-guide-1.x/)

## Development

Expand Down
84 changes: 84 additions & 0 deletions docs/api-reference.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
# 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

::: acp.core.connect_to_agent

::: acp.stdio.spawn_agent_process

::: acp.stdio.spawn_client_process

::: acp.agent.connection.AgentSideConnection
options:
members:
- __init__
- listen
- session_update
- request_permission
- ext_method
- ext_notification
- close

::: acp.client.connection.ClientSideConnection
options:
members:
- __init__
- initialize
- new_session
- load_session
- resume_session
- prompt
- cancel
- ext_method
- ext_notification
- close

## Protocol v2 (Preview) & Negotiation

::: acp.experimental.negotiation.AgentProtocolRouter
options:
members:
- __init__
- connect
- run

::: acp.experimental.v2.agent.run_agent

::: acp.experimental.v2.client.connect_to_agent

## Web Transport (`[http]`)

::: acp.http.client.create_http_stream

::: acp.http.asgi.create_asgi_app

::: acp.ws.client.create_websocket_stream

## Contrib Utilities

::: acp.contrib.session_state.SessionAccumulator
options:
members:
- apply
- snapshot
- subscribe
- reset

::: acp.contrib.tool_calls.ToolCallTracker
options:
members:
- start
- progress
- append_stream_text
- view
- tool_call_model
- forget

::: acp.contrib.permissions.PermissionBroker
options:
members:
- request_for
17 changes: 8 additions & 9 deletions docs/experimental-v2.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# Experimental Protocol v2
# Protocol v2 (Preview)

> **Preview.** Protocol v2 lives under `acp.experimental` and tracks [`schema-v2.0.0-beta.4`](https://github.com/agentclientprotocol/agent-client-protocol/releases/tag/schema-v2.0.0-beta.4).
> "Preview is the same stage our RFDs go through before we complete them. The work is implemented and ready for broad review. For v2, that means we think the design is settled enough to build on. If you were waiting for the Draft to stop moving before you started, this is the time to start." — [ACP v2 is available in Preview](https://agentclientprotocol.com/announcements/acp-v2-preview)

Connection methods and agent/client handlers accept expanded snake_case parameters, responses and nested payloads use `acp.experimental.v2.schema` models, and extra keyword arguments serialize into `_meta`.
Protocol v2 bindings and runtime live under `acp.experimental.v2` and track [`schema-v2.0.0-beta.4`](https://github.com/agentclientprotocol/agent-client-protocol/releases/tag/schema-v2.0.0-beta.4). Connection methods and handlers accept expanded snake_case parameters, nested payloads use `acp.experimental.v2.schema` models, and extra keyword arguments serialize into `_meta`.

## Client and agent usage

Expand All @@ -15,7 +15,7 @@ from acp.experimental import v2

class MyClient(v2.Client):
async def session_update(self, session_id: str, update: v2.schema.SessionUpdate, **kwargs: Any) -> None:
handle_update(session_id, update)
print(session_id, update)


connection = v2.connect_to_agent(MyClient(), transport)
Expand Down Expand Up @@ -60,15 +60,14 @@ class MyAgent(v2.Agent):
await v2.run_agent(MyAgent())
```

V2 connections require a successful `initialize` handshake before other methods and validate requests and responses strictly.
If the agent rejects `initialize`, the client can retry on the same connection. A rejected repeat leaves the previous successful initialization in effect.
V2 connections require a successful `initialize` handshake before other methods and validate requests and responses strictly. If the agent rejects `initialize`, the client can retry on the same connection; a rejected repeat leaves the previous successful initialization in effect.

## Key v2 behaviors

- **Asynchronous prompt submission**: `session/prompt` returns `PromptResponse(message_id=...)` once the user message is accepted, while updates stream independently. Pass `idempotency_key` (1–255 chars) so retried submissions reuse the original `message_id`.
- **Expanded union calls**: `set_config_option` infers `type` (`"boolean"` for `bool`, `"id"` otherwise, or pass a custom `type`); `create_elicitation` accepts either `session_id` or `request_id` along with form or URL parameters.
- **Patch updates**: In updates like `SessionToolCallUpdate` and `SessionTerminalUpdate`, omit a field to keep its value or pass `None` to clear it. Serialize with `update.model_dump(by_alias=True, exclude_unset=True)` to preserve that distinction.
- **Notices and replay**: Agents can emit live advisory `v2.schema.SessionNotice(...)` updates, and clients can request retained history via `resume_session(..., replay_from=v2.schema.ReplayFromStartVariant())`.
- **Notices, subagents, and replay**: Agents can emit live `v2.schema.SessionNotice(...)` and `v2.schema.SessionSubagentUpdate(...)` updates, and clients can request retained history via `resume_session(..., replay_from=v2.schema.ReplayFromStartVariant())`, ending with `SessionReplayComplete`.
- **Reusable union aliases**: `v2.schema` exports `SessionUpdate`, `ContentBlock`, `StateUpdate`, `BackgroundWork`, and `AvailableCommand`.

## Dual-stack v1/v2 negotiation
Expand All @@ -85,10 +84,10 @@ router = AgentProtocolRouter(
await router.run()
```

The router calls each version's factory and `on_connect` at most once per connection. Before sending another request, the client can repeat `initialize` with the selected version or downgrade to a lower supported version. The router switches protocol versions after a successful downgrade.
The router calls each version's factory and `on_connect` at most once per connection. Before sending another request, the client can repeat `initialize` with the selected version or downgrade to a lower supported version; the router switches protocol versions after a successful downgrade.

## Extensions, cancellation, and MCP-over-ACP

- Call `ext_method("vendor/method", ...)` and `ext_notification("vendor/event", ...)` on connections, and implement `ext_method`, `ext_notification`, or `on_connect` on `v2.Agent` / `v2.Client` for vendor extensions and connection setup (the SDK prepends and strips the wire `_` prefix, matching v1).
- Call `ext_method("vendor/method", ...)` and `ext_notification("vendor/event", ...)` on connections, and implement `ext_method`, `ext_notification`, or `on_connect` on `v2.Agent` / `v2.Client` (the SDK prepends and strips the wire `_` prefix, matching v1).
- `$/cancel_request` cancels running handler tasks and outgoing requests automatically; use `cancel_session(session_id=...)` for active session work.
- [Stateless MCP-over-ACP](protocol-features.md#stateless-mcp-over-acp) uses `v2.schema.McpResultResponse`, `McpErrorResponse`, and `MessageMcpResponse` when the agent advertises `capabilities.session.mcp.acp = {}`.
27 changes: 15 additions & 12 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,28 @@

# Agent Client Protocol SDK (Python)

Build ACP agents and clients in Python with generated Pydantic models and asyncio transports over stdio, Streamable HTTP, and WebSocket.
Build [Agent Client Protocol (ACP)](https://agentclientprotocol.com/) agents and clients in Python with generated Pydantic models and asyncio transports over stdio, Streamable HTTP, and WebSocket.

> **ACP v2 is available in Preview:** "Preview is the same stage our RFDs go through before we complete them. The work is implemented and ready for broad review. For v2, that means we think the design is settled enough to build on. If you were waiting for the Draft to stop moving before you started, this is the time to start." — [ACP v2 is available in Preview](https://agentclientprotocol.com/announcements/acp-v2-preview)

```bash
pip install agent-client-protocol
# Optional: pip install "agent-client-protocol[http]"
# Optional remote transports:
pip install "agent-client-protocol[http]"
```

## Where to start
## Guides

- **[Quickstart](quickstart.md)** — Run the echo agent, wire it into an editor or CLI client, and write your first custom agent.
- **[Protocol Features (v1)](protocol-features.md)** — Use unstable opt-in features, session notices, stateless MCP-over-ACP, request cancellation, and extension methods.
- **[Web Transport](web-transport.md)** — Run ACP over Streamable HTTP (HTTP/2 + SSE) and WebSocket with Starlette.
- **[Experimental Protocol v2](experimental-v2.md)** — Explore the preview v2 API (`schema-v2.0.0-beta.4`) and dual-stack `AgentProtocolRouter`.
- **[Contrib Utilities](contrib.md)** — Reuse stateful helpers for session aggregation, tool call tracking, and permission prompts.
- **[Quickstart](quickstart.md)** — Connect an agent to an ACP client, spawn agents from Python, and stream messages and tool calls.
- **[Protocol Features (v1)](protocol-features.md)** — Enable unstable methods, stream session notices, bridge stateless MCP-over-ACP, cancel requests, and add extensions.
- **[Web Transport](web-transport.md)** — Run ACP over Streamable HTTP and WebSocket with Starlette.
- **[Protocol v2 (Preview)](experimental-v2.md)** — Build on the v2 preview runtime and serve v1/v2 together with `AgentProtocolRouter`.
- **[Contrib Utilities](contrib.md)** — Reuse stateful helpers for session snapshots, tool call tracking, and permission prompts.

## Ecosystem and operations
## Reference & Project

- **[Use Cases](use-cases.md)** — Agents and clients built with this SDK.
- **[Testing & Conformance](testing.md)** — Local checks, ACP TCK conformance, and real-world interoperability checks.
- **[Releasing](releasing.md)** — Schema updates and release workflow.
- **[API Reference](api-reference.md)** — Signatures and docstrings for the primary SDK entrypoints.
- **[Migration Guides](migration-guide-1.x.md)** — Upgrade notes for 1.x and earlier releases.
- **[Use Cases](use-cases.md)** · **[Testing & Conformance](testing.md)** · **[Releasing](releasing.md)**

Questions and feedback are welcome in [GitHub Discussions](https://github.com/agentclientprotocol/python-sdk/discussions) and on [Zulip](https://agentclientprotocol.zulipchat.com/).
74 changes: 74 additions & 0 deletions docs/migration-guide-1.x.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
# Migrating to ACP Python SDK 1.x

Key breaking changes when upgrading from `0.12.x` to `1.0.0` and from `1.0.x` to `1.1.0`.

## 0.12.x to 1.0.0

### 1. Construct `acp.schema` models directly

`acp.helpers` and its top-level builder functions (`text_block`, `update_agent_message_text`, `start_tool_call`, and friends) were removed. Instantiate generated models from `acp.schema` directly — discriminator fields such as `type` and `sessionUpdate` have defaults:

```python
from acp.schema import AgentMessageChunk, TextContentBlock, ToolCallStart

chunk = AgentMessageChunk(content=TextContentBlock(text="Hello"))
tool_call = ToolCallStart(tool_call_id="call-1", title="Read file", kind="read", status="in_progress")
```

### 2. Update authentication and schema types

- `EnvVarAuthMethod` was replaced by `TerminalAuthMethod`.
- `ToolCall` and `ToolCallUpdate` gained an optional programmatic `name` field.
- Accepted elicitation responses validate content strictly against `acp.schema` models.

### 3. Install the `[http]` extra for web transports

Streamable HTTP and WebSocket transports moved to Starlette and `httpx2[http2]` under the optional `http` extra:

```bash
pip install "agent-client-protocol[http]"
```

See [Web Transport](web-transport.md) for current client and ASGI server usage.

## 1.0.x to 1.1.0

Changes in `1.1.0` primarily affect **unstable** protocol features updated by the upstream `schema-v1.35.0` release:

### 1. Move MCP-over-ACP to stateless `mcp_message`

`connect_mcp` and `disconnect_mcp` were removed. Unstable MCP-over-ACP now uses stateless `mcp_message` requests and `notify_mcp` notifications keyed by `server_id` and `request_id`:

```python
from uuid import uuid4

from acp.schema import McpErrorResponse

response = await conn.mcp_message(
server_id="project-tools",
request_id=uuid4().hex,
method="tools/list",
params={},
)
if isinstance(response, McpErrorResponse):
print("MCP error:", response.error)
```

See [Stateless MCP-over-ACP](protocol-features.md#stateless-mcp-over-acp) for the full handshake and metadata keys.

### 2. Remove dropped unstable methods

- Next edit suggestions (`start_nes`, `suggest_nes`, `close_nes`, `accept_nes`, `reject_nes`) and document notifications (`did_open`, `did_change`, `did_close`, `did_save`, `did_focus`) were removed.
- `PlanUpdateFile` was removed alongside the schema's `file` plan update variant.

### 3. Expect stricter validation on local models and `mcpServers`

- Passing an invalid local Pydantic model instance inside a list field now raises `ValidationError` instead of being silently dropped.
- A malformed entry in `session/new`'s `mcpServers` list now raises `ValidationError` instead of being skipped.

## Verify after upgrading

```bash
make check
make test
```
Loading
Loading