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 stopReference: dr-nib/backend/src/agent/loop.js, stops.js, self.js, limits.js.
One turn, precisely
- 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.
- 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.
- 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.
- Propose. The model returns one tool call, up to 3 independent free calls as a batch,
submit_answerwith a validated final answer, ordone. Malformed JSON gets one minimal-context retry, then counts as a failed step — two in a row stops the run. - 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.
- 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.
- Execute. Metered, audited (
tool.callevents carry cost + result summary), throws become failed steps rather than dead runs. - 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:
| Stop | Meaning |
|---|---|
done-signal / finish-tool | model finished / validated answer accepted |
judge-answered | JEV ruled history sufficient |
evidence-covered | every checklist item matched in observations |
no-novelty | consecutive near-identical observations |
streak-exhausted | same tool succeeding over and over |
executed-duplicate | identical successful call proposed again |
skip-loop | identical proposal skipped repeatedly |
failure-budget | 3 consecutive tool failures |
proposal-lost | model can’t produce valid JSON |
llm-unreachable / judge-unreachable | provider/judge silent — stops instead of running blind |
max-steps / deadline / cost-budget / token-budget | hard envelopes |
verdict-void | payload changed after approval |
Standalone loop defaults
| Envelope | Default | Source |
|---|---|---|
| Max steps | 6 | standalone default; ordinary direct-evidence and gratitude stages pass 3 |
| Wall clock | 10 min | operational ceiling |
| Tool spend | $1 | accumulated tool-cost stop threshold; payment gates also apply |
| LLM tokens | 120k in+out | accumulated loop threshold, including recorded model usage |
| Failure budget | 3 consecutive | escalate, 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.