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 filesystem helpers 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: decode it with a library such as fxamacker/cbor. The raw body is the full CBOR-encoded protocol Message body (v, t, p), not just the inner payload.
Typical flow
Constants
FlagTerminal
FLAG_TERMINAL, the cross-SDK constant spelling.
FlagSessionStart
FLAG_SESSION_START.
FlagShutdown
FLAG_SHUTDOWN.
Functions
m.ConnectAgentSandbox()
Example
Example
core.ready handshake. Sandbox names are limited to 128 UTF-8 bytes. Use context.WithTimeout to override the default 10s handshake timeout.
Parameters
ctxcontext.ContextBounds the handshake; defaults to a 10s timeout if none is set.
namestringSandbox name, up to 128 UTF-8 bytes.
Returns
Connected client.
error
Typed microsandbox error.
m.ConnectAgentPath()
Example
Example
agentd relay socket by path. Use this when you already have the socket path, for example one returned by AgentSocketPath(). Use context.WithTimeout to override the default 10s handshake timeout.
Parameters
ctxcontext.ContextBounds the handshake; defaults to a 10s timeout if none is set.
pathstringFilesystem path of the relay socket.
Returns
Connected client.
error
Typed microsandbox error.
m.AgentSocketPath()
Example
Example
agentd relay socket path without connecting. Returns the same path ConnectAgentSandbox() would dial internally (preferring the hashed path, falling back to the legacy name-derived path), so you can talk to agentd over a raw byte transport (for example a transparent relay that splices bytes between a WebSocket and the socket) instead of this frame client. The sandbox need not be running; the path is derived from the name and the configured home directory.
Parameters
namestringSandbox name, up to 128 UTF-8 bytes.
Returns
string
Relay socket path.
error
Typed microsandbox error.
AgentClient methods
c.Request()
Example
Example
core.fs.request to its core.fs.response).
Parameters
ctxcontext.ContextCancels the request.
flagsuint8Frame flag byte, e.g.
FlagSessionStart.body[]byteCBOR-encoded protocol message body.
Returns
The single response frame.
error
Typed microsandbox error.
c.Stream()
Example
Example
AgentStream carries the protocol correlation id (read it with ID() and pass it to Send() for follow-up frames), and yields frames one at a time via Next().
Parameters
ctxcontext.ContextCancels opening the stream.
flagsuint8Frame flag byte for the opening frame, e.g.
FlagSessionStart.body[]byteCBOR-encoded protocol message body.
Returns
Open stream of raw frames.
error
Typed microsandbox error.
c.Send()
Example
Example
AgentStream.ID().
Parameters
ctxcontext.ContextCancels the send.
iduint32Correlation id of an open session.
flagsuint8Frame flag byte.
body[]byteCBOR-encoded protocol message body.
Returns
error
Typed microsandbox error.
c.ReadyBytes()
Example
Example
core.ready frame body as CBOR bytes. Captured during connect, so this reads from the cached handshake rather than producing protocol traffic.
Returns
[]byte
CBOR-encoded
core.ready frame body.error
Typed microsandbox error.
c.Close()
Example
Example
Returns
error
Typed microsandbox error.
c.CloseCtx()
Example
Example
Close(), but lets you bound or cancel the teardown.
Parameters
ctxcontext.ContextCancels the close.
Returns
error
Typed microsandbox error.
AgentStream methods
s.Next()
Example
Example
nil, nil at EOF, so loop until the frame is nil or carries FlagTerminal.
Parameters
ctxcontext.ContextCancels waiting for the next frame.
Returns
Next frame, or
nil at EOF.error
Typed microsandbox error.
s.ID()
Example
Example
AgentClient.Send() for follow-up frames in the session.
Returns
uint32
Correlation id for this session.
s.Close()
Example
Example
Parameters
ctxcontext.ContextCancels the close.
Returns
error
Typed microsandbox error.
Types
AgentClient
Returned by ConnectAgentSandbox() · ConnectAgentPath()
Low-level client for talking toagentd through the sandbox relay socket. All bodies are raw CBOR bytes: encode and decode them in your code with a library like fxamacker/cbor, and build typed convenience methods on top of this client. Construct it with one of the package-level connect functions.
| Method | Returns | Description |
|---|---|---|
Request(ctx, flags, body) | (*RawFrame, error) | Send one frame, await one response |
Stream(ctx, flags, body) | (*AgentStream, error) | Open a streaming session |
Send(ctx, id, flags, body) | error | Send a follow-up frame on a correlation id |
ReadyBytes() | ([]byte, error) | Cached core.ready handshake frame body |
Close() | error | Release the handle (idempotent) |
CloseCtx(ctx) | error | Release the handle with a context |
AgentStream
Returned by Stream()
An open raw agent streaming session. Drive it by callingNext() until it returns nil, which happens after a frame carrying FlagTerminal or when the underlying stream is exhausted.
| Method | Returns | Description |
|---|---|---|
Next(ctx) | (*RawFrame, error) | Pull the next frame; nil at EOF |
ID() | uint32 | Protocol correlation id; pass to Send() for follow-up frames |
Close(ctx) | error | Release the stream handle |
RawFrame
Returned by Request() · yielded by Next()
A raw protocol frame.Body is the CBOR-encoded Message body (v, t, p) as it appeared on the wire; decode it with a CBOR library such as fxamacker/cbor.
| Field | Type | Description |
|---|---|---|
| ID | uint32 | Correlation id from the frame header |
| Flags | uint8 | Frame flags (FlagTerminal, FlagSessionStart, …) |
| Body | []byte | Raw CBOR-encoded body bytes |