Skip to content

Commit 2c3e449

Browse files
author
Chojan Shang
committed
docs: polish docs for next release
Signed-off-by: Chojan Shang <chojan.shang@vesoft.com>
1 parent d17e4ea commit 2c3e449

File tree

3 files changed

+62
-43
lines changed

3 files changed

+62
-43
lines changed

README.md

Lines changed: 39 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,10 @@ Python SDK for the Agent Client Protocol (ACP). Build agents that speak ACP over
66
77
**Highlights**
88

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
9+
- Generated `pydantic` models that track the upstream ACP schema (`acp.schema`)
10+
- Async base classes and JSON-RPC plumbing that keep stdio agents tiny
11+
- Process helpers such as `spawn_agent_process` for embedding agents and clients directly in Python
12+
- Batteries-included examples that exercise streaming updates, file I/O, and permission flows
1213

1314
## Install
1415

@@ -29,6 +30,37 @@ uv add agent-client-protocol
2930

3031
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/.
3132

33+
### Launching from Python
34+
35+
Embed the agent inside another Python process without spawning your own pipes:
36+
37+
```python
38+
import asyncio
39+
import sys
40+
from pathlib import Path
41+
42+
from acp import spawn_agent_process
43+
from acp.schema import InitializeRequest, NewSessionRequest, PromptRequest, TextContentBlock
44+
45+
46+
async def main() -> None:
47+
agent_script = Path("examples/echo_agent.py")
48+
async with spawn_agent_process(lambda _agent: YourClient(), sys.executable, str(agent_script)) as (conn, _proc):
49+
await conn.initialize(InitializeRequest(protocolVersion=1))
50+
session = await conn.newSession(NewSessionRequest(cwd=str(agent_script.parent), mcpServers=[]))
51+
await conn.prompt(
52+
PromptRequest(
53+
sessionId=session.sessionId,
54+
prompt=[TextContentBlock(type="text", text="Hello!")],
55+
)
56+
)
57+
58+
59+
asyncio.run(main())
60+
```
61+
62+
`spawn_client_process` mirrors this pattern for the inverse direction.
63+
3264
### Minimal agent sketch
3365

3466
```python
@@ -71,9 +103,10 @@ Full example with streaming and lifecycle hooks lives in [examples/echo_agent.py
71103

72104
## Examples
73105

74-
- `examples/echo_agent.py`: self-contained streaming agent suitable for smoke tests
75-
- `examples/client.py`: interactive console client that can spawn any ACP agent subprocess
76-
- `examples/duet.py`: demo launcher that starts both the example client and agent together
106+
- `examples/echo_agent.py`: the canonical streaming agent with lifecycle hooks
107+
- `examples/client.py`: interactive console client that can launch any ACP agent via stdio
108+
- `examples/agent.py`: richer agent showcasing initialization, authentication, and chunked updates
109+
- `examples/duet.py`: launches both example agent and client using `spawn_agent_process`
77110

78111
## Documentation
79112

docs/index.md

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@ Welcome to the Python SDK for the Agent Client Protocol (ACP). The package ships
44

55
## What you get
66

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
7+
- Pydantic models generated from the upstream ACP schema (`acp.schema`)
8+
- Async agent/client wrappers with JSON-RPC task supervision built in
9+
- Process helpers (`spawn_agent_process`, `spawn_client_process`) for embedding ACP nodes inside Python applications
10+
- Examples that showcase streaming updates, file operations, and permission flows
1011

1112
## Getting started
1213

@@ -20,10 +21,10 @@ Welcome to the Python SDK for the Agent Client Protocol (ACP). The package ships
2021
```
2122
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.
2223

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.
24+
Prefer a guided tour? Head to the [Quickstart](quickstart.md) for terminal, editor, and programmatic launch walkthroughs.
2425

2526
## Documentation map
2627

27-
- [Quickstart](quickstart.md): install, run, and extend the echo agent
28+
- [Quickstart](quickstart.md): install, run, and embed the echo agent, plus next steps for extending it
2829

2930
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/quickstart.md

Lines changed: 17 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,17 @@ pip install agent-client-protocol
1515
uv add agent-client-protocol
1616
```
1717

18-
## 2. Run the echo agent
18+
## 2. Launch the Echo agent (terminal)
1919

20-
Launch the ready-made echo example, which streams text blocks back over ACP:
20+
Start the ready-made echo example — it streams text blocks back to any ACP client:
2121

2222
```bash
2323
python examples/echo_agent.py
2424
```
2525

26-
Keep it running while you connect your client.
26+
Leave this process running while you connect from an editor or another program.
2727

28-
## 3. Connect from your client
28+
## 3. Connect from an editor
2929

3030
### Zed
3131

@@ -52,45 +52,27 @@ Any ACP client that communicates over stdio can spawn the same script; no additi
5252

5353
### Programmatic launch
5454

55-
You can also embed the agent inside another Python process without shelling out manually. Use
56-
`acp.spawn_agent_process` to bootstrap the child and receive a `ClientSideConnection`:
57-
5855
```python
5956
import asyncio
6057
import sys
6158
from pathlib import Path
6259

6360
from acp import spawn_agent_process
6461
from acp.interfaces import Client
65-
from acp.schema import (
66-
DeniedOutcome,
67-
InitializeRequest,
68-
NewSessionRequest,
69-
PromptRequest,
70-
RequestPermissionRequest,
71-
RequestPermissionResponse,
72-
SessionNotification,
73-
TextContentBlock,
74-
)
62+
from acp.schema import InitializeRequest, NewSessionRequest, PromptRequest, SessionNotification, TextContentBlock
7563

7664

7765
class SimpleClient(Client):
78-
async def requestPermission(self, params: RequestPermissionRequest) -> RequestPermissionResponse:
79-
return RequestPermissionResponse(outcome=DeniedOutcome(outcome="cancelled"))
80-
81-
async def sessionUpdate(self, params: SessionNotification) -> None: # noqa: D401 - logging only
82-
print("update:", params)
66+
async def requestPermission(self, params): # pragma: no cover - minimal stub
67+
return {"outcome": {"outcome": "cancelled"}}
8368

84-
# Optional client methods omitted for brevity
69+
async def sessionUpdate(self, params: SessionNotification) -> None:
70+
print("update:", params.sessionId, params.update)
8571

8672

8773
async def main() -> None:
88-
script = Path("examples/echo_agent.py").resolve()
89-
90-
async with spawn_agent_process(lambda agent: SimpleClient(), sys.executable, str(script)) as (
91-
conn,
92-
_process,
93-
):
74+
script = Path("examples/echo_agent.py")
75+
async with spawn_agent_process(lambda _agent: SimpleClient(), sys.executable, str(script)) as (conn, _proc):
9476
await conn.initialize(InitializeRequest(protocolVersion=1))
9577
session = await conn.newSession(NewSessionRequest(cwd=str(script.parent), mcpServers=[]))
9678
await conn.prompt(
@@ -103,8 +85,7 @@ async def main() -> None:
10385
asyncio.run(main())
10486
```
10587

106-
Inside the context manager the subprocess is monitored, stdin/stdout are tied into ACP, and the
107-
connection cleans itself up on exit.
88+
`spawn_agent_process` manages the child process, wires its stdio into ACP framing, and closes everything when the block exits. The mirror helper `spawn_client_process` lets you drive an ACP client from Python as well.
10889

10990
## 4. Extend the agent
11091

@@ -120,4 +101,8 @@ class MyAgent(Agent):
120101
return PromptResponse(stopReason="end_turn")
121102
```
122103

123-
Hook it up with `AgentSideConnection` inside an async entrypoint and wire it to your client. Refer to [examples/echo_agent.py](https://github.com/psiace/agent-client-protocol-python/blob/main/examples/echo_agent.py) for the complete structure, including lifetime hooks (`initialize`, `newSession`) and streaming responses.
104+
Hook it up with `AgentSideConnection` inside an async entrypoint and wire it to your client. Refer to:
105+
106+
- [`examples/echo_agent.py`](https://github.com/psiace/agent-client-protocol-python/blob/main/examples/echo_agent.py) for the smallest streaming agent
107+
- [`examples/agent.py`](https://github.com/psiace/agent-client-protocol-python/blob/main/examples/agent.py) for an implementation that negotiates capabilities and streams richer updates
108+
- [`examples/duet.py`](https://github.com/psiace/agent-client-protocol-python/blob/main/examples/duet.py) to see `spawn_agent_process` in action alongside the interactive client

0 commit comments

Comments
 (0)