agent
Class info¶
Classes¶
| Name | Children | Inherits |
|---|---|---|
| Agent aclientp.v2.agent Base class of a v2 agent. Override the methods the agent supports. |
||
| AgentSideConnection aclientp.v2.agent **UNSTABLE**: Connection of a v2 agent to a client. |
🛈 DocStrings¶
UNSTABLE: Agent side of the draft ACP v2 protocol.
Subclass :class:Agent and override the methods the agent supports; every other
request is answered with -32601 (Method not found), and other notifications are
ignored. :class:AgentSideConnection runs the JSON-RPC connection, enforces the v2
initialization rules and offers typed calls to the client.
Mirrors the agent bindings of the pinned TypeScript SDK (schema/references.toml).
PROTOCOL_VERSION
module-attribute
¶
The protocol version this module implements.
Agent
¶
Base class of a v2 agent. Override the methods the agent supports.
Source code in src/aclientp/v2/agent.py
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 | |
archive_session
async
¶
archive_session(params: ArchiveSessionRequest) -> ArchiveSessionResponse
auth_status
async
¶
auth_status(params: AuthStatusRequest) -> AuthStatusResponse
cancel
async
¶
cancel(params: CancelSessionNotification) -> None
cancel_terminal
async
¶
cancel_terminal(params: CancelTerminalRequest) -> CancelTerminalResponse
cancel_tool_call
async
¶
cancel_tool_call(params: CancelToolCallRequest) -> CancelToolCallResponse
close_session
async
¶
close_session(params: CloseSessionRequest) -> CloseSessionResponse
delete_session
async
¶
delete_session(params: DeleteSessionRequest) -> DeleteSessionResponse
disable_provider
async
¶
disable_provider(params: DisableProviderRequest) -> DisableProviderResponse
ext_method
async
¶
Handle a custom (_-prefixed) request; params is None if omitted.
fork_session
async
¶
fork_session(params: ForkSessionRequest) -> ForkSessionResponse
initialize
async
¶
initialize(params: InitializeRequest) -> InitializeResponse
Handle initialize; protocol_version of params is always 2.
list_providers
async
¶
list_providers(params: ListProvidersRequest) -> ListProvidersResponse
list_sessions
async
¶
list_sessions(params: ListSessionsRequest) -> ListSessionsResponse
login
async
¶
login(params: LoginAuthRequest) -> LoginAuthResponse
logout
async
¶
logout(params: LogoutAuthRequest) -> LogoutAuthResponse
mcp_message
async
¶
mcp_message(params: MessageMcpRequest) -> MessageMcpResponse
mcp_notification
async
¶
mcp_notification(params: MessageMcpNotification) -> None
new_session
async
¶
new_session(params: NewSessionRequest) -> NewSessionResponse
prompt
async
¶
prompt(params: PromptRequest) -> PromptResponse
Handle session/prompt: insert the message and return its ID right away.
Report the turn with state_update notifications; do not wait for it here.
Source code in src/aclientp/v2/agent.py
resume_session
async
¶
resume_session(params: ResumeSessionRequest) -> ResumeSessionResponse
Handle session/resume (send replay_complete after a requested replay).
session_options
async
¶
session_options(params: SessionOptionsRequest) -> SessionOptionsResponse
session_status
async
¶
session_status(params: SessionStatusRequest) -> SessionStatusResponse
set_provider
async
¶
set_provider(params: SetProviderRequest) -> SetProviderResponse
set_session_config_option
async
¶
set_session_config_option(params: SetSessionConfigOptionRequest) -> SetSessionConfigOptionResponse
Handle session/set_config_option.
set_session_title
async
¶
set_session_title(params: SetSessionTitleRequest) -> SetSessionTitleResponse
unarchive_session
async
¶
unarchive_session(params: UnarchiveSessionRequest) -> UnarchiveSessionResponse
AgentSideConnection
¶
UNSTABLE: Connection of a v2 agent to a client.
Enforces the v2 rules: requests before initialize get -32600 and
notifications are ignored, initialize may only be repeated before other
requests, request IDs must be strings or integers, and batches get -32600.
Source code in src/aclientp/v2/agent.py
274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 | |
PROTOCOL_VERSION
class-attribute
instance-attribute
¶
PROTOCOL_VERSION = PROTOCOL_VERSION
The protocol version this connection speaks.
__init__
¶
__init__(
to_agent: Callable[[AgentSideConnection], Agent] | Agent,
input_stream: ByteSendStream,
output_stream: ByteReceiveStream,
observers: list[StreamObserver] | None = None,
) -> None
Start the connection.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
to_agent
|
Callable[[AgentSideConnection], Agent] | Agent
|
The agent, or a factory receiving this connection. |
required |
input_stream
|
ByteSendStream
|
Stream to the client. |
required |
output_stream
|
ByteReceiveStream
|
Stream from the client. |
required |
observers
|
list[StreamObserver] | None
|
Observers of the raw messages. |
None
|
Source code in src/aclientp/v2/agent.py
auth_status_update
async
¶
auth_status_update(params: AuthStatusUpdateNotification) -> None
Report a change of the authentication status (auth/status_update).
close
async
¶
complete_elicitation
async
¶
complete_elicitation(params: CompleteElicitationNotification) -> None
Report that a URL elicitation is complete (elicitation/complete).
create_elicitation
async
¶
create_elicitation(params: CreateElicitationRequest) -> CreateElicitationResponse
Ask the user for structured input (elicitation/create).
Source code in src/aclientp/v2/agent.py
ext_method
async
¶
handle
async
¶
Handle one incoming message (the connection's handler).
Source code in src/aclientp/v2/agent.py
mcp_message
async
¶
mcp_message(params: MessageMcpRequest) -> MessageMcpResponse
Send an mcp/message request to the client.
mcp_notification
async
¶
mcp_notification(params: MessageMcpNotification) -> None
on_connection
classmethod
¶
on_connection(
connection: Connection, to_agent: Callable[[AgentSideConnection], Agent] | Agent
) -> AgentSideConnection
Serve v2 on an existing connection whose handler delegates to :meth:handle.
Used by the version router, which owns the connection until initialize.
Source code in src/aclientp/v2/agent.py
request_permission
async
¶
request_permission(params: RequestPermissionRequest) -> RequestPermissionResponse
Ask the user for permission (session/request_permission).
Source code in src/aclientp/v2/agent.py
session_update
async
¶
session_update(params: UpdateSessionNotification) -> None
parse_initialize
¶
parse_initialize(params: Any) -> InitializeRequest
Parse initialize params as v2.
A version below 2 is rejected with -32022. A request for a newer version was
written for a schema this endpoint does not know, so it is read leniently (a
malformed info becomes unknown) and answered as v2.