stdio
Class info¶
Classes¶
| Name | Children | Inherits |
|---|---|---|
| StdinStream aclientp.stdio Wrapper for stdin that implements ByteReceiveStream interface. |
||
| StdoutStream aclientp.stdio Wrapper for stdout that implements ByteSendStream interface. |
🛈 DocStrings¶
StdinStream
¶
Bases: ByteReceiveStream
Wrapper for stdin that implements ByteReceiveStream interface.
Source code in src/aclientp/stdio.py
aclose
async
¶
receive
async
¶
Read bytes from stdin.
Uses read1() which returns as soon as any data is available, rather than blocking until max_bytes are read.
Source code in src/aclientp/stdio.py
StdoutStream
¶
Bases: ByteSendStream
Wrapper for stdout that implements ByteSendStream interface.
Source code in src/aclientp/stdio.py
aclose
async
¶
connect_to_agent
¶
connect_to_agent(
client: Client,
input_stream: ByteSendStream,
output_stream: ByteReceiveStream,
**connection_kwargs: Any,
) -> ClientSideConnection
Create a ClientSideConnection to an ACP agent.
This is the recommended entry point for client-side connections.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
client
|
Client
|
The client implementation. |
required |
input_stream
|
ByteSendStream
|
ByteSendStream for sending to the agent. |
required |
output_stream
|
ByteReceiveStream
|
ByteReceiveStream for receiving from the agent. |
required |
**connection_kwargs
|
Any
|
Additional keyword arguments for ClientSideConnection. |
{}
|
Returns:
| Type | Description |
|---|---|
ClientSideConnection
|
A ClientSideConnection connected to the agent. |
Source code in src/aclientp/stdio.py
run_agent
async
¶
run_agent(
agent: Agent | Callable[[AgentSideConnection], Agent],
input_stream: ByteSendStream | None = None,
output_stream: ByteReceiveStream | None = None,
**connection_kwargs: Any,
) -> None
Run an ACP agent over stdio or provided streams.
This is the recommended entry point for running agents. It handles stream setup and connection lifecycle automatically, and returns once the client disconnects (or raises when cancelled).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
agent
|
Agent | Callable[[AgentSideConnection], Agent]
|
An Agent implementation or a factory callable that takes an AgentSideConnection and returns an Agent. Using a factory allows the agent to access the connection for client communication. |
required |
input_stream
|
ByteSendStream | None
|
ByteSendStream the agent writes to (defaults to stdout). |
None
|
output_stream
|
ByteReceiveStream | None
|
ByteReceiveStream the agent reads from (defaults to stdin). |
None
|
**connection_kwargs
|
Any
|
Additional keyword arguments for AgentSideConnection. |
{}
|
Example with direct agent
Example with factory
Source code in src/aclientp/stdio.py
spawn_agent_process
async
¶
spawn_agent_process(
to_client: Callable[[Agent], Client],
command: str,
*args: str,
env: Mapping[str, str] | None = None,
cwd: str | Path | None = None,
log_stderr: bool = False,
**connection_kwargs: Any,
) -> AsyncGenerator[tuple[ClientSideConnection, Process]]
Spawn an ACP agent subprocess and return a ClientSideConnection to it.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
to_client
|
Callable[[Agent], Client]
|
Factory function that creates a Client from an Agent. |
required |
command
|
str
|
The command to execute. |
required |
*args
|
str
|
Arguments for the command. |
()
|
env
|
Mapping[str, str] | None
|
Environment variables for the subprocess. |
None
|
cwd
|
str | Path | None
|
Working directory for the subprocess. |
None
|
log_stderr
|
bool
|
If True, log stderr output from the subprocess. |
False
|
**connection_kwargs
|
Any
|
Additional arguments for ClientSideConnection. |
{}
|
Source code in src/aclientp/stdio.py
spawn_client_process
async
¶
spawn_client_process(
to_agent: Callable[[AgentSideConnection], Agent],
command: str,
*args: str,
env: Mapping[str, str] | None = None,
cwd: str | Path | None = None,
log_stderr: bool = False,
**connection_kwargs: Any,
) -> AsyncGenerator[tuple[AgentSideConnection, Process]]
Spawn an ACP client subprocess and return an AgentSideConnection to it.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
to_agent
|
Callable[[AgentSideConnection], Agent]
|
Factory function that creates an Agent from an AgentSideConnection. |
required |
command
|
str
|
The command to execute. |
required |
*args
|
str
|
Arguments for the command. |
()
|
env
|
Mapping[str, str] | None
|
Environment variables for the subprocess. |
None
|
cwd
|
str | Path | None
|
Working directory for the subprocess. |
None
|
log_stderr
|
bool
|
If True, log stderr output from the subprocess. |
False
|
**connection_kwargs
|
Any
|
Additional arguments for AgentSideConnection. |
{}
|
Source code in src/aclientp/stdio.py
spawn_stdio_connection
async
¶
spawn_stdio_connection(
handler: MethodHandler,
command: str,
*args: str,
env: Mapping[str, str] | None = None,
cwd: str | Path | None = None,
observers: list[StreamObserver] | None = None,
log_stderr: bool = False,
) -> AsyncGenerator[tuple[Connection, Process]]
Spawn a subprocess and bind its stdio to a low-level Connection.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
handler
|
MethodHandler
|
Method handler for the connection. |
required |
command
|
str
|
The command to execute. |
required |
*args
|
str
|
Arguments for the command. |
()
|
env
|
Mapping[str, str] | None
|
Environment variables for the subprocess. |
None
|
cwd
|
str | Path | None
|
Working directory for the subprocess. |
None
|
observers
|
list[StreamObserver] | None
|
Optional stream observers. |
None
|
log_stderr
|
bool
|
If True, log stderr output from the subprocess. |
False
|
Source code in src/aclientp/stdio.py
stdio_streams
async
¶
stdio_streams() -> tuple[StdinStream, StdoutStream]
Create stdio anyio-compatible streams (cross-platform).
Returns (stdin, stdout) as byte stream wrappers compatible with ByteReceiveStream and ByteSendStream interfaces.