Web World Models: deterministic worlds for AI agents, built with code + LLMs
AI agents learn faster in environments that are consistent, controllable, and rich enough to matter. A new approach called "Web World Models" pairs strict world rules in TypeScript with LLM-generated descriptions, giving you both reliability and depth.
The result: agents can explore persistent worlds that behave the same way every time, while still feeling alive.
Key points for builders
- Two-layer design: TypeScript enforces rules; an LLM fills in descriptions, dialog, and flavor.
- Determinism by default: hash functions seed content so the same input always yields the same output.
- Graceful degradation: when the LLM stalls, the system falls back to templates without breaking the rules.
- Seven demos show range: travel atlases, a sci-fi universe, a reactive sandbox, a 3D explorer, a wiki generator, long-form books, and an AI-driven card game.
How it works
The "world" is split into two layers. The first is pure code (TypeScript) that defines entities, relationships, and valid actions. Think schemas, state transitions, and guardrails that prevent impossible moves like walking through locked doors or overspending virtual currency.
The second layer is the LLM. It generates descriptions, NPC dialog, quests, and aesthetic details only after the code validates an action. This separation means creativity never overrides the rules. You don't negotiate physics with prose.
Deterministic persistence with zero storage
Instead of saving world state to a database, the system uses hash functions to regenerate content on demand. Coordinates, IDs, or other fixed inputs feed a hash that seeds the random parameters for generation. Same input, same output-every time.
A "planet" you visit today will be the same tomorrow because the seed is stable, not because it was stored. The team describes this as "object permanence with no storage cost." If the LLM is unavailable, the engine serves predefined templates so the experience stays functional.
- Concept refresher: hash functions provide consistent outputs for the same inputs.
What they built (and why it matters)
- Infinite Travel Atlas: Click anywhere on Earth and get routes, points of interest, and stories. Geography comes from code; descriptions from the LLM.
- Galaxy Travel Atlas: A procedural sci-fi universe with galaxies, systems, and planets. Code sets structure; the LLM adds missions, characters, and briefings.
- AI Spire (card game): Users propose a card ("big fire damage that also freezes"). TypeScript schemas validate costs, types, and effects before adding it to the deck.
- AI Alchemy: A sandbox where elements react. The engine enforces rules; the LLM proposes new interactions.
- Cosmic Voyager: 3D planet explorer with ongoing AI commentary.
- WWMPedia: Generator for wiki-style articles.
- Bookshelf: Generative long-form literature with structure managed by code.
Collectively, these demos show a pattern any team can adopt: rules and state transitions live in code; LLMs handle narrative and UX details. That division keeps systems predictable under load and during outages.
Why this is useful for AI agents
Agents need stable affordances to learn. Code-first worlds give you repeatable interactions and deterministic outcomes, so training signals are clean. LLMs then provide the variety and context that prevents agents from overfitting to toy problems.
This approach sits between rigid databases and free-form generation. It offers enough structure for evaluation and enough texture for exploration. That's a solid recipe for curriculum learning, tool-use practice, and long-horizon tasks.
Limits and open questions
- Multi-agent scale: How do rules and determinism hold with many concurrent agents and complex interdependencies?
- Rule evolution: Can you safely hot-swap mechanics without breaking seeds or invalidating prior "permanent" content?
- Latency budgets: Where should you cache, pre-seed, or template to keep frame times acceptable?
How to prototype your own web world model
- Model the domain in TypeScript: define entities, actions, and constraints. Treat it like a state machine with strict guards.
- Use a deterministic PRNG seeded by a hash of stable inputs (IDs, coordinates, timestamps you control). Keep seed derivation dead simple and documented.
- Generate text with an LLM only after action validation. Pass the minimal context needed and include the governing rules in-system to reduce drift.
- Validate LLM output against schemas (zod/TypeScript interfaces). Reject or repair invalid responses before they touch game state.
- Implement fallback content templates. Your world should be playable with zero LLM availability.
- Log seeds, inputs, and action traces for reproducibility. You'll thank yourself during debugging and evaluation.
Security and reliability tips
- Constrain prompts. Never let user input modify the rule layer. Keep action handlers pure and testable.
- Rate-limit generation and cache by seed. Many "unique" requests are repeats with the same inputs.
- Version your rule set. If rules change, version seeds so old and new content don't collide.
Where to go next
If you want a deeper theoretical backdrop, arXiv is a good starting point for prior work on world models and agent learning: arXiv.
Building skills for agent ecosystems? Browse practical AI engineering courses here: AI courses by skill.
Your membership also unlocks: