AgentClient is the low-level raw transport for talking to agentd through a running sandbox’s relay socket. For most applications, use Sandbox, exec, and fs instead. Reach for this API when you are building protocol-level tools or higher-level SDK helpers.
All request and response bodies are raw CBOR bytes. The SDK handles framing and correlation ids, but it does not encode or decode the CBOR message body for you. The raw body is the full CBOR-encoded protocol Message body (v, t, and p), not just the inner payload.
Typical flow
Constants
| Name | Value | Description |
|---|---|---|
FLAG_TERMINAL | 0b0000_0001 | Last frame for a correlation id |
FLAG_SESSION_START | 0b0000_0010 | First frame of a streaming session |
FLAG_SHUTDOWN | 0b0000_0100 | Shutdown frame |
Constructors
AgentClient.connect_sandbox()
Example
Example
Parameters
namestrSandbox name, up to 128 UTF-8 bytes.
timeoutfloat | NoneConnection timeout in seconds.
None uses the default.Returns
AgentClient
Connected client.
AgentClient.connect()
Example
Example
socket_path().
Parameters
pathstrPath to the agentd relay socket.
timeoutfloat | NoneConnection timeout in seconds.
None uses the default.Returns
AgentClient
Connected client.
AgentClient.socket_path()
Example
Example
agentd relay socket path without connecting. Returns the same path connect_sandbox() would dial, so you can talk to agentd over a raw byte transport (for example a transparent relay that splices bytes to and from the socket) instead of this frame client. The sandbox need not be running. Sandbox names are limited to 128 UTF-8 bytes.
Parameters
namestrSandbox name, up to 128 UTF-8 bytes.
Returns
str
Filesystem path to the relay socket.
Instance methods
client.request()
Example
Example
Parameters
flagsintFrame flag byte, e.g. a combination of
FLAG_* constants.bodybytesCBOR-encoded protocol message body.
Returns
The response frame.
client.stream()
Example
Example
AgentStream carries the protocol correlation id and is also an async iterator of raw frames.
Parameters
flagsintFrame flag byte; pass
FLAG_SESSION_START to open a session.bodybytesCBOR-encoded protocol message body.
Returns
Open streaming session.
client.send()
Example
Example
id from the AgentStream returned by stream().
Parameters
idintCorrelation id of an open session, from
stream.id.flagsintFrame flag byte.
bodybytesCBOR-encoded protocol message body.
client.ready_bytes()
Example
Example
core.ready frame body as CBOR bytes.
Returns
bytes
CBOR-encoded
core.ready frame body.client.close()
Example
Example
Types
RawFrame
Returned by request() · yielded by AgentStream
A raw protocol frame with a CBOR-encoded body.| Field | Type | Description |
|---|---|---|
| id | int | Protocol correlation id |
| flags | int | Frame flag byte (combination of FLAG_* constants) |
| body | bytes | CBOR-encoded protocol message body |
AgentStream
Returned by stream()
An open raw agent stream. Carries the protocol correlation id and is both an async context manager and an async iterator ofRawFrame. Iteration stops once a frame with FLAG_TERMINAL set is delivered or the stream reaches EOF.
| Property / Method | Type | Description |
|---|---|---|
| id | int | Protocol correlation id; pass to send() for follow-up frames |
| next() | Awaitable[RawFrame | None] | Read the next frame; returns None at EOF |
| close() | Awaitable[None] | Release the stream handle early; safe to call more than once |
async with | AgentStream | Async context manager; closes the stream on exit |
async for | RawFrame | Async iterator over frames until terminal or EOF |
Example
Example