Skip to content

API Reference parrot.integrations.agentd.protocol

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

parrot.integrations.agentd.protocol

View source

JSON-RPC 2.0 / NDJSON wire protocol for the Agent CLI Daemon (agentd).

This module implements the foundation of the daemon wire format described in sdd/specs/agent-cli-daemon.spec.md §2 ("Wire Protocol"). It provides:

  • Pydantic v2 models for JSON-RPC 2.0 requests, responses, errors, and notifications.
  • Error-code constants (both the JSON-RPC standard range and the application-specific range used by agentd).
  • Method-name constants for the full RPC surface exposed by the daemon.
  • An NDJSON framing codec (read_message / write_message) built on top of asyncio.StreamReader / asyncio.StreamWriter, with a configurable maximum line size to avoid unbounded buffering.

No I/O beyond stream helpers lives here; socket accept/dispatch logic is implemented in server.py (TASK-2211) and the client in client.py (TASK-2213).

Attribute AGENT_BUSY

Attribute DEFAULT_MAX_LINE_BYTES

Attribute INTERNAL_ERROR

Attribute INVALID_PARAMS

Attribute INVALID_REQUEST

Attribute JSONRPC_VERSION

Type: Literal['2.0']

Attribute METHOD_AGENT_INFO

Attribute METHOD_AGENT_INVOKE

Attribute METHOD_CHAT_COMPLETE

Attribute METHOD_CHAT_DELTA

Attribute METHOD_CHAT_ERROR

Attribute METHOD_CHAT_SEND

Attribute METHOD_DAEMON_SHUTDOWN

Attribute METHOD_DAEMON_STATUS

Attribute METHOD_EVENTS_SUBSCRIBE

Attribute METHOD_EVENTS_UNSUBSCRIBE

Attribute METHOD_EVENT_JOB_ERROR

Attribute METHOD_EVENT_JOB_EXECUTED

Attribute METHOD_EVENT_SHUTDOWN

Attribute METHOD_NOT_FOUND

Attribute METHOD_SCHEDULES_ADD

Attribute METHOD_SCHEDULES_LIST

Attribute METHOD_SCHEDULES_PAUSE

Attribute METHOD_SCHEDULES_REMOVE

Attribute METHOD_SCHEDULES_RESUME

Attribute METHOD_TOOLS_LIST

Class MalformedMessageError

Raised when an incoming line is not valid JSON or not a known shape.

Parameter Type Default Description
message str
rpc_id int | str | None None

Attributes:

Attribute Type Description
rpc_id The JSON-RPC id recovered from the malformed payload, if any could be salvaged (best-effort), else None.

Class OversizedLineError

Raised when an incoming NDJSON line exceeds the configured limit.

Attribute PARSE_ERROR

Class ProtocolError

Base class for all agentd wire-protocol errors.

Class RpcError

JSON-RPC 2.0 error object.

Fields:

Field Type Default Description
code int Numeric error code (JSON-RPC standard or agentd application range — see the module-level constants).
message str Short, human-readable error description.
data Any | None None Optional additional error context (never a traceback — those are logged daemon-side only, per spec §2 "Error Handling").

Class RpcNotification

JSON-RPC 2.0 notification object (no id — no reply expected).

Used for server-initiated messages: streaming chat.delta/ chat.complete/chat.error, and fan-out scheduler/daemon events (event.job_executed, event.job_error, event.shutdown).

Fields:

Field Type Default Description
jsonrpc Literal['2.0'] JSONRPC_VERSION Always "2.0".
method str Notification method name.
params dict[str, Any] Notification payload, as a mapping.

Class RpcRequest

JSON-RPC 2.0 request object.

Fields:

Field Type Default Description
jsonrpc Literal['2.0'] JSONRPC_VERSION Always "2.0".
id int | str Request identifier, echoed back in the matching RpcResponse.
method str RPC method name (see METHOD_* constants).
params dict[str, Any] Method parameters, as a mapping.

Class RpcResponse

JSON-RPC 2.0 response object.

Exactly one of result / error is expected to be set, mirroring the JSON-RPC 2.0 spec (enforced by callers, not validated here to keep the model permissive for partial/streaming construction).

Fields:

Field Type Default Description
jsonrpc Literal['2.0'] JSONRPC_VERSION Always "2.0".
id int | str | None Echoes the originating request's id.
result Any | None None The method's return value, when successful.
error RpcError | None None An RpcError, when the call failed.

Attribute SCHEDULER_UNAVAILABLE

Attribute SCHEDULE_NOT_FOUND

Attribute UNKNOWN_AGENT_METHOD

Function read_message

Read one NDJSON-framed JSON-RPC message from reader.

Handles both split frames (a single message arriving across multiple reads) and coalesced frames (multiple \n-terminated messages delivered in one underlying read) transparently — both are standard asyncio.StreamReader behaviours, since readuntil buffers until it finds the separator regardless of how many underlying reads that takes.

read_message(reader: asyncio.StreamReader, *, max_line_bytes: int = DEFAULT_MAX_LINE_BYTES) -> AnyRpcMessage | None

Parameter Type Default Description
reader asyncio.StreamReader The stream to read a single line from.
max_line_bytes int DEFAULT_MAX_LINE_BYTES Maximum allowed size (bytes) of one line, enforced BEFORE JSON parsing to avoid unbounded buffering on hostile or broken input.

Returns: AnyRpcMessage | None — The parsed message, or None on a clean EOF with no data pending.

Raises:

  • OversizedLineError — If the line exceeds max_line_bytes.
  • MalformedMessageError — If the line is not valid JSON, or not a recognizable JSON-RPC shape.

Function write_message

Serialize model and write it as one NDJSON line to writer.

write_message(writer: asyncio.StreamWriter, model: AnyRpcMessage) -> None

Parameter Type Default Description
writer asyncio.StreamWriter The stream to write the encoded line to. Callers are responsible for calling await writer.drain() afterwards to respect backpressure.
model AnyRpcMessage The RpcRequest / RpcResponse / RpcNotification to encode.

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