Transforming GitHub Copilot into a Dungeon Master

Please note that this experiment is incomplete. It's a proof of concept to verify some hypotheses about how GitHub Copilot works and about prompting. In fact, it's always a question of prompting 😉.

Instruction File: copilot-instructions.md?

Are you familiar with copilot-instructions.md? This file allows you to define coding practices, conventions, languages, and any useful instructions to guide GitHub Copilot when generating code or chat responses.

The instructions in this file are automatically added to each request sent to Copilot Chat when working in the relevant repository. (For more information, see: Adding repository custom instructions for GitHub Copilot)

When developing a generative AI application, I compose the prompt to send to the LLM with the following elements:

  • System instructions for the LLM

  • Context (necessary data from various sources)

  • Conversation history

  • User question

If I draw a parallel with GitHub Copilot, copilot-instructions.md represents the system instructions for the LLM, and my repository's source code represents the context to help the LLM.

GenAI PromptCopilot Prompt
System instructions for the LLMcopilot-instructions.md
ContextRepository content
Conversation historyConversation history
User questionUser question

On this rainy Sunday in early May (and it's May 4th - get the reference?), I thought it was the perfect time to verify a question that's been on my mind for a few weeks: Can we use GitHub Copilot for something other than code generation?. For example, could I use GitHub Copilot as the Dungeon Master for a small role-playing game? 🤔 ... "You're crazy! Oh yes!"

It's All About the Prompt

So, VSCode would be my dungeon, and GitHub Copilot would be the game master 🔥

Since copilot-instructions.md represents the system instructions, here's how I structured it:

Structure of the copilot-instructions.md File

copilot-instructions.md is structured in a hierarchical and clear manner to allow GitHub Copilot to understand its role and responsibilities:

  1. Header and identity: I define the "nickname" (Bob) and the role (Dungeon Master) of Copilot.

  2. Core responsibilities:

    • Game navigation (referencing the files that will serve as context, here dungeon.md)

    • Interaction management

    • Combat system

    • Dialogue with NPCs (referencing the files that will serve as context, here npc.md)

  3. Technical requirements: I explain to Copilot/Bob how to use the data files:

    • Data structure usage (parsing files)

    • Game state tracking (health, inventory, position)

  4. Response format: I give precise instructions on how Copilot/Bob should format its responses, including:

    • Starting with the room description

    • Immediately mentioning any NPCs present

    • Presenting interaction options

    • Structuring dialogues and combat

  5. Command reference: I provide a complete list of commands the player can use, so Copilot/Bob can remind the player during chat interactions:

  • go [direction] - Move to an adjacent room

  • look - Get detailed description of current room

  • take [item] - Add an item to inventory

  • use [item] - Use an item from inventory

  • talk to [npc] - Initiate conversation with an NPC

  • ask [npc] about [topic] - Ask specific questions to NPCs

  • attack [monster] - Initiate combat with a monster

  • flee - Attempt to escape from combat

  • inventory - List current items carried

  1. Restrictions: It's also important to set clear limitations on what Copilot/Bob should not do.

This well-organized structure allows Copilot/Bob to easily understand its role and act accordingly, to ensure a coherent and "immersive" gaming experience (use your imagination 😜).

The most important parts are the sections on core responsibilities and response format, as they precisely define how Copilot/Bob should behave and respond to the player.

📝 Here is the (first) complete version of copilot-instructions.md that I used: https://github.com/aethelgard/The-Forgotten-Fortress/blob/main/.github/copilot-instructions.md

Structure of Context Files

Context File: npc.md, the Non-Player Characters

The npc.md file serves as a database for all non-player characters (NPCs) that Copilot/Bob the Dungeon Master can introduce into the adventure. Here's how we'll use it:

  1. Context inclusion: The npc.md file must be accessible to Copilot/Bob along with the copilot-instructions.md and dungeon.md files. Together, these files form the complete knowledge base for the game. This is why I reference npc.md and dungeon.md in the instructions file copilot-instructions.md.

  2. Cross-referencing: When the player enters a room containing an NPC (according to dungeon.md), Copilot/Bob must consult npc.md to get complete information about this NPC.

  3. Dynamic interactions: When the player talks to an NPC using the command "talk to [name]" or "ask [name] about [topic]", Copilot/Bob uses the predefined dialogues in npc.md to generate appropriate responses.

  4. Limitation to provided information: Copilot/Bob should never invent new dialogues or characteristics for NPCs that are not present in npc.md.

Structure of the npc.md File

I structured the npc.md file as clearly as possible to facilitate its use by Copilot/Bob:

  1. General header: Explains the format structure for NPCs.

  2. Sections by NPC: Each NPC has its own section with:

    • Name: Unique identifier for the NPC

    • Location: Room where the NPC can be found

    • Description: Physical appearance and behavior

    • Background: Character history and motivations

    • Dialogue: Structured list of possible questions and their corresponding answers

  3. Dialogue format:

    • Dialogues are organized in question-answer pairs

    • Each question is preceded by "Question:"

    • Each answer is preceded by "Answer:"

    • This structure allows Copilot/Bob to easily identify the appropriate response to a player's question

  4. Narrative content: NPC responses often contain:

    • Hints about the dungeon's history

    • Information about hidden treasures

    • Tips for defeating monsters

    • Potential side quests

So, for example, when the player enters the Library, Copilot/Bob should:

  1. Consult dungeon.md to see that Elmdrin is there

  2. Get Elmdrin's description from npc.md

  3. Integrate this information into the room description

  4. Propose the option "talk to Elmdrin" among the possible actions

This organization should allow Copilot/Bob to create a coherent gaming experience, with interactions with the dungeon's characters.

📝 Here is the complete version of npc.md: https://github.com/aethelgard/The-Forgotten-Fortress/blob/main/npc.md

Context File: dungeon.md

The dungeon.md file will serve as a complete map and database for the entire dungeon. Copilot/Bob will use it as follows:

  1. Source of truth: It's the main reference for all spatial information and dungeon contents. Copilot/Bob must constantly refer to it to ensure game coherence.

  2. Dynamic navigation: When the player uses a command like "go north", Copilot/Bob consults dungeon.md to determine if this direction is available from the current room and where it leads.

  3. Description generation: When the player enters a new room, Copilot/Bob uses the exact description provided in dungeon.md, without inventing additional details (or at least trying, as it's not possible to adjust Copilot's Temperature parameter).

  4. Environment interactions: For commands like "take [item]" or "look", Copilot/Bob checks in dungeon.md if the mentioned object exists in the current room. ✋ Copilot/Bob knows how to use its conversation history to manage your inventory and even remember that you've already picked up gold coins or a potion in a previous room 😮.

  5. Combat management: Monster statistics in each room (health, damage) are defined in dungeon.md and must be respected during combat. ✋ Copilot/Bob knows how to use its conversation history to manage combat, your hit points, those of the monsters you're fighting, and it will remember if a monster has been killed 😲.

Structure of the dungeon.md File

Here too, the dungeon.md file is methodically structured to facilitate its use by Copilot/Bob:

  1. Explanatory header: Describes the format structure for each room.

  2. Sections by room: Each dungeon room has its own section with:

    • Room name: Unique identifier

    • Description: Detailed description of the environment

    • Exits: List of available directions and connected rooms

    • Treasures: Valuable objects the player can collect (with their gold value)

    • Healing items: Potions, food, and other health-restoring objects

    • Monsters: Hostile creatures with their statistics (health, damage)

    • NPCs: Non-player characters present in the room

  3. Spatial relationships: Connections between rooms are clearly defined, creating a coherent map that the player can explore.

  4. Difficulty progression: Monsters and challenges generally become more difficult as the player delves deeper into the dungeon (of course, this depends on how you created your dungeon).

  5. Special elements: Some rooms contain special elements like secret passages or locked doors requiring specific keys.

For example, when a player is in the "Main Corridor" and uses the command "go north", Copilot/Bob should:

  1. Consult the "Main Corridor" section in dungeon.md

  2. Verify that "North: Grand Chamber" is indeed an available exit

  3. Move the player to the "Grand Chamber" room

  4. Present the complete description of this new room

  5. Mention the presence of the NPC "Court Jester Ghost (Jibbo)"

  6. Indicate the new movement and interaction options

As with the npc.md file, this organization will allow Copilot/Bob to maintain game coherence and manage interactions between the player, the environment (the dungeon), and the various characters.

📝 Here is the complete version of dungeon.md: https://github.com/aethelgard/The-Forgotten-Fortress/blob/main/dungeon.md

🤔 But Does It Really Work?

I haven't explored the entire dungeon yet, but the result is quite surprising (I used Claude 3.5 Sonnet).

✋ VERY IMPORTANT: for the game to work properly, when you're in the chat, you need to add the CodeBase to the context for each interaction/question (or add the 2 files npc.md and dungeon.md to the context). This is a constraint 😞.

Everything is ready for new adventures 🧙🏻‍♂️

Speak with the DM

Enter in a room

NPC

Combat

Inventory

1
Subscribe to my newsletter

Read articles from Philippe Charrière directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Philippe Charrière
Philippe Charrière