Harness

Runs and state

A run is one job for the agent, with its own Scute task, session and guard state. How it starts, resumes, closes and stores state.

A run is one job the agent does: one conversation, one call, one ticket. It owns a short-lived Scute task, a session, and what the guards remember (verifications, confirmations, filed approvals, counters). Every check happens inside a run.

Start a run#

const run = harness.run({  id: chat.id,  actsFor: user.scuteId,  task: { actions: ["invoice:read", "invoice:refund"], resources: ["invoice"], ttl: 900, ref: "ticket-88" },  context: { channel: "web" },});
idstring
Where the run's state lives. Reuse one id per conversation so a later request picks up where the last one stopped. Default: a random UUID.
actsFor / acts_forstring
The Scute app user the agent works for. Omit for an agent working on its own.
taskobject
Narrows the task: actions (permission slugs), resources (invoice:42 or invoice), ttl (seconds), ref (your reference). Python takes these four as top-level keyword arguments.
requesterobject
Who asked, when it is not the person the agent acts for (a helpdesk caller): email, phone, app_user_id, name. Used by requesterOnly and grounding.
parentRun
The run that started this one (orchestrator to sub-agent). The child task records the parent and cannot outlive it.
tokenstring
A task token your backend minted, for an agent process without SCUTE_SECRET. See task tokens.
sessionobject
Session details for voice and chat: channel (default chat), externalRef (external_ref, default the run id), caller.
contextobject
Sent with every engine check, for policy conditions on context.*.

harness.run() makes no network call. The task starts on the first call that needs it.

The task#

  • Started on first use. The first engine check, verification or property read mints the task with SCUTE_SECRET (POST /v1/apps/:app_id/authz/agents/:agent/tasks). The token is kept in the run's state and never passed to the model or to onDecision.
  • Renewed when it expires. A token within 5 seconds of its expiry is replaced by a new task on the next call.
  • Closed for good when Scute says the token is dead before its expiry (401 invalid_task_token: revoked, completed, or the agent suspended), when an engine check answers with reason task_closed or budget_exceeded (Scute paused the agent for going over its budget), or when a decoy is called. A closed run never mints a new task: every later Scute call from it throws task_closed (409), so permissions denies every check. Start a new run with a new id.

End a run#

TypeScriptPythonRubyEffect
await run.complete()run.complete()run.complete!Ends the session and completes the task
await run.revoke()run.revoke()run.revoke!Ends the session and revokes the task; the token stops working everywhere

Closing the task in Scute needs SCUTE_SECRET. On a run with a backend token, TypeScript looks the task up and closes it when it has the secret; without it, the run stops locally and the call throws no_credentials, so you know your backend still has to close the task. Python and Ruby end the session and stop the run locally; your backend closes the task. Suspending the agent in Scute ends all of its tasks.

State and stores#

Run state is stored under scute:run:<agent>:<who>:<id>, where <who> is actsFor, a hash of the task token for token runs, or self. Reusing an id for a different person never carries the first person's task, verification or approvals over. State is kept for the task's remaining lifetime plus one day.

Hourly budget counters are stored under scute:hour:<agent>:<person>, shared across runs.

The default store is in memory. That works for one long-lived process and for tests. With several processes or serverless functions, pass a shared store, or a run resumed on another instance starts over.

import type { Store } from "@scute/harness";const store: Store = {  get: (key) => redis.get(key),  set: async (key, value, ttlSeconds) => {    await redis.set(key, value, ttlSeconds ? { EX: ttlSeconds } : undefined);  },};createHarness({ agent: "support-bot", store });

A store is anything with get(key) and set(key, value, ttl), values are JSON strings, and ttl is in seconds. Ruby ships MemoryStore and CacheStore (any ActiveSupport::Cache store); Python ships MemoryStore; TypeScript ships memoryStore().

Updates to one hourly counter are serialized within a process. Across processes the store decides, so use one with atomic writes when a limit must hold exactly.

Concurrency#

Checks within one run go one at a time. When the model asks for three tools in one step, each check sees the budgets the previous one reserved, and a single-use approval cannot be spent twice. A call that may run takes its share of the budgets when it is allowed, before the next check looks.

Snapshot#

run.snapshot() (Ruby: run.snapshot) returns a copy of the run's state: task id, expiry, session, verification time, filed approvals, call count and spend. Python and Ruby mask tokens in it ("***") and drop the task token. The TypeScript snapshot is the full state, task token included, so keep it out of logs.