Stop Your AI Agent from Guessing - Ship AI with Laravel EP3

Laravel News| 00:12:21|Apr 9, 2026
Chapters13
The chapter highlights the limitation of chatbots that can only talk but not access data, showing how they would have to fabricate responses about orders. It then introduces giving agents real tools to look up orders and customer data.

Give your AI support agent real data access with Laravel tools, so it can look up orders and customer history instead of guessing.

Summary

Laravel News’s Harris demonstrates turning a talking AI agent into a data-powered assistant by adding tangible tools. Instead of guessing, the agent now calls PHP classes (tools) that query the database for orders and customer history. The video walks through creating two tools—order lookup and customer history—defining their descriptions, schemas, and handle methods, and wiring them into the agent’s decision flow. You’ll see concrete steps: artisan make tool, building an Order model with relationships, and seeding test data including order 1042. Harris also explains guiding prompts (tool usage rules) and how to cap steps to control API usage (max steps = five). The result is an agent that returns real order data (status, total, shipping) and customer history instead of fabricating details. The proof-of-concept is tested in Tinkerwell with a sample order number and then with a customer email, showing the agent extracting and presenting precise data. The session ends with tips on limiting tool calls and hints at future memory and multi-turn capabilities. Overall, it’s a hands-on roadmap for shipping AI with Laravel using robust data contracts and tooling.

Key Takeaways

  • Two Laravel tools were added: order lookup (returns order status, total, and shipping info) and customer history (last five orders by email).
  • The order lookup tool schema uses an integer order_id as a required parameter and queries the Order model with its associated User data.
  • A full Order model and migrations were created (foreign user_id, status string, total decimal) and relationships defined (User hasMany Orders; Order belongsTo User).
  • The AI prompt was updated with explicit tool usage guidelines: use order lookup when a customer mentions an order number, use customer history when a customer provides an email.
  • Max steps for the agent were suggested to cap API usage, with a default of five steps.
  • Test data included a seeded order 1042 and a customer named Sara to demonstrate real responses instead of guessing.
  • The process demonstrates a clear separation between AI-generated text and live data, reducing hallucinations and improving accuracy.

Who Is This For?

Laravel developers and AI engineers who want to ship chatty AI agents that actually query live data instead of guessing, with concrete tooling and prompts to prevent hallucinations.

Notable Quotes

"Tools fix this."
Intro line highlighting that giving tools to the AI makes it capable of looking up real data.
"The schema down here again defines the parameters and the handle method is what runs when the tool gets called."
Explains how a tool communicates with the AI via schema and execution.
"The agent decides when to use them."
Key idea: tool usage is driven by the agent, not hard-coded prompts.
"Max steps is going to be five."
Practical constraint to control API budget and flow.

Questions This Video Answers

  • How do I wire Laravel tools to an AI agent so it can fetch live order data?
  • What is a practical way to prevent an AI assistant from guessing in Laravel apps?
  • How do I implement a tool contract in Laravel for AI-driven customer support?
  • How can I cap an AI agent's tool calls with a max steps limit in Laravel?
LaravelPHPAI dialog systemsTools contractDatabase toolingArtisan commandsTinkerwellSeeded data
Full Transcript
Our support agent can talk to customers but it can't do anything. Ask it about an order and it has to make something up. No database access yet. So as you can see in our example here we try to ask for the order 1042 and it says I'm happy to help check on order 1042. I don't have direct access to all the systems here but if you share either and then it goes forth and goes on. If you already have a tracking number, send it over and I can help you interpret the last status. If needed, a human agent can follow up with the exact shipment details. That's not what we need though. I'm Harris from Lar News. Today, we're giving our agents real tools to look up orders and customer data. Let's get right to it. So, right now, our support agent has instructions and can generate responses. You can see the prompt here, but it's completely disconnected from our application data. customer asks about the order and the agent has no way to check that out. Tools fix this. There are PHP classes the AI can call during a conversation. We define that each tool does what parameters it accepts and the agent decides when to use them. So what we pretty much have in this case is we get the customer message, we give it to the agent, the agent decides which tool to use, the tool queries the database, and then the agent uses the result in the response. Pretty straightforward. Let's build this. Let's scaffold our first tool. Let's go back to our terminal down here. Let's run PHP artisan make tool. And then we call this order lookup. Let's open this up in our editor order lookup. So you can see that it implements this tool contract. We have the description again. We have the handle method and we also have the schema definition down here. For the description, if you're not familiar with that, it tells the AI what this tool does. That's how the agent decides whether to use it or not. The schema down here again defines the parameters and the handle method is what runs when the tool gets called. Let's fill this in. Let's start with a description. So what do we want in this case? We want to look up an order by its order number and returns order status, total items. And we also want the shipping information. Perfect. You need to be specific. The better the description is, the better the agent knows when to reach for this tool. Next, let's go down to our schema. For our parameters, we really want the order ID. In this case, schema, which is an integer, of course. The description will be that the order number to look up because this is what we have in this case and we obviously need this to be required. So we just need the order ID. The agent extracts from the customer message on its own. Now the handle method. This is where we hit the database. Now before we write the handle method, we need an order model for it to query. Let's create that quickly. Let's go back to our terminal. Artisan make model order. We're going to create the migration and the factory as well. Let's go back. Let's open up our migration. And what do we need? We need of course to say that the ID is a foreign ID of user ID. And we also have a constraint. And let's cascade on delete. We also want this to have status. This is string. And let's also add a total which is going to be a decimal. I believe that's enough. Let's go back to order model. Let's set the fillables. So it's going to be our user ID status total. And let's have some relationships here. So start with users. So user which is going to be a belongs to relationship. So belongs to and then we have the user class. Now let's go and do the inverse. Let's go into our user. Scroll down and add public function orders. This is a has many of course. So return this has many order plus. And now we are done. Let's run our migration. So some PHP doesn't migrate. Migration is done. So, we'll see test data after we finish both tools. Now, back to the handle method. Let's go back to our order lookup here. And let's start typing. This is where we hit the database. So, order equals order with user because we need the user as well. Now, let's find specific order ID. If we don't get any orders for any reason, let's return order not found. But if we did find the order, then we just return JSON and code, which is going to be an array in this case. And in our array, we're going to have the order ID because we are going to use that with the user status. Last but not least, we're going to have the customer name. It's going to be order user name. So we find the order, we return the data as JSON and the agent uses this to craft its response. And if there is no order, we just return a simple message and the agent tells the customer that they didn't find the order. One tool is good, but let's give the agent a bit more context, right? A second tool that pulls up a customer's recent order history. Let's go back to our terminal. Let's create a new tool. So, PHP art design make tool. See how easy it is to create those tools. Customer history is going to be this one. Let's go back. Open customer history. And what will the description be in this case? Now, we're going to say that look up a customer's recent order history by their email address orders. Let's go down to our schema and schema definition. In this case, we only include the email. So, schema string description will be the customer's email address. And let's add this as required. And you can obviously come here and make it more pretty if you want. Let's do that. Nice. It takes an email, finds the customer, returns the last five orders. Now the most crucial part is to implement the handle method to get. Let's go up here. Let's find the user. So user where email and let's get the first user that we find. Again let's add a safeguard. So if there is no user customer not found but if there is a user then let's get the last five orders. So, user orders, let's get the latest ones, take five out of them. Let's get them out. And let's map this out. So, what we're going to do here is we're going to since we have the order, we're going to use the order ID. That's what we need. Then we have the status total a stat. It's going to be the created ads timestamp but more nicely visualized. And that's it, I believe. So, let's close this down and return again the JSON and code. It's going to be an array. We got the customer name, the email, the total orders, and the recent order as well. Now, let's go back to our support agent now. And now, we tell the support agent about these tools. we add has tools and the tools method. So let's go up here and we don't only need an agent now but we have this thing called has tools this interface. Let's import that of course. And now let's scroll down and add a new method which is going to be called tools. It's that easy. This is going to return us it. So we have two tools in this case right? So the order lookup tool and we also need the customer history tool. So an array of two tools and last but not least we would like to update our guidelines of course to accept for all this. I'm going to copy and paste the already defined prompt and we can discuss this together. Let's go here paste the new prompt and let's discuss this now. As you can see when a customer mentions an order number use the order lookup tool to get real data. When a customer provides their email, use a customer history tool for context. Now, our prompt tells our AI to use those specific tools in order to get the right data out. So, we also updated the instructions to tell the agent exactly when to use those tools. Before we test, we need orders in the database. So, I've already seeded mine with test data, including an order 1042 and a customer named Sara with a few orders. So the cedar and the factory are in the GitHub repo if you want to do the exact same thing with exact same data. Let's test now. I'll prompt the agent directly. Let's go to Tinkerwell for that. And we're going to use this exact prompt. We're going to use our support agent and we're going to say, "Hi, can you check on my order 1042? It was supposed to arrive yesterday." And then we're going to get back the text. Let's see what this gives us. I checked order 1042. It's currently marked as a ship and was placed on 26th of March. I'm sorry it didn't arrive when expected. I'm not seeing delivery details from this lookup. So, the best next step is for a human support agent to review the shipment status and carrier tracking in more details. If you want, I can also help you draft a message for support. Or if you have the shipping email tracking number, send it here and I will help the credit. So, the agent looked up order 1042 from our database with real status, real total, and real date. And we didn't guess this time. That's pretty cool. So, let's try one with an email. I'm going to change my prompt. And this time, I will say, "Hi, my email is sacample.com. I think I was charged twice on my recent orders." Let's run this. Now, we provided the email. So, we should be proing the second tool. Hi, Sara. I'm sorry to hear that. I can help you look into it. I found your five most recent orders and then we'll list some orders here. Could you tell me which order looks like the one with the duplicate charge? If you're not sure, let me know. The amount that was charged twice or the last four dieses of the card. Once I have the order number, I can check the order details and help with next steps. The agent pulled Sara's order history, found potential duplicate, and gave a specific response with actual order numbers and amounts. So go back to our support agent. I have a quick tip for you. By default, the agent can call tools as many times as needed. So to limit that, you can use max steps. Let's go up here and right above max tokens. Let's do max steps. And let's say that the maximum number of steps is going to be five. So, five steps is a good default, enough to look up an order and pull customer history, but it won't burn through your API budget on a single request, and that's what we want to aim for. Our support agent went from a chatbot that can only talk to an assistant that can look things up. Tools connect the AI to your data, and the agents decide when to use them. Next time we're adding conversation memory multi-turn ts where the agents remembers everything discussed so far.

Get daily recaps from
Laravel News

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