AI agents often need access to current online information to answer questions and complete research tasks. Connecting web search tools to LlamaIndex lets agents retrieve relevant results, explore news, and gather information from websites.
In this article, we’ll integrate web search tool with LlamaIndex using Python. We’ll explore direct search queries and connect the search tool to an AI agent that can retrieve information based on user prompts.
Why Do LlamaIndex Agents Need Web Search?
LlamaIndex agents can retrieve and process information using the data sources and tools connected to them. However, they do not automatically have access to live information from the web. This can limit their ability to answer questions about recent events, news, product updates, or industry developments.
Adding a web search tool gives agents access to external information. They can retrieve relevant search results, gather information from websites, and use the retrieved content to generate more informed responses.
How to Give a LlamaIndex Agent Web Search Capabilities
Geekflare provides an integration that connects its web search tools to LlamaIndex agents. The integration supports web, news, and image searches, along with Google Search Engine Results Page (SERP) retrieval.
You can use the search tool directly from Python or register it with a LlamaIndex agent. This lets developers retrieve online information and use it in AI-powered workflows.
Set Up the Python Environment
Before using Geekflare’s search tool with LlamaIndex, install the required package and configure your API key.
Prerequisites
Make sure you have:
- Python 3.10 or later.
llama-index-coreversion 0.12–0.14.- A Geekflare account and API key.
- An LLM API key for the agent method. I’ll use Claude in this tutorial.
Step 1: Install the Python Package
Open your terminal and run:
pip install llama-index-tools-geekflare
This installs Geekflare’s integration package for LlamaIndex.
Step 2: Configure Your Geekflare API Key
Get your API key from the Geekflare dashboard.
Set it as an environment variable so the integration can authenticate your requests.
For macOS or Linux:
export GEEKFLARE_API_KEY="YOUR_GEEKFLARE_API_KEY"
For Windows PowerShell:
$env:GEEKFLARE_API_KEY="YOUR_GEEKFLARE_API_KEY"
Replace the placeholder with your actual API key.
Step 3: Perform Web Searches Using LlamaIndex and Geekflare
Geekflare lets you perform web searches directly through Python or connect its search tool to a LlamaIndex agent. We’ll explore both methods using the search query “Latest developments in electric vehicles”.
Method 1: Call the Search Tool Directly
You can use GeekflareToolSpec to perform a search and retrieve results without creating an AI agent.
Create a Python file named web_search.py and add the following code:
from llama_index.tools.geekflare import GeekflareToolSpec
# Initialize the Geekflare integration
geekflare = GeekflareToolSpec()
# Search the web and retrieve up to 5 results
result = geekflare.search(
"Latest developments in electric vehicles",
limit=5,
source="web"
)
# Display the search results
print(result)
Here, search() sends the query to Geekflare and retrieves up to five web results. The source parameter specifies the search type. You can choose web, news, or images.
Run the script:
python web_search.py
The tool returns a Python dictionary containing the search results and related information.
Here is the response:

Method 2: Use the Search Tool with a LlamaIndex Agent
You can also connect Geekflare’s search tool to a LlamaIndex agent. This lets an LLM process search requests and use the retrieved results to prepare responses.
For this example, I’ll use Claude Sonnet 5.5. First, install the Anthropic integration:
pip install llama-index-llms-anthropic
Get your API key from the Anthropic Console and configure it as an environment variable.
For macOS or Linux:
export ANTHROPIC_API_KEY="YOUR_ANTHROPIC_API_KEY"
For Windows PowerShell:
$env:ANTHROPIC_API_KEY="YOUR_ANTHROPIC_API_KEY"
Replace the placeholder with your actual API key.
Create the LlamaIndex agent
Create a file named web_search_agent.py and add the following code:
import asyncio
from llama_index.core.agent.workflow import FunctionAgent
from llama_index.llms.anthropic import Anthropic
from llama_index.tools.geekflare import GeekflareToolSpec
# Initialize Geekflare
spec = GeekflareToolSpec()
# Select only the web search tool
tools = [
tool for tool in spec.to_tool_list()
if tool.metadata.name == "search"
]
# Create an agent using Claude
agent = FunctionAgent(
tools=tools,
llm=Anthropic(model="claude-sonnet-5-5")
)
async def main():
# Ask the agent to research a topic and summarize the findings
response = await agent.run(
"Search for the latest developments in electric vehicles "
"and summarize the key findings."
)
# Display the agent's response
print(response)
if __name__ == "__main__":
asyncio.run(main())
The agent receives the search request, uses Geekflare to retrieve relevant results, and passes the information to Claude to prepare a summary.
Run the script:
python web_search_agent.py
Here is the response:

Step 4: Explore Geekflare Web Search Parameters
Geekflare provides several parameters to customize search requests and control the results returned. You can use these options to narrow searches, retrieve specific types of content, and target particular websites or locations.
Here are some useful parameters you can configure:
| Parameter | Description | Example |
|---|---|---|
limit | Sets the maximum number of search results to retrieve. | 5 |
source | Selects the search type. Supports web, news, and images. | "news" |
serp | Enables full Google Search Engine Results Page retrieval. | True |
city | Targets search results for a specific city. | "London,England,United Kingdom" |
location | Sets the target country using its country code. | "US" |
time | Filters results by time. Supports h, d, w, m, and y. | "d" |
include_domains | Restricts results to specified websites. | ["reddit.com"] |
exclude_domains | Excludes specified websites from search results. | ["pinterest.com"] |
scrape | Extracts content from the returned search result pages. | True |
grounded_answer | Requests an AI-generated answer grounded in search results. | True |
For example, you can retrieve recent news about electric vehicles from the past week:
result = geekflare.search(
"electric vehicle industry updates",
source="news",
limit=5,
time="w"
)
print(result)
You can also enable serp=True to retrieve the full Google search results page. This includes organic results, AI Overviews, related searches, and People Also Ask sections.
These parameters help you customize searches based on the information your application needs.
Frequently Asked Questions
Can LlamaIndex perform web searches?
Yes. You can connect Geekflare’s search tool to LlamaIndex and perform web searches directly or through an AI agent.
Which Python package enables web search with LlamaIndex?
The llama-index-tools-geekflare package integrates Geekflare’s search capabilities with LlamaIndex.
Can I search for news and images using Geekflare?
Yes. Set the source parameter to news or images to retrieve the corresponding search results.
Can I retrieve Google SERP results with LlamaIndex?
Yes. Set serp=True in the search function to retrieve Google search results.
Do I need an LLM to use Geekflare’s search tool?
No. You can call GeekflareToolSpec().search() directly. An LLM is required when you want to connect the search tool to an AI agent and generate responses from the retrieved results
Conclusion
LlamaIndex lets developers connect external search tools to AI agents and retrieve information from the web. Geekflare adds web, news, and image search capabilities through its Python integration.
You can call the search tool directly for specific queries or connect it to a LlamaIndex agent to research topics and summarize retrieved information. Choose the approach that best fits your application.