golem-mark-read-only-scala

Marks Scala 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-scala
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: golem-mark-read-only-scala
Source: https://github.com/golemcloud/golem/tree/main/golem-skills/skills/scala/golem-mark-read-only-scala
Command: npx skills add https://github.com/golemcloud/golem --skill golem-mark-read-only-scala

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 and blocking behind slow writes. This Skill shows how to mark Scala agent methods as read-only so Golem caches their results, bypasses the queue on cache hits, and traps forbidden side effects at runtime.

Core Features & Use Cases

  • Read-Only Annotation: Apply the @readOnly annotation to Scala agent methods to guarantee a side-effect-free contract, with writes to persistent state, outgoing HTTP, and RPC calls trapping with a ReadOnlyViolation error.
  • Configurable Cache Policies: Choose between until-write (default), ttl(<duration>), and no-cache policies via the annotation's cache argument.
  • Automatic Per-Principal Caching: Methods receiving a Principal parameter are automatically cached per principal, with HTTP responses switching to Cache-Control: private and Vary: Authorization.
  • Use Case: Expose a getCount() query on a counter agent 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

Add the @readOnly annotation to my Scala agent's getCount method so its result is cached until the next write.

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

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

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

Add the @readOnly annotation from golem.runtime.annotations to the method. Golem then caches the result, bypasses the invocation queue on cache hits, and traps writes to persistent state, outgoing HTTP, and RPC calls with a ReadOnlyViolation error.

How do I set a cache TTL on a read-only Golem agent method?

Pass a cache argument to the annotation, such as @readOnly(cache = "ttl(30 seconds)"). The duration parses as a Scala Duration, so forms like "ttl(500 millis)" or "ttl(1 minute)" also work. The default policy is "until-write".

Does Golem detect all side effects in read-only methods?

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

Can I use @readOnly on an ephemeral Golem agent?

No. Read-only on an ephemeral agent fails to compile because ephemeral agents have no shared state to read. Remove the annotation or make the agent durable instead.

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

If the method signature receives a Principal parameter, the SDK automatically caches results per principal and emits Cache-Control: private with Vary: Authorization. The Principal is injected by the runtime and is not part of the method's input schema.