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/Build agents
NEW TO RUNIFOLD?Build the complete mental model in 45 minutes
Build agents

Stream without losing semantics

Consume visible text while preserving reasoning, usage, warnings, and provider events.

Practical guide·8 min

Why streaming is different

A stream is the Agent execution loop in motion, not a sequence of text fragments. It can contain model deltas, tool boundaries, retrieval completion, usage updates, warnings, and one terminal outcome.

Use streaming when latency or live progress matters. Use prompt when only the complete result matters.

Consume a stream

Poll the stream until it ends. Each item can fail, so handle the Result instead of assuming every event is present.

use futures_util::StreamExt;
use runifold::AgentStreamEvent;
 
let mut events = agent.stream("Explain the incident", &run);
while let Some(event) = events.next().await {
    match event? {
        AgentStreamEvent::Model { event, .. } => render_model_event(event),
        AgentStreamEvent::UsageUpdated { usage } => update_usage(usage),
        AgentStreamEvent::Completed { outcome } => save(outcome),
        _ => {}
    }
}

Render provider-neutral ModelStreamEvent values rather than decoding a provider's wire protocol in application code.

Terminal state

Do not reconstruct the final answer by concatenating visible deltas. The Completed event contains the canonical AgentOutcome: final response, transcript, counters, warnings, and usage.

A healthy consumer handles unknown future variants with a wildcard match and persists the terminal outcome exactly once.

Cancellation and disconnects

A disconnected browser does not automatically mean the server-side run should continue. Decide explicitly whether to cancel the RunContext, detach and persist progress, or hand work to a durable workflow.

For HTTP delivery, SSE is convenient for browser text; NDJSON is often simpler for typed server-to-server events. Keep transport framing separate from Runifold event semantics.