How to Add Real-Time Web Search to LlamaIndex Agents
Learn how to add real-time web search to LlamaIndex agents. This guide covers web search tools, structured search results, source filtering, country and language settings, RAG workflows, SDK and MCP integration, and TalorData use cases.
LlamaIndex agents are useful when you want an AI application to reason, use tools, retrieve context, and answer user questions with more than just model memory.
But there is one common problem.
Many questions require fresh web information.
A user may ask about today’s product prices, recent company news, competitor rankings, search results, policy updates, new product launches, or public web changes. If the agent only relies on a static knowledge base, it may miss recent information.
That is where real-time web search becomes useful.
By adding a web search tool to a LlamaIndex agent, you can let the agent search the web when fresh information is needed, extract structured results, select relevant sources, and use those results in its final answer.
A practical workflow looks like this:
User question
↓
LlamaIndex agent
↓
Real-time web search tool
↓
Structured search results
↓
Source filtering
↓
Answer with fresh web context
This guide explains how to add real-time web search to LlamaIndex agents, what data to return, how to design the search tool, and how TalorData can support this workflow.
Why Add Real-Time Web Search to LlamaIndex Agents?
A normal LlamaIndex agent can work well with internal documents, knowledge bases, and predefined tools.
But many real business questions depend on live or recently updated web data.
Examples:
| User Question | Why Real-Time Search Helps |
| What are the latest pricing changes in this market? | Prices may change frequently |
| Which competitors launched new products this month? | Product launches are time-sensitive |
| What sources are ranking for this keyword today? | Search results change over time |
| What are people saying about this brand recently? | Public web content changes quickly |
| Which pages should we use for this research task? | Source discovery requires fresh search |
| What changed in this policy or documentation? | Static knowledge may be outdated |
Without real-time search, the agent can only answer from its existing context.
With real-time search, the agent can decide when to retrieve fresh web data before answering.
The goal is not to make the agent search for everything.
The goal is to give it a reliable search tool when the question depends on fresh external information.
What Should a Web Search Tool Do?
A web search tool for a LlamaIndex agent should not simply return a wall of raw HTML.
That gives the model too much noise and too little structure.
A better web search tool should return clean, structured search results.
Useful fields include:
| Field | Why It Matters |
| Title | Helps the agent understand the result topic |
| URL | Shows the source page |
| Domain | Helps identify source origin |
| Snippet | Gives a short preview of the content |
| Position | Shows result order |
| Search engine | Useful for multi-engine workflows |
| Country | Useful for market-specific search |
| Language | Useful for localized answers |
| Device | Useful for SEO or SERP comparison |
| Collection time | Shows when the data was retrieved |
A simple result may look like this:
{
"position": 1,
"title": "2026 Market Report for Smart Home Devices",
"url": "https://www.example.com/smart-home-market-report",
"domain": "example.com",
"snippet": "A recent report covering market trends, major brands, product categories, and pricing changes.",
"collected_at": "2026-07-15T09:00:00Z"
}
This format is easier for an agent to read, filter, cite, summarize, and pass into a RAG workflow.
When Should the Agent Use Web Search?
Not every question needs web search.
The agent should use real-time search when the answer depends on current, public, or external information.
Good search triggers include:
| Trigger | Example |
| Freshness | latest, recent, today, this week, 2026 |
| Market research | competitors, pricing, market trends |
| Search visibility | rankings, SERP results, top pages |
| Source discovery | find sources, collect URLs, compare pages |
| Public web updates | policy changes, announcements, launches |
| Local or regional data | country-specific results, language-specific results |
| Product research | Shopping results, seller pages, product comparisons |
The agent may not need web search for:
| Question Type | Better Source |
| Internal policy question | Internal knowledge base |
| User account question | Internal database or API |
| Historical concept explanation | Existing indexed documents |
| Private company data | Approved internal source |
| Static documentation already indexed | Existing RAG index |
This separation matters.
A search tool should improve the answer, not turn every task into a slow internet treasure hunt.
A Simple LlamaIndex Web Search Architecture
A clean architecture usually has four parts:
| Layer | Role |
| Agent | Decides whether to call the search tool |
| Search tool | Collects structured web search results |
| Filtering layer | Selects relevant results and removes noise |
| Answer layer | Uses selected results to answer the user |
A practical flow:
User asks a question
↓
Agent checks whether fresh web data is needed
↓
Agent calls web_search(query, country, language, device)
↓
Search tool returns structured results
↓
Agent filters relevant titles, snippets, and URLs
↓
Agent answers with fresh source context
This keeps the system focused.
The search tool retrieves data.
The agent interprets the data.
The final answer uses only the results that are relevant to the user’s question.
Step 1: Define the Search Tool
Start by defining what the search tool should accept and return.
A simple search tool can accept:
| Parameter | Purpose |
| query | The search query |
| country | Target country or market |
| language | Search result language |
| device | Desktop or mobile |
| num_results | Number of results to return |
Example tool input:
{
"query": "latest smart home device market trends",
"country": "us",
"language": "en",
"device": "desktop",
"num_results": 10
}
Example tool output:
{
"query": "latest smart home device market trends",
"country": "us",
"language": "en",
"results": [
{
"position": 1,
"title": "Smart Home Device Market Trends 2026",
"url": "https://www.example.com/smart-home-trends",
"domain": "example.com",
"snippet": "Recent trends in smart home devices, including security, energy management, and connected appliances."
}
]
}
This makes the tool predictable.
Predictable tools are easier for agents to call and easier for developers to debug.
Step 2: Wrap Web Search as an Agent Tool
In LlamaIndex, an agent can use tools to perform external actions.
A web search function can be wrapped as a callable tool, then made available to the agent.
A conceptual Python example:
def web_search(query: str, country: str = "us", language: str = "en") -> dict:
"""
Search the public web and return structured results.
Use this tool when the user needs fresh public information,
recent market data, search result pages, or source discovery.
"""
results = search_api.search(
query=query,
country=country,
language=language,
device="desktop"
)
return {
"query": query,
"country": country,
"language": language,
"results": results
}
The important part is the tool description.
The agent needs to understand when to use the tool.
A weak description:
Search the web.
A better description:
Search the public web for fresh or recently updated information. Use this tool for current events, market research, competitor research, product pricing, search result analysis, source discovery, and questions that require up-to-date public web context.
Tool descriptions are not decoration.
They guide the agent’s decision-making.
Step 3: Keep Search Results Structured
Do not pass huge raw pages into the agent unless the task truly needs full page content.
For the first step, structured search results are usually enough.
A good search result object includes:
{
"position": 1,
"title": "Example Market Report",
"url": "https://www.example.com/report",
"domain": "example.com",
"snippet": "A short summary of the page content.",
"type": "organic",
"collected_at": "2026-07-15T09:00:00Z"
}
This helps the agent:
- Compare sources
- Select relevant URLs
- Understand search intent
- Identify source domains
- Avoid reading irrelevant pages
- Decide whether deeper crawling is needed
A useful rule:
Search first. Fetch full pages only when needed.
This keeps the workflow faster, cheaper, and easier to control.
Step 4: Add Source Filtering
Raw search results are not automatically useful.
The agent should filter results before using them.
Useful filtering rules include:
| Rule | Why It Helps |
| Remove irrelevant results | Reduces noise |
| Prefer authoritative domains | Improves source quality |
| Remove duplicate URLs | Avoids repeated context |
| Group by domain | Prevents one site from dominating |
| Keep top relevant results | Controls token usage |
| Store collection time | Preserves freshness context |
Example filtering logic:
Start with 10 search results.
Remove irrelevant results.
Remove duplicate URLs.
Group results by domain.
Keep the top 3 to 5 relevant sources.
Use those sources in the answer or RAG workflow.
This matters because search results are discovery data.
They are not automatically final evidence.
The agent should select sources before summarizing or answering.
Step 5: Decide When to Crawl Source Pages
Sometimes titles and snippets are enough.
Sometimes the agent needs full page content.
Use full page crawling when:
| Situation | Why Crawl |
| The user asks for detailed comparison | Snippets are too short |
| The answer needs exact claims | Full page context is needed |
| The agent must summarize a source | Page content is required |
| The source URL is important for RAG | The page should be indexed |
| The snippet is ambiguous | Full content reduces uncertainty |
A safe workflow:
Search web
↓
Select relevant source URLs
↓
Fetch selected pages
↓
Extract clean content
↓
Use extracted content as context
↓
Generate answer
This is better than blindly crawling every result.
The point is to collect enough context, not to feed the model the entire internet like a desperate buffet.
Step 6: Add Country and Language Settings
Real-time search becomes more useful when the agent can search by country and language.
For example, a market research agent may need different results for the United States, Germany, and Japan.
Useful settings include:
| Setting | Example |
| Country | us, gb, de, jp |
| Language | en, de, ja |
| Device | desktop, mobile |
| Result count | 10, 20, 50 |
| Time range | recent results when supported |
Example:
{
"query": "electric scooter price comparison",
"country": "de",
"language": "de",
"device": "desktop"
}
This allows the agent to answer market-specific questions.
Example user question:
Compare visible electric scooter sources in Germany and the United States.
The agent can run two searches:
Search 1: electric scooter price comparison, country = de, language = de
Search 2: electric scooter price comparison, country = us, language = en
Then it can compare source domains, titles, snippets, and ranking patterns.
Step 7: Use Search Results in RAG Workflows
Real-time web search can also support RAG pipelines.
A common pattern:
User question
↓
Agent searches the web
↓
Agent selects relevant source URLs
↓
System fetches or extracts selected pages
↓
Pages are added to temporary context or a vector index
↓
Agent answers using retrieved web context
This is useful for:
| Workflow | Example |
| Research assistant | Build a brief from recent web sources |
| Competitor research | Compare visible competitor pages |
| Market monitoring | Track new public updates |
| SEO assistant | Analyze search result titles and snippets |
| Product research | Collect product pages and seller sources |
| News monitoring | Summarize recent public updates |
Search results are good for discovery.
RAG is useful when the system needs deeper content from selected sources.
Do not confuse the two.
Search finds candidate sources.
RAG helps use the selected content.
Step 8: Store Search Logs and Snapshots
If your agent uses web search in production, store search logs.
Useful fields include:
| Field | Purpose |
| user_query | Original user question |
| search_query | Query sent to the search tool |
| country | Target country |
| language | Search language |
| results | Structured search results |
| selected_urls | URLs used in the final answer |
| collected_at | Search time |
| agent_decision | Why the agent searched |
| final_answer_id | Link to the generated answer |
This helps with:
- Debugging
- Evaluation
- Quality control
- Source review
- Cost tracking
- Repeatability
- Compliance review
A search-enabled agent should not be a black box.
If it searched, you should know what it searched, what it found, and what it used.
How TalorData Helps Add Real-Time Web Search to LlamaIndex Agents
TalorData can act as the structured web data layer for LlamaIndex agents.
Instead of building and maintaining search collection, crawling, parsing, cleaning, and structured extraction yourself, teams can use TalorData to provide real-time search and web data tools for agent workflows.
TalorData supports two practical integration paths:
| Integration Method | Best For |
| Python SDK | Fast prototypes, proof-of-concept projects, single-agent apps, local development |
| MCP Server | Production environments, multi-agent systems, shared tool access, team workflows |
A practical TalorData and LlamaIndex workflow looks like this:
User question
↓
LlamaIndex agent
↓
TalorData web search tool
↓
Structured search results
↓
Optional source crawling or extraction
↓
Fresh context for the agent
↓
Final answer, report, or RAG workflow
TalorData can support workflows such as:
| Workflow | How Real-Time Search Helps |
| Research assistant | Retrieve fresh public web results |
| Competitor research | Compare visible sources and pages |
| SEO assistant | Analyze search result titles, snippets, and URLs |
| Market monitoring | Track recent updates across public sources |
| Product research | Collect current product and seller pages |
| RAG Q&A | Add fresh source context beyond static indexes |
| Content assistant | Generate briefs from recent search results |
The main value is not just access to web data.
The value is giving the agent structured, reusable, and configurable web data that can be searched, filtered, logged, and used safely.
Final Thoughts
Adding real-time web search to LlamaIndex agents makes agents more useful for questions that depend on fresh public information.
The basic process is:
Define when the agent should search.
Create a structured web search tool.
Return titles, URLs, domains, snippets, and timestamps.
Filter relevant results.
Fetch source pages only when needed.
Use selected results in the answer or RAG workflow.
Log search activity for review and evaluation.
For research assistants, SEO tools, competitor monitoring, market research, product analysis, and RAG applications, real-time web search gives LlamaIndex agents access to current web context.
A static knowledge base tells the agent what it already knows.
Real-time web search helps the agent find what changed.
FAQ
Can LlamaIndex agents use real-time web search?
Yes. A LlamaIndex agent can use a web search function as a callable tool. The tool can return structured search results such as titles, URLs, domains, snippets, and timestamps.
When should a LlamaIndex agent use web search?
Use web search when the question depends on fresh public information, recent market data, competitor research, search result analysis, product pricing, or source discovery.
Should the search tool return raw HTML?
Usually no. It is better to start with structured search results. Fetch full pages only when the agent needs deeper source content.
Can web search results be used in RAG?
Yes. Search results can help discover relevant source URLs. Selected pages can then be fetched, cleaned, and used as context in a RAG workflow.
What is the difference between SDK and MCP integration?
SDK integration is usually better for quick prototypes and single-agent apps. MCP Server integration is better for production systems, multi-agent workflows, and shared tool access across teams.