Give Your Laravel AI Agent Live Web Search with WebSearch Tool
Laravel AI #Laravel #AI Agent #WebSearch #PHP #OpenAI #Support Bot

Give Your Laravel AI Agent Live Web Search with WebSearch Tool

3 min read Mohamed Said Mohamed Said

Why Your AI Agent Needs Live Web Access

A well-built Laravel AI support agent can query order history, search a knowledge base, and hold multi-turn conversations. But the moment a customer asks "Is FedEx experiencing delays right now?", a static knowledge base falls flat. Shipping carrier statuses, outage pages, and real-time availability change by the minute — and training data can be months stale.

Episode 8 of the Ship AI with Laravel series solves this by wiring the agent into the live web using the SDK's built-in provider tools.

The Two Provider Tools: WebSearch and WebFetch

The Laravel AI SDK ships with two provider-level tools:

  • WebSearch — queries the web and returns a ranked list of results.
  • WebFetch — fetches and reads a specific URL's content.

Note: WebFetch is currently supported on Anthropic and Gemini only. Because this series runs on OpenAI, WebSearch is the right choice and handles the use case well.

Adding WebSearch to the Support Agent

The integration involves three decisions:

  1. Cap the result count. The example limits results to five to keep context concise and costs predictable.
  2. Define an allow list. Restrict the domains the agent may search. Without this, the agent could browse anywhere on the internet and return unvetted content to customers.
  3. Update the system instructions. Tell the agent to be transparent about the source of its answer — distinguishing between your official policy and something retrieved from the live web.

A simplified configuration looks like this:

WebSearch::make()
    ->maxResults(5)
    ->allowedDomains([
        'fedex.com',
        'ups.com',
        'usps.com',
    ])

The provider handles the actual HTTP requests and ranking; your code only declares the constraints.

Testing Real-World Queries

With WebSearch active, the agent handles two scenarios that previously produced unhelpful responses:

  • FedEx delay check — the agent queries both the order record and FedEx's live status page, then synthesises a single answer.
  • USPS Priority Mail transit time — instead of guessing from potentially outdated training data, the agent returns the current published estimate.

You can also bias results by geographic region if your customer base is concentrated in a specific area, giving locally relevant answers without extra application logic.

The Agent's Full Tool Set (After Episode 8)

At this point the support agent has five tools available:

  • Order lookup
  • Customer history
  • Knowledge base search
  • Document search
  • Live web search

It can now answer from your database, your internal documentation, and the live web — covering the full spectrum from structured business data to real-time external information.

Key Takeaways

  • Use the SDK's WebSearch provider tool to give a Laravel AI agent access to live web results.
  • Always define an allowedDomains list — leaving it open lets the agent retrieve and surface arbitrary web content.
  • Cap maxResults to control context size and inference cost.
  • Update system instructions so the agent cites whether an answer comes from internal policy or a live web source.
  • WebFetch (for reading a specific URL) is currently limited to Anthropic and Gemini; OpenAI users should rely on WebSearch.
  • Location biasing is available when your users are concentrated in a specific region.

Source: Ship AI with Laravel: Give Your AI Agent Live Web Search — Laravel News, June 18, 2026

Found this useful?

Frequently Asked Questions

3 questions
Q01 Why is the domain allow list required when using WebSearch in a Laravel AI agent?
Without an allow list, the agent can browse any website and return unvetted content directly to customers. Restricting allowed domains ensures the agent only retrieves information from trusted sources, such as official carrier status pages.
Q02 Can I use WebFetch instead of WebSearch with OpenAI in Laravel?
No. WebFetch is currently supported only on Anthropic and Gemini providers. If your Laravel AI project runs on OpenAI, you should use WebSearch, which covers the same real-time lookup use case.
Q03 How do I limit the number of web results returned by the WebSearch tool?
Pass a maxResults value when configuring the tool — for example, setting it to 5. This keeps the context window concise and helps control inference costs.

Continue reading

More Articles

View all