Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion docs/experimental-v2.md
Original file line number Diff line number Diff line change
Expand Up @@ -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())
```
Expand Down Expand Up @@ -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 = {}`.
19 changes: 11 additions & 8 deletions docs/web-transport.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,28 +12,31 @@ 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=[...])
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
Expand Down
5 changes: 3 additions & 2 deletions examples/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
)
from acp.interfaces import Client
from acp.schema import (
AcpMcpServer,
AgentCapabilities,
AgentMessageChunk,
AudioContentBlock,
Expand Down Expand Up @@ -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")
Expand All @@ -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)
Expand Down
18 changes: 17 additions & 1 deletion examples/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,14 @@
RequestPermissionResponse,
ResourceContentBlock,
SessionInfoUpdate,
SessionUpdateCompactionSummaryChunk,
SessionUpdateCompactionUpdate,
SessionUpdateCursorUpdate,
SessionUpdateNotice,
SessionUpdatePromptSuggestionsUpdate,
SessionUpdateSessionMessage,
SessionUpdateSessionMessageChunk,
SessionUpdateSubagentUpdate,
TerminalOutputResponse,
TextContentBlock,
ToolCallProgress,
Expand Down Expand Up @@ -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):
Expand Down
18 changes: 17 additions & 1 deletion examples/gemini.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,14 @@
RequestPermissionResponse,
ResourceContentBlock,
SessionInfoUpdate,
SessionUpdateCompactionSummaryChunk,
SessionUpdateCompactionUpdate,
SessionUpdateCursorUpdate,
SessionUpdateNotice,
SessionUpdatePromptSuggestionsUpdate,
SessionUpdateSessionMessage,
SessionUpdateSessionMessageChunk,
SessionUpdateSubagentUpdate,
TerminalOutputResponse,
TerminalToolCallContent,
TextContentBlock,
Expand Down Expand Up @@ -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):
Expand Down
Loading