Guides

Agents & tools

Autonomous agent loops, tool policy gates, the in-process sandbox, and the trust boundaries that apply.

Updated Nov 13, 20265 min readv0.3.0-beta
On this page7 sections

sofuu.agent defines and runs the agent loop: a named definition, a task, a tool set, a budget, and a trace. Runs can be cancelled, listed, and inspected, and every tool call passes through validation and policy before it executes.

Define an agent

JavaScript
sofuu.agent.define({
  name: "researcher",
  system: "You research accurately. Cite sources with URLs.",
  tools: ["web", "memory", "system"],
  memory: "agent",
  approve: "sensitive",
  budget: { maxSteps: 12, maxWallMs: 120_000 },
});

define(def) registers a definition and returns a handle. run also accepts a definition object directly.

FieldMeaning
nameRequired registry name.
systemThe system prompt carried by the definition.
toolsTool names, domain packs, inline tool objects, or connected MCP clients.
memory"shared", "agent", or "off". Scopes over one physical brain file.
provider, modelOptional per-agent backend selection.
budgetmaxSteps, maxDepth, maxTokens, and maxWallMs.
approve"none", "sensitive", or "all".
agentsNames of sub-agents this definition may delegate to.
rlm"auto", "on", or "off" for long-context routing.
identityOptional { role, expertise } metadata.

Definitions live in memory and can also be loaded from ~/.sofuu/agents/*.js with sofuu.agent.loadDir(). Those files are trusted scripts: they execute in global scope like any other user script.

Run, cancel, and inspect

JavaScript
const result = await sofuu.agent.run(
  "researcher",
  "Compare ARM NEON and AVX2",
);

console.log(result.answer);
console.log(result.stopped, result.usage);

run(handleOrNameOrDef, task, opts) returns a promise. Options include context, history, signal, onStep, onApproval, toolTimeoutMs, and per-run provider or model overrides.

Result fieldMeaning
answerFinal text produced by the run.
stepsStep records for the run.
subRunsNested runs started by delegation.
usageToken usage accumulated across the run.
traceThe structured event trace.
stoppedWhy the run ended, including cancellation.
runId, nameIdentity of the run and its definition.

sofuu.agent.cancel(id) marks the run cancelled and fires its abort handlers; it returns false when the id is not active. sofuu.agent.list() returns registry summaries with tool counts, MCP server counts, sub-agents, and 24-hour run counts. sofuu.agent.renderTrace(result) renders the trace as text for logs or host display. sofuu.agent.runMany() and sofuu.agent.mapContext() are available for concurrent runs and context reduction.

Tools

SourceHow it is added
Inline toolsAn object with name, description, parameters, and execute(args).
Domain toolpacksA pack name such as "coding", "web", "memory", or "system".
MCPA connected client in tools, or a server configured in ~/.sofuu/mcp.json.
PluginsTools registered by defineTool, subject to the plugin pipeline.
Host toolsNative tools registered through the C ABI.
PackToolsNotes
codingread_file, write_file, edit_file, apply_patch, grep, glob, list_dir, bash, code_eval, todo_writeFilesystem tools use the project jail. SOFUU_NO_SHELL=1 removes bash.
webweb_search, web_openKeyless search and readable page fetching.
memorymemory_search, memory_rememberRecall and persist against the local QTSQ brain.
systemsystem_infoRuntime version, platform, CPU, GPU engine, RAM, and capabilities.

Non-coding agents receive no coding tools by default. Agents opt in with a pack, individual tool names, or "all".

Policy and approvals

Validation runs before permission, policy, and execution. A bad argument returns E_SCHEMA and the tool never runs. The coding reader jail checks both the lexical path and the real path, and refuses a symlink inside the project that points outside it. bash is filtered by SOFUU_NO_SHELL, tools.deny, shell.enabled, and shell.allow; an allowlist judges every chain segment, not just the first command.

sofuu.tools.list() reports each tool's policy.allowed and requiresApproval flags, so a host can render the same inventory the model sees. Agent-level netPolicy matches the URL host only, and the infrastructure SSRF guards remain underneath it.

Approval decisions follow the definition and the active policy:

  • approve: "sensitive" prompts for tools outside the read-only auto-pass set; "all" prompts for every tool; "none" relies on policy.
  • opts.onApproval(tool, args) or the host approval channel decides. The loop emits approval_request {id, tool, args, risky, mode}.
  • Policy is authoritative over the definition. approval.mode: "always" prompts even for approve: "none" and bypasses the session cache; "never" suppresses the gate; a deny always wins. Each decision emits a policy event with a rule id.
  • A missing answer, a callback error, a cancellation, or the tool timeout all deny. An always grant applies only to the rest of that run, and bash grants are command-scoped.

Hosts that park prompts can settle them explicitly:

JavaScript
const pending = sofuu.agent.pendingApprovals(); // [{ id, tool }]
const settled = sofuu.agent.resolveApproval(pending[0].id, true, false);

resolveApproval(id, allow, always) returns {ok:true} or {ok:false, error}. The same two operations are exposed through the C funnel as agent.pendingApprovals and agent.resolveApproval.

Sandbox and enforcement limits

sofuu.sandbox.run(source, options) evaluates JavaScript or TypeScript in a separate QuickJS runtime with its own heap and intrinsics.

JavaScript
const result = await sofuu.sandbox.run(source, {
  preset: "standard",
  fuel: 20_000_000,
  timeoutMs: 10_000,
  maxMemoryMB: 64,
});
PresetWorkloadDeadlineFuelMemory
strictUntrusted model-generated code2 s5M instructions32 MB
standardDeveloper scripting10 s20M instructions64 MB
computeMath, simulations, ETL300 sunlimited512 MB
workerLong-running background worknoneunlimited256 MB

The result carries success, result, errorType, code, fuelUsed, elapsedMs, and captured logs. A deadline violation carries E_TIMEOUT.

The sandbox is a separate runtime with no host globals, no I/O, no process, no module system, no subprocess, and no route to sofuu.* unless you bridge a value into globals. It is not a defence against native extensions (there are none), a multi-tenant scheduler, or a module loader. It also cannot interrupt a bridged host function that blocks; the deadline meters sandbox execution, not the host callback.

Tool policy applies at the tool-call boundary. Code inside the sandbox does not inherit the host tool inventory or its policy decisions unless you bridge a function that performs those calls. Plugins remain in-process and are not made safe by the sandbox. No layer here is a universal isolation boundary.

Execution status

Local inference is an experimental preview. Selected embedded Kaze paths have recorded real model-and-authorized-MCP journeys on local debug builds, including one using existing local weights. That evidence does not establish every provider, released artifact or application. Verify each example's backend and execution path before claiming an end-to-end result.

Next steps