Building Your Own AI Town with ai-town
The Problem
You’ve read the Generative Agents paper and thought, “Cool, but how do I actually build something like that without drowning in Python, TensorFlow, and sadness?” Or maybe you just want a customizable playground for AI characters in a virtual world, with multiplayer support baked in. Either way, starting from scratch is a pain, and most open-source projects in this space are either too academic or too rigid.
What This Does
ai-town is a starter kit for creating your own virtual town where AI characters live, chat, and interact. It's built with TypeScript and designed to be extended. The back-end is powered by Convex, which handles the shared global state, transactions, and simulation logic. The front-end is a React app, with heavy use of PixiJS for rendering the game world. The project is containerized with Docker, so you can spin it up locally or deploy it to Fly.io.
The structure is clean and modular. The back-end logic lives in convex/, with subfolders for the simulation engine (convex/engine), AI character behaviors (convex/aiTown/), and utilities (convex/util/). The front-end is in src/, featuring components like src/components/Game.tsx for the main game view and src/components/Player.tsx for handling player interactions. Config files like docker-compose.yml and fly.toml make deployment straightforward.
Real-World Use
Say you want to build a multiplayer AI-powered RPG where players interact with NPCs that actually remember past conversations. Start by forking this repo, spinning it up with docker-compose up, and plugging in your LLM of choice (OpenAI, Ollama, or whatever speaks to the OpenAI API). The AI backend logic is in convex/aiTown/, so tweaking how characters behave or introducing new ones is as simple as editing agent.ts or game.ts.
Here’s a simple example of sending player input to the game:
Want to customize the map? Check out the tilesets in src/editor/tilesets/ or edit the animations in data/animations/. The modular structure keeps everything organized and approachable.
The Bottom Line
ai-town is a solid foundation for anyone building AI-driven virtual worlds or multiplayer simulation games. It's not perfect—the dependency on Convex might be a dealbreaker for some, and the setup could be overkill for smaller projects. But if you’re serious about creating your own AI town, this is a fantastic place to start. Just be ready to get your hands dirty with TypeScript and Docker.