Skip to content

Commit 4261539

Browse files
authored
docs: redesign README and reorganize documentation (#210)
* docs: redesign README and reorganize documentation * docs: replace oversized tables in README and guides with structured lists * docs: tighten README and guides to focus on core user-visible flows
1 parent 132a02a commit 4261539

12 files changed

Lines changed: 357 additions & 792 deletions

‎README.md‎

Lines changed: 78 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -2,74 +2,105 @@
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 models and asyncio transports over stdio, Streamable HTTP, and WebSocket.
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+
For experimental HTTP/WebSocket transports, install the `http` extra (`pip install "agent-client-protocol[http]"`). Requires Python 3.10–3.15.
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+
## Quick example
2625

27-
## Who benefits
26+
### Build an agent
2827

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/).
28+
```python
29+
import asyncio
30+
from typing import Any
31+
from uuid import uuid4
3332

34-
## How to get started
33+
from acp import PROTOCOL_VERSION, Agent, InitializeResponse, NewSessionResponse, PromptResponse, run_agent
34+
from acp.interfaces import Client
35+
from acp.schema import AgentMessageChunk, TextContentBlock
3536

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.
3937

40-
## Quick links
38+
class EchoAgent(Agent):
39+
def on_connect(self, conn: Client) -> None:
40+
self._conn = conn
4141

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/> |
42+
async def initialize(self, protocol_version: int, **kwargs: Any) -> InitializeResponse:
43+
return InitializeResponse(protocol_version=PROTOCOL_VERSION)
5244

53-
## Project layout
45+
async def new_session(self, cwd: str, **kwargs: Any) -> NewSessionResponse:
46+
return NewSessionResponse(session_id=uuid4().hex)
5447

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
48+
async def prompt(self, session_id: str, prompt: list[Any], **kwargs: Any) -> PromptResponse:
49+
for block in prompt:
50+
text = getattr(block, "text", "")
51+
await self._conn.session_update(
52+
session_id=session_id,
53+
update=AgentMessageChunk(content=TextContentBlock(text=text)),
54+
)
55+
return PromptResponse(stop_reason="end_turn")
6056

61-
## Developer commands
6257

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.
58+
if __name__ == "__main__":
59+
asyncio.run(run_agent(EchoAgent()))
60+
```
61+
62+
### Drive an agent from Python
63+
64+
```python
65+
import asyncio
66+
import sys
67+
from typing import Any
68+
69+
from acp import PROTOCOL_VERSION, Client, spawn_agent_process
70+
from acp.schema import TextContentBlock
71+
72+
73+
class SimpleClient(Client):
74+
async def session_update(self, session_id: str, update: Any, **kwargs: Any) -> None:
75+
print(session_id, update)
76+
77+
78+
async def main() -> None:
79+
async with spawn_agent_process(SimpleClient(), sys.executable, "examples/echo_agent.py") as (conn, _proc):
80+
await conn.initialize(protocol_version=PROTOCOL_VERSION)
81+
session = await conn.new_session(cwd=".", mcp_servers=[])
82+
await conn.prompt(session_id=session.session_id, prompt=[TextContentBlock(text="Hello ACP!")])
6783

68-
Keep docs and examples current whenever you ship public API or transport changes, and prefer Conventional Commits (`feat:`, `fix:`, etc.) when submitting patches.
6984

70-
## Community & support
85+
asyncio.run(main())
86+
```
87+
88+
## Documentation
89+
90+
- [Quickstart](https://agentclientprotocol.github.io/python-sdk/quickstart/) — Connect your agent to Zed, Toad, Lody, or T3 Code, or drive agents programmatically.
91+
- [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`).
92+
- [Web Transport](https://agentclientprotocol.github.io/python-sdk/web-transport/) — Serve and consume ACP over Streamable HTTP and WebSocket (`[http]`).
93+
- [Experimental Protocol v2](https://agentclientprotocol.github.io/python-sdk/experimental-v2/) — Preview v2 runtime (`schema-v2.0.0-beta.4`) and dual-stack `AgentProtocolRouter`.
94+
- [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/)
95+
96+
## Development
97+
98+
```bash
99+
make install # Set up uv environment and pre-commit hooks
100+
make check # Format, lint, type-check, and dependency check
101+
make test # Run pytest suite
102+
```
103+
104+
## Community
71105

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!
106+
Join the conversation on [GitHub Discussions](https://github.com/agentclientprotocol/python-sdk/discussions), [Zulip](https://agentclientprotocol.zulipchat.com/), or [agentclientprotocol.com](https://agentclientprotocol.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)