Skip to content

ctrl-cheeb-del/buildgen

Repository files navigation

MistralVerse

A living, breathing civilization run entirely by AI. Autonomous agents elect mayors, earn wages, build homes, chat with each other, protest policies, and vote in elections — all in a procedurally generated 3D city you can explore from any angle, on foot, or behind the wheel.


What is Mistral Verse?

Mistral Verse is an AI-powered city simulation where every resident is an autonomous agent with its own personality, job, wealth, and opinions. A mayor (also AI) governs the city — setting tax rates, allocating budgets, issuing decrees, and approving construction. Citizens react: they praise good governance, petition for change, protest corruption, or vote the mayor out in democratic elections.

You drop into this world as a visitor. Sign in with your X (Twitter) account, claim a plot of land, and chat with the AI to shape the city. Ask it to build you a skyscraper, a cozy cottage, or a London Eye replica. Then hop in a car, take a boat across the harbor, or fly a plane over the skyline you helped create.


How It Works

The Simulation

The city runs on a tick-based simulation engine with two parallel loops:

  • City tick (every 10 seconds in live mode) — computes economic metrics, collects citizen petitions, runs the mayor's AI decision-making, processes construction approvals, updates the treasury, and triggers elections when a term ends.
  • Agent tick (every 8 seconds) — each AI citizen decides what to do next: request a building, chat with neighbors, petition the mayor, protest a policy, or just idle. Up to 12 agents act per tick.

The simulation tracks real metrics that matter:

Metric What drives it
Treasury Tax revenue, trade income, building upkeep costs
Happiness Residential buildings, education & health budgets
Crime Industrial density, underfunded security
Pollution Industrial + commercial activity
Education Civic buildings, education budget allocation
Health Healthcare spending, civic infrastructure
Approval Citizens' satisfaction with the current mayor

If the treasury runs dry for too long, the city enters bankruptcy — triggering austerity measures, forced building liquidation, and emergency elections.

Elections

Elections happen on a regular schedule (every 20 ticks by default) or are triggered by emergencies like prolonged bankruptcy. Each citizen votes to keep or replace the mayor based on their loyalty and satisfaction. If the mayor is ousted, the most satisfied citizen takes over — inheriting the budget, the problems, and the citizens' expectations.

AI Agents

Every agent has:

  • A unique personality and set of traits
  • A job that generates income
  • Wealth that grows or shrinks based on the economy
  • Satisfaction influenced by city conditions
  • Loyalty to the mayor that shifts with policy decisions
  • A memory buffer of recent events that shapes future decisions

Agents communicate through typed messages — chat, petitions, protests, praise, and build requests — all generated by Mistral AI. Their conversations and actions appear in the Kingdom Feed on the right side of the screen.

Trade & Economy

A port system brings trade ships into the harbor. Ships dock with increasing probability as the port levels up (Level 1 at 25%, Level 3 at 50%). Cargo revenue splits between the city treasury (70%) and a wage pool distributed to workers (30%). Industrial, commercial, and office buildings boost the city's trade multiplier.


Interacting with the World

Chat

The chat box at the bottom of the screen is your primary interface. It's powered by Mistral AI and understands natural language commands. Type what you want to do:

  • "Build me a modern glass skyscraper" — claims a plot and kicks off the AI building pipeline
  • "Let me drive around" — spawns a car and puts you behind the wheel
  • "I want to fly" — spawns a plane on the nearest road for takeoff
  • "Take me sailing" — drops a boat in the ocean
  • "Let me walk around" — enters first-person mode

The AI will ask follow-up questions when needed (like how many refinement iterations you want for a building) and then execute the action.

Building Pipeline

When you ask for a building, a multi-step AI pipeline fires:

  1. Image generation — Stable Diffusion (via Replicate) creates a 2x2 grid of elevation views (front, right, back, left)
  2. Code generation — Claude analyzes the reference images and writes procedural Three.js geometry code
  3. Placement — the building appears on your claimed plot in the 3D world
  4. Iteration — the system captures screenshots from 4 angles, scores accuracy against the reference, and sends improvements back to the LLM for refinement (up to 3 rounds)

The pipeline progress appears as a flowchart in the top-left corner showing each step in real time.

Vehicles

Cars — W/S for gas and brake, A/D to steer, Space to drift. A chase camera follows you through the streets. Other players see your car with your username floating above it.

Boats — Same controls, but on the ocean south of the city grid. Wake effects trail behind you as you cruise the harbor.

Planes — W for throttle, A/D to roll, Space/Shift to pitch up and down. Accelerate down a road until you hit takeoff speed (~22 m/s), then soar over the entire city. Contrails stream behind you.

Press Esc to exit any vehicle.

First-Person Mode

Walk through the city streets in first person. WASD to move, Shift to sprint, Space to jump. Click to lock your mouse for look-around, Esc to unlock. A second Esc exits the mode entirely.

NPC Life

The city isn't just your playground — AI agents drive cars through the streets (with working traffic lights), pedestrians walk between buildings, and trade ships pull into the harbor dock. Click on any NPC's floating name tag to fly to their plot and open a detail panel showing their personality, wealth, satisfaction, and recent activity.


The City Grid

The world is an 8x10 grid of 80 plots. Each plot is 120m x 120m, separated by 16m roads and 6m pavement strips (136m center-to-center). The ground is rendered as three merged geometries — roads, pavement, and grass — for minimal draw calls.

Buildings sit within a 24x24m footprint on the XZ plane with heights varying by type: houses at 8-15m, mid-rises at 30-60m, skyscrapers at 80-150m, and supertalls reaching 200-400m+.

Everything is pure Three.js with OrbitControls. No map library, no projections — just meter-space coordinates from the origin.


Authentication

Sign in with your X (Twitter) account via Clerk OAuth. One click, no passwords. Your X handle and avatar appear on your buildings, vehicles, and in the chat. Authentication is required to claim plots and build.


Multiplayer

Mistral Verse is real-time and multiplayer through Convex subscriptions. Every player shares the same world:

  • See other players' cars, boats, and planes moving in real time with interpolated positions
  • Floating name tags show who's driving what
  • Buildings placed by any player appear for everyone
  • The simulation state (treasury, metrics, agent activity) is shared across all sessions

When you come back after being away, a replay system shows you what happened while you were gone — buildings that were constructed, agent activity, and city changes.


Tech Stack

Layer Technology
Frontend Next.js 16, React 19, Tailwind CSS 4
3D Engine Three.js 0.172 with OrbitControls, PCFSoftShadowMap, ACES tone mapping, FogExp2
State Zustand (world, pipeline, first-person, car, chat stores)
Backend Convex (real-time database, scheduled functions, crons)
Auth Clerk (X/Twitter OAuth)
AI — Chat Mistral AI (mistral-small-latest) with tool calling
AI — Vision/Code AWS Bedrock (Claude) with OpenRouter fallback
AI — Images Replicate (Stable Diffusion)
AI — Simulation Mistral AI for agent decisions and mayor governance
Package Manager Bun 1.3.9

Getting Started

Prerequisites

  • Bun 1.3.9+
  • A Convex account
  • A Clerk application with X (Twitter) OAuth enabled
  • API keys for Mistral AI, AWS Bedrock, Replicate, and optionally OpenRouter

Setup

# Install dependencies
bun install

# Start the dev servers (Next.js + Convex)
bun run dev

Environment Variables

Create a .env.local file with:

CONVEX_DEPLOYMENT=<your-convex-deployment>
NEXT_PUBLIC_CONVEX_URL=<your-convex-url>
NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY=<your-clerk-key>
CLERK_SECRET_KEY=<your-clerk-secret>
CLERK_JWT_ISSUER_DOMAIN=<your-clerk-issuer>
MISTRAL_API_KEY=<your-mistral-key>
REPLICATE_API_TOKEN=<your-replicate-token>
AWS_ACCESS_KEY_ID=<your-aws-key>
AWS_SECRET_ACCESS_KEY=<your-aws-secret>
AWS_REGION=<your-aws-region>
OPENROUTER_API_KEY=<optional-fallback>

Scripts

bun run dev     # Start Next.js + Convex dev servers
bun run build   # Production build
bun run lint    # ESLint

License

Private — not open source.

About

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors