docs/ez-agent-ruby/lib/ez_agent.md

Ruby libraries: extend and orchestrate EzAgent

These standard-library-only libraries provide typed daemon access, a process adapter to the standalone Go webfetch executable, and prepared append-only orchestration with scheduler-owned settled tails:

ruby
1require "ez_agent/api" # typed client and capability providers
2require "ez_agent/webfetch" # HTTP(S) and WebSockets through Go
3require "ez_agent/workflow" # API plus prepared Workflow graph

require "ez_agent/buffer" loads a transport-neutral buffer helper without Workflow or API initialization. Construct EzAgent::Buffer.new(invoke: callable) and call read(buffer_name, offset: nil, length: nil) or stat(buffer_name). The callable receives two positional arguments: "buffer" and a string-keyed argument hash using the existing buffer tool's operator, buffer_name, and, when supplied, offset and length fields. Names and ranges pass through unchanged. The helper returns the callable's result unchanged, including any turns, attachments, or error result, and propagates exceptions without retry.

Buffers in managed Ruby

Inside a run-cmd Ruby execution, buffers is available without an explicit require or constructor. It invokes the buffer tool through the execution's leaf-scoped broker. Use an exact buffer name supplied by a tool result or manifest; do not reconstruct its namespace or ID. For example, with a known text file name:

ruby
1require "json"
2name = "file:notes.txt"
3turn = buffers.read(name, offset: "0", length: "100")
4stat = buffers.stat(name)
5flags = JSON.parse(turn.dig("advanced", "other_meta") || "{}")
6
7matches = []
8unless flags["is_error"] || turn["attachment_blob"]
9 # Text reads include a buffer header before the blank line.
10 body = turn.fetch("content", "").partition("\n\n").last
11 matches = body.lines.grep(/warning/i)
12end
13result({"read" => turn, "stat" => stat, "matches" => matches})

read and stat return the canonical tool-result PendingTurn as a Ruby hash, not an envelope containing a turn field. Ordinary tool errors appear in the turn's content and JSON advanced.other_meta (is_error); they are not raised by the helper. Supported images and PDFs arrive in attachment_blob, which the example retains in the original turn rather than filtering as text. Text headers and range hints are tool output, not file content. Ranges use the buffer tool's line or byte syntax; its defaults apply when omitted.

The helper does not retry transport failures. If an invocation's acceptance or cancellation is uncertain, effects may have occurred; do not automatically retry. Standalone Ruby scripts do not receive the managed buffers method. For substantial workflows, save the Ruby script and run it via run-cmd with the Bash interpreter. Workflow's physical evidence attachments and command capture are independent of buffer tool availability and of managed Ruby's capture_stdout and capture_stderr toggles.

require "ez_agent/incident" provides the internal incident-only audit writer. It is independent of these public libraries and creates no files on healthy execution. Its Go/Ruby API and schema are shared by the service and Ruby instrumentation owners.

Choose a surface

NeedStart here
Connect to the daemon; use sessions, prompts, events, or maintenanceAPI — calls
Provide tools, plugins, or macrosAPI — providers
Declare agents, queries, fanout, commands, selection, assertions, or structured outputWorkflow
Read historical notes for removed Workflow APIsRemoval notes
Fetch HTTP(S) or WebSocket resources through the standalone transportWebFetch
Inspect frame contractsJSONL API reference
Package scripts with the private runtimeWrapper and runtime packaging

Ownership

The API, WebFetch, and Workflow loaders are lib/ez_agent/api.rb, lib/ez_agent/webfetch.rb, and lib/ez_agent/workflow.rb. The independent buffer adapter is lib/ez_agent/buffer.rb. API owns the initiating AF_UNIX client, typed services, immutable values/events, request correlation, and capability-provider runtime. WebFetch owns executable discovery, direct process invocation, bounded capture, and framed local message records. It does not implement HTTP, TLS, or RFC 6455. Workflow builds an in-memory prepared graph over that typed API; eval freezes the initial shape and only scheduler-owned on_done callbacks may append finite atomic tails. It does not parse frames, own daemon or database state, persist a workflow ledger, or resume an evaluator process.

RoleKey source
Public loaderslib/ez_agent/api.rb, lib/ez_agent/webfetch.rb, lib/ez_agent/workflow.rb
Transport and request correlationlib/ez_agent/api/client.rb, event.rb
Typed operations and valueslib/ez_agent/api/sessions.rb, values.rb
Tool/plugin/macro providerslib/ez_agent/api/capabilities.rb
Prepared graph and evaluatorlib/ez_agent/workflow/

Extension rules

  • Keep daemon access typed; do not add a public raw-frame escape hatch.
  • Validate required fields while preserving unknown string-keyed extensions in immutable projections.
  • API close releases local resources and does not stop the daemon.
  • Provider registration is local and cumulative; duplicate capability names fail.
  • require "ez_agent/api" must not load Workflow.
  • Workflow construction must remain service-free. eval is the service and execution boundary.
  • Workflow replay keys are caller-owned invalidation boundaries, not persisted prompt/config/dependency signatures.

Detail authorities

  • API behavior: API reference, then lib/ez_agent/api/ and Ruby API source tests.
  • WebFetch behavior: WebFetch reference, then lib/ez_agent/webfetch.rb and ez-agent-ruby/test/webfetch_test.rb.
  • Workflow behavior: Workflow reference, then lib/ez_agent/workflow/ and ez-agent-ruby/test/workflow_test.rb.
  • Frame names and payloads: JSONL API reference.