docs/ez-agent-ruby.md

Ruby add-on

The Ruby add-on (ez-agent-ruby/) provides a typed EzAgent client, a standalone-transport WebFetch adapter, a prepared append-only Workflow API, and the private CRuby runtime used by the launcher. Library authors should start with lib/ez_agent.md; packagers should start with cmd/ez-agent-ruby.md.

Choose a surface

GoalStart here
Call daemon services or implement tools, plugins, and macrosEzAgent::API
Read or mutate per-key Ruby state and use notificationsrequire "ez_agent/state"; see Ruby state
Declare and evaluate a prepared orchestration graphStart with the human-facing Workflow lifecycle, then use the exact EzAgent::Workflow reference
Read historical notes for removed Workflow APIsRemoval notes
Fetch HTTP(S), use WebSockets, or access authorized MCP services through ez-agent-webfetchEzAgent::WebFetch
Build or invoke the self-extracting Linux/amd64 launcherLauncher and runtime README
Produce the embedded runtime ZIPRuntime packager

Ownership boundaries

SurfaceOwnsDoes not own
EzAgent::APIAF_UNIX adaptation, typed requests/results, events, and provider dispatchraw public frame sending, daemon lifecycle, or Workflow policy
Capability providersTool/plugin/macro definitions, announcements, workers, acknowledgements, heartbeatsWorkflow graph scheduling
EzAgent::WebFetchProcess adaptation, bounded capture, framed records, structured MCP handles/resultsHTTP(S), TLS, proxy, RFC 6455, MCP/OAuth and retained daemon implementation
EzAgent::Workflow < EzAgent::WorkflowAgentIn-memory graph construction, scheduling, heuristic replay, commands, buffers, result dispositions, and a lossy projection through existing visualizer 0.1JSONL framing, database/schema state, a durable Workflow ledger, or a new visualizer payload/version
Runtime launcher/packagerRuntime installation, validation, pruning, and executiona general Ruby installation

The builtin uses the same launcher for managed Ruby workers exposed through run-cmd. Their managed execution interface is not available to standalone Ruby; see the builtin worker notes.

Workflow construction is service-free. Workflow is the root Agent and the only object with eval; explicit children, nested Agents, and fanout members share the same recursive WorkflowAgent interface. Agent declarations are lazy. The root leaf is materialized for evaluation, while another Agent receives a stable leaf only when eligible local work or descendant admission requires it. Generation zero runs on that stable leaf. Later conversation generations and retries are sibling leaves grouped beneath it, while fork ancestry follows the prior trusted head or captured source. Persistence identifiers are strict version-3 lookup keys; turns and runtime state remain service authority. There is no automatic prompt/config/dependency invalidation and no restart scheduler.

Important operational rules

EzAgent::State.new(api, leaf_id: leaf) wraps the builtins.ruby_state macro. get, set, delete, wait_any, wait_key, prepare_wait, wait, cancel_wait, and notify return response hashes. Conditional set/delete take if_key_revision:. Domain failures raise EzAgent::StateError with code, revision, and key_revision; provider failures use the API error hierarchy. The default macro transport timeout is 35 seconds, allowing for a 30-second domain wait. No operation is retried automatically. Named notifications work on fresh valid leaves. On Linux, file-backed state uses the daemon's stable-key attachment RPC, as described in the builtin guide.

ruby
1require "ez_agent/state"
2
3state = EzAgent::State.new(api, leaf_id: leaf_id)
4begin
5 current = state.get("counter")
6 state.set("counter", current.fetch("value") + 1,
7 if_key_revision: current.fetch("key_revision"))
8rescue EzAgent::StateError => error
9 # Missing state and revision conflicts carry their current revisions.
10 warn "#{error.code}: #{error.message} (#{error.key_revision})"
11end

prepare_wait("name") returns a hash containing "handle"; pass that handle to wait or cancel_wait. wait_any(revision, timeout_ms: ...) and wait_key(key, key_revision, timeout_ms: ...) wait directly for revision changes. Calls return result hashes, including "outcome" for waits. The client holds no dictionary snapshot or lock. API transport errors remain API errors, not StateError.

  • Require ez_agent/api for direct service access; require ez_agent/workflow for the prepared Workflow API plus the typed API.
  • Canonical EzAgent::API::StoredTurn values preserve raw other_meta and expose exit_message / exit_classification for service-owned Agent-run outcomes. stop_reason normally remains the separate provider/model generation result; the synthetic public-abort assistant uses interrupted with exit_message "ABORT".
  • Response matching uses opaque request_id values, not arrival order.
  • Typed result and event wrappers retain the connection-local itr value. HistorySnapshot, LeafStatistics, and LeafUpdated expose the required leaf-tip contract, including an empty string for no tip. LeafUpdated also exposes the complete model, thinking, name, state, queue, timing, and typed progress projection. The Ruby API does not use itr to reorder or reject snapshots, and Workflow does not subscribe to leaf_updated.
  • Connection#close is local client shutdown and never daemon-wide shutdown.
  • A Workflow's initial graph is complete before eval. Ordinary callbacks cannot add nodes; only on_done may synchronously and atomically append a finite tail from inline scheduler control flow.
  • A Workflow evaluates once. Whole-program replay rebuilds the graph and may reconstruct known success, structured failure, model error, or interruption by key and occurrence before preparing fresh prompts or buffers.
  • Commands always use direct argv, run sequentially whenever reached, and need explicit timeouts when an operational bound is required. Inline, external, result-derived, merged, and command-output buffers do not force a model consumer fresh; lazy prompt/buffer blocks run only for fresh issue.
  • Fresh model completion is event-driven. There is no model-duration cutoff; the 30-second stats sweep only recovers missed completion signals.
  • Replay reconstructs model records, not filesystem mutations. Shared-worktree workflows must serialize writers, assert the intended artifacts and test outcomes with command dispositions, and version affected keys or the Workflow nonce when side effects must be reproduced.
  • A borrowed API connection supports one Workflow and remains caller-owned.
  • An owned prepared Workflow produces and advertises its lossy query/command workload projection through the existing ruby.workflow//0.1 payload. A borrowed Workflow does not register a visualizer macro and emits ordinary fallback progress only.

Authorities

Subscription-backed addons

The optional read-only access_source reader on leaf snapshots and stats reports the daemon's resolved route; absent and unknown values are neutral. Existing Ruby constructors, positional/keyword calls, and callbacks are unchanged. See the typed API reference.

Ruby addons and user-owned helpers may invoke subscription models only within the authenticated user's authorized EzAgent workflow. They must not serve another person using that grant, bypass limits, or expose a general-purpose subscription API to unrelated products. These are OpenAI service-access obligations, not extra restrictions on EzAgent's BSD license. See OAuth/service authorization.