Counting visitors…
Browse all docs
Start · 9Find your path through RunifoldLearn Runifold in 45 minutesUnderstand the complete Runifold platformYour first trustworthy runChoose the right execution APIChoose crates and Cargo featuresBuild common Runifold applicationsRunifold frequently asked questionsTroubleshoot Runifold applications
Execution kernel · 7Understand RunContextCoordinate external effects safelyBound work with budgets and cancellationHandle errors and retries safelyEvents, journals, and execution evidenceDesign capability-safe executionRecover safely from checkpoints
Models & providers · 7Route across models without duplicate outputChoose and configure a providerUse the provider-neutral model protocolBuild on the Provider Runtime contractUse OpenAI control-plane and Realtime APIsTest and benchmark provider adaptersSet up OpenAI, Anthropic, Gemini, and Ollama
Agents · 7Build and configure an AgentGive an Agent typed toolsAdd conversations and semantic memoryDelegate to child Agents safelyReturn structured Rust valuesStream without losing semanticsGround an Agent with retrieval
Durable workflows · 7Compose deterministic workflowsMake workflows durableOperate durable workflow workersCoordinate timers, signals, and durable waitsRun multi-tenant workflow infrastructureRun parallel branches and safe racesVersion and evolve durable workflows
Integrations · 7Connect through MCPChoose stores and persistence boundariesExpose durable work through MCP TasksBuild and evaluate retrieval pipelinesUse MCP Resources, Prompts, and SamplingCache MCP responses without crossing authorityDeploy Runifold in a Rust web service
Quality & operations · 10Test without the networkEvaluate quality and prevent regressionsObserve the complete run treeRun safely in browsers and at the edgeRead reliability claims preciselyRun reproducible evaluations in CIOperate Runifold with SLOsGovern Task retention and deletionArchive audit evidence to S3-compatible WORM storageManage compatibility and trusted releases
Docs/Trusted execution
NEW TO RUNIFOLD?Build the complete mental model in 45 minutes
Trusted execution

Bound work with budgets and cancellation

Apply hard limits across an entire run tree and stop descendants with structured cancellation.

Practical guide·10 min

Budget dimensions

Budget can bound tokens, cost in micro-USD, wall-clock duration, model turns, tool calls, and delegations. Limits apply to the shared run tree, not just one Agent loop.

Choose limits from product behavior and failure cost. A token cap alone does not protect a tool-heavy or highly parallel run.

Create a bounded context

use runifold::{Budget, BudgetTracker, CapabilitySet, RunContext};
 
let run = RunContext::root(
    BudgetTracker::new(Budget {
        tokens: Some(20_000),
        turns: Some(10),
        tool_calls: Some(6),
        delegations: Some(2),
        ..Budget::default()
    }),
    CapabilitySet::new(),
);

Budget exhaustion is a typed terminal condition. Surface it separately from a provider outage or malformed model output.

Deadlines

Add a deadline at the ingress boundary so provider calls, tools, and child runs observe the same remaining lifetime.

use std::time::{Duration, Instant};
 
let run = run.with_deadline(Instant::now() + Duration::from_secs(20));

A deadline limits total useful time; an individual network timeout limits one operation. Production systems normally need both.

Hierarchical cancellation

Cancellation propagates from parent to descendants. Long-running tools should observe their ToolContext and stop cooperatively. Cancellation is not a rollback: already-completed external effects still exist.

Record the cancellation reason and return a stable application status rather than an arbitrary transport error.

Parallel reservations

Parallel work must reserve shared budget before it starts. This avoids every branch independently observing the same remaining allowance and collectively overspending it.

Keep a small reserve for cleanup, persistence, and the final response. Treat reservation mismatch as an accounting defect, not a retry hint.