golem-mark-read-only-ts

Marks TypeScript agent methods as read-only for side-effect-free queries and result caching.

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

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill requires @golemcloud/golem-ts-sdk, zod.

What problem does it solve?

Golem agent methods that only read state still go through the full invocation pipeline and cannot be cached. This Skill shows how to mark TypeScript agent methods as read-only so the host can treat them as pure queries, enforce a no-side-effect contract at runtime, and cache their results.

Core Features & Use Cases

  • Read-Only Method Declaration: Set readOnly: true on a method(...) spec in defineAgent to declare a pure read over already-loaded agent state.
  • Runtime Enforcement: Writes to persistent state, outgoing HTTP (fetch), and RPC calls trap with a ReadOnlyViolation error before they execute.
  • Configurable Cache Policies: Choose no-cache, until-write, or a { ttlNanos } time-to-live, and optionally key the cache per caller principal with usesPrincipal.
  • Use Case: Expose a getCount query on a counter agent as an HTTP GET endpoint that participates in HTTP caching semantics without loading the agent or queuing an invocation.

Quick Start

Ask the AI to mark the getCount method of your Golem TypeScript counter agent as read-only with the until-write cache policy.

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

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

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

Set readOnly: true on the method(...) spec inside defineAgent from @golemcloud/golem-ts-sdk. For finer control, pass an object like readOnly: { cache: 'until-write' } instead of the boolean.

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

Three policies exist: no-cache never caches, until-write caches until a mutating method runs, and { ttlNanos } caches for a fixed time-to-live. Adding usesPrincipal: true keys the cache per caller principal.

What operations are blocked inside a read-only Golem agent method?

Writes to persistent state, outgoing HTTP via fetch, and RPC calls to other agents trap with a ReadOnlyViolation error before running. In-memory mutation, clock reads, randomness, and environment variable reads are not detected and must be avoided manually.

Why does my read-only method not trap when mutating this state?

Assigning to a state field is a plain in-memory write, not a host call, so the durability layer never sees it and no ReadOnlyViolation is raised. Keeping the method mutation-free is the developer's responsibility.

Can a read-only Golem agent method call another agent over RPC?

No, RPC calls trap with ReadOnlyViolation inside read-only methods. Perform read-only RPC fan-out from a regular non-read-only method instead, as described in the golem-call-another-agent-ts guidance.