Agentic AI Systems
An agentic I Ching divination system – it casts the yarrow stalks, dispatches a search agent to gather the current state of the world, and synthesizes both into a reading. The pattern is ancient. The context is contemporary.
The Oracle
Context
The Premise
COSMOS is an agentic AI system that uses I Ching divination as its decision architecture. It generates present and future state hexagrams using the traditional yarrow stalk method, then dispatches a search agent to gather current news, economic, and weather data before synthesizing both into a reading.
The project explores what happens when you use structured randomness as the entry point for an agentic system – replacing the user prompt with a cast, and grounding the output in live world conditions rather than a static knowledge base.
What It Is
A serverless agentic system with three stages: stochastic yarrow stalk casting in pure JavaScript; an agentic web search loop that gathers current geopolitical, economic, environmental, and scientific conditions from trusted primary sources; and an Anthropic API call that synthesizes hexagram tradition and world context into a reading.
Two interfaces share the same backend – a public oracle with rate limiting, and a password-protected terminal with deeper context and more search calls.
Process
The project demonstrates an ability to decompose a complex problem into its component parts, make defensible design decisions at each layer, and compose those parts into a system that a development team could extend or hand off.
That means knowing which questions to ask before writing a line of code – about data quality, source reliability, authentication architecture, token budgets, and what the system should and shouldn't do.
Design Decisions
COSMOS needed current context, not static knowledge. An agentic architecture – one that searches and retrieves before it synthesizes – was the only way to ground the reading in the present moment rather than the model's training data.
A frontier model paired with a constrained token budget. The reading needed the reasoning depth that only a large model can provide, but unconstrained API calls would make the system economically unviable at any real scale. Token budgets were a design decision meant to facilitate scaling – keeping the system economically viable as usage grows without sacrificing the reasoning depth the reading requires.
Most AI systems are optimized for predictable, repeatable outputs. COSMOS is intentionally different – the cast introduces genuine randomness that the system has to interpret rather than resolve.
Architecture
yarrow.js
Casting Engine
Pure JavaScript implementation of the yarrow stalk method. Produces the canonical probability distribution – old yin 1/16, young yang 5/16, young yin 7/16, old yang 3/16 – via a 16-bucket weighted random function. Computes present and future hexagrams via the King Wén lookup table. Runs entirely client-side; no server round-trip required to cast.
iching_complete.json
I Ching Corpus
All 64 hexagrams with Wilhelm and Baynes translations – judgment, image, and all six line texts. Structured for prompt assembly: each hexagram object includes number, Chinese and English name, trigram designations, and full line data with position labels and text. The corpus is the authoritative textual input to every reading.
reading.js
Netlify Function
The agentic backend. Receives casting data from the client, runs a web search agent scoped to trusted sources – Reuters, AP, BBC, NPR, NOAA, NASA, IMF – assembles a structured prompt from hexagram text and world context, and calls the Anthropic API to generate the reading. The password-protected interface issues a signed JWT that the reading function verifies independently on each request.