Skip to main content

A Python implement of Agent Client Protocol (ACP, by Zed Industries)

Project description

Agent Client Protocol

Agent Client Protocol (Python)

Python SDK for the Agent Client Protocol (ACP). Build agents that speak ACP over stdio so tools like Zed can orchestrate them.

Each release tracks the matching ACP schema version. Contributions that improve coverage or tooling are very welcome.

Highlights

  • Generated pydantic models that track the upstream ACP schema (acp.schema)
  • Async base classes and JSON-RPC plumbing that keep stdio agents tiny
  • Process helpers such as spawn_agent_process for embedding agents and clients directly in Python
  • Batteries-included examples that exercise streaming updates, file I/O, and permission flows
  • Optional Gemini CLI bridge (examples/gemini.py) for the gemini --experimental-acp integration
  • Experimental contrib modules (acp.contrib) that streamline session state, tool call tracking, and permission prompts

Install

pip install agent-client-protocol
# or with uv
uv add agent-client-protocol

Quickstart

  1. Install the package and point your ACP-capable client at the provided echo agent:
    pip install agent-client-protocol
    python examples/echo_agent.py
    
  2. Wire it into your client (e.g. Zed → Agents panel) so stdio is connected; the SDK handles JSON-RPC framing and lifecycle messages.

Prefer a step-by-step walkthrough? Read the Quickstart guide or the hosted docs: https://psiace.github.io/agent-client-protocol-python/.

Launching from Python

Embed the agent inside another Python process without spawning your own pipes:

import asyncio
import sys
from pathlib import Path

from acp import spawn_agent_process, text_block
from acp.schema import InitializeRequest, NewSessionRequest, PromptRequest


async def main() -> None:
    agent_script = Path("examples/echo_agent.py")
    async with spawn_agent_process(lambda _agent: YourClient(), sys.executable, str(agent_script)) as (conn, _proc):
        await conn.initialize(InitializeRequest(protocolVersion=1))
        session = await conn.newSession(NewSessionRequest(cwd=str(agent_script.parent), mcpServers=[]))
        await conn.prompt(
            PromptRequest(
                sessionId=session.sessionId,
                prompt=[text_block("Hello!")],
            )
        )


asyncio.run(main())

spawn_client_process mirrors this pattern for the inverse direction.

Minimal agent sketch

import asyncio

from acp import (
    Agent,
    AgentSideConnection,
    InitializeRequest,
    InitializeResponse,
    NewSessionRequest,
    NewSessionResponse,
    PromptRequest,
    PromptResponse,
    session_notification,
    stdio_streams,
    text_block,
    update_agent_message,
)


class EchoAgent(Agent):
    def __init__(self, conn):
        self._conn = conn

    async def initialize(self, params: InitializeRequest) -> InitializeResponse:
        return InitializeResponse(protocolVersion=params.protocolVersion)

    async def newSession(self, params: NewSessionRequest) -> NewSessionResponse:
        return NewSessionResponse(sessionId="sess-1")

    async def prompt(self, params: PromptRequest) -> PromptResponse:
        for block in params.prompt:
            text = block.get("text", "") if isinstance(block, dict) else getattr(block, "text", "")
            await self._conn.sessionUpdate(
                session_notification(
                    params.sessionId,
                    update_agent_message(text_block(text)),
                )
            )
        return PromptResponse(stopReason="end_turn")


async def main() -> None:
    reader, writer = await stdio_streams()
    AgentSideConnection(lambda conn: EchoAgent(conn), writer, reader)
    await asyncio.Event().wait()


if __name__ == "__main__":
    asyncio.run(main())

Full example with streaming and lifecycle hooks lives in examples/echo_agent.py.

Examples

  • examples/echo_agent.py: the canonical streaming agent with lifecycle hooks
  • examples/client.py: interactive console client that can launch any ACP agent via stdio
  • examples/agent.py: richer agent showcasing initialization, authentication, and chunked updates
  • examples/duet.py: launches both example agent and client using spawn_agent_process
  • examples/gemini.py: connects to the Gemini CLI in --experimental-acp mode, with optional auto-approval and sandbox flags

Helper APIs

Use acp.helpers to build protocol payloads without manually shaping dictionaries:

from acp import (
    start_read_tool_call,
    text_block,
    tool_content,
    update_available_commands,
    update_tool_call,
)

start = start_read_tool_call("call-1", "Inspect config", path="config.toml")
commands = update_available_commands([])
update = update_tool_call("call-1", status="completed", content=[tool_content(text_block("Done."))])

Helpers cover content blocks (text_block, resource_link_block), embedded resources, tool calls (start_edit_tool_call, update_tool_call), and session updates (update_agent_message_text, update_available_commands, update_current_mode, session_notification).

Contrib helpers

The experimental acp.contrib package captures patterns from reference integrations:

  • SessionAccumulator (acp.contrib.session_state) merges SessionNotification streams into immutable snapshots for UI rendering.
  • ToolCallTracker (acp.contrib.tool_calls) generates consistent tool call starts/updates and buffers streamed content.
  • PermissionBroker (acp.contrib.permissions) wraps permission requests with sensible default option sets.

Read more in docs/contrib.md.

Documentation

Gemini CLI bridge

Want to exercise the gemini CLI over ACP? The repository includes a Python replica of the Go SDK's REPL:

python examples/gemini.py --yolo  # auto-approve permissions
python examples/gemini.py --sandbox --model gemini-2.5-pro

Defaults assume the CLI is discoverable via PATH; override with --gemini or ACP_GEMINI_BIN=/path/to/gemini.

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:

ACP_ENABLE_GEMINI_TESTS=1 ACP_GEMINI_BIN=/path/to/gemini uv run python -m pytest tests/test_gemini_example.py

The test gracefully skips when authentication prompts (e.g. missing GOOGLE_CLOUD_PROJECT) block the interaction.

Development workflow

make install                     # create uv virtualenv and install hooks
ACP_SCHEMA_VERSION=<ref> make gen-all  # refresh generated schema bindings
make check                       # lint, types, dependency analysis
make test                        # run pytest + doctests

After local changes, consider updating docs/examples if the public API surface shifts.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

agent_client_protocol-0.5.0.tar.gz (149.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

agent_client_protocol-0.5.0-py3-none-any.whl (47.1 kB view details)

Uploaded Python 3

File details

Details for the file agent_client_protocol-0.5.0.tar.gz.

File metadata

File hashes

Hashes for agent_client_protocol-0.5.0.tar.gz
Algorithm Hash digest
SHA256 1fd85e602b16c94a248b3b2796979967660a1c3b1064c5281fb9335db6d64821
MD5 39f56cb3b3f440615d8e74b2fc0c1999
BLAKE2b-256 2ca856b89848fa2e072b245d07657a9b508e65b18c730f845a89ae50fe2a5c31

See more details on using hashes here.

File details

Details for the file agent_client_protocol-0.5.0-py3-none-any.whl.

File metadata

File hashes

Hashes for agent_client_protocol-0.5.0-py3-none-any.whl
Algorithm Hash digest
SHA256 d16127698465edef5fa9c83549b5f30f1195215c7cba9c963f9a1c1e99aa8f0c
MD5 83abf32168fe169dbf25374966a49d9a
BLAKE2b-256 337d3c8175d2650a0ad8edc49d1ea9c31c17313479709a17a61dc738e1d15fa0

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page