Skip to content

Repository files navigation

Agent Client Protocol

Agent Client Protocol — Python SDK

PyPI Python CI Docs

Python SDK for building Agent Client Protocol (ACP) agents and clients, with generated Pydantic models and asyncio transports over stdio, Streamable HTTP, and WebSocket.

Installation

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

For experimental HTTP/WebSocket transports, install the http extra (pip install "agent-client-protocol[http]"). Requires Python 3.10–3.15.

Quick example

Build an agent

import asyncio
from typing import Any
from uuid import uuid4

from acp import PROTOCOL_VERSION, Agent, InitializeResponse, NewSessionResponse, PromptResponse, run_agent
from acp.interfaces import Client
from acp.schema import AgentMessageChunk, TextContentBlock


class EchoAgent(Agent):
    def on_connect(self, conn: Client) -> None:
        self._conn = conn

    async def initialize(self, protocol_version: int, **kwargs: Any) -> InitializeResponse:
        return InitializeResponse(protocol_version=PROTOCOL_VERSION)

    async def new_session(self, cwd: str, **kwargs: Any) -> NewSessionResponse:
        return NewSessionResponse(session_id=uuid4().hex)

    async def prompt(self, session_id: str, prompt: list[Any], **kwargs: Any) -> PromptResponse:
        for block in prompt:
            text = getattr(block, "text", "")
            await self._conn.session_update(
                session_id=session_id,
                update=AgentMessageChunk(content=TextContentBlock(text=text)),
            )
        return PromptResponse(stop_reason="end_turn")


if __name__ == "__main__":
    asyncio.run(run_agent(EchoAgent()))

Drive an agent from Python

import asyncio
import sys
from typing import Any

from acp import PROTOCOL_VERSION, Client, spawn_agent_process
from acp.schema import TextContentBlock


class SimpleClient(Client):
    async def session_update(self, session_id: str, update: Any, **kwargs: Any) -> None:
        print(session_id, update)


async def main() -> None:
    async with spawn_agent_process(SimpleClient(), sys.executable, "examples/echo_agent.py") as (conn, _proc):
        await conn.initialize(protocol_version=PROTOCOL_VERSION)
        session = await conn.new_session(cwd=".", mcp_servers=[])
        await conn.prompt(session_id=session.session_id, prompt=[TextContentBlock(text="Hello ACP!")])


asyncio.run(main())

Documentation

Development

make install    # Set up uv environment and pre-commit hooks
make check      # Format, lint, type-check, and dependency check
make test       # Run pytest suite

Community

Join the conversation on GitHub Discussions, Zulip, or agentclientprotocol.com.

Releases

Packages

Used by

Contributors

Languages