Skip to content

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

Level0 — Agentic Game Engine

AI-powered game creation platform with autonomous multi-agent orchestration, persistent memory, and self-healing code generation.

Describe a game. Watch four AI agents plan, code, QA-test, and respond in real time — then play it instantly in your browser.


🧠 Architecture Overview

Level0 is built on a multi-agent orchestration pipeline that mirrors production-grade autonomous systems. Every game generation request flows through a deterministic agent DAG with feedback loops, memory persistence, and file integrity guarantees.

User Prompt
    │
    ▼
┌──────────┐    ┌──────────┐    ┌──────────┐    ┌───────────┐
│ PLANNER  │───▶│  CODER   │───▶│  TESTER  │───▶│ RESPONDER │
│ Agent    │    │  Agent   │    │  Agent   │    │  Agent    │
│ (T=0.7)  │    │ (T=0.7)  │    │ (T=0.2)  │    │ (T=0.8)  │
└──────────┘    └─────┬────┘    └────┬─────┘    └───────────┘
                      │              │
                      │   ◀──FIX──   │  ← Up to 3 iterations
                      └──────────────┘

Agent Roles

Agent Temperature Purpose
Planner 0.7 Decomposes user intent into a numbered step-by-step implementation plan. Considers existing game state, memory context, and Phaser 3 API surface.
Coder 0.7 Generates complete, structured game files via Gemini function calling (generate_game_files tool). Enforces file integrity — never drops or truncates files across iterations.
Tester 0.2 Deep QA review with static analysis: brace/parenthesis matching, CDN validation, scene registration verification, Phaser config audit. Returns APPROVED or FIX: with actionable instructions.
Responder 0.8 Generates contextual, human-friendly responses describing what was built, key features implemented, and suggestions for next steps. No more hardcoded messages.

🔁 Self-Healing Feedback Loop

The Coder ↔ Tester loop runs up to 3 iterations per request:

  1. Static Validation — Structural checks before the Tester agent even runs:

    • Missing required files (index.html, styles.css, *.js)
    • Empty or suspiciously short files (<10 chars)
    • Mismatched braces {} and parentheses ()
    • Missing Phaser CDN reference
    • Unlinked script tags
    • Missing game-container div
    • Phaser.Game instantiation check
  2. AI-Powered Code Review — The Tester agent receives truncated file contents (first/last 25 lines for large files) and reviews for:

    • Runtime-breaking JavaScript errors
    • Undefined variable references
    • Incorrect Phaser API usage
    • Scene lifecycle method completeness
    • Physics configuration correctness
  3. Fix Propagation — If the Tester returns FIX:, instructions are injected into the Coder's next prompt along with full existing file contents, ensuring targeted surgical fixes rather than full regeneration.

  4. File Integrity Guard — ensureFileIntegrity() merges new output with previous file versions, automatically restoring any files that were dropped or emptied during generation.


💾 Dual-Layer Memory System

Level0 implements a dual-layer memory architecture for persistent agent context:

Layer 1: Structured Agent Memory (Database)

  • Stored as JSONB in the games.agent_memory column
  • Each entry includes role, content, and timestamp
  • Persists across sessions — reload a game and the agents remember all prior context
  • Memory is injected into every agent's prompt as [ROLE]: content pairs
  • Supports roles: user, planner, coder, tester, assistant, system

Layer 2: Backboard Thread Memory (External)

  • Integration with Backboard.io Assistants API
  • Creates a persistent thread per game (backboard_thread_id)
  • Every agent action is stored as a thread message with memory: "Auto" for automatic semantic indexing
  • Enables cross-session context retrieval and semantic search over project history
  • Thread management: auto-creation on first generation, persistent across all subsequent interactions

Memory in the UI

  • Memory Panel — Expandable widget showing recent memory entries with role-based color coding and timestamps
  • Entry Count — Real-time display of total memory entries in the status bar
  • Backboard Status — Visual indicator when external Backboard thread is active

🎮 Features

Game Generation

  • Natural Language → Playable Game — Describe any 2D game concept and get a complete Phaser 3 implementation
  • Iterative Refinement — Chat-based workflow for modifications ("add power-ups", "make it harder")
  • Multi-File Output — Generates index.html, styles.css, game.js, and additional scene files as needed
  • Auto-Generated Titles — AI creates catchy game titles from your description
  • AI-Generated Responses — The Responder agent writes contextual replies about what was built and what to try next

Autonomous Error Recovery

  • Runtime Error Detection — Catches JavaScript errors in the game preview iframe
  • Validation Error Detection — Pre-flight checks before rendering
  • Auto-Fix Pipeline — Errors are automatically sent back through the agent pipeline (up to 3 attempts)
  • Graceful Degradation — Falls back to manual fix suggestions after max retries

Real-Time Agent Visibility

  • Agent Pipeline Widget — Shows each agent's status (running/completed/failed) with loop iteration tracking
  • Step Details — Expandable details showing plan content, file listings, and tester feedback
  • Live Progress — Simulated step indicators during generation with real data overlay on completion

Code Workspace

  • Multi-File Editor — CodeMirror-based editor with syntax highlighting for HTML, CSS, and JavaScript
  • Live Preview — Instant game preview with hot-reload on file changes
  • File Explorer — Navigate between game files with file-type icons

Project Management

  • Dashboard — Grid view of all created games with timestamps
  • Auto-Save — Games auto-persist 2 seconds after any file change
  • Version History — Chat messages with game snapshots for version restoration
  • Rename/Delete — Full CRUD on game projects

Publishing

  • Itch.io Integration — One-click publish to itch.io via backend function
  • ZIP Export — Bundle game files for manual distribution

🏗️ Tech Stack

Layer Technology
Frontend React 18, TypeScript, Vite, Tailwind CSS
UI Components shadcn/ui, Radix Primitives, Lucide Icons
Code Editor CodeMirror 6 (HTML, CSS, JS language support)
Layout react-resizable-panels for workspace layout
Backend Supabase (Postgres, Auth, Edge Functions, RLS)
AI Models Google Gemini 2.5 Flash (4 agents: Planner, Coder, Tester, Responder)
Memory Supabase JSONB + Backboard.io Threads API
Game Engine Phaser 3.87 (CDN-loaded in generated games)
Bundling JSZip for itch.io publishing

🗄️ Database Schema

games
├── id (uuid, PK)
├── user_id (uuid, FK → profiles)
├── title (text)
├── description (text)
├── initial_idea (text)
├── current_files (jsonb)
├── agent_memory (jsonb, default: [])      ← Agent memory persistence
├── backboard_thread_id (text)             ← External memory thread
├── thumbnail_url (text)
├── created_at / updated_at (timestamptz)

chat_messages
├── id (uuid, PK)
├── game_id (uuid, FK → games)
├── role (text: user | assistant)
├── content (text)
├── game_files (jsonb)
├── created_at (timestamptz)

game_versions
├── id (uuid, PK)
├── game_id (uuid, FK → games)
├── version_number (integer)
├── files (jsonb)
├── notes (text)
├── deployment_url (text)
├── created_at (timestamptz)

profiles
├── id (uuid, PK)
├── email (text)
├── display_name (text)
├── created_at / updated_at (timestamptz)

All tables enforce Row-Level Security (RLS) — users can only access their own data.


🔐 Security

  • RLS Policies on every table (SELECT, INSERT, UPDATE, DELETE scoped to auth.uid())
  • JWT Validation on edge functions with auth header forwarding
  • Service Role Key used only server-side for game state persistence
  • No client-side API keys — all AI calls routed through edge functions

🚀 Edge Functions

Function Purpose
generate-game-orchestrated Main multi-agent pipeline: Planner → Coder → Tester → Responder with feedback loop
generate-game Legacy single-shot generation (automatic fallback)
publish-to-itch Bundles and publishes game files to itch.io

📊 Agent Pipeline Metrics

Each generation returns structured telemetry:

  • agentSteps[] — Full trace of every agent invocation with timestamps and status
  • memorySummary — Current memory state including entry count and recent entries
  • loopsUsed — Number of Coder ↔ Tester iterations before approval
  • approved — Whether the Tester approved or max loops were reached
  • plan — The Planner's step-by-step implementation plan

🎨 Design System

Level0 uses a custom dark-mode design system built on HSL color tokens:

  • Primary: Bright Cyan (hsl(180, 100%, 50%))
  • Accent: Neon Green (hsl(110, 100%, 56%))
  • Background: Dark Navy (hsl(218, 65%, 9%))
  • Glassmorphism: Multi-layer blur with subtle gradients
  • Glow Effects: CSS box-shadow chains for neon aesthetics
  • Animated Background: Floating radial gradients with 20s infinite animation

Setup

Prerequisites

  • Node.js 18+
  • Supabase project (or Lovable Cloud)

Environment Variables (Edge Function Secrets)

Secret Required Purpose
GOOGLE_API_KEY ✅ Gemini API for all 4 agents
BACKBOARD_API_KEY Optional Backboard.io memory integration
BACKBOARD_ASSISTANT_ID Optional Backboard assistant for thread creation

Without Backboard, orchestration still runs fully — memory is stored in the database only.


License

MIT

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages