Choosing between durable and ephemeral agents in a Rust Golem project. Use when the user asks about agent durability modes, making an agent stateless, or configuring agent persistence.
By default, all Golem agents are durable:
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
}
}
Use ephemeral mode for stateless, per-invocation agents where persistence is not needed:
#[agent_definition(ephemeral)]
pub trait StatelessHandler {
fn new() -> Self;
fn handle(&self, input: String) -> String;
}
| 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) |
When in doubt, use the default (durable). Ephemeral mode is an optimization for agents that genuinely don't need persistence.