|
1 | | -# Agent Client Protocol - Python SDK |
| 1 | +# Agent Client Protocol (Python) |
2 | 2 |
|
3 | | -A Python implementation of the Agent Client Protocol (ACP) used by editors like Zed to talk to external agents over stdio. |
| 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. |
4 | 4 |
|
| 5 | +- Package name: `agent-client-protocol` (import as `acp`) |
5 | 6 | - Repository: https://github.com/psiace/agent-client-protocol-python |
6 | 7 | - Docs: https://psiace.github.io/agent-client-protocol-python/ |
7 | 8 |
|
8 | | -## What this provides |
9 | | - |
10 | | -- Typed ACP client/agent primitives (`acp` package under `src/`) |
11 | | -- A runnable example: a bridge that wraps mini-swe-agent as an ACP agent |
12 | | -- Reference implementations under `reference/` for learning and comparison |
13 | | - |
14 | | -## Quick start |
15 | | - |
16 | | -Install the development environment: |
| 9 | +## Install |
17 | 10 |
|
18 | 11 | ```bash |
19 | | -make install |
| 12 | +pip install agent-client-protocol |
| 13 | +# or |
| 14 | +uv add agent-client-protocol |
20 | 15 | ``` |
21 | 16 |
|
22 | | -Run quality checks: |
| 17 | +## Development (contributors) |
23 | 18 |
|
24 | 19 | ```bash |
25 | | -make check |
| 20 | +make install # set up venv |
| 21 | +make check # lint + typecheck |
| 22 | +make test # run tests |
26 | 23 | ``` |
27 | 24 |
|
28 | | -Run tests: |
| 25 | +## Minimal agent example |
29 | 26 |
|
30 | | -```bash |
31 | | -make test |
| 27 | +```python |
| 28 | +# agent_main.py |
| 29 | +import asyncio |
| 30 | +from acp import Agent, AgentSideConnection, Client, InitializeRequest, InitializeResponse, PromptRequest, PromptResponse, SessionNotification, stdio_streams, PROTOCOL_VERSION |
| 31 | +from acp.schema import ContentBlock1, SessionUpdate2 |
| 32 | + |
| 33 | +class EchoAgent(Agent): |
| 34 | + def __init__(self, client: Client) -> None: |
| 35 | + self.client = client |
| 36 | + |
| 37 | + async def initialize(self, _p: InitializeRequest) -> InitializeResponse: |
| 38 | + return InitializeResponse(protocolVersion=PROTOCOL_VERSION) |
| 39 | + |
| 40 | + async def prompt(self, p: PromptRequest) -> PromptResponse: |
| 41 | + text = "".join([getattr(b, "text", "") for b in p.prompt if getattr(b, "type", None) == "text"]) or "(empty)" |
| 42 | + await self.client.sessionUpdate(SessionNotification( |
| 43 | + sessionId=p.sessionId, |
| 44 | + update=SessionUpdate2(sessionUpdate="agent_message_chunk", content=ContentBlock1(type="text", text=f"Echo: {text}")), |
| 45 | + )) |
| 46 | + return PromptResponse(stopReason="end_turn") |
| 47 | + |
| 48 | +async def main() -> None: |
| 49 | + reader, writer = await stdio_streams() |
| 50 | + AgentSideConnection(lambda c: EchoAgent(c), writer, reader) |
| 51 | + await asyncio.Event().wait() |
| 52 | + |
| 53 | +if __name__ == "__main__": |
| 54 | + asyncio.run(main()) |
32 | 55 | ``` |
33 | 56 |
|
34 | | -## Example: Mini SWE Agent bridge |
| 57 | +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. |
35 | 58 |
|
36 | | -A minimal ACP bridge for mini-swe-agent is provided under [`examples/mini_swe_agent`](file:///Users/psiace/OSS/agent-client-protocol-python/examples/mini_swe_agent/README.md). It shows how to: |
| 59 | +## Example: Mini SWE Agent bridge |
37 | 60 |
|
38 | | -- Parse a prompt from ACP content blocks |
39 | | -- Stream agent output to the client with `session/update` |
40 | | -- Map command execution to `tool_call` and `tool_call_update` |
| 61 | +A minimal ACP bridge for mini-swe-agent is provided under [`examples/mini_swe_agent`](examples/mini_swe_agent/README.md). It demonstrates: |
41 | 62 |
|
42 | | -See the example’s README or the docs quickstart for Zed configuration. |
| 63 | +- Parsing a prompt from ACP content blocks |
| 64 | +- Streaming agent output via `session/update` |
| 65 | +- Mapping command execution to `tool_call` and `tool_call_update` |
43 | 66 |
|
44 | 67 | ## Documentation |
45 | 68 |
|
46 | | -- Getting started: [docs/index.md](docs/index.md) |
47 | 69 | - Quickstart: [docs/quickstart.md](docs/quickstart.md) |
48 | | -- Mini SWE Agent example details: [docs/mini-swe-agent.md](docs/mini-swe-agent.md) |
49 | | - |
50 | | -## Notes |
51 | | - |
52 | | -- The `reference/` directory contains educational examples and may include optional dependencies. These are not required to use the example bridge. |
| 70 | +- Mini SWE Agent example: [docs/mini-swe-agent.md](docs/mini-swe-agent.md) |
0 commit comments