Configuring Agent Durability (MoonBit)
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. If you are worried about oplog volume or replay cost (long-running agents, heartbeats, polling, recurring tasks), do not try to skip persistence. Use durable with periodic snapshots instead (see below).
A standard durable agent:
#derive.agent
struct CounterAgent {
name: String
mut count: UInt
}
fn CounterAgent::new(name: String) -> CounterAgent {
{ name, count: 0 }
}
pub fn CounterAgent::increment(self: Self) -> UInt {
self.count = self.count + 1
self.count
}
pub fn CounterAgent::get_count(self: Self) -> UInt {
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.
#derive.agent(snapshotting="every_n(10)") // snapshot every 10 successful calls
struct CounterAgent { ... }