Give Your AI Agent Live Web Search - Ship AI with Laravel EP8
Chapters15
The chapter explains the limitation of static knowledge bases when questions require up-to-the-minute information, highlighting the need for real-time data access beyond traditional FAQs.
Laravel News shows how to empower an AI agent with live web search (FedEx, USPS, UPS) to fetch real-time data and reduce guesswork.
Summary
Harris from Laravel News demonstrates adding live web search to a support agent built with the Laravel AI SDK. The key idea is to query current information for time-sensitive questions the knowledge base can’t cover, like carrier delays or outage pages. Web search is configured to a maximum of five results per query, and domains are restricted to FedEx.com, UPS.com, and USPS.com to avoid pulling in irrelevant sources. Web fetch is introduced as a way to read full pages, but the example sticks with web search since OpenAI is being used in this video. The presenter guides viewers through updating the routes and prompts to incorporate the new web tools, and he emphasizes clearly distinguishing information from the knowledge base versus external web results. He also demonstrates a live test route (support web test) to verify the agent can pull current data and even asks a generic question like “How long does USPS priority mail usually take to arrive?” to show real-time results. A location bias feature is highlighted, allowing results to be prioritized for the US, which is useful for region-specific carriers or service pages. Finally, the video reinforces the importance of an allow list to prevent the agent from browsing the entire internet, and it teases future steps like production infrastructure, cued responses, and middleware for logging and rate limiting.
Key Takeaways
- Web search is configured with a hard cap of five results per search to keep responses fast and relevant.
- Allowed domains are restricted to FedEx.com, UPS.com, and USPS.com to prevent navigation to unrelated sites.
- Location bias can be set (e.g., US) to tailor results for region-specific carriers or services.
- Web fetch exists as a companion tool, but the current setup uses web search due to the chosen provider (OpenAI).
- An explicit allow list is essential to prevent the agent from wandering the entire web and returning dubious results.
- The new web tools (web search, web fetch) are added alongside existing tools like order lookup, customer history, and knowledge-base search.
- Live tests show real-time data can override stale training data, reducing hallucinations for time-sensitive questions.
Who Is This For?
Essential viewing for Laravel developers who want to add live web search capabilities to their AI agents, especially for customer support scenarios that require up-to-date information.
Notable Quotes
"Our support agent can look up orders, search our knowledge base, and hold real conversations now."
—Introduction to the agent’s capabilities before introducing live web search.
"We will be using web searchs and web fetss that Laravel AI SDK gives us access to."
—Opening the core feature: enabling live web search and fetch.
"The thing that matters the most in this case is the last line clearly distinguish between our policies for from the knowledge base and external information from web search."
—Emphasizing source transparency between internal knowledge and web results.
"So web search lets the agent search the web like a user would."
—Explaining how the web search capability works at a high level.
"Without the allow list, your agent can browse anywhere on the internet and return whatever it finds to your customer, which is not ideal."
—Warning about the need for domain restrictions to prevent unwanted browsing.
Questions This Video Answers
- How do I add live web search to a Laravel AI agent using the Laravel AI SDK?
- Can I restrict a web search to specific domains like FedEx, USPS, and UPS for real-time support data?
- What are best practices for biasing web search results by location in a customer support bot?
- How does web fetch differ from web search in Laravel AI integrations, and when should you use each?
- How can I test a Laravel AI route that includes web search to ensure it returns current information?
Full Transcript
Our support agent can look up orders, search our knowledge base, and hold real conversations now. But when a customer asks, "Is FedEx experiencing delays right now?" For example, the agent has nothing. Our knowledge base doesn't cover things that change by the minute. So, take a look at this code right here. We will now be using web searchs and web fetss that Laravel AI SDK gives us access to. I'm Harris from LA News and today we're giving our agent access to the live web so it can find realtime information when our internal data falls short. Let's get right to it.
Think about the questions our knowledge base can't answer. Shipping carrier delays current product availability outage status pages maybe anything that changes in real time right now the agent either hallucinates or says I don't know. SDK though sips with two provider tools for this. One is web search to find information on the web and web fetch to read specific pages. The AI provider in this case handles the actual searching and fetching. So we just configure which domains to allow and how many results to return. Let's add them right now. Let's go now to our support as file.
Let's scroll down to the tools we have. So up until now we have order lookup, customer history, similarity search, and file search. And the next thing we're going to add now is the web search. So let's go ahead and do that right now. So down here, let's go ahead and say that new web searchs and import that at the top. Then let's say that we need a maximum of five. And the maximum here in this case is the maximum number of searches it can do. So let's set this to five. So we don't have too many services in one go.
And the next thing is we will allow some specific domains. So the first one will be like we mentioned FedEx.com. Then the next one is going to be UPS and last but not least uspbs.com. I think these are enough for now. Save. Let's beautify this a bit. Let's give them each one their own new line. And we're ready. So web search lets the agent search the web like a user would max set to five. In this case we set a limit to five results per search. Then we have the allow. And what this does it restricts which domains agent can hit.
You don't want to support agent browsing random websites. So we lock this down to shipping carriers only. So the SDK also has web fetch, a tool that lets the agent read the full content of a specific URL that's supported on a thropping a Gemini at the moment of this video. Since we're using OpenAI, we'll stick to web search for now, which covers this use case. Let's also update the instructions so the asen knows when to reach the web searchs. Let's go up here in our instructions prompt and let's switch that for the new one. So copy that and paste it right here and let's discuss this.
The thing that matters the most in this case is the last line clearly distinguish between our policies for from the knowledge base and external information from web search. This last line matters a lot. We want the agent to be transparent about where its information comes from. Right? So our official policies versus something it found on the web that you don't really know if it's actually correct or not. Here you have the complete support agent in this case. You can take a look post the video or you can find all the files in our GitHub repository posted in the link below.
Let's see this in action now. So let's go back to our routes file. Scroll down right around here. After chat we're going to add a new route and it's going to be a get request. So route get let's call this one support web test. Let's add our closure. And what do we have in our closure in this case? First we want to get agent which is going to be new support agent. Of course the next thing is we need to get the user. So the user let's get the first user just for the sake of this example.
So user first and then let's have a response. Now we're going to call we're going to call the prompt from our agent. So response will be agent for user and then we pass the user. Of course the prompt will be this. My order 1042 shipped for via FedEx 3 days ago but the tracking hasn't updated. Is FedEx having any issues right now? Let's pull this down here so we can see it better. Perfect. We are ready. And now let's do a return. And here we are going to return response text. And I think we're ready.
Let's fix this for user here. Nice. Let's go now into our route file and let's visit support web test. And we got the result back. I'm sorry about the lack of updates. I'd check your order 1042 and it does so as shipped from our side. As for FedEx, I found official FedEx pages indicating the delays can happen due to operational local or weather related issues, but I did not find a clear current US service alert page in the results confirming widespread active outits right now. Okay, now we have actually a really cool way to check if the postal services are down or not.
How cool is this? Let's go back to our file here to rare route file and instead of this prompt, let's move that out and let's try a very generic search. So, how long does USPS priority mail usually take to arrive? Again, let's go back, refresh, and let's see the result. USPS priority mail usually takes two to three days to arrive according to USPS. Nice. So now we're actually using the search, the online search with real current information instead of guessing from training data that could be all right in some months from now. One more thing, if your customers are in a specific region, you can bias search results with a location.
Let's see how we can do that. Let's go back to our Z editor and let's move back to support agent. And down here what we could add is under allow we can add location and here we can say which country made. So let's say we want only to check for the US location. So US it's as easy as that. So location biases results towards a specific country. It's very useful if you're shipping carriers or service pages differ by region. Before we wrap up, let's talk about the allow list. This is not optional. Without it, your agent can browse anywhere on the internet and return whatever it finds to your customer, which is not ideal always, right?
So, we have two things we need to take into account always. The first one is the max number of searches. If we switch this to something like 10, for example, your agent can search anywhere. So, refrain from doing that. And also make sure you add your allow list down here in order to contain where your search agent is going to take effect. Our support agent now has five tools. Order lookup, customer history, knowledgebased search, document search, and web search. It can answer questions from our database, our knowledge base and live web that covers most of what real support agent needs dayto-day.
So next time we are adding the production infrastructure, cued responses, provider failover, and middleware for logging and rate limiting. The stuff that keeps this running at 2 in the morning when you're asleep. See you in the next
More from Laravel News
Get daily recaps from
Laravel News
AI-powered summaries delivered to your inbox. Save hours every week while staying fully informed.









