Agent Client Protocol (ACP) Python SDK

0.9.0 · active · verified Thu Apr 09

The `agent-client-protocol` is a Python implementation of the Agent Client Protocol (ACP) by Zed Industries, designed to facilitate communication between AI agents and clients. It provides classes for building agents, clients, and handling protocol messages with schema validation. Currently at version 0.9.0, the library releases updates driven by upstream ACP schema changes and SDK improvements, typically every few months.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to define a basic `Agent` that responds to text messages. In a production environment, this agent would be instantiated and registered with an `AgentServer` which handles the underlying communication transport (e.g., standard I/O, sockets) to an ACP client. The `send_message` method is overridden here for demonstration purposes; normally it would leverage the server's transport.

import asyncio
from acp.agents import Agent
from acp.schemas import Message, MessageContents, TextResourceContents, MessageID

class SimpleEchoAgent(Agent):
    """
    A simple agent that echoes back any text message it receives.
    In a real application, this agent would be registered with an AgentServer
    and communicate via a transport layer (e.g., stdio).
    """
    # In a full setup, send_message would use the transport for communication.
    # We override it here purely for demonstration purposes in this quickstart.
    async def send_message(self, message: Message) -> None:
        if message.contents and message.contents.text:
            print(f"Agent sending: '{message.contents.text.text}'")

    async def handle_message(self, message: Message) -> None:
        if message.contents and message.contents.text:
            response_text = f"Echo from agent: {message.contents.text.text}"
            response_message = Message(
                id=MessageID.new_id(),
                contents=MessageContents(
                    text=TextResourceContents(text=response_text)
                ),
                parent_id=message.id,
            )
            await self.send_message(response_message)
        else:
            print(f"Agent received non-text message: {message.id}")

async def run_agent_example():
    agent = SimpleEchoAgent()

    # Simulate an incoming message that a real server would pass to the agent
    incoming_message = Message(
        id=MessageID.new_id(),
        contents=MessageContents(
            text=TextResourceContents(text="Hello ACP!")
        )
    )

    print(f"Simulating client sending: '{incoming_message.contents.text.text}'\n")
    await agent.handle_message(incoming_message)

    print("\nAgent quickstart example finished.")

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

view raw JSON →