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.6.3.tar.gz (152.4 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.6.3-py3-none-any.whl (47.6 kB view details)

Uploaded Python 3

File details

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

File metadata

File hashes

Hashes for agent_client_protocol-0.6.3.tar.gz
Algorithm Hash digest
SHA256 ea01a51d5b55864c606401694dad429d83c5bedb476807d81b8208031d6cf3d8
MD5 fad1f28244bf3fef144d705a6899d536
BLAKE2b-256 c6fe147187918c5ba695db537b3088c441bcace4ac9365fae532bf36b1494769

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for agent_client_protocol-0.6.3-py3-none-any.whl
Algorithm Hash digest
SHA256 184264bd6988731613a49c9eb89d7ecd23c6afffe905c64f1b604a42a9b20aef
MD5 cc50971d50ecc261b4dd7297cc76d500
BLAKE2b-256 9c2e62d1770a489d3356cd75e19cd61583e7e411f1b00ab9859c73048621e4c2

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