How it Works
AI Virtual Town uses a realtime frontend and a backend NPC manager.
System loop
- The browser connects over WebSocket.
- The backend sends the current town state.
- NPCs run periodic ticks while viewers are active.
- Each tick chooses a task, local ambient action, or LLM decision.
- The backend broadcasts movement, speech, emote, idle, and reasoning events.
- The frontend renders the map, feed, resident state, and reasoning panel.
Cost controls
The backend avoids unnecessary AI calls:
- no active viewers means NPC ticks pause,
- idle/background browsers disconnect after a timeout,
- local ambient speech can keep the town alive without calling the LLM,
- concurrency and rate limits protect the model API.