· 3 min read · repo

Cantrip

An ornate portal labeled CANTRIP and MAGICAL-GEOMETRIC FORMAL CHAMBER, with GATE repeated around the frame and a bearded figure standing inside

Putting language in a loop can make it come alive. We call it chanting, and it is one of the oldest tools of magic. You say words, the words change the room, the room changes you, you say different words. The static intelligence of language comes alive through repetition and feedback.

That is also what an agent is. A language model predicts the next token; put it in a loop with an environment, and something emerges that wasn’t in the instructions.

Cantrip names the parts. The full spec borrows vocabulary from the tradition that D&D borrowed from:

  • Circle — the bounded environment the entity acts within
  • Medium — the substrate the entity thinks in (a REPL, a chat, a shell)
  • Gates — boundary crossings where the circle opens outward (API calls, file writes, child entities)
  • Wards — hard constraints (turn limits, resource caps, scope restrictions)
  • Loom — every turn recorded as a tree of threads, forkable and replayable
  • Entity — what arises from the loop. You don’t build it. You design the circle, and it emerges.

I published it as a ghost library: provide the spec and the behavioral tests, let the user generate their own implementation in whatever language they want. Point your coding agent at it and say “implement this in Elixir” and it will. The repo ships four reference implementations — TypeScript, Python, Clojure, Elixir — but the point is the spec, not the code. Copy the spellbook, cast your own.

The code came first. I built the TypeScript prototype in February 2026 from Alex Zhang’s Recursive Language Model paper — hook a language model to a REPL, put context in as a variable, let it spawn sub-agents that pass variables around without reading what’s inside. It processed over six million tokens without context rot.

RLM architecture diagram showing a root layer with LLM and environment branching into depth-1 sub-layers

A cantrip that writes other cantrips is the Familiar — the coordinator entity that delegates and summons and dismisses. You can summon one from example 16 in the TypeScript implementation. Be careful what you wish for. It is minimally warded.

thejaymo wrote a 13,000-word essay series placing Cantrip in the history of text-adventure world design. An annotated bibliography of 40 sources maps the intellectual lineage.

Read the announcement | Read the spec | Read the bibliography