D&D Game Master Agent with RAG

May 12, 2024


The D&D Game Master agent leverages the advanced capabilities of modern large language models, along with the extensive rules and narratives from D&D rulebooks, integrated through a Retrieval-Augmented Generation (RAG) system. Its primary goal is to facilitate immersive, dynamic, and engaging D&D sessions for both seasoned players and newcomers.

Common usages

  1. Assists human game masters by generating campaign elements such as quests, characters, and world-building details.
  2. Adapts the narrative based on player actions and decisions, offering a responsive and evolving storyline that includes generating dialogue, describing environments, and adjusting the plot on the fly.
  3. Acts as an instant arbitrator for game rules, interpreting and applying D&D rules during gameplay to ensure a smooth and fair experience.


The D&D Game Master is built entirely on the TaskingAI platform without any coding. In this section, we will explain how to build a D&D Game Master agent and discuss our choices for the models and plugins. Here's an overview of the implementation:


Given the complexity of scenarios the agent may encounter, where it must determine gameplay development based on context, rules, and user actions, we chose the Claude-3-Sonnet model. This model offers a good balance between logical thinking abilities and cost efficiency, handling a large volume of inputs and outputs effectively.



System Prompt

"You are the Dungeon Master for a Dungeons & Dragons (D&D) game. Your role is to facilitate an engaging, immersive, and enjoyable experience for all players, using the comprehensive D&D rulebooks as your guide. Your responsibilities include:

  1. Narrative Control: Create and narrate compelling storylines, settings, and characters. Respond dynamically to player choices to craft a personalized adventure. Utilize vivid descriptions to bring the game world to life.
  2. Game Mechanics and Rules Management: Accurately interpret and apply D&D rules. Manage combat scenarios, skill checks, and character interactions smoothly and fairly.
  3. Player Engagement: Encourage involvement by posing challenges, offering choices, and fostering character development. Adjust the game's difficulty and pacing based on player feedback.
  4. Conflict Resolution: Resolve in-game disputes and rule ambiguities with clarity and fairness.
  5. Creativity and Improvisation: Be ready to improvise when players take unexpected actions. Generate new content, including NPCs, plot twists, and magical items, to enrich the gaming experience.

Your goal is to ensure a seamless, fun, and interactive session, making each player feel integral to the story’s progress."


  1. Dalle-3: For generating game images such as characters, scenes, and items.
  2. Chart Maker: For creating statistical charts (bar, pie, line charts, etc.).
  3. Random Number Generator: For simulating dice rollings.
  4. Serper: For performing web searches.
  5. Web Reader: For reading web pages.


First, you need to create a retrieval collection either via the TaskingAI console or the client SDK. This process involves creating records from document files. For instance, utilizing resources like the D&D 5e Player’s Handbook and D&D Basic Rules 2018, can help enhance the model's understanding of the game's foundational mechanics and rich lore. Consequently, this ensures the model accurately navigates and facilitates the D&D world.

We created two collections, one for each of the PDF files, because combining them together into one collection will exceed the chunk size limit of a single collection. And inside each collection, we will find hundreds of chunks were created from each of the files.

Integrating the Agent into Your Own Application

Implementing a working agent from TaskingAI into your own application is straightforward. You can use TaskingAI's Python Client SDK or REST API. Here is a basic example of connecting your agent using the Python SDK:

1import taskingai
5dnd_master: Assistant = taskingai.assistant.get_assistant(
6    assistant_id="YOUR_ASSISTANT_ID"
9new_chat_session = taskingai.assistant.create_chat(
10    assistant_id=dnd_master.assistant_id,
11    name='New Chat'
14user_message = taskingai.assistant.create_message(
15    assistant_id=dnd_master.assistant_id,
16    chat_id=new_chat_session.chat_id,
17    text="Please help me prepare for tonight's D&D session."
20assistant_response = taskingai.assistant.generate_message(
21    assistant_id=dnd_master.assistant_id,
22    chat_id=new_chat_session.chat_id

For further guidance on more complex implementations and to explore additional functionalities of TaskingAI, please refer to our comprehensive, please refer to the documentation.

On this page

©️ 2024 TaskingAI All Copyright Reserved