Skip to content

Commit 1f5d9b0

Browse files
committed
docs: redesign README and reorganize documentation
1 parent ac611b0 commit 1f5d9b0

12 files changed

Lines changed: 575 additions & 700 deletions

‎README.md‎

Lines changed: 113 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -2,74 +2,140 @@
22
<img alt="Agent Client Protocol" src="https://zed.dev/img/acp/banner-dark.webp">
33
</a>
44

5-
# Agent Client Protocol (Python)
5+
# Agent Client Protocol — Python SDK
66

7-
Build ACP-compliant agents and clients in Python with generated schema models, asyncio transports, and runnable demos.
7+
[![PyPI](https://img.shields.io/pypi/v/agent-client-protocol)](https://pypi.org/project/agent-client-protocol/)
8+
[![Python](https://img.shields.io/pypi/pyversions/agent-client-protocol)](https://pypi.org/project/agent-client-protocol/)
9+
[![CI](https://github.com/agentclientprotocol/python-sdk/actions/workflows/main.yml/badge.svg)](https://github.com/agentclientprotocol/python-sdk/actions/workflows/main.yml)
10+
[![Docs](https://img.shields.io/badge/docs-GitHub%20Pages-blue)](https://agentclientprotocol.github.io/python-sdk/)
811

9-
> Releases track the upstream ACP schema; contributions that tighten coverage or tooling are always welcome.
12+
Python SDK for building [Agent Client Protocol (ACP)](https://agentclientprotocol.com/) agents and clients with generated Pydantic v2 models, asyncio JSON-RPC transports, and runnable examples.
1013

11-
## Install
14+
## Installation
1215

1316
```bash
1417
pip install agent-client-protocol
1518
# or
1619
uv add agent-client-protocol
1720
```
1821

19-
## At a glance
22+
Optional extras:
2023

21-
- **Spec parity:** Generated Pydantic models in `acp.schema` track every ACP release so payloads stay valid.
22-
- **Direct construction:** Generated discriminator fields have defaults, so models can be instantiated directly.
23-
- **Runtime ergonomics:** Async base classes, stdio JSON-RPC plumbing, and lifecycle helpers keep custom agents tiny.
24-
- **Examples ready:** Streaming, permissions, Gemini bridge, and duet demos live under `examples/`.
25-
- **Contrib utilities:** Session accumulators, tool call trackers, and permission brokers share patterns from real deployments.
24+
```bash
25+
# Streamable HTTP and WebSocket transports (experimental)
26+
pip install "agent-client-protocol[http]"
27+
28+
# Logfire / OpenTelemetry instrumentation
29+
pip install "agent-client-protocol[logfire]"
30+
```
31+
32+
Requires Python 3.10–3.15.
33+
34+
## Quick example
35+
36+
### Build an agent
37+
38+
```python
39+
import asyncio
40+
from typing import Any
41+
from uuid import uuid4
42+
43+
from acp import PROTOCOL_VERSION, Agent, InitializeResponse, NewSessionResponse, PromptResponse, run_agent
44+
from acp.interfaces import Client
45+
from acp.schema import AgentMessageChunk, TextContentBlock
46+
47+
48+
class EchoAgent(Agent):
49+
def on_connect(self, conn: Client) -> None:
50+
self._conn = conn
2651

27-
## Who benefits
52+
async def initialize(self, protocol_version: int, **kwargs: Any) -> InitializeResponse:
53+
return InitializeResponse(protocol_version=PROTOCOL_VERSION)
2854

29-
- Agent authors who need typed models and event-stream ergonomics for ACP-compatible assistants.
30-
- Client integrators embedding ACP parties inside Python applications or wrapping existing CLIs via stdio.
31-
- Tooling teams experimenting with permission flows, streaming UX, or Gemini bridges without re-implementing transports.
32-
See real adopters like kimi-cli in the [Use Cases list](https://agentclientprotocol.github.io/python-sdk/use-cases/).
55+
async def new_session(self, cwd: str, **kwargs: Any) -> NewSessionResponse:
56+
return NewSessionResponse(session_id=uuid4().hex)
3357

34-
## How to get started
58+
async def prompt(self, session_id: str, prompt: list[Any], **kwargs: Any) -> PromptResponse:
59+
for block in prompt:
60+
text = getattr(block, "text", "")
61+
await self._conn.session_update(
62+
session_id=session_id,
63+
update=AgentMessageChunk(content=TextContentBlock(text=text)),
64+
)
65+
return PromptResponse(stop_reason="end_turn")
3566

36-
- Follow the [Quickstart guide](https://agentclientprotocol.github.io/python-sdk/quickstart/) for installation, echo-agent validation, editor wiring (e.g. Zed), and programmatic launch recipes.
37-
- Browse the [example gallery](https://github.com/agentclientprotocol/python-sdk/tree/main/examples) to see progressively richer integrations you can copy or extend.
38-
- Skim the [docs hub](https://agentclientprotocol.github.io/python-sdk/) for focused references on contrib helpers, releasing, and transport details.
3967

40-
## Quick links
68+
if __name__ == "__main__":
69+
asyncio.run(run_agent(EchoAgent()))
70+
```
71+
72+
### Connect from a client
73+
74+
```python
75+
import asyncio
76+
import sys
77+
from typing import Any
78+
79+
from acp import PROTOCOL_VERSION, Client, spawn_agent_process
80+
from acp.schema import TextContentBlock
81+
4182

42-
| Need | Link |
43-
|--------------------|------------------------------------------------------------------------|
44-
| Docs hub | <https://agentclientprotocol.github.io/python-sdk/> |
45-
| Quickstart | <https://agentclientprotocol.github.io/python-sdk/quickstart/> |
46-
| Use cases | <https://agentclientprotocol.github.io/python-sdk/use-cases/> |
47-
| Contrib helpers | <https://agentclientprotocol.github.io/python-sdk/contrib/> |
48-
| Releasing workflow | <https://agentclientprotocol.github.io/python-sdk/releasing/> |
49-
| Examples | <https://github.com/agentclientprotocol/python-sdk/tree/main/examples> |
50-
| Tests | <https://github.com/agentclientprotocol/python-sdk/tree/main/tests> |
51-
| PyPI | <https://pypi.org/project/agent-client-protocol/> |
83+
class SimpleClient(Client):
84+
async def session_update(self, session_id: str, update: Any, **kwargs: Any) -> None:
85+
print(session_id, update)
5286

53-
## Project layout
5487

55-
- `src/acp/`: runtime package (agents, clients, transports, schema bindings, contrib utilities)
56-
- `schema/`: upstream JSON schema sources (regenerate via `make gen-all`)
57-
- `docs/`: MkDocs content backing the published documentation
58-
- `examples/`: runnable scripts covering stdio orchestration patterns
59-
- `tests/`: pytest suite with golden fixtures and optional Gemini coverage
88+
async def main() -> None:
89+
async with spawn_agent_process(SimpleClient(), sys.executable, "examples/echo_agent.py") as (conn, _proc):
90+
await conn.initialize(protocol_version=PROTOCOL_VERSION)
91+
session = await conn.new_session(cwd=".", mcp_servers=[])
92+
await conn.prompt(session_id=session.session_id, prompt=[TextContentBlock(text="Hello ACP!")])
6093

61-
## Developer commands
6294

63-
- `make install` provisions the `uv` virtualenv and installs pre-commit hooks.
64-
- `make check` runs Ruff formatting/linting, type analysis, dependency hygiene, and lock verification.
65-
- `make test` executes `pytest` (with doctests) inside the managed environment.
66-
- `ACP_SCHEMA_VERSION=<ref> make gen-all` refreshes protocol artifacts when the schema advances.
95+
asyncio.run(main())
96+
```
97+
98+
## Protocol and transport support
99+
100+
| Capability | Import / Extra | Status | Reference |
101+
| --- | --- | --- | --- |
102+
| ACP v1 (`schema-v1.35.0`) | `acp`, `acp.schema` | Stable | [Quickstart](https://agentclientprotocol.github.io/python-sdk/quickstart/) · [Protocol Features](https://agentclientprotocol.github.io/python-sdk/protocol-features/) |
103+
| ACP v2 (`schema-v2.0.0-beta.4`) + dual-stack router | `acp.experimental.v2`, `acp.experimental.AgentProtocolRouter` | Preview | [Experimental v2](https://agentclientprotocol.github.io/python-sdk/experimental-v2/) |
104+
| Stdio JSON-RPC (NDJSON) | Built-in (`run_agent`, `connect_to_agent`, `spawn_agent_process`) | Stable | [Quickstart](https://agentclientprotocol.github.io/python-sdk/quickstart/) |
105+
| Streamable HTTP & WebSocket | `acp.http`, `acp.ws` (`[http]`) | Experimental | [Web Transport](https://agentclientprotocol.github.io/python-sdk/web-transport/) |
106+
| Stateless MCP-over-ACP | `acp` / `acp.experimental.v2` | Unstable / Preview | [Protocol Features](https://agentclientprotocol.github.io/python-sdk/protocol-features/#stateless-mcp-over-acp) |
107+
| Session, tool call, and permission helpers | `acp.contrib` | Experimental | [Contrib Utilities](https://agentclientprotocol.github.io/python-sdk/contrib/) |
108+
109+
## Documentation
110+
111+
| Topic | Link |
112+
| --- | --- |
113+
| Documentation hub | <https://agentclientprotocol.github.io/python-sdk/> |
114+
| Quickstart | <https://agentclientprotocol.github.io/python-sdk/quickstart/> |
115+
| Protocol features (v1) | <https://agentclientprotocol.github.io/python-sdk/protocol-features/> |
116+
| Web transport (HTTP & WebSocket) | <https://agentclientprotocol.github.io/python-sdk/web-transport/> |
117+
| Experimental protocol v2 | <https://agentclientprotocol.github.io/python-sdk/experimental-v2/> |
118+
| Contrib utilities | <https://agentclientprotocol.github.io/python-sdk/contrib/> |
119+
| Use cases | <https://agentclientprotocol.github.io/python-sdk/use-cases/> |
120+
| Testing & conformance | <https://agentclientprotocol.github.io/python-sdk/testing/> |
121+
| Releasing | <https://agentclientprotocol.github.io/python-sdk/releasing/> |
122+
| Runnable examples | <https://github.com/agentclientprotocol/python-sdk/tree/main/examples> |
123+
124+
## Development
125+
126+
```bash
127+
make install # Create uv environment and install pre-commit hooks
128+
make check # Lockfile check, Ruff lint/format, ty type check, deptry
129+
make test # Run pytest with doctests
130+
make gen-check # Verify generated schema bindings match schema/
131+
make docs-test # Build MkDocs site strictly
132+
```
67133

68-
Keep docs and examples current whenever you ship public API or transport changes, and prefer Conventional Commits (`feat:`, `fix:`, etc.) when submitting patches.
134+
To regenerate protocol bindings when upstream schemas advance, run `ACP_SCHEMA_VERSION=<ref> make gen-all` (or `make gen-v2` for v2).
69135

70-
## Community & support
136+
## Community
71137

72-
- File issues or feature requests at <https://github.com/agentclientprotocol/python-sdk>.
73-
- Discuss ideas or get help via GitHub Discussions: <https://github.com/agentclientprotocol/python-sdk/discussions>.
74-
- Join the broader ACP conversations at <https://agentclientprotocol.com/>, the Zed community channels, or the community Zulip: <https://agentclientprotocol.zulipchat.com/>.
75-
- Shared learnings, integrations, or third-party transports are welcome additions to the documentation—open a PR!
138+
- Issues and pull requests: <https://github.com/agentclientprotocol/python-sdk>
139+
- Discussions: <https://github.com/agentclientprotocol/python-sdk/discussions>
140+
- ACP specification and ecosystem: <https://agentclientprotocol.com/>
141+
- Zulip chat: <https://agentclientprotocol.zulipchat.com/>

‎docs/contrib.md‎

Lines changed: 17 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,26 @@
1-
# Experimental Contrib Modules
1+
# Contrib Utilities
22

3-
The helpers under `acp.contrib` package recurring patterns we saw in integrations such as Toad, kimi-cli, and Gemini. Keep in mind they are experimental—APIs can still shift as we learn. Use this page as a menu:
3+
> **Experimental.** Modules under `acp.contrib` package opt-in stateful helpers for common client and agent workflows. Their APIs may evolve across releases.
44
5-
- **`session_state.SessionAccumulator`** — build a canonical, immutable snapshot of every session update so UIs can render tool calls and plans without re-implementing state machines.
6-
- **`tool_calls.ToolCallTracker` + `permissions.PermissionBroker`** — coordinate streamed tool call updates and permission prompts from one place.
5+
## Available helpers
76

8-
## SessionAccumulator (`acp.contrib.session_state`)
7+
- **`acp.contrib.session_state.SessionAccumulator`** — aggregates incoming `SessionNotification` updates into immutable `SessionSnapshot` models for UI rendering.
8+
- **`acp.contrib.tool_calls.ToolCallTracker`** — tracks active tool call lifecycles and emits canonical `ToolCallStart` / `ToolCallProgress` updates.
9+
- **`acp.contrib.permissions.PermissionBroker`** — coordinates `request_permission` prompts using tracked tool call state and default approve/reject options.
910

10-
**Use it when:** you need a live, merged view of `SessionNotification` events (e.g. tool calls, plan entries, user/agent messages) to drive UI widgets.
11+
## `SessionAccumulator` (`acp.contrib.session_state`)
1112

12-
**Key capabilities**
13+
Feed raw `SessionNotification` events into one accumulator per UI controller and render from immutable snapshots:
1314

14-
- `SessionAccumulator.apply(notification)` reconciles `tool_call` and `tool_call_update` payloads, even if the start event arrives late.
15-
- `snapshot()` returns an immutable `SessionSnapshot` Pydantic model containing the plan, current mode, commands, and ordered message history.
16-
- Raw tool input/output payloads are copied when applying notifications and creating snapshots, so nested payload mutations do not change the accumulated state.
17-
- `subscribe(callback)` lets you push snapshots into stores or UI components whenever state changes.
18-
- Automatic reset on session-change (toggle with `auto_reset_on_session_change`).
15+
- `apply(notification)` merges message chunks, plan updates, mode/config changes, and `tool_call` / `tool_call_update` payloads (including out-of-order updates).
16+
- `snapshot()` returns an immutable `SessionSnapshot` Pydantic model with copied tool input/output payloads.
17+
- `subscribe(callback)` pushes updated snapshots to subscribers whenever state changes.
18+
- `auto_reset_on_session_change` resets accumulated state automatically when a new `session_id` arrives.
1919

20-
> Tip: Create one accumulator per UI controller. Feed every raw `SessionNotification` into it and render from `snapshot.tool_calls` / `snapshot.user_messages` instead of mutating state manually.
20+
## `ToolCallTracker` and `PermissionBroker` (`acp.contrib.tool_calls`, `acp.contrib.permissions`)
2121

22-
## ToolCallTracker & PermissionBroker (`acp.contrib.tool_calls`, `acp.contrib.permissions`)
22+
Share a single `ToolCallTracker` with `PermissionBroker` in your agent loop to keep tool updates and permission requests synchronized:
2323

24-
**Use them when:** your agent runtime synthesises tool call IDs, streams arguments, and prompts the user for approval. The helpers centralise the bookkeeping so you don’t juggle raw Pydantic models.
25-
26-
- `ToolCallTracker.start()/progress()/append_stream_text()` emits canonical `ToolCallStart` / `ToolCallProgress` updates and keeps an in-memory view via `view()` or `tool_call_model()`.
27-
- `PermissionBroker.request_for()` wraps `requestPermission` RPCs. It reuses tracker state (or a provided `ToolCall`), lets you append extra content, and defaults to Approve / Approve for session / Reject options.
28-
- Omit `options` or pass `None` to use broker defaults. An explicit empty option list raises `MissingPermissionOptionsError` before the permission request is sent; the same applies to empty `default_options` when no per-request options are supplied.
29-
- `default_permission_options()` exposes that canonical option triple if you need to customise it.
30-
31-
> Tip: Keep one tracker near the agent event loop. Emit notifications through it and share the tracker with `PermissionBroker` so permission prompts always match the latest tool call state.
32-
33-
## Design Guardrails
34-
35-
To stay aligned with the ACP schema, the contrib layer follows a few rules:
36-
37-
- Schema data classes continue to live in `acp.schema`. Contrib helpers clone them with `.model_copy(deep=True)` before mutation.
38-
- The core runtime never imports contrib modules implicitly—you opt in when they help.
39-
- Helpers focus on painful bookkeeping (tool call aggregation, permission UX) and leave product-specific policy to your application.
40-
41-
Try the contrib modules, then open an issue or PR with feedback so we know which APIs should graduate into the stable surface.
24+
- `ToolCallTracker.start()`, `progress()`, and `append_stream_text()` emit `ToolCallStart` and `ToolCallProgress` updates while maintaining an in-memory view via `view()` and `tool_call_model()`.
25+
- `PermissionBroker.request_for()` builds and sends `request_permission` calls using tracked tool call state (or an explicit `ToolCall`) and optional extra content blocks.
26+
- `default_permission_options()` provides the standard **Approve**, **Approve for session**, and **Reject** option triple. Omitting `options` or passing `None` applies the broker's defaults; passing an empty list raises `MissingPermissionOptionsError` before sending the request.

0 commit comments

Comments
 (0)