Skip to content
项目

关于

Python SDK for ACP clients and agents.

人工智能与机器学习

这些数字如何统计

实测星标增长

24小时
0
7天
+2
15天
+5
1个月
正在收集历史

各周期内的星标净变化,周期相互重叠,并非每日新增。缺失的测量保持空白。星标代表关注度,不代表软件质量。

README.md

原文
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.

ACP v2 is in Preview: "Preview is the same stage our RFDs go through before we complete them. The work is implemented and ready for broad review. For v2, that means we think the design is settled enough to build on. If you were waiting for the Draft to stop moving before you started, this is the time to start." — ACP v2 is available in Preview · See the Protocol v2 (Preview) guide.

Installation

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

For Streamable HTTP and 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.

探索相关项目

加载中…