router
Class info¶
Classes¶
| Name | Children | Inherits |
|---|---|---|
| RoutedAgentConnection aclientp.router A client connection served by the v1 or the v2 agent, chosen on ``initialize``. |
🛈 DocStrings¶
Route an agent's client connection to its ACP v1 or v2 implementation.
The router owns the connection until a valid initialize request arrives. Before
that, notifications are ignored, other requests get -32600, and a JSON-RPC batch
gets a single -32600. initialize selects the highest configured version at or
below the requested one (v1-only endpoints keep the legacy fallback to v1); the
selected implementation then handles initialize and every later message. A
connection is never re-routed.
Mirrors AgentProtocolRouter of the pinned TypeScript SDK
(schema/references.toml).
RoutedAgentConnection
¶
A client connection served by the v1 or the v2 agent, chosen on initialize.
Source code in src/aclientp/router.py
protocol_version
instance-attribute
¶
The selected protocol version; None until initialize arrived.
__init__
¶
__init__(
input_stream: ByteSendStream,
output_stream: ByteReceiveStream,
*,
v1: Callable[[AgentSideConnection], Agent] | Agent | None = None,
v2: Callable[[AgentSideConnection], Agent] | Agent | None = None,
observers: list[StreamObserver] | None = None,
debug_file: str | None = None,
) -> None
Start routing a connection.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
input_stream
|
ByteSendStream
|
Stream to the client. |
required |
output_stream
|
ByteReceiveStream
|
Stream from the client. |
required |
v1
|
Callable[[AgentSideConnection], Agent] | Agent | None
|
The v1 agent, or a factory receiving its connection. |
None
|
v2
|
Callable[[AgentSideConnection], Agent] | Agent | None
|
The v2 agent, or a factory receiving its connection. |
None
|
observers
|
list[StreamObserver] | None
|
Observers of the raw messages. |
None
|
debug_file
|
str | None
|
File to log every message to, as |
None
|