Skip to content

API Reference parrot.integrations.agentd.client

github-actions[bot] edited this page Dec 2, 2026 · 4 revisions

parrot.integrations.agentd.client

View source

Async Unix-domain-socket JSON-RPC client for the Agent CLI Daemon.

Implements Module 6 of sdd/specs/agent-cli-daemon.spec.md: the single shared client consumed by the Rich console (proxy.py, TASK-2214), the one-shot parrot ask command, and the MCP stdio proxy (mcp_server.py, TASK-2215). A background reader task demultiplexes incoming NDJSON lines: RPC responses are matched to pending futures by id; streaming chat.* notifications are routed by stream_id to per-stream queues; event.* notifications are delivered to an optional callback.

Class AgentDaemonClient

Async JSON-RPC 2.0 / NDJSON client over a Unix domain socket.

Parameter Type Default Description
reader asyncio.StreamReader
writer asyncio.StreamWriter
max_line_bytes int DEFAULT_MAX_LINE_BYTES
on_event Callable[[str, dict[str, Any]], Any] | None None

Attributes:

Attribute Type Description
on_event Optional callback invoked with (method, params) for every event.* notification received (scheduler/daemon fan-out events — distinct from chat.* stream notifications).

Method AgentDaemonClient.connect

Connect to a daemon's UDS socket, retrying with a fixed backoff.

connect(socket_path: Path, *, retries: int = 3, backoff: float = 0.5, max_line_bytes: int = DEFAULT_MAX_LINE_BYTES, on_event: Callable[[str, dict[str, Any]], Any] | None = None) -> AgentDaemonClient

Parameter Type Default Description
socket_path Path Path to the daemon's Unix domain socket.
retries int 3 Number of connection attempts before giving up.
backoff float 0.5 Seconds to sleep between attempts (survives a systemctl restart window).
max_line_bytes int DEFAULT_MAX_LINE_BYTES NDJSON line-size limit; also sizes the StreamReader buffer, which otherwise defaults to 64 KiB and kills the reader task on any response larger than that.
on_event Callable[[str, dict[str, Any]], Any] | None None Optional event.* notification callback.

Returns: AgentDaemonClient — A connected AgentDaemonClient.

Raises:

  • DaemonNotRunning — If all retries attempts fail, with an actionable message.

Method AgentDaemonClient.call

Issue a request and await its response.

call(method: str, *, params: dict[str, Any] | None = None, **kwargs: Any) -> Any

Parameter Type Default Description
method str RPC method name.
params dict[str, Any] | None None Explicit params mapping. Merged with **kwargs (kwargs win on key collision) -- use this when a param key would otherwise collide with this method's own method/params argument names (e.g. agent.invoke's own "method" param: call("agent.invoke", params={"method": "some_method"})).
**kwargs Any {} Method parameters, for the common case where no param name collides with call()'s own signature.

Returns: Any — The response result.

Raises:

  • RpcRemoteError — If the daemon returns an error response.
  • ConnectionClosed — If the connection closes before a response arrives.

Method AgentDaemonClient.stream

Issue a streaming chat.send and yield events as they arrive.

stream(prompt: str, **metadata: Any) -> AsyncIterator[StreamEvent]

Parameter Type Default Description
prompt str The prompt to send.
**metadata Any {} Extra chat.send metadata, passed through as-is.

Returns: AsyncIterator[StreamEvent]

Method AgentDaemonClient.subscribe_events

Subscribe to daemon/scheduler events and register the callback.

subscribe_events(callback: Callable[[str, dict[str, Any]], Any]) -> None

Parameter Type Default Description
callback Callable[[str, dict[str, Any]], Any] Invoked with (method, params) for every event.* notification received from this point on.

Method AgentDaemonClient.close

Close the connection: cancel the reader, fail pending calls/streams.

close() -> None

Class ConnectionClosed

Raised against pending calls/streams when the connection is closed.

Class DaemonNotRunning

Raised when connect() exhausts its retries with no live daemon.

Class RpcRemoteError

Raised when a call() receives a JSON-RPC error response.

Parameter Type Default Description
code int
message str

Attributes:

Attribute Type Description
code The JSON-RPC (or agentd application-range) error code.
message The error message.

Class StreamEvent

One event yielded by AgentDaemonClient.stream().

Fields:

Field Type Default Description
kind Literal['delta', 'complete', 'error'] "delta", "complete", or "error".
text str | None None Incremental text (only set when kind == "delta").
response Any | None None Final response (only set when kind == "complete").
usage dict[str, Any] | None None Usage metadata (only set when kind == "complete").
error str | None None Error message (only set when kind == "error").

Function resolve_socket

Resolve a daemon identifier into a concrete socket path.

resolve_socket(name_or_path: str) -> Path

Parameter Type Default Description
name_or_path str Either an existing filesystem path to a socket, or a bare service name (resolved via default_socket_path()).

Returns: Path — The concrete socket path (existence/liveness is NOT re-checked here — AgentDaemonClient.connect() handles that).

Architecture

Clients

Bots & Agents

Memory

Knowledge

Tools & Toolkits

Flows

Experts

Skills

Stores & Loaders

MCP & A2A

Server & APIs

Integrations

Outputs & A2UI

Prompts

Security

Operations

Migration

SDD Tooling

LLM Wiki

Deployment

Decisions

API Reference

Clone this wiki locally