golem-mark-read-only-rust

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

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, and there is no built-in way to cache their results or guarantee they are side-effect free. This Skill shows how to mark Rust agent methods as read-only so Golem caches results, bypasses the invocation queue on cache hits, and traps writes, outgoing HTTP, and RPC calls with a ReadOnlyViolation error.

Core Features & Use Cases

  • Read-Only Method Marking: Apply the #[read_only] attribute to agent trait methods to enforce a pure-read contract at runtime.
  • Configurable Cache Policies: Choose between until_write (default), ttl with humantime durations like "30s", or no_cache for uncached pure computation.
  • 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: A counter agent exposes a get_count method mapped to an HTTP GET endpoint; marking it read-only lets repeated queries return cached results instantly with proper Cache-Control and ETag headers, even while a slow write is being processed.

Quick Start

Add the #[read_only] attribute to my Rust agent's get_count method so its result is cached and served without queueing.

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

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

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

Add the #[read_only] attribute from golem_rust to the method in your agent definition trait. The method should take &self and be a pure read of already-loaded state; Golem then caches its result and traps any writes, HTTP calls, or RPC with ReadOnlyViolation.

What cache policies does the Golem read_only attribute support?

The #[read_only] attribute supports three cache policies: until_write (the default, cached until the next non-read-only invocation), ttl with a humantime duration like "30s", and no_cache which disables caching while keeping the side-effect-free contract.

Does Golem detect all impurity 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 for those cases is the developer's responsibility.

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

If a read-only method takes a Principal parameter, the SDK automatically caches results per principal and HTTP responses use Cache-Control: private with Vary: Authorization. The Principal is auto-injected by the runtime and is not part of the method's input schema.

Why does read_only fail to compile on an ephemeral agent?

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