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
| Goal | Start here |
|---|---|
| Call daemon services or implement tools, plugins, and macros | EzAgent::API |
| Read or mutate per-key Ruby state and use notifications | require "ez_agent/state"; see Ruby state |
| Declare and evaluate a prepared orchestration graph | Start with the human-facing Workflow lifecycle, then use the exact EzAgent::Workflow reference |
| Read historical notes for removed Workflow APIs | Removal notes |
Fetch HTTP(S), use WebSockets, or access authorized MCP services through ez-agent-webfetch | EzAgent::WebFetch |
| Build or invoke the self-extracting Linux/amd64 launcher | Launcher and runtime README |
| Produce the embedded runtime ZIP | Runtime packager |
Ownership boundaries
| Surface | Owns | Does not own |
|---|---|---|
EzAgent::API | AF_UNIX adaptation, typed requests/results, events, and provider dispatch | raw public frame sending, daemon lifecycle, or Workflow policy |
| Capability providers | Tool/plugin/macro definitions, announcements, workers, acknowledgements, heartbeats | Workflow graph scheduling |
EzAgent::WebFetch | Process adaptation, bounded capture, framed records, structured MCP handles/results | HTTP(S), TLS, proxy, RFC 6455, MCP/OAuth and retained daemon implementation |
EzAgent::Workflow < EzAgent::WorkflowAgent | In-memory graph construction, scheduling, heuristic replay, commands, buffers, result dispositions, and a lossy projection through existing visualizer 0.1 | JSONL framing, database/schema state, a durable Workflow ledger, or a new visualizer payload/version |
| Runtime launcher/packager | Runtime installation, validation, pruning, and execution | a 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.
| 1 | require "ez_agent/state" |
| 2 | |
| 3 | state = EzAgent::State.new(api, leaf_id: leaf_id) |
| 4 | begin |
| 5 | current = state.get("counter") |
| 6 | state.set("counter", current.fetch("value") + 1, |
| 7 | if_key_revision: current.fetch("key_revision")) |
| 8 | rescue EzAgent::StateError => error |
| 9 | # Missing state and revision conflicts carry their current revisions. |
| 10 | warn "#{error.code}: #{error.message} (#{error.key_revision})" |
| 11 | end |
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/apifor direct service access; requireez_agent/workflowfor the prepared Workflow API plus the typed API. - Canonical
EzAgent::API::StoredTurnvalues preserve rawother_metaand exposeexit_message/exit_classificationfor service-owned Agent-run outcomes.stop_reasonnormally remains the separate provider/model generation result; the synthetic public-abort assistant usesinterruptedwithexit_message"ABORT". - Response matching uses opaque
request_idvalues, not arrival order. - Typed result and event wrappers retain the connection-local
itrvalue.HistorySnapshot,LeafStatistics, andLeafUpdatedexpose the required leaf-tip contract, including an empty string for no tip.LeafUpdatedalso exposes the complete model, thinking, name, state, queue, timing, and typed progress projection. The Ruby API does not useitrto reorder or reject snapshots, and Workflow does not subscribe toleaf_updated. Connection#closeis local client shutdown and never daemon-wide shutdown.- A Workflow's initial graph is complete before
eval. Ordinary callbacks cannot add nodes; onlyon_donemay 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.1payload. A borrowed Workflow does not register a visualizer macro and emits ordinary fallback progress only.
Authorities
- Typed API source:
ez-agent-ruby/lib/ez_agent/api.rbandez-agent-ruby/lib/ez_agent/api/; API reference. - Workflow authoring lifecycle:
agent-api/ruby-workflow-lifecycle.html; exact source/API authority remains the Workflow reference below. - Workflow source:
ez-agent-ruby/lib/ez_agent/workflow.rbandez-agent-ruby/lib/ez_agent/workflow/; Workflow reference. - Wire contracts:
agent-api/jsonl-api.html. - Workflow identifier encoding:
agent-api/ez-agent-csv.html. - Workflow visualizer payload:
agent-api/ruby-workflow-0.1.html. - Runtime packaging:
ez-agent-ruby/internal/runtimepayload/,internal/launcher/, andcmd/package-runtime/.
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.