Skip to content

Agent Client Protocol (Python) - v0.0.1

Choose a tag to compare

@PsiACE PsiACE released this 06 Sep 10:26
· 36 commits to main since this release

A minimal Python SDK for the Agent Client Protocol (ACP). Build agents that talk to ACP clients (e.g. Zed) over stdio.

Install

pip install agent-client-protocol

Minimal agent

import asyncio
from acp import Agent, AgentSideConnection, Client, InitializeRequest, InitializeResponse, PromptRequest, PromptResponse, SessionNotification, stdio_streams, PROTOCOL_VERSION
from acp.schema import ContentBlock1, SessionUpdate2

class EchoAgent(Agent):
    def __init__(self, client: Client):
        self.client = client
    async def initialize(self, _p: InitializeRequest) -> InitializeResponse:
        return InitializeResponse(protocolVersion=PROTOCOL_VERSION)
    async def prompt(self, p: PromptRequest) -> PromptResponse:
        await self.client.sessionUpdate(SessionNotification(
            sessionId=p.sessionId,
            update=SessionUpdate2(sessionUpdate="agent_message_chunk", content=ContentBlock1(type="text", text="Hello from ACP")),
        ))
        return PromptResponse(stopReason="end_turn")

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

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

Use this executable from your ACP client.

More