Configuring Agent Durability (TypeScript)
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:
import { BaseAgent, agent } from '@golemcloud/golem-ts-sdk';
@agent()
class CounterAgent extends BaseAgent {
private readonly name: string;
private value: number = 0;
constructor(name: string) {
super();
this.name = name;
}
async increment(): Promise<number> {
this.value += 1;
return this.value;
}
async getCount(): Promise<number> {
return this.value;
}
}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.
@agent({ snapshotting: { every: 10 } }) // snapshot every 10 successful calls
class CounterAgent extends BaseAgent { ... }
@agent({ snapshotting: { periodic: "30s" } }) // or at most once per interval
class HeartbeatAgent extends BaseAgent { ... }See golem-custom-snapshot-ts for snapshotting modes and saveSnapshot / loadSnapshot overrides.
Ephemeral Agents
Use ephemeral mode for stateless, per-invocation agents where persistence is not needed:
- State is discarded after each invocation completes
- No oplog is maintained — lower overhead
- Useful for pure functions, request handlers, or adapters
@agent({ mode: "ephemeral" })
class StatelessHandler extends BaseAgent {
async handle(input: string): Promise<string> {
return `processed: ${input}`;
}
}When to Choose Which
| Use Case | Mode |
|---|---|
| Counter, shopping cart, workflow orchestrator | Durable (default) |
| Stateless request processor, transformer | Ephemeral |
| Long-running saga or multi-step pipeline | Durable (default) |
| Pure computation, no side effects worth persisting | Ephemeral |
| Agent that calls external APIs with at-least-once semantics | Durable (default) |
| Long-running agent with heartbeats, polling, or recurring tasks | Durable + periodic snapshots |
| Any durable agent whose oplog grows so large that replay is slow | Durable + periodic snapshots |
When in doubt, use the default (durable). Ephemeral mode is an optimization for agents that genuinely don’t need persistence. Add periodic snapshots whenever recovery time matters — see golem-custom-snapshot-ts.