Skip to content

Commit 9574002

Browse files
author
Chojan Shang
committed
docs: polish everything
Signed-off-by: Chojan Shang <chojan.shang@vesoft.com>
1 parent 510ee42 commit 9574002

File tree

4 files changed

+139
-209
lines changed

4 files changed

+139
-209
lines changed

README.md

Lines changed: 39 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,66 +1,50 @@
11
# Agent Client Protocol (Python)
22

3-
A Python implementation of the Agent Client Protocol (ACP). Use it to build agents that communicate with ACP-capable clients (e.g. Zed) over stdio.
3+
Python SDK for the Agent Client Protocol (ACP). Build agents that speak ACP over stdio so tools like Zed can orchestrate them.
44

5-
> This library version is compatible with the corresponding ACP version. However, we lack sufficient resources to release each version. Welcome to contribute!
5+
> Each release tracks the matching ACP schema version. Contributions that improve coverage or tooling are very welcome.
66
7-
- Package name: `agent-client-protocol` (import as `acp`)
8-
- Repository: https://github.com/psiace/agent-client-protocol-python
9-
- Docs: https://psiace.github.io/agent-client-protocol-python/
10-
- Featured: Listed as the first third-party SDK on the official ACP site — see https://agentclientprotocol.com/libraries/community
7+
**Highlights**
8+
9+
- Typed dataclasses generated from the upstream ACP schema (`acp.schema`)
10+
- Async agent base class plus stdio transport helpers for quick bootstrapping
11+
- Included examples that stream content updates and tool calls end-to-end
1112

1213
## Install
1314

1415
```bash
1516
pip install agent-client-protocol
16-
# or
17+
# or with uv
1718
uv add agent-client-protocol
1819
```
1920

20-
## Development (contributors)
21+
## Quickstart
2122

22-
```bash
23-
make install # set up venv
24-
ACP_SCHEMA_VERSION=<ref> make gen-all # generate meta.py & schema.py
25-
make check # lint + typecheck
26-
make test # run tests
27-
```
23+
1. Install the package and point your ACP-capable client at the provided echo agent:
24+
```bash
25+
pip install agent-client-protocol
26+
python examples/echo_agent.py
27+
```
28+
2. Wire it into your client (e.g. Zed → Agents panel) so stdio is connected; the SDK handles JSON-RPC framing and lifecycle messages.
2829

29-
## Minimal agent example
30+
Prefer a step-by-step walkthrough? Read the [Quickstart guide](docs/quickstart.md) or the hosted docs: https://psiace.github.io/agent-client-protocol-python/.
3031

31-
See a complete streaming echo example in [examples/echo_agent.py](examples/echo_agent.py). It streams back each text block using `session/update` and ends the turn.
32+
### Minimal agent sketch
3233

3334
```python
3435
import asyncio
3536

36-
from acp import (
37-
Agent,
38-
AgentSideConnection,
39-
InitializeRequest,
40-
InitializeResponse,
41-
NewSessionRequest,
42-
NewSessionResponse,
43-
PromptRequest,
44-
PromptResponse,
45-
SessionNotification,
46-
stdio_streams,
47-
)
48-
from acp.schema import TextContentBlock, AgentMessageChunk
37+
from acp import Agent, AgentSideConnection, PromptRequest, PromptResponse, SessionNotification, stdio_streams
38+
from acp.schema import AgentMessageChunk, TextContentBlock
4939

5040

5141
class EchoAgent(Agent):
5242
def __init__(self, conn):
5343
self._conn = conn
5444

55-
async def initialize(self, params: InitializeRequest) -> InitializeResponse:
56-
return InitializeResponse(protocolVersion=params.protocolVersion)
57-
58-
async def newSession(self, params: NewSessionRequest) -> NewSessionResponse:
59-
return NewSessionResponse(sessionId="sess-1")
60-
6145
async def prompt(self, params: PromptRequest) -> PromptResponse:
6246
for block in params.prompt:
63-
text = block.get("text", "") if isinstance(block, dict) else getattr(block, "text", "")
47+
text = getattr(block, "text", "")
6448
await self._conn.sessionUpdate(
6549
SessionNotification(
6650
sessionId=params.sessionId,
@@ -83,17 +67,27 @@ if __name__ == "__main__":
8367
asyncio.run(main())
8468
```
8569

86-
Run this executable from your ACP-capable client (e.g. configure Zed to launch it). The library takes care of the stdio JSON-RPC transport.
87-
88-
## Example: Mini SWE Agent bridge
70+
Full example with streaming and lifecycle hooks lives in [examples/echo_agent.py](examples/echo_agent.py).
8971

90-
A minimal ACP bridge for mini-swe-agent is provided under [`examples/mini_swe_agent`](examples/mini_swe_agent/README.md). It demonstrates:
72+
## Examples
9173

92-
- Parsing a prompt from ACP content blocks
93-
- Streaming agent output via `session/update`
94-
- Mapping command execution to `tool_call` and `tool_call_update`
74+
- `examples/mini_swe_agent`: bridges mini-swe-agent into ACP, including a duet launcher and Textual TUI client
75+
- Additional transport helpers are documented in the [Mini SWE guide](docs/mini-swe-agent.md)
9576

9677
## Documentation
9778

98-
- Quickstart: [docs/quickstart.md](docs/quickstart.md)
99-
- Mini SWE Agent example: [docs/mini-swe-agent.md](docs/mini-swe-agent.md)
79+
- Project docs (MkDocs): https://psiace.github.io/agent-client-protocol-python/
80+
- Local sources: `docs/`
81+
- [Quickstart](docs/quickstart.md)
82+
- [Mini SWE Agent bridge](docs/mini-swe-agent.md)
83+
84+
## Development workflow
85+
86+
```bash
87+
make install # create uv virtualenv and install hooks
88+
ACP_SCHEMA_VERSION=<ref> make gen-all # refresh generated schema bindings
89+
make check # lint, types, dependency analysis
90+
make test # run pytest + doctests
91+
```
92+
93+
After local changes, consider updating docs/examples if the public API surface shifts.

docs/index.md

Lines changed: 21 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -1,67 +1,30 @@
1-
# Agent Client Protocol (Python)
1+
# Agent Client Protocol SDK (Python)
22

3-
A Python implementation of the Agent Client Protocol (ACP). Build agents that communicate with ACP-capable clients (e.g. Zed) over stdio.
3+
Welcome to the Python SDK for the Agent Client Protocol (ACP). The package ships ready-to-use transports, typed protocol models, and examples that stream messages to ACP-aware clients such as Zed.
44

5-
## Install
5+
## What you get
66

7-
```bash
8-
pip install agent-client-protocol
9-
```
7+
- Fully typed dataclasses generated from the upstream ACP schema (`acp.schema`)
8+
- Async agent base class and stdio helpers to spin up an agent in a few lines
9+
- Examples that demonstrate streaming updates and tool execution over ACP
1010

11-
## Minimal usage
11+
## Getting started
1212

13-
```python
14-
import asyncio
13+
1. Install the package:
14+
```bash
15+
pip install agent-client-protocol
16+
```
17+
2. Launch the provided echo agent to verify your setup:
18+
```bash
19+
python examples/echo_agent.py
20+
```
21+
3. Point your ACP-capable client at the running process (for Zed, configure an Agent Server entry). The SDK takes care of JSON-RPC framing and lifecycle transitions.
1522

16-
from acp import (
17-
Agent,
18-
AgentSideConnection,
19-
InitializeRequest,
20-
InitializeResponse,
21-
NewSessionRequest,
22-
NewSessionResponse,
23-
PromptRequest,
24-
PromptResponse,
25-
SessionNotification,
26-
stdio_streams,
27-
)
28-
from acp.schema import TextContentBlock, AgentMessageChunk
23+
Prefer a guided tour? Head to the [Quickstart](quickstart.md) for step-by-step instructions, including how to run the agent from an editor or terminal.
2924

25+
## Documentation map
3026

31-
class EchoAgent(Agent):
32-
def __init__(self, conn):
33-
self._conn = conn
27+
- [Quickstart](quickstart.md): install, run, and extend the echo agent
28+
- [Mini SWE Agent guide](mini-swe-agent.md): bridge mini-swe-agent over ACP, including duet launcher and Textual client
3429

35-
async def initialize(self, params: InitializeRequest) -> InitializeResponse:
36-
return InitializeResponse(protocolVersion=params.protocolVersion)
37-
38-
async def newSession(self, params: NewSessionRequest) -> NewSessionResponse:
39-
return NewSessionResponse(sessionId="sess-1")
40-
41-
async def prompt(self, params: PromptRequest) -> PromptResponse:
42-
for block in params.prompt:
43-
text = block.get("text", "") if isinstance(block, dict) else getattr(block, "text", "")
44-
await self._conn.sessionUpdate(
45-
SessionNotification(
46-
sessionId=params.sessionId,
47-
update=AgentMessageChunk(
48-
sessionUpdate="agent_message_chunk",
49-
content=TextContentBlock(type="text", text=text),
50-
),
51-
)
52-
)
53-
return PromptResponse(stopReason="end_turn")
54-
55-
56-
async def main() -> None:
57-
reader, writer = await stdio_streams()
58-
AgentSideConnection(lambda conn: EchoAgent(conn), writer, reader)
59-
await asyncio.Event().wait()
60-
61-
62-
if __name__ == "__main__":
63-
asyncio.run(main())
64-
```
65-
66-
- Quickstart: [quickstart.md](quickstart.md)
67-
- Mini SWE Agent example: [mini-swe-agent.md](mini-swe-agent.md)
30+
Source code lives under `src/acp/`, while tests and additional examples are available in `tests/` and `examples/`. If you plan to contribute, see the repository README for the development workflow.

docs/mini-swe-agent.md

Lines changed: 34 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,54 @@
11
# Mini SWE Agent bridge
22

3-
> Just a show of the bridge in action. Not a best-effort or absolutely-correct implementation of the agent.
3+
This example wraps mini-swe-agent behind ACP so editors such as Zed can interact with it over stdio. A duet launcher is included to run a local Textual client beside the bridge for quick experimentation.
44

5-
This example wraps mini-swe-agent behind ACP so Zed can run it as an external agent over stdio. It also includes a local Textual UI client connected via a duet launcher
5+
## Overview
66

7-
## Behavior
7+
- Accepts ACP prompts, concatenates text blocks, and forwards them to mini-swe-agent
8+
- Streams language-model output via `session/update``agent_message_chunk`
9+
- Emits `tool_call` / `tool_call_update` pairs for shell execution, including stdout and return codes
10+
- Sends a final `agent_message_chunk` when mini-swe-agent prints `COMPLETE_TASK_AND_SUBMIT_FINAL_OUTPUT`
811

9-
- Prompts: text blocks are concatenated into a single task string. (Resource embedding is not used in this example.)
10-
- Streaming: only LM output is streamed via `session/update``agent_message_chunk`.
11-
- Tool calls: when the agent executes a shell command, the bridge sends:
12-
- `tool_call` with `kind=execute`, pending status, and a bash code block containing the command
13-
- `tool_call_update` upon completion, including output and a `rawOutput` object with `output` and `returncode`
14-
- Final result: on task submission (mini-swe-agent prints `COMPLETE_TASK_AND_SUBMIT_FINAL_OUTPUT` as the first line), a final `agent_message_chunk` with the submission content is sent.
12+
## Requirements
1513

16-
## Configuration
14+
- Python environment with `mini-swe-agent` installed (`pip install mini-swe-agent`)
15+
- ACP-capable client (e.g. Zed) or the bundled Textual client
16+
- Optional: `.env` file at the repo root for shared configuration when using the duet launcher
1717

18-
Environment variables control the model:
18+
If `mini-swe-agent` is missing, the bridge falls back to the reference copy at `reference/mini-swe-agent/src`.
1919

20-
- `MINI_SWE_MODEL`: model ID (e.g. `openrouter/openai/gpt-4o-mini`)
21-
- `OPENROUTER_API_KEY` for OpenRouter; or `OPENAI_API_KEY` / `ANTHROPIC_API_KEY` for native providers
22-
- Optional `MINI_SWE_MODEL_KWARGS`: JSON, e.g. `{ "api_base": "https://openrouter.ai/api/v1" }` (auto-injected for OpenRouter if missing)
20+
## Configure models and credentials
2321

24-
Agent behavior automatically maps the appropriate API key based on the chosen model and available environment variables.
22+
Set environment variables before launching the bridge:
2523

26-
If `mini-swe-agent` is not installed in the venv, the bridge attempts to import a vendored reference copy under `reference/mini-swe-agent/src`.
24+
- `MINI_SWE_MODEL`: model identifier such as `openrouter/openai/gpt-4o-mini`
25+
- `OPENROUTER_API_KEY` for OpenRouter models, or `OPENAI_API_KEY` / `ANTHROPIC_API_KEY` for native providers
26+
- Optional `MINI_SWE_MODEL_KWARGS`: JSON blob of extra keyword arguments (OpenRouter defaults are injected automatically when omitted)
2727

28-
## How to run
28+
The bridge selects the correct API key based on the chosen model and available variables.
2929

30-
- In Zed (editor integration): configure an agent server to launch `examples/mini_swe_agent/agent.py` and set the environment variables there. Use Zed’s “Open ACP Logs” to inspect `tool_call`/`tool_call_update` and message chunks.
31-
- In terminal (local TUI): run the duet launcher to start both the agent and the Textual client with the same environment and dedicated pipes:
30+
## Run inside Zed
31+
32+
Add an Agent Server entry targeting `examples/mini_swe_agent/agent.py` and provide the environment variables there. Use Zed’s “Open ACP Logs” panel to observe streamed message chunks and tool call events in real time.
33+
34+
## Run locally with the duet launcher
35+
36+
To pair the bridge with the Textual TUI client, run:
3237

3338
```bash
3439
python examples/mini_swe_agent/duet.py
3540
```
3641

37-
The launcher loads `.env` from the repo root (using python-dotenv) so both processes share the same configuration.
38-
39-
### TUI usage
42+
Both processes inherit settings from `.env` (thanks to `python-dotenv`) and communicate over dedicated pipes.
4043

41-
- Hotkeys: `y` → YOLO, `c` → Confirm, `u` → Human, `Enter` → Continue.
42-
- In Human mode, you’ll be prompted for a bash command; it will be executed and streamed back as a tool call.
43-
- Each executed command appears in the “TOOL CALLS” section with live status and output.
44+
**TUI shortcuts**
45+
- `y`: YOLO
46+
- `c`: Confirm
47+
- `u`: Human (prompts for a shell command and streams it back as a tool call)
48+
- `Enter`: Continue
4449

45-
## Files
50+
## Related files
4651

47-
- Agent entry: [`examples/mini_swe_agent/agent.py`](https://github.com/psiace/agent-client-protocol-python/blob/main/examples/mini_swe_agent/agent.py)
48-
- Duet launcher: [`examples/mini_swe_agent/duet.py`](https://github.com/psiace/agent-client-protocol-python/blob/main/examples/mini_swe_agent/duet.py)
49-
- Textual client: [`examples/mini_swe_agent/client.py`](https://github.com/psiace/agent-client-protocol-python/blob/main/examples/mini_swe_agent/client.py)
52+
- Agent entrypoint: `examples/mini_swe_agent/agent.py`
53+
- Duet launcher: `examples/mini_swe_agent/duet.py`
54+
- Textual client: `examples/mini_swe_agent/client.py`

0 commit comments

Comments
 (0)