Skip to main content

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

Project description

Agent Client Protocol (Python)

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.

Install

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

Development (contributors)

make install   # set up venv
make check     # lint + typecheck
make test      # run tests

Minimal agent example

See a complete streaming echo example in examples/echo_agent.py. It streams back each text block using session/update and ends the turn.

import asyncio

from acp import (
    Agent,
    AgentSideConnection,
    InitializeRequest,
    InitializeResponse,
    NewSessionRequest,
    NewSessionResponse,
    PromptRequest,
    PromptResponse,
    SessionNotification,
    stdio_streams,
)
from acp.schema import ContentBlock1, SessionUpdate2


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(
                SessionNotification(
                    sessionId=params.sessionId,
                    update=SessionUpdate2(
                        sessionUpdate="agent_message_chunk",
                        content=ContentBlock1(type="text", text=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())

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.

Example: Mini SWE Agent bridge

A minimal ACP bridge for mini-swe-agent is provided under examples/mini_swe_agent. It demonstrates:

  • Parsing a prompt from ACP content blocks
  • Streaming agent output via session/update
  • Mapping command execution to tool_call and tool_call_update

Documentation

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.3.0.tar.gz (190.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.3.0-py3-none-any.whl (19.3 kB view details)

Uploaded Python 3

File details

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

File metadata

File hashes

Hashes for agent_client_protocol-0.3.0.tar.gz
Algorithm Hash digest
SHA256 d85a9580ff5b1dba5cc21a70d03e11c741e414d1c65f1f80b709b3329954cb55
MD5 e9096d54006573bfe99f90fe3f2b80a3
BLAKE2b-256 1b0cbdd2015359674b60166723eada707c1fc0dafa95dd635ba7ae63025a84f3

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for agent_client_protocol-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 c950d0498cdc091363afac82c2816af16f6e74b7cbfec464b3066948cb916243
MD5 dc13b835295aa6676fae356668ec4e24
BLAKE2b-256 0ae63d3491da6337ecd17dd44f80029017b6b82a7a633e08e708b684942f4808

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