Laravel AI SDK: I Built a D&D Terminal Game with AI as Dungeon Master

Laravel| 00:12:28|Feb 18, 2026
Chapters9
Introduces a dungeon escape game concept and the idea of using AI as the dungeon master within a terminal environment.

A hands-on tour building a terminal-based D&D game with Laravel AI SDK, turning an AI model into a Dungeon Master that tracks health, inventory, and turns, with practical testing tips.

Summary

The Laravel creator demonstrates how to spin up a text-based dungeon game in the terminal using the Level AI SDK. The video walks through creating an agent called DD Master, wiring it to manage health, inventory, and decision prompts. You’ll see actionable steps like running PHP artisan make:agent, configuring the agent’s instruction set, and testing locally via a tinker shell or a dedicated console command. The presenter emphasizes practical testing—showing how to call the agent prompt, capture responses, and handle memory between turns with Laravel remembers conversation. They also cover common gotchas, such as ensuring a user exists for conversation persistence and migrating the Level AI SDK database tables. The demo includes a quick CLI UI tweak via a separate console command (dungeon play) to render a nicer terminal interface, including a health indicator and turn-based prompts. The takeaway is that the AI SDK isn’t limited to chatbots—it’s a springboard for games and experiments in Laravel. Finally, the host invites viewers to explore more about the AI SDK on levelai.com, and to share what they’ll build next.

Key Takeaways

  • Create a dedicated agent with PHP artisan make:agent and name it DD Master to encapsulate game rules and persona.
  • Configure the agent with explicit instructions (e.g., track health, provide 2-3 choices, 5–10 turns) so the AI behaves as a dungeon master.
  • Use Laravel remembers conversation (with migrations) to maintain context across turns, avoiding resets between prompts.
  • Ensure a user exists in the database for ongoing conversations; tie the agent to that user for continuity.
  • Test locally via a tinker session or a custom Artisan command (AI test) to simulate game turns and prompts.
  • Leverage a custom terminal UI (dungeon play) to render health, inventory, and turn-based actions for a nicer player experience.
  • The AI SDK is versatile beyond chatbots, enabling games, experiments, and rapid prototypes with Laravel.

Who Is This For?

Laravel developers curious about adding AI-driven interactivity or games to their apps, and anyone exploring the Level AI SDK for rapid prototyping in a PHP/Laravel environment.

Notable Quotes

"You are a dungeon master for the escape artisan. This our game, a textbased dungeon escape game. The player is an artisan trapped in a mysterious dungeon."
Shows the core role and game setup given to the AI agent.
"Always give two to three clear choices at the end of each turn."
Highlights a concrete game rule embedded in the agent’s instruction.
"If health reaches zero the game is over."
Stakes the gameplay mechanic directly into the agent's behavior.
"Remembered conversation. Laravel is doing all of that for you."
Explains how memory across turns is handled by the framework.
"A fully playable dungeon game built with just a few lines of code and the level AI SDK."
Summarizes the wow-factor of the prototype.

Questions This Video Answers

  • How do you build a text-based terminal game with Laravel and the AI SDK?
  • What is a DD Master agent in Level AI SDK and how do you configure it?
  • How can I maintain conversation history in Laravel when using AI prompts?
  • What steps are required to test an AI-driven game locally with Laravel Tinker?
  • Can the Level AI SDK be used for games beyond chatbots in Laravel?
Laravel AI SDKLevel AI SDKDD Master agentconversational memoryLaravel remember conversationartisan make:agenttinkerconsole commandsterminal UItext-based games
Full Transcript
You awake on cold stone. The air smells of rust and forgotten magic. The last thing you remember, accepting the mysterious commission, not as only darkness and the sound of something breathing. This is not your typical level tutorial because today we're building something different. text base dungeon escape game right in the terminal using the level AI SDK and we're going to turn an AI model into a dungeon master and it will track your health, your inventory and of course it will try to kill you. Let's build it. All right, so let's get this started. So we're going to create a little game here step by step. Um this won't be an introduction to the AI SDK. We have a dedicated video and stream with Taylor and Josh about what it is and how you can use it. So this will be just a way of how you can use it in order to create this little game that I have prepared here. So let's see if we can make this work. Again, if you want to learn more about the AI SDK, come here to the website.com/ai where we have all the information about our tools, the AI SDK boost and our MCP server. And here you can find also the documentation of our label AI SDK. Okay, but back to our project here. First, we're going to start by creating an agent and we're going to do this by PHP artisan make agent similar to a lot of other files we can generate with artisan. And now what should the agent be named? So an agent in level AIDK world is a PHP class that holds all the information about a specialized assistant. So for example, if you want to create a support bot, you create an support agent and then you provide all information that you need in order to make the AI model that you're going to use a specialized version of this sales coach of this support type or of this game instructor like what we are going to do here. So we're going to call this DD master here. Will your agent general structure output? So in our case, we're going to say no, but later we're going to need this. So if we say no, we're just getting back messages and not structure output like a JSON or array and so on. Okay, here we go. Let's open this up our new DD master agent. So this is what the default class looks like. First, we have some instruction. So this is what we're going to share with the a model so that it has an idea of what it should do and how it should behave. And of course, I've prepared something here already. So, you are a dungeon master for the escape artisan. This our game, a textbased dungeon escape game. The player is an artisan trapped in a mysterious dungeon. Guide them through rooms, puzzle, and encounters as they try to escape. Rules: Describe scenes vividly but concisely. Track player health. Always give two to three clear choices at the end of each turn. game should last five to 10 turns and if health reaches zero the game is over. Okay, so far so good. Then we have some messages. We're going to talk about those a little bit later and also tools. Okay, cool. So now we've set up this agent. So how are we going to give this a try and use it? So if you want to create some kind of conversation here, we probably would need a custom UI which you have to build yourself in order to use this agent in the customized way that you want to. But I found there are two cool ways in order to test this locally. First, you can do this inside a route. Just create an agent prompt and response um dump out there and you see the response. But also what you can do is what I like to do is inside tinker wall. I'm going to do this there because that's also very nice and I don't have to mess with my routes. So I'm creating here a new DD master agent here and then I'm going to return um this should be a string response equals to our agent prompt and then we provide our message I am ready for the game. I think this should be it. I have already set up an API key for entropic in this case but you can use any of the providers that the level AISDK supports a lot of them. So, if I refresh this. All right, it's already loading. So, let's see what we get back here. And here we are. Escape Ardisan. You awaken on cold stone, head throbbing. The last thing you remember is examining an ancient tapestry in the merchants hall. Then, darkness. I like it already. Your eyes adjust to the dim torch light. You are in a cramped cell with them walls covered in moss. Your artisan tools are gone. Save for a small chisel that somehow remained in your boot. Oh, this is looking good. We have our health. We have our inventory. And now we have some options to choose from. What do you do? And yeah, of course, we can now reply here. So, we can just test this one way. So I think there's one cool way how you can test this very easily inside your application locally. So let me show you back in here. I'm going to create a new console command here with level ID in PHPtorm and I'm going to call this AI test command. So the idea is that we create a command, an artisan command that we can run where we can have a basic conversation here with our agent in order to see if it's working as we want to because later of course you need to build your custom chat or use case UI how you're going to use this but for now I think this is a good idea and it's not very difficult. So first we'll create our agent for our DD master with the make method. Yes. And now we're providing here a loop. So we have a message which we get by using the text prompt helper in lava. We're just calling this u. So this is what we input into the application and then we're going to get a response by using our agent prompt and then the message and then we're just going to info out here the response like this. Okay, I think this should already be enough. Let's add no return return type here. And I think we're good to go. Let's try this out. PHP artisan AI test. Okay, I am ready for the game. Let's see if this is working. Okay, we got something back here. Yeah, very similar to before it looks like. Of course, a very fun thing about using AI as this dungeon master. And by the way, I'm not super familiar with the DD world. So if I get anything wrong, any terms, I'm sorry. I'm just trying this out here. I think it's a good idea. Just let me know what I what I did wrong. So, but yeah, in this case, we're using AI as our dungeon master. So, this means every game that we try to start again will be a little bit different, which I think is really cool. So, again, here the beginning is very similar. Cold stone floor presses against your cheek as your conscious returns. Oh my god, this is super exciting. And we get this bag. And now the idea is at the end we have an input again because our loop is still going. What do you do? I go with option one here. So let's see if this conversation is already working. And it is not. Let's see why. AI provider is overloaded. That's really a lot of fun while you do some recording. Okay, we got a response back. Let's take a look. And you can see it looks like it's starting again from scratch. H why is that? Let's take a look. So inside our agent here, the the D master, we are using here the conversational interface. That's why we also have this messages here, but we're not providing them. So if you want to have the conversation going with the AI knowing about your conversation, the messages from before, you have to feed it here. So one way would be to load all of them from the database here and provide them here inside this message method. But there is an easier way to do this through a trade which is called remembers conversation. So now Laravel is doing all of that for yourself. So you have to make sure that you run the migrations that came with the level EI SDK so that you have the tables which I have already done. I've run them already and you need to get rid of this here because this is now overriding that the messages would be provided to the conversation. So if I remove this now it should work. Let's give it another try using option one here again. And now with a little bit of luck we should see that this game this conversation is now ongoing. And let's take a look. H, it's still not working. So why is that? So there's another thing that you have to remember. Let's close this here. So let's go back to our command here. So if you have a conversation going, this is always tied to a specific user. So this means it's important here when we create a new agent that in this case we're going to do this for a specific user. And we're just grabbing the first one here. So make you have to make sure that you have a user inside the database. And now for our example, this should be fine. So let's try this out again. I'm ready for the game. So now it should really work. Let's take a look. Okay, I'm going with option one here. Search the cell. And now let's take a look. Searching the cell. Yeah. So you can see it's working. Now we're moving on. You kneel and you run your practice artisan hands along the rough stone floor walls looking for anything to use behind the loose stone near the back corner. you fine. Oh my god, this is working and I can move on and now use the next steps. Provide the next clues here, my next um orders here what I want to do and the game already works. And you don't have to stop here. Of course, this is not ready. There are a lot of things how we can improve this game. So maybe we can tweak the prompt to make it even better. We can think about do we want to show the conversation maybe on a website a nice chat UI where we can show this or maybe do we want to create a nice terminal game. Hm. Did I do that with a little bit of help from my friend OPUS? Let's take a look. PHP artisan dungeon play. And here we go. Here's a little escape artisan game where we have a way nicer UI here. There's a lot you can do these days with tuis. So there's a lot you can do in the terminal. I have a lot of nice team members who can tell me a lot about them. And now look at this. We have here a little image here. We have um where we are currently. We have the text here. We have some nice UI with my hearts, my health, and my inventor the turn and what I want to do. So, how cool is this? And as you can see, we didn't do that much in order to make the PR basic prototype work. And I just use a little bit of work and AI in order to make this look nice as well. And that's just it. A fully playable dungeon game built with just a few lines of code and the level AI SDK. So, this SDK and AI is not just for chatbots, for content generation, or summarizing something. You can get really creative with those things as well. build games, experiments, whatever. And also, by the way, this is also a fun way how you can learn the level AI SDK. So, please give it a look, like and subscribe this video if you liked it. And please check out the level AI SDK and let me know what you are going to build with it. Bye. The dungeon claimed another soul, not with fire, not with magic, but with a missing semicolon. On line 47,

Get daily recaps from
Laravel

AI-powered summaries delivered to your inbox. Save hours every week while staying fully informed.