golem-custom-snapshot-scala

Implements snapshot-based recovery and custom state serialization for Golem Scala agents.

1.5k|212|Updated Nov 24, 2023
One-click install
npx skills add https://github.com/golemcloud/golem --skill golem-custom-snapshot-scala
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: golem-custom-snapshot-scala
Source: https://github.com/golemcloud/golem/tree/main/golem-skills/skills/scala/golem-custom-snapshot-scala
Command: npx skills add https://github.com/golemcloud/golem --skill golem-custom-snapshot-scala

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Long-running Golem agents accumulate large oplogs from heartbeats, polling loops, and frequent state changes, making recovery slow because every restart replays the full history. This Skill shows how to enable snapshotting in Scala agents so recovery starts from the latest snapshot, and how to support manual snapshot-based component updates.

Core Features & Use Cases

  • Automatic JSON Snapshotting: Mix Snapshotted[S] into the agent implementation to serialize a case class state via zio-schema with no manual serialization code.
  • Custom Binary Hooks: Define saveSnapshot() and loadSnapshot() convention methods for compact binary encoding or cross-language compatibility.
  • Flexible Snapshot Policies: Configure every(N) or periodic(duration) modes in the @agentDefinition annotation to control snapshot frequency.
  • Use Case: A counter agent invoked thousands of times per day enables snapshotting = "every(10)" with Snapshotted[CounterState], so recovery replays only the entries after the latest snapshot instead of the entire oplog.

Quick Start

Add snapshot-based recovery to my Scala Golem agent by enabling snapshotting in the agent definition and mixing in Snapshotted with a case class state.

Frequently Asked Questions about golem-custom-snapshot-scala

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I enable snapshotting for a Golem Scala agent?

Set the snapshotting parameter in the @agentDefinition annotation, for example snapshotting = "every(1)" or "periodic(30s)". Without this annotation parameter, no snapshot exports are generated for the agent.

How do I implement automatic state persistence in a Scala agent?

Bundle mutable state into a case class with a derived zio-schema Schema instance, then mix Snapshotted[S] into the implementation class. The macro generates snapshot handlers that serialize the state field as JSON automatically.

What snapshotting modes does the Golem Scala SDK support?

The snapshotting parameter accepts "disabled", "enabled", "every(N)" for snapshotting every N successful calls, and "periodic(duration)" such as "periodic(30s)". Note the server default policy is disabled, so "enabled" alone may have no effect.

When should I use custom saveSnapshot and loadSnapshot hooks?

Use custom hooks when you need compact binary encoding or compatibility with non-Scala components. Define saveSnapshot returning Future[Array[Byte]] and loadSnapshot taking the bytes, and the macro wires them into the snapshot exports.

Why is agent recovery slow and how do snapshots fix it?

Without snapshotting, every recovery replays the full oplog from the beginning, which grows expensive for agents with heartbeats or frequent state changes. Periodic snapshots compact the oplog so recovery starts from the latest snapshot and replays only later entries.