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 Prompt | Copilot Prompt |
System instructions for the LLM | copilot-instructions.md |
Context | Repository content |
Conversation history | Conversation history |
User question | User 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:
Header and identity: I define the "nickname" (Bob) and the role (Dungeon Master) of Copilot.
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
)
Technical requirements: I explain to Copilot/Bob how to use the data files:
Data structure usage (parsing files)
Game state tracking (health, inventory, position)
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
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 roomlook
- Get detailed description of current roomtake [item]
- Add an item to inventoryuse [item]
- Use an item from inventorytalk to [npc]
- Initiate conversation with an NPCask [npc] about [topic]
- Ask specific questions to NPCsattack [monster]
- Initiate combat with a monsterflee
- Attempt to escape from combatinventory
- List current items carried
- 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:
Context inclusion: The
npc.md
file must be accessible to Copilot/Bob along with thecopilot-instructions.md
anddungeon.md
files. Together, these files form the complete knowledge base for the game. This is why I referencenpc.md
anddungeon.md
in the instructions filecopilot-instructions.md
.Cross-referencing: When the player enters a room containing an NPC (according to
dungeon.md
), Copilot/Bob must consultnpc.md
to get complete information about this NPC.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.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:
General header: Explains the format structure for NPCs.
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
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
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:
Consult
dungeon.md
to see that Elmdrin is thereGet Elmdrin's description from
npc.md
Integrate this information into the room description
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:
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.
Dynamic navigation: When the player uses a command like
"go north"
, Copilot/Bob consultsdungeon.md
to determine if this direction is available from the current room and where it leads.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'sTemperature
parameter).Environment interactions: For commands like
"take [item]"
or"look"
, Copilot/Bob checks indungeon.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 😮.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:
Explanatory header: Describes the format structure for each room.
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
Spatial relationships: Connections between rooms are clearly defined, creating a coherent map that the player can explore.
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).
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:
Consult the
"Main Corridor"
section indungeon.md
Verify that
"North: Grand Chamber"
is indeed an available exitMove the player to the
"Grand Chamber"
roomPresent the complete description of this new room
Mention the presence of the NPC
"Court Jester Ghost (Jibbo)"
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
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
