Skip to Content

Agent loop

Processing scope: this reference describes the ordinary research/API contract. Browser-encrypted state, verified worker key delivery and hosted-model boundaries are documented in Privacy & confidential processing. Ordinary API/MCP access is not a private-project decryption interface.

Availability: This ordinary API is retired on both networks. Its testnet deployment was stopped on 26 Oct 2026, so the ordinary API/MCP examples below are historical reference and must not be used for new runs. Use private Dr. Nib on testnet  or mainnet . Historical ordinary records are retained; direct legacy API reads need a reviewed restoration.

Dr. Nib’s research agent chooses what evidence to pursue next, whether another round or a priced source is worth the remaining budget, and when to stop and write. Its activity feed shows brief research notes for completed stages alongside proposals, verdicts, reasons, and costs; it does not expose private model chain of thought or raw reasoning tokens. The model proposes, the structured decision model JEV disposes, tools execute. Termination is enforced in code with explicit bounds, never requested in prompt prose.

Task + evidence checklist → propose a tool → validate schema, scope, duplicates and limits → deterministic free-read approval or JEV judgment → execute and record the result → review coverage / continue / synthesize and stop

Reference: dr-nib/backend/src/agent/loop.js, stops.js, self.js, limits.js.

One turn, precisely

  1. Budgets first. Deadline, accumulated tool spending and token totals are checked before the next loop iteration. The next call and final synthesis can add usage; these cumulative checks are not a provider-enforced hard token/dollar limit. Payment tools separately check their quote, per-call ceiling and run balance before signing.
  2. Self-model. Every turn injects a fresh snapshot: identity, network, the tool registry and separate sandbox/spending availability flags, chain RPC + USDC address, wallet balance, run budget left plus its cap, the plan estimate, elapsed minutes, and run status, steps left. Reasoning from a stale snapshot is how agents promise spends they cannot make.
  3. Checklist focus. One LLM call per run extracts up to 5 bare measurable facts the task needs (“base fee gwei”, not “current testnet fee”). Each turn aims at the first uncovered item, so multi-part tasks get one immediate ask instead of overwhelm.
  4. Propose. The model returns one tool call, up to 3 independent free calls as a batch, submit_answer with a validated final answer, or done. Malformed JSON gets one minimal-context retry, then counts as a failed step — two in a row stops the run.
  5. Schema + duplicate gates. Unknown tools and missing inputs die free with actionable feedback. Only successful executions poison the fingerprint (canonical key order, so reordered args can’t dodge it); failures stay retryable.
  6. Judge. Free reads run on a deterministic policy row. Onchain spending tools always go to JEV with cost, history, and still-missing items in view. The verdict staples the canonical call fingerprint and is re-checked immediately before execution — a payload change after approval voids it.
  7. Execute. Metered, audited (tool.call events carry cost + result summary), throws become failed steps rather than dead runs.
  8. Learn. Successes feed coverage and novelty checks; failures shape the next proposal’s history. Every 3rd step re-plans from the trajectory so far.

Stop reasons

The loop records why it stopped; the surrounding research workflow handles that result:

StopMeaning
done-signal / finish-toolmodel finished / validated answer accepted
judge-answeredJEV ruled history sufficient
evidence-coveredevery checklist item matched in observations
no-noveltyconsecutive near-identical observations
streak-exhaustedsame tool succeeding over and over
executed-duplicateidentical successful call proposed again
skip-loopidentical proposal skipped repeatedly
failure-budget3 consecutive tool failures
proposal-lostmodel can’t produce valid JSON
llm-unreachable / judge-unreachableprovider/judge silent — stops instead of running blind
max-steps / deadline / cost-budget / token-budgethard envelopes
verdict-voidpayload changed after approval

Standalone loop defaults

EnvelopeDefaultSource
Max steps6standalone default; ordinary direct-evidence and gratitude stages pass 3
Wall clock10 minoperational ceiling
Tool spend$1accumulated tool-cost stop threshold; payment gates also apply
LLM tokens120k in+outaccumulated loop threshold, including recorded model usage
Failure budget3 consecutiveescalate, don’t spiral

These defaults come from the ordinary tool loop’s agent/limits.js and can be overridden by its caller. They are not the whole research-run duration or private-agent limits. Quick/standard/deep research separately allows 1/2/4 follow-up retrieval rounds after its initial round.

Report completion

Report-writing calls reserve additional output-token headroom for reasoning as well as prose. Replies that end at the token limit are not saved as finished prose. Short reports retry a transient empty or failed model response up to three times and keep the source excerpts bounded; if all attempts fail, the run fails visibly instead of delivering a placeholder. Long-report sections retry at most three times, then show an explicit pending section. Usage from every completed attempt remains metered, including discarded partial replies. Abstracts that cannot finish are omitted.

Memory, two levels

  • In-run: shaped history (tool + literal input + outcome), coverage state, novelty window, re-plans.
  • Across ordinary loop tasks: selected failure outcomes can produce advisory lessons, stored in the shared ordinary database with a local-file fallback and reused by task similarity. This is not an owner-private memory store and is not imported by the confidential workflow.

Failure posture

Proposer failure, judge outage and tool failure produce distinct stop/result records. A transient ordinary judge transport failure or HTTP 502/503/504 permits one retry; other judge HTTP responses do not. The loop still attempts a final bounded synthesis, then uses an evidence extract or an explicit no-evidence answer if synthesis fails. This non-empty loop answer is not a guarantee of a successful research report. Ordinary stage exceptions can mark a run failed; private unknown-outcome recovery follows its separate checkpoint and reservation rules.

Private workflow loop

The private agent uses private-research-agent.js, encrypted activity and durable operation journals. It applies the approved source/tool scope, calls actual hosted JEV, enforces bounded proposals and validates report evidence. Its loop bound is depth rounds plus three; exact public requests and payments pass the private disclosure/approval path. Private completed operations restore without repurchase. Interrupted model completions have bounded, operator-covered recovery; unknown tool and payment outcomes stay fenced. The ordinary loop’s shared episodic lessons, Railway sandbox assumptions and default constants do not carry over. See models and tools.

Last updated on