Golem configure durability scala

From golemcloud/golem · View interactive version

Golem configure durability scala is an AI agent skill from the GitHub repository golemcloud/golem. Choosing between durable and ephemeral agents in a Scala Golem project. Use when the user asks about agent durability modes, making an agent stateless, or configuring agent persistence.

How to use this skill

Skill file

Configuring Agent Durability (Scala)

Durable Agents (Default)

By default, all Golem agents are durable:

You cannot opt out of oplog writes for a durable agent. Do not skip persistence to reduce replay cost. Use durable with periodic snapshots instead (see below); snapshots do not reduce stored oplog volume.

A standard durable agent:

import golem.runtime.annotations.{agentDefinition, agentImplementation}
import golem.BaseAgent

import scala.concurrent.Future

@agentDefinition(mount = "/counters/{name}")
trait CounterAgent extends BaseAgent {
  class Id(val name: String)
  def increment(): Future[Int]
  def getCount(): Future[Int]
}

@agentImplementation()
final class CounterAgentImpl(private val name: String) extends CounterAgent {
  private var count: Int = 0

  override def increment(): Future[Int] = Future.successful {
    count += 1
    count
  }

  override def getCount(): Future[Int] = Future.successful(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. Snapshots reduce replay work, not stored oplog volume. Periodic snapshots run at invocation boundaries; they do not interrupt an endless handler. Split heartbeats and polling into bounded, self-scheduled invocations.

@agentDefinition(snapshotting = "every(10)")     // snapshot every 10 successful calls
trait CounterAgent extends BaseAgent { ... }

@agentDefinition(snapshotting = "periodic(30s)") // or at most once per interval
trait HeartbeatAgent extends BaseAgent { ... }

See CODE0 for snapshotting modes and Snapshotted[S] / custom binary save/load hooks.

Ephemeral Agents

Use ephemeral mode for stateless, per-invocation agents where persistence is not needed:

import golem.runtime.annotations.{agentDefinition, DurabilityMode}

@agentDefinition(mode = DurabilityMode.Ephemeral)
trait StatelessHandler extends BaseAgent {
  class Id()
  def handle(input: String): Future[String]
}

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 CODE0.

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.