You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The package code lives under `src/acp`, exposing the high-level Agent, transport helpers, and generated protocol schema. Generated artifacts such as `schema/` and `src/acp/schema.py` are refreshed via `scripts/gen_all.py` against the upstream ACP schema. Integration examples are in `examples/`, including `echo_agent.py` and the mini SWE bridge. Tests reside in `tests/` with async fixtures and doctests; documentation sources live in `docs/` and publish via MkDocs. Built distributions drop into `dist/` after builds.
4
+
-`src/acp/`: runtime package exposing agent/client abstractions, transports, and the generated `schema.py`.
-`make gen-all` — refresh protocol artifacts when the ACP schema version advances (`ACP_SCHEMA_VERSION=<ref>` to pin an upstream tag).
8
15
9
16
## Coding Style & Naming Conventions
10
-
Target Python 3.10+ with type hints and 120-character lines enforced by Ruff (`pyproject.toml`). Prefer dataclasses/pydantic models from the schema modules rather than bare dicts. Tests may ignore security lint (see per-file ignores) but still follow snake_case names. Keep public API modules under `acp/*` lean; place utilities in internal `_`-prefixed modules when needed.
17
+
- Target Python 3.10+ with four-space indentation and type hints on public APIs.
18
+
- Ruff enforces formatting and lint rules (`uv run ruff check`, `uv run ruff format`); keep both clean before publishing.
19
+
- Prefer dataclasses or generated Pydantic models from `acp.schema` over ad-hoc dicts. Place shared utilities in `_`-prefixed internal modules.
20
+
- Prefer the builders in `acp.helpers` (for example `text_block`, `start_tool_call`) when constructing ACP payloads. The helpers instantiate the generated Pydantic models for you, keep literal discriminator fields out of call sites, and stay in lockstep with the schema thanks to the golden tests (`tests/test_golden.py`).
11
21
12
22
## Testing Guidelines
13
-
Pytest is the main framework with `pytest-asyncio` for coroutine tests and doctests activated on modules. Name test files `test_*.py` and co-locate fixtures under `tests/conftest.py`. Aim to cover new protocol surfaces with integration-style tests using the async agent stubs. Generate coverage reports via `tox -e py310` when assessing CI parity.
23
+
- Tests live in `tests/` and must be named `test_*.py`. Use `pytest.mark.asyncio` for coroutine coverage.
24
+
- Run `make test` (or `uv run python -m pytest`) prior to commits; include reproducing steps for any added fixtures.
25
+
- Gemini CLI coverage is disabled by default. Set `ACP_ENABLE_GEMINI_TESTS=1` (and `ACP_GEMINI_BIN=/path/to/gemini`) to exercise `tests/test_gemini_example.py`.
14
26
15
27
## Commit & Pull Request Guidelines
16
-
Commit history follows Conventional Commits (`feat:`, `fix:`, `docs:`). Scope commits narrowly and include context on affected protocol version or tooling. PRs should describe agent behaviors exercised, link related issues, and mention schema regeneration if applicable. Attach test output (`make check` or targeted pytest) and screenshots only when UI-adjacent docs change. Update docs/examples when altering the public agent API.
28
+
- Follow Conventional Commits (`feat:`, `fix:`, `docs:`, etc.) with succinct scopes, noting schema regenerations when applicable.
29
+
- PRs should describe exercised agent behaviours, link relevant issues, and include output from `make check` or focused pytest runs.
30
+
- Update documentation and examples whenever public APIs or transport behaviours change, and call out environment prerequisites for new integrations.
17
31
18
32
## Agent Integration Tips
19
-
Leverage `examples/mini_swe_agent/` as a template when bridging other command executors. Use `AgentSideConnection` with `stdio_streams()` for ACP-compliant clients; document any extra environment variables in README updates.
33
+
- Bootstrap agents from `examples/echo_agent.py` or `examples/agent.py`; pair with `examples/client.py` for round-trip validation.
34
+
- Use `spawn_agent_process` / `spawn_client_process` to embed ACP parties directly in Python applications.
35
+
- Validate new transports against `tests/test_rpc.py` and, when applicable, the Gemini example to ensure streaming updates and permission flows stay compliant.
Python SDK for the Agent Client Protocol (ACP). Build agents that speak ACP over stdio so tools like Zed can orchestrate them.
@@ -6,9 +10,11 @@ Python SDK for the Agent Client Protocol (ACP). Build agents that speak ACP over
6
10
7
11
**Highlights**
8
12
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
13
+
- Generated `pydantic` models that track the upstream ACP schema (`acp.schema`)
14
+
- Async base classes and JSON-RPC plumbing that keep stdio agents tiny
15
+
- Process helpers such as `spawn_agent_process` for embedding agents and clients directly in Python
16
+
- Batteries-included examples that exercise streaming updates, file I/O, and permission flows
17
+
- Optional Gemini CLI bridge (`examples/gemini.py`) for the `gemini --experimental-acp` integration
12
18
13
19
## Install
14
20
@@ -29,29 +35,75 @@ uv add agent-client-protocol
29
35
30
36
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/.
31
37
38
+
### Launching from Python
39
+
40
+
Embed the agent inside another Python process without spawning your own pipes:
41
+
42
+
```python
43
+
import asyncio
44
+
import sys
45
+
from pathlib import Path
46
+
47
+
from acp import spawn_agent_process, text_block
48
+
from acp.schema import InitializeRequest, NewSessionRequest, PromptRequest
49
+
50
+
51
+
asyncdefmain() -> None:
52
+
agent_script = Path("examples/echo_agent.py")
53
+
asyncwith spawn_agent_process(lambda_agent: YourClient(), sys.executable, str(agent_script)) as (conn, _proc):
Defaults assume the CLI is discoverable via `PATH`; override with `--gemini` or `ACP_GEMINI_BIN=/path/to/gemini`.
166
+
167
+
The smoke test (`tests/test_gemini_example.py`) is opt-in to avoid false negatives when the CLI is unavailable or lacks credentials. Enable it locally with:
168
+
169
+
```bash
170
+
ACP_ENABLE_GEMINI_TESTS=1 ACP_GEMINI_BIN=/path/to/gemini uv run python -m pytest tests/test_gemini_example.py
171
+
```
172
+
173
+
The test gracefully skips when authentication prompts (e.g. missing `GOOGLE_CLOUD_PROJECT`) block the interaction.
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.
4
8
5
9
## What you get
6
10
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
11
+
- Pydantic models generated from the upstream ACP schema (`acp.schema`)
12
+
- Async agent/client wrappers with JSON-RPC task supervision built in
13
+
- Process helpers (`spawn_agent_process`, `spawn_client_process`) for embedding ACP nodes inside Python applications
14
+
- Helper APIs in `acp.helpers` that mirror the Go/TS SDK builders for content blocks, tool calls, and session updates. They instantiate the generated Pydantic types for you, so call sites stay concise without sacrificing validation.
15
+
- Examples that showcase streaming updates, file operations, permission flows, and even a Gemini CLI bridge (`examples/gemini.py`)
10
16
11
17
## Getting started
12
18
@@ -20,11 +26,27 @@ Welcome to the Python SDK for the Agent Client Protocol (ACP). The package ships
20
26
```
21
27
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.
22
28
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.
29
+
Prefer a guided tour? Head to the [Quickstart](quickstart.md) for terminal, editor, and programmatic launch walkthroughs.
30
+
31
+
## Gemini CLI bridge
32
+
33
+
If you have access to the Gemini CLI (`gemini --experimental-acp`), run:
34
+
35
+
```bash
36
+
python examples/gemini.py --yolo
37
+
```
38
+
39
+
Flags mirror the Go SDK example:
40
+
41
+
-`--gemini /path/to/cli` or `ACP_GEMINI_BIN` to override discovery
-`--yolo` auto-approves permission prompts with sensible defaults
44
+
45
+
An opt-in smoke test lives at `tests/test_gemini_example.py`. Enable it with `ACP_ENABLE_GEMINI_TESTS=1` (and optionally `ACP_GEMINI_TEST_ARGS`) when the CLI is authenticated; otherwise the test stays skipped.
24
46
25
47
## Documentation map
26
48
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
49
+
-[Quickstart](quickstart.md): install, run, and embed the echo agent, plus next steps for extending it
50
+
-[Releasing](releasing.md): schema upgrade workflow, version bumps, and publishing checklist
29
51
30
52
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.
0 commit comments