Building a Multi-Agent Role-Playing Game System with Large Language Models

    This article explains how to design and engineer a multi-agent tabletop role-playing system powered by large language models. It covers why the setting is harder than simple turn-taking chat, how to define structured character profiles, how to schedule speakers, why a game-master agent is needed, and how to turn huge session logs into publishable content.

    Building a Multi-Agent Role-Playing Game System with Large Language Models

    As large language models have improved, letting multiple AI characters talk, cooperate, and conflict inside one shared scene has become an appealing content format. Tabletop role-playing is a strong test of multi-agent collaboration: distinct characters must interact under shared rules, and a host (KP/GM) must judge actions and guide the story. Drawing on hands-on system building, this article outlines the main design points and engineering practices.

    1. Why Tabletop Role-Playing Is Harder Than It Looks

    A common first idea is to write a system prompt for each character and let them speak in turn. In practice, the complexity is much higher and shows up on three levels:

    1. Keeping characters consistent. Each AI character must hold a stable personality, speech habits, stance, and goals across hundreds of turns. In long contexts, models often drift: a quiet character suddenly becomes talkative, or a berserker turns polite. Prompt design, context management, and output checks all need to work together.

    2. Action resolution and rules. Role-playing is not pure chat. After a dice roll, an action succeeds or fails, and the plot branches. The system needs resolution logic that is separate from dialogue generation, and the result must be written back into later context.

    3. Explosive growth of source material. A session lasting a few hours can produce tens of thousands of dialogue records, much of it small talk, repetition, and stalled progress. Filtering, cutting, and reorganizing that raw log into something publishable is a large amount of work.

    2. Character System Design: Profiles Are the Foundation

    The first step is a structured character profile. A practical pattern is a four-part definition: role, personality tags, behavioral boundaries, and goals or motives. For example:

    1. role: Hero
    2. persona: Hot-blooded and impulsive, values loyalty, acts before thinking
    3. boundaries: Rejects schemes and intrigue; cannot persuade companions to abandon the adventure
    4. goal: Lead the party to defeat the demon lord and win glory
    5. speech_style: Short sentences, frequent exclamation marks, likes calling teammates by nicknames

    Structured definitions help in two ways. They can be injected into system prompts programmatically, and they can later be walked to generate derivative assets such as character cards and character-art descriptions. For visuals, a shared character-art style template keeps the look consistent, which strongly affects whether the content feels coherent.

    3. Dialogue Orchestration: Fixed Turns or Open Competition

    Two common ways to schedule multi-character dialogue are:

    Fixed rotation. Call each character in turn order. This is controllable and cheaper, but it lacks dramatic tension and makes natural replies harder.

    Event-driven selection. A scheduler chooses the next speaker from context, using heuristics such as who was addressed, who has a stake, and who has a strong urge to speak.

    A hybrid works well in practice: follow rotation by default, and insert extra exchange rounds when characters conflict or when a character’s goal is touched. The decision can be a simple scoring function:

    1. def pick_next_speaker(context, roles):
    2. scores = []
    3. for role in roles:
    4. s = relevance(context, role) # relevance to the current topic
    5. s += 2 if role in context.targets # whether the role was addressed directly
    6. s -= context.spoke_recently(role) * 3 # reduce domination of the conversation
    7. scores.append((s, role))
    8. return max(scores)[1]

    4. Adding a GM: From Group Chat to Directed Drama

    If characters only generate dialogue on their own, the plot easily drifts or loops. A game-master agent is therefore useful. Its duties include:

    • Advancing the plot: when dialogue stalls, introduce a new event, NPC, or change in the environment;
    • Resolving actions: when a character declares an action, apply preset rules (which can be a simplified dice system) and output success or failure plus consequences;
    • Pulling the scene back: when discussion leaves the main line, steer it back without being abrupt.

    In implementation, the GM can be a higher-privilege role. Besides dialogue text, its output includes structured story-state updates, such as event flags, quest progress, and changes to each character’s status. These updates go into a shared global state store. Before each turn, every character can read the latest world state, which avoids absurd dialogue caused by unsynchronized information.

    5. Production Pipeline: From Tens of Thousands of Records to a Finished Piece

    This stage is easy to underestimate. A practical pipeline has four steps:

    1. Structure the logs. For every model call, record the character name, timestamp, turn number, and emotion label, and write structured files rather than plain text.
    2. Filter automatically. Use rules plus a smaller model to drop small talk, repetition, and off-topic content. This often removes more than half of the material.
    3. Edit by hand. From the GM’s point of view, the author adds guiding narration and transitions. Machines still do not replace this control of dramatic pacing.
    4. Assemble the performance. Align text with character art and voiceover on a script timeline, then render in batches.

    6. Closing Notes

    A multi-agent role-playing system may look like “letting AIs chat,” but stable, high-quality, reproducible content is really a combined engineering problem: prompt design, state management, scheduling, and a content pipeline. Three practical habits help: prepare assets early, leave enough time for debugging, and automate uncontrollable steps as soon as possible. Exhaustion is normal, but when characters with very different personalities actually play out a good scene under rules you designed, the result can make the rework worthwhile.