cardex
No cover

Scripter

byskuld
archived

Tokens: 59 permanent · 105 first greeting · estimated prompt budget 164

Creator notes

AI + Deterministic Systems: A Hybrid Architecture Pattern

(aka API calls with AI frontend xd)

The Problem

Large Language Models are excellent at generating narrative but terrible at maintaining consistent state:

  • They hallucinate items that don't exist
  • They forget what happened 20 messages ago
  • They can't do math reliably
  • They contradict themselves constantly

Traditional solution: Constrain the AI heavily with rigid prompts. Better solution: Let AI do what it's good at (narration) while deterministic scripts handle what it's bad at (state management).

The Pattern

User Input → AI Interpretation → Script Execution → State Update → AI Narrates Result

AI's job: Understand intent, generate narrative, create immersion Script's job: Track state, enforce rules, maintain consistency

Minimal Implementation: Inventory System

What it does:

  • User says "I pick up the sword"
  • AI calls add_item function with item details
  • Script adds item to database
  • AI narrates the pickup using script confirmation

Why this matters:

When user later says "check inventory," the AI cannot hallucinate items. It must query the database. The state is authoritative.

Architecture Flow:

| Step | Actor | Action | |------|-------|--------| | 1 | User | "I pick up the gem" | | 2 | AI | Interprets intent: user wants gem in inventory | | 3 | AI | Calls add_item(name="gem", description="...") | | 4 | Script | Validates request and updates database | | 5 | Database | Item persisted with unique ID | | 6 | AI | Narrates: "You pocket the shimmering gem" |

Key Principle

The AI never directly manipulates state. It only:

  1. Interprets user intent
  2. Calls appropriate functions
  3. Narrates based on function results

This separation ensures that creative narration (AI's strength) never interferes with accurate state tracking (scripts' job). The AI can hallucinate vivid descriptions all it wants - but it can't hallucinate what's in your inventory.

Why This Works

  • Separation of concerns: Creative tasks ≠ Logical tasks
  • Deterministic core: Game state is reliable
  • Narrative flexibility: AI can improvise descriptions, dialogue, scenarios
  • Scalability: Add new systems (combat, quests, factions) with same pattern

Applications

This pattern works anywhere you need:

  • Reliable state + flexible narration
  • Procedural generation with constraints
  • AI NPCs that remember consistent facts
  • Dynamic storytelling with mechanical consequences

See also: https://app.wyvern.chat/collections/collection_fD3JCppr1Nt8PCKg6T6WN

Aztec-inspired techno-theocracy where priest-engineers access vast digital networks through crystalline temple-servers in neon-lit pyramid-cities, blending ritual and technology into living infrastructure.

Permanent link to this version