golem-mark-read-only-moonbit

Marks MoonBit agent methods as read-only to enable result caching and side-effect enforcement.

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

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Golem agent methods that only read state still go through the full invocation queue and agent loading, wasting resources on pure queries. This Skill shows how to mark MoonBit agent methods as read-only so Golem caches results, bypasses the queue on cache hits, and traps forbidden side effects like persistent writes, outgoing HTTP, and RPC calls.

Core Features & Use Cases

  • Read-Only Annotation: Apply the #derive.read_only attribute to any MoonBit agent method to declare it a pure read of loaded state.
  • Configurable Cache Policies: Choose between until_write (default), ttl with a nanosecond duration, or no_cache to control how long cached results stay valid.
  • Automatic Per-Principal Caching: Methods taking a Principal parameter are automatically cached per principal, with HTTP responses switching to Cache-Control: private and Vary: Authorization.
  • Use Case: Expose a counter agent's get_count method as an HTTP GET endpoint that returns instantly from cache with proper Cache-Control and ETag headers, even while a slow write is being processed.

Quick Start

Mark my MoonBit agent's get_count method as read-only with the default until-write cache policy using the derive attribute.

Frequently Asked Questions about golem-mark-read-only-moonbit

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

FAQPage Schema
How do I mark a MoonBit agent method as read-only in Golem?

Place the #derive.read_only attribute directly before the method, in the same position as #derive.prompt_hint. Golem then caches the result per method and normalized input, and traps persistent writes, outgoing HTTP, and RPC calls with a ReadOnlyViolation error.

What cache policies are available for read-only Golem agent methods?

Three policies exist: until_write (the default, cached until the next non-read-only invocation), ttl with a duration in nanoseconds, and no_cache which runs every time while keeping the side-effect-free contract. Pass them via #derive.read_only(cache="ttl", ttl="30000000000").

Does Golem detect all impurity in read-only agent methods?

No. Writes to persistent state, outgoing HTTP, and RPC calls trap with ReadOnlyViolation, but in-memory mutation of mut fields, clock reads, randomness, and environment variable reads are not detected. Keeping the method pure in those respects is the developer's responsibility.

How does per-principal caching work for read-only methods?

It is derived automatically from the method signature. If the method takes a Principal parameter, results are cached per principal and HTTP responses use Cache-Control: private with Vary: Authorization; otherwise results are shared and responses are Cache-Control: public.

Why does read-only fail to compile on an ephemeral agent?

Ephemeral agents have no shared persistent state to read, so the read-only attribute has no effect and compilation fails. Either remove #derive.read_only or make the agent durable.