From 335753400ae4554b5ec007e4de170bb58a0cdb8c Mon Sep 17 00:00:00 2001 From: Chojan Shang Date: Sun, 29 Nov 2026 14:11:55 +0800 Subject: [PATCH] docs: fix v2 quickstart, web transport snippets, and example annotations --- docs/experimental-v2.md | 7 ++++++- docs/web-transport.md | 19 +++++++++++-------- examples/agent.py | 5 +++-- examples/client.py | 18 +++++++++++++++++- examples/gemini.py | 18 +++++++++++++++++- 5 files changed, 54 insertions(+), 13 deletions(-) diff --git a/docs/experimental-v2.md b/docs/experimental-v2.md index 63932b0f..7da03777 100644 --- a/docs/experimental-v2.md +++ b/docs/experimental-v2.md @@ -51,6 +51,11 @@ class MyAgent(v2.Agent): async def new_session(self, cwd: str, **kwargs: Any) -> v2.schema.NewSessionResponse: return v2.schema.NewSessionResponse(session_id="session-1") + async def prompt( + self, session_id: str, prompt: list[v2.schema.ContentBlock], **kwargs: Any + ) -> v2.schema.PromptResponse: + return v2.schema.PromptResponse(message_id="msg-1") + await v2.run_agent(MyAgent()) ``` @@ -83,6 +88,6 @@ Each connection invokes the selected factory once and runs strictly under the ne ## Extensions, cancellation, and MCP-over-ACP -- Call `ext_method("_vendor/method", ...)` and `ext_notification("_vendor/event", ...)` on connections, and implement `ext_method`, `ext_notification`, or `on_connect` on `v2.Agent` / `v2.Client` for vendor extensions and connection setup. +- Call `ext_method("vendor/method", ...)` and `ext_notification("vendor/event", ...)` on connections, and implement `ext_method`, `ext_notification`, or `on_connect` on `v2.Agent` / `v2.Client` for vendor extensions and connection setup (the SDK prepends and strips the wire `_` prefix, matching v1). - `$/cancel_request` cancels running handler tasks and outgoing requests automatically; use `cancel_session(session_id=...)` for active session work. - [Stateless MCP-over-ACP](protocol-features.md#stateless-mcp-over-acp) uses `v2.schema.McpResultResponse`, `McpErrorResponse`, and `MessageMcpResponse` when the agent advertises `capabilities.session.mcp.acp = {}`. diff --git a/docs/web-transport.md b/docs/web-transport.md index d145878f..86588d82 100644 --- a/docs/web-transport.md +++ b/docs/web-transport.md @@ -12,21 +12,14 @@ pip install "agent-client-protocol[http]" ## Client usage -Pass a Streamable HTTP or WebSocket transport into `connect_to_agent`: +Pass either a Streamable HTTP or a WebSocket transport into `connect_to_agent`: ```python from acp import PROTOCOL_VERSION, connect_to_agent from acp.http import create_http_stream -from acp.ws import create_websocket_stream -# Streamable HTTP transport = create_http_stream("http://localhost:8000/acp") conn = connect_to_agent(my_client, transport) - -# WebSocket -transport = await create_websocket_stream("ws://localhost:8000/acp") -conn = connect_to_agent(my_client, transport) - await conn.initialize(protocol_version=PROTOCOL_VERSION) session = await conn.new_session(cwd="/tmp", mcp_servers=[]) await conn.prompt(session_id=session.session_id, prompt=[...]) @@ -34,6 +27,16 @@ await conn.close() await transport.close() ``` +Or connect over WebSocket: + +```python +from acp import connect_to_agent +from acp.ws import create_websocket_stream + +transport = await create_websocket_stream("ws://localhost:8000/acp") +conn = connect_to_agent(my_client, transport) +``` + Both transports also support `load_session()` and `resume_session()` when advertised by the agent, streaming replay updates over the connection channel before switching to live session traffic. ## Server usage diff --git a/examples/agent.py b/examples/agent.py index d032c40d..a68d8286 100644 --- a/examples/agent.py +++ b/examples/agent.py @@ -15,6 +15,7 @@ ) from acp.interfaces import Client from acp.schema import ( + AcpMcpServer, AgentCapabilities, AgentMessageChunk, AudioContentBlock, @@ -66,7 +67,7 @@ async def new_session( self, cwd: str, additional_directories: list[str] | None = None, - mcp_servers: list[HttpMcpServer | SseMcpServer | McpServerStdio] | None = None, + mcp_servers: list[HttpMcpServer | SseMcpServer | AcpMcpServer | McpServerStdio] | None = None, **kwargs: Any, ) -> NewSessionResponse: logging.info("Received new session request") @@ -79,8 +80,8 @@ async def load_session( self, cwd: str, session_id: str, + mcp_servers: list[HttpMcpServer | SseMcpServer | AcpMcpServer | McpServerStdio] | None = None, additional_directories: list[str] | None = None, - mcp_servers: list[HttpMcpServer | SseMcpServer | McpServerStdio] | None = None, **kwargs: Any, ) -> LoadSessionResponse | None: logging.info("Received load session request %s", session_id) diff --git a/examples/client.py b/examples/client.py index bc961dda..f8dddfda 100644 --- a/examples/client.py +++ b/examples/client.py @@ -40,6 +40,14 @@ RequestPermissionResponse, ResourceContentBlock, SessionInfoUpdate, + SessionUpdateCompactionSummaryChunk, + SessionUpdateCompactionUpdate, + SessionUpdateCursorUpdate, + SessionUpdateNotice, + SessionUpdatePromptSuggestionsUpdate, + SessionUpdateSessionMessage, + SessionUpdateSessionMessageChunk, + SessionUpdateSubagentUpdate, TerminalOutputResponse, TextContentBlock, ToolCallProgress, @@ -118,7 +126,15 @@ async def session_update( | CurrentModeUpdate | ConfigOptionUpdate | SessionInfoUpdate - | UsageUpdate, + | UsageUpdate + | SessionUpdateNotice + | SessionUpdateCompactionUpdate + | SessionUpdateCompactionSummaryChunk + | SessionUpdatePromptSuggestionsUpdate + | SessionUpdateCursorUpdate + | SessionUpdateSubagentUpdate + | SessionUpdateSessionMessage + | SessionUpdateSessionMessageChunk, **kwargs: Any, ) -> None: if not isinstance(update, AgentMessageChunk): diff --git a/examples/gemini.py b/examples/gemini.py index c803982b..6c1e63fb 100644 --- a/examples/gemini.py +++ b/examples/gemini.py @@ -46,6 +46,14 @@ RequestPermissionResponse, ResourceContentBlock, SessionInfoUpdate, + SessionUpdateCompactionSummaryChunk, + SessionUpdateCompactionUpdate, + SessionUpdateCursorUpdate, + SessionUpdateNotice, + SessionUpdatePromptSuggestionsUpdate, + SessionUpdateSessionMessage, + SessionUpdateSessionMessageChunk, + SessionUpdateSubagentUpdate, TerminalOutputResponse, TerminalToolCallContent, TextContentBlock, @@ -134,7 +142,15 @@ async def session_update( # noqa: C901 | CurrentModeUpdate | ConfigOptionUpdate | SessionInfoUpdate - | UsageUpdate, + | UsageUpdate + | SessionUpdateNotice + | SessionUpdateCompactionUpdate + | SessionUpdateCompactionSummaryChunk + | SessionUpdatePromptSuggestionsUpdate + | SessionUpdateCursorUpdate + | SessionUpdateSubagentUpdate + | SessionUpdateSessionMessage + | SessionUpdateSessionMessageChunk, **kwargs: Any, ) -> None: if isinstance(update, AgentMessageChunk):