golem-custom-snapshot-moonbit

Implements snapshot-based recovery and custom save/load functions for MoonBit 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-moonbit
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: golem-custom-snapshot-moonbit
Source: https://github.com/golemcloud/golem/tree/main/golem-skills/skills/moonbit/golem-custom-snapshot-moonbit
Command: npx skills add https://github.com/golemcloud/golem --skill golem-custom-snapshot-moonbit

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 guides you through enabling snapshot-based recovery and implementing custom snapshot save/load functions in MoonBit, so recovery starts from the latest snapshot and manual component updates between incompatible versions become possible.

Core Features & Use Cases

  • Automatic JSON Snapshotting: Derive ToJson and @json.FromJson on the agent struct and set #derive.agent(snapshotting="every_n(N)") for zero-effort JSON-based persistence.
  • Custom Binary Snapshots: Implement the Snapshottable trait with save_snapshot and load_snapshot methods for custom serialization, versioning, and cross-version migration.
  • Oplog Compaction: Periodic snapshots compact the oplog so recovery replays only entries after the latest snapshot instead of the full history.
  • Use Case: A counter agent that increments every few seconds builds a huge oplog over weeks; enabling every_n(1) snapshotting with a custom 8-byte binary format keeps recovery fast and supports safe updates between incompatible component versions.

Quick Start

Add snapshot-based recovery to my MoonBit Golem agent by deriving ToJson and FromJson and enabling every_n snapshotting on the agent struct.

Frequently Asked Questions about golem-custom-snapshot-moonbit

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

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

Add the snapshotting attribute to the derive macro, for example #derive.agent(snapshotting="every_n(1)"), and derive ToJson and @json.FromJson on the agent struct. The code generation tool then automatically provides a JSON-based Snapshottable implementation.

How do I implement custom snapshot serialization in MoonBit?

Implement the Snapshottable trait manually with save_snapshot returning Bytes and load_snapshot taking Bytes and returning Result[Unit, String]. A custom impl overrides the automatic JSON-based implementation generated by the SDK.

Why is my Golem agent recovery getting slower over time?

Recovery replays the full oplog from the beginning, so agents with heartbeats, polling loops, or frequent state changes accumulate large oplogs. Enabling periodic snapshotting with every_n(N) lets recovery start from the latest snapshot and replay only subsequent entries.

Can I disable oplog persistence to reduce storage for a durable agent?

No, you cannot opt out of oplog writes for a durable agent. Instead of skipping persistence, enable snapshot-based recovery so the oplog is compacted and replay cost stays bounded.

What happens when load_snapshot returns an error during an update?

Returning Err from load_snapshot signals that the snapshot is incompatible, causing the update to fail gracefully. The agent reverts to the old version instead of loading corrupted or unmigratable state.

When should I use custom binary snapshots instead of JSON snapshotting?

Use custom binary snapshots when you need compact serialization, a versioned snapshot format, or migration logic between component versions with changed state schemas. Automatic JSON snapshotting is preferred when the struct can simply derive ToJson and FromJson.