Skip to documentation
SLOP

tiny.acp

Reference tiny.acp

Overview · API · Code relationships · Verification · Audit

Overview

A coding agent often runs as a separate program: the caller starts it, sends it a prompt, and reads back its progress and its reply. The package is a client for such agents: it runs the agent as a child process and exchanges messages with it over the child's standard input and output, one JSON message per line. A caller starts the agent, opens a session, sends prompts, and gets back the reply text and the reason the agent stopped. The line reader the client uses is also exported on its own, for any program that reads newline-separated messages from a pipe within a fixed memory budget.

The agent's process, and every process it starts, has to stop when the caller says so. Every message the agent sends has to be recorded exactly and in order before anything acts on it. Each request the agent makes to run a tool has to be answered by the caller's rules. Memory has to stay bounded whatever the agent sends.

The agent is another program: it can write a line of any length, send any number of progress messages, and stream a reply of any size. The agent starts programs of its own to run tools, and stopping the agent alone would leave those programs running. While a prompt is in flight, the agent's final response arrives after a stream of progress messages and requests of its own, and each one has to be handled in order before the response can be read. A record written after the client acts can fall behind what the agent saw: a permission answer sent first has already reached the agent when the recording of it fails.

The Agent Client Protocol (https://agentclientprotocol.com/) defines the messages. The client sends initialize, session/new, session/prompt and session/cancel, and it handles the agent's session/update notifications and session/request_permission requests. JSON-RPC 2.0 (https://www.jsonrpc.org/specification) supplies the message format: every message carries "jsonrpc":"2.0", each request carries a numeric id that its response repeats, and the client answers a request it does not handle with error code -32601, "method not found". The client speaks version 1 of the protocol, and its tests replay one message of each of the eleven kinds of session update that version defines.

The client owns the agent's process: it starts the agent in a process group of its own with standard error discarded. To cancel or tear down, the client signals the whole group to terminate and then to die, so the tools the agent started stop with it, and teardown also waits for the agent to exit.

The client runs one request at a time: each call writes its request and then handles the agent's messages until the matching response arrives.

Input is bounded by one buffer sized from the caller's line limit (ReaderLimits) and allocated before the agent starts. A line longer than that limit stops reading for good, before any JSON is parsed. The line limit bounds the reader's buffer alone: the JSON the client parses, the updates it builds and the reply it collects come from the caller's allocator. Traffic is bounded by caller limits (TransferLimits) on each outgoing message, each incoming update, the number of updates, and the size and chunk count of one prompt's reply, and a zero limit is refused. At a reply limit the client keeps what fit, records which update it left out, asks the agent to stop with one session/cancel, and still returns the agent's final response.

The client hands every message it acts on to a set of callbacks the caller supplies (an observer, Observer) and waits for each call to return before it goes on, so the caller records each message first. Each update the client passes on carries a nonzero number the caller picks for this client (a transport epoch), and the caller records each change of that number before it starts a client. The client also numbers the updates from 1 in arrival order (an update sequence) for its whole life, and passes on the exact line the agent sent with each one. A client with no observer fails with error.MissingDurableObserver at the first update or permission request. The observer may answer each permission request, and every decision reaches the observer before the answer reaches the agent. When the callbacks give no answer, the client checks two caller lists (a permission policy, PermissionPolicy), tool kinds and tool-title prefixes, and it rejects every request that neither list allows. The client tells the agent it offers no client capabilities, and it answers any other request from the agent with "method not found".

Definitions

Types and contracts

Public types and contracts.

Namespaces

Public namespaces.

Values and defaults

Public values and defaults.

Code relationships

Direct static dependencies extracted from parsed source by semantic graph analysis.

Uses: tiny.pluck, tiny.smg, tiny.sys
Used by: None

Verification

No verification records are cataloged for this module in this build.

Audit

EvidenceValue
Sourcelib/acp/src/root.zig
Definitions32 of 32 documented
Members0 of 0 documented
Public names32 API, 127 indexed
Version26.7.0
Revisiondaab053ee433