Configuring Agent Durability (Rust)
Durable Agents (Default)
By default, all Golem agents are durable:
- State persists across invocations, failures, and restarts
- Every side effect is recorded in an oplog (operation log)
- On failure, the agent is transparently recovered by replaying the oplog
- No special code needed — durability is automatic
You cannot opt out of oplog writes for a durable agent. The oplog is how durability works — every side effect must be recorded. Do not try to skip persistence. Use durable with periodic snapshots to reduce replay cost (see below); snapshots do not reduce stored oplog volume.
A standard durable agent:
use golem_rust::{agent_definition, agent_implementation};
#[agent_definition]
pub trait CounterAgent {
fn new(name: String) -> Self;
fn increment(&mut self) -> u32;
fn get_count(&self) -> u32;
}
struct CounterAgentImpl {
name: String,
count: u32,
}
#[agent_implementation]
impl CounterAgent for CounterAgentImpl {
fn new(name: String) -> Self {
Self { name, count: 0 }
}
fn increment(&mut self) -> u32 {
self.count += 1;
self.count
}
fn get_count(&self) -> u32 {
self.count
}
}
Durable with Periodic Snapshots
Same durability guarantees as the default durable mode, but recovery starts from the latest snapshot instead of replaying the full oplog from the beginning. Use this whenever the oplog grows unboundedly — long-running agents, high-frequency state changes, heartbeats, polling loops, recurring tasks.
Snapshots reduce replay work, not stored oplog volume. Automatic snapshots run between successful
invocations, not inside an endless handler. Split recurring work into bounded invocations.
The implementation must derive serde Serialize and Deserialize for default snapshots, or
provide custom save_snapshot / load_snapshot hooks; the annotation alone is not enough.
#[agent_definition(snapshotting = "every(10)")] // snapshot every 10 successful calls
pub trait CounterAgent { ... }
#[agent_definition(snapshotting = "periodic(30s)")] // or at most once per interval
pub trait HeartbeatAgent { ... }