Laravel Tutorials

Ship AI with Laravel: Give Your AI Agent Live Web Search

Published

▶️ Watch the video tutorial (8 minutes)

Our agent can look up orders, search the knowledge base, and hold real conversations. But ask it "is FedEx having delays right now?" and it has nothing useful to say. Our knowledge base covers our policies, not things that change by the minute. Shipping carrier delays, current product availability, outage pages. The agent either guesses or admits it doesn't know.

In this episode we fix that by giving the agent access to the live web. The SDK ships with two provider tools: WebSearch to find information online and WebFetch to read a specific page. The provider handles the actual searching, so we just configure which domains to allow and how many results to return.

I add WebSearch to the support agent, cap it at five results, and lock the allow list down to shipping carriers. That allow list is the part you don't skip. Without it the agent could browse anywhere on the internet and hand whatever it finds back to a customer. I also update the instructions so the agent stays transparent about where its answer came from, our official policy versus something it pulled off the web.

Then I test it. I ask about an order that shipped via FedEx with no tracking update, and the agent checks both the order and FedEx's status. I ask how long USPS Priority Mail takes, and it returns the current answer instead of guessing from training data that might be months old. I also show how to bias results by location if your customers are in a specific region.

One note: WebFetch is currently supported on Anthropic and Gemini. Since this series runs on OpenAI, we stick with WebSearch, which handles the use case fine.

That gives the agent five tools: order lookup, customer history, knowledge base search, document search, and now live web search. It can answer from our database, our documentation, and the live web.

Next episode we add the production infrastructure. Queued responses, provider failover, and middleware for logging and rate limiting. The stuff that keeps this running at 2am when you're asleep.

⭐ GitHub: https://github.com/harris21/ship-ai-with-laravel

▶️ Watch Episode 8 now →

Harris Raftopoulos photo

Senior Software Engineer • Staff & Educator @ Laravel News • Co-organizer @ Laravel Greece Meetup

Sponsored

masteringlaravel logo
Laravel Code Review

Get expert guidance in a few days with a Laravel code review

Visit Laravel Code Review

The latest

View all →
Laravel Rulebook: Business Rules That Change by Date image

Laravel Rulebook: Business Rules That Change by Date

Read article
Taylor disabled GitHub Issues on most Laravel open-source packages. image

Taylor disabled GitHub Issues on most Laravel open-source packages.

Read article
Exclude Vendor and Default Commands in `php artisan dev` image

Exclude Vendor and Default Commands in `php artisan dev`

Read article
The Laracon Archive image

The Laracon Archive

Read article
Group Adjacent Collection Items in Laravel with chunkBy() image

Group Adjacent Collection Items in Laravel with chunkBy()

Read article
Laravel queue:work Now Prints Why the Worker Stopped image

Laravel queue:work Now Prints Why the Worker Stopped

Read article