golem-custom-snapshot-rust

Implements snapshot-based recovery and custom save/load functions for Rust agents on Golem.

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

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. Snapshotting compacts the oplog so recovery starts from the latest snapshot, and it also enables manual updates between incompatible component versions.

Core Features & Use Cases

  • Snapshotting Modes: Configure snapshotting on #[agent_definition] with "every(N)" (per N invocations) or "periodic(duration)" (time-based) policies.
  • Automatic Serde Snapshotting: Derive Serialize/Deserialize on the agent struct and the SDK generates JSON-based snapshot handlers with no custom code.
  • Custom Binary Snapshots: Implement save_snapshot and load_snapshot for compact binary formats, cross-version migration, or compatibility with non-Rust components.
  • Use Case: A counter agent invoked thousands of times per day enables snapshotting = "every(1)" so recovery replays only entries after the latest snapshot instead of the entire oplog.

Quick Start

Add snapshotting to my Rust Golem agent by enabling the snapshotting attribute and deriving serde Serialize and Deserialize on the agent struct.

Frequently Asked Questions about golem-custom-snapshot-rust

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

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

Add the snapshotting attribute to the #[agent_definition] macro, for example snapshotting = "every(1)" or snapshotting = "periodic(30s)". Without this attribute no snapshot exports are generated, and the server default policy is disabled.

How do I implement custom save_snapshot and load_snapshot in Rust?

Implement both async methods on the agent implementation: save_snapshot returns Result<Vec<u8>, String> with the serialized state, and load_snapshot takes Vec<u8> and restores state, returning Result<(), String>. Both must be implemented together or the macro fails at compile time.

Does Golem Rust support automatic snapshotting without custom code?

Yes. If the agent struct derives serde Serialize and Deserialize, the #[agent_implementation] macro auto-generates JSON-based snapshot handlers. Custom implementations of save_snapshot and load_snapshot bypass this automatic behavior.

Why is Golem agent recovery slow for long-running agents?

Recovery replays the entire oplog from the beginning, which grows with every heartbeat, poll, and state change. Enabling periodic or every(N) snapshotting lets recovery start from the latest snapshot and replay only subsequent entries.

What happens when load_snapshot returns an error during an update?

Returning Err from load_snapshot causes the update to fail and the agent reverts to the old version. This makes it safe to reject incompatible or corrupted snapshot bytes during version migration.