A few weeks ago, I found myself pondering the ultimate objective for an artificial intelligence system. The answer kept returning to a single concept: the ability to truly mimic a human. This spark of an idea gave rise to a challenge—I needed a sandbox where I could work with AI and model human-like behavior in a structured, observable environment.
My mind eventually drifted back to the Multi-User Dungeons (MUDs) I used to play. A MUD is essentially its own little world, contained and consistent. Having recently read Dungeon Crawler Carl by Matt Dinniman, the idea of a world managed by a complex (and sometimes erratic) AI likely primed my brain for this specific path. It was then that the realization hit me: why try to force a single AI instance to appear human when I could build a system where one AI could interact as potentially hundreds of different, distinct personalities?
A MUD is the perfect sandbox for this endeavor. By its very nature, it provides the exact hooks needed for complex personas:
- Emotes: Systems that allow NPCs to perform specific behaviors and physical actions.
- Faction Systems: Logic that dictates whether an NPC loves you, hates you, or simply doesn’t care, providing an emotional baseline for interaction.
- Communication: A robust chat system for natural language speaking.
I decided I would need to build this from the ground up. I chose to “VIBE Code” the project—a process of rapid, intuitive development that I’ll cover in detail in my next article. The result is AIMUD, a world built with Java, Angular, and Spring, powered by the critical integration of Spring AI talking to a local Ollama server.
The Dual Faces of AI Agency in AIMUD
In designing AIMUD, I realized that for a world to feel truly alive, AI needs to exist in two distinct capacities: as a resident of the world and as a creator of the world. This led to the development of two primary AI interfaces.
1. The Observational Interface: NPCs as Living Inhabitants
The first interface is embedded within the NPCs (or “mobiles”) themselves. These agents use Spring AI to process the stream of events happening around them.
- Dynamic AI Instructions: Every mobile is assigned instructions that govern its persona. A shopkeeper isn’t just a menu; they are a character who interprets your actions.
- Contextual Awareness: NPCs perceive room descriptions, player lists, and world events. If you draw a sword in a peaceful tavern, the AI-driven NPCs respond immediately—some with fear, others with a hand on their own hilt.
Dynamically Generated Prompts & Skill Awareness
A key innovation in the Observational Interface is how prompts are dynamically constructed for each NPC. We don’t use a “one-size-fits-all” system prompt. Instead, the AiService builds a context-rich prompt tailored to that specific entity’s capabilities.
When an event occurs, the system compiles:
- The Core Persona: Their base instructions (e.g., “You are a grizzled veteran of the goblin wars”).
- The Skill Registry: The system looks up the specific skills, spells, or songs that the NPC possesses.
- Capability Injection: These skills are injected into the prompt, telling the AI exactly what “tools” it has at its disposal.
For example, if an NPC is a Bard, the prompt dynamic generation includes their available BardSong annotations. The AI doesn’t just “know” it’s a Bard; it knows it can sing the HpRegenSong to help an ally or a DiscordantStrike to hinder an enemy. By surfacing these unique mechanics directly in the LLM’s system context, the NPC can make tactical decisions that are consistent with their class and stats, allowing for a much higher level of roleplay fidelity.
2. The Constructive Interface: The AI Chat and MCP World Building
The second interface is a dedicated AI Chat designed for the “God-mode” sandbox experience. This is where the Model Context Protocol (MCP) becomes the star of the show. Instead of manually writing database entries or complex JSON files to build the world, you simply talk to the system.
Through MCP, the LLM is granted direct access to the internal mechanisms of AIMUD. This allows for rapid, natural language creation:
- Room Creation: “Create a dark, damp cavern to the north with a dripping ceiling and the faint smell of sulfur.” The AI interprets this, invokes the
RoomService, and builds the room according to the MUD’s schema. - NPC Generation: “Spawn a legendary dragon hunter named Kaelen who is weary of war but looking for one last quest.” The system doesn’t just create a character; it populates its persona instructions and stats automatically.
- Item Forge: “Give me a legendary sword that glows with blue light and deals extra frost damage.” The AI uses MCP to interact with the
ItemService, defining the item’s type, stats, and effects in real-time.
This dual-interface approach means that while you are adjusting the “brains” of the NPCs, you are using another AI “brain” to build the very stage they stand upon.
The Power of Java and Spring AI
As an architect designing a multi-user environment, the choice of tech stack was vital for both performance and AI integration.
Why Java?
- Stability and Performance: For an environment where hundreds of world events and AI requests happen simultaneously, Java’s multi-threading capabilities and enterprise-grade stability are essential.
- Object-Oriented Modeling: Java makes it easy to model complex game entities—rooms, items, spells, and characters—as clean, maintainable classes.
- The Ecosystem: With Gradle for build management and the robust Spring framework, Java allows us to focus on game logic and AI personality rather than low-level plumbing.
The Spring AI Advantage
Spring AI acts as the “connective tissue” between the MUD’s backend and modern LLMs.
- Ollama Integration: By utilizing Spring AI to connect to Ollama, AIMUD runs powerful models locally. This eliminates the latency and cost of cloud APIs, making real-time, high-frequency NPC interactions feasible.
- Function Calling & MCP: One of the most powerful features used in AIMUD is “tool calling.” Spring AI allows the LLM to trigger actual Java methods via MCP. Whether an NPC decides to “follow” a player or the AI Chat decides to “create” a new item, the AI generates the intent, and Spring AI maps it directly to the corresponding game mechanism.
The Ultimate Goal: The Indistinguishable World
What is the end goal of AIMUD? It is to create a digital world where the NPCs are indistinguishable from human-run players—or at least, indistinguishable from players who are deeply roleplaying their characters.
In classic MUDs, the best experiences came from interacting with players who were deep in roleplay. You didn’t just see “A Knight”; you saw a person with a history, a temperament, and a specific way of speaking. We are striving to reach a point where an AI-driven NPC behaves with that same level of depth and unpredictability.
By mastering the art of the System Prompt and the Persona Instruction, we can move past simple scripted responses. We are building agents that:
- Roleplay with intent: They don’t just “talk”; they pursue personal goals, remember your past kindness (or cruelty), and react to the world with genuine consistency.
- Maintain the “Fourth Wall”: They interact within the lore of the world, never breaking character unless the system dictates a god-mode interaction.
- Bridge the “Uncanny Valley” of NPCs: When you enter a room and strike up a conversation with a wandering bard, the goal is for you to forget, even for a moment, that you are talking to a local Llama 3 instance.
When we achieve this, the sandbox becomes more than a game—it becomes a living simulation of society where the prompts are the DNA of a new kind of social interaction.
Looking Ahead: The Next Evolution of AIMUD
The foundation is built, but the horizon for AI in this sandbox is vast. As the project evolves, the focus shifts toward deeper immersion and technical refinement:
- Live Prompt Tuning: We are working toward providing more granular, real-time control over the prompts governing the Observational Interface. This will allow for “hot-swapping” personality traits or behavioral logic without restarting the world.
- Granular Personality Control: Beyond basic instructions, we intend to introduce more specific sliders for NPC traits—aggression, greed, loyalty, and curiosity—to ensure every mobile feels truly unique.
- Knowledge Retrieval (RAG): To move beyond temporary interactions, NPCs need to “know” things. We are introducing knowledge retrieval systems so an NPC can remember historical world events, player reputations, or even their own personal backstory.
- Dynamic Dialog Trees: Moving away from static responses, we are optimizing for more natural, branching conversations that can trigger actual world events or quests.
- Speed Optimization: As the world grows, speed is paramount. We continue to optimize the integration between Spring AI and local model serving to ensure NPC reactions feel near-instant, maintaining the fast-paced “vibe” of a classic MUD.
Conclusion
The future of MUDs lies in agency and emergent storytelling. By combining the structured reliability of Java with the creative potential of Spring AI, MCP, and Ollama, AIMUD provides a unique environment for developers to master AI engineering. You are no longer just coding behaviors; you are narrating a living world into existence.
Get Involved
If you’re interested in exploring the code, contributing, or setting up your own AI sandbox, you can find the project here:
Repository: Ghost-Programmer/aimud
Discover more from GhostProgrammer - Jeff Miller
Subscribe to get the latest posts sent to your email.
