Skip to main content
Prerequisites
  • Python 3.10 or higher
  • PraisonAI Agents package installed
  • At least one search provider configured (API key or package)
The search_web tool provides a unified interface for web search that automatically tries multiple providers in order, falling back to the next if one fails.

Search Provider Priority

PriorityProviderRequirements
1TavilyTAVILY_API_KEY + tavily-python
2ExaEXA_API_KEY + exa_py
3You.comYDC_API_KEY + youdotcom
4DuckDuckGoduckduckgo_search (no API key)
5SearxNGrequests + running SearxNG instance

Installation

pip install praisonaiagents

# Install at least one search provider:
pip install duckduckgo_search  # Free, no API key required
# OR
pip install tavily-python      # Requires TAVILY_API_KEY
# OR
pip install exa_py             # Requires EXA_API_KEY
# OR
pip install youdotcom          # Requires YDC_API_KEY

Setup

# Optional: Set API keys for premium providers
export TAVILY_API_KEY=your_tavily_api_key
export EXA_API_KEY=your_exa_api_key
export YDC_API_KEY=your_ydc_api_key
export OPENAI_API_KEY=your_openai_api_key

Basic Usage

from praisonaiagents.tools import search_web

# Automatically uses the best available provider
results = search_web("AI trends 2025")

for r in results:
    print(f"Title: {r['title']}")
    print(f"URL: {r['url']}")
    print(f"Provider: {r['provider']}")
    print()

With Max Results

from praisonaiagents.tools import search_web

results = search_web("Python programming tutorials", max_results=10)

Specify Providers

from praisonaiagents.tools import search_web

# Only try specific providers in order
results = search_web(
    "machine learning",
    providers=["duckduckgo", "tavily"]
)

Check Available Providers

from praisonaiagents.tools import get_available_providers

providers = get_available_providers()
for p in providers:
    status = "✓" if p["available"] else "✗"
    reason = p.get("reason", "") or ""
    print(f"{p['name']:12} {status} {reason}")

With PraisonAI Agent

from praisonaiagents import Agent
from praisonaiagents.tools import search_web

agent = Agent(
    name="SearchAgent",
    role="Web Researcher",
    goal="Find information on the web",
    tools=[search_web]
)

result = agent.start("What are the latest developments in quantum computing?")
print(result)

Multi-Agent Research

from praisonaiagents import Agent, PraisonAIAgents
from praisonaiagents.tools import search_web

researcher = Agent(
    name="Researcher",
    role="Research Analyst",
    goal="Research topics thoroughly",
    tools=[search_web]
)

writer = Agent(
    name="Writer",
    role="Content Writer",
    goal="Write engaging content based on research"
)

agents = PraisonAIAgents(agents=[researcher, writer])
result = agents.start("Research and write about AI trends in 2025")
print(result)

Fallback Logic

For each provider in order:
  1. Check API key (if required) → skip if not set
  2. Check package availability → skip if not installed
  3. Try search → on success, return results
  4. On failure → log error and try next provider
This ensures your search always works as long as at least one provider is available.

Response Format

Each result contains:
FieldTypeDescription
titlestrResult title
urlstrResult URL
snippetstrResult description/snippet
providerstrName of the provider that returned the result

Error Handling

If all providers fail, returns a list with a single error dict:
results = search_web("query")
if results and "error" in results[0]:
    print(f"Search failed: {results[0]['error']}")

Parameters

ParameterTypeDefaultDescription
querystrrequiredSearch query string
max_resultsint5Maximum number of results
providerslistNoneList of provider names to try in order
searxng_urlstrNoneCustom SearxNG instance URL

Key Points

  • Zero configuration: Works with DuckDuckGo out of the box (no API key)
  • Automatic fallback: Tries providers in order until one succeeds
  • Unified response: Same response format regardless of provider
  • Provider info: Each result includes which provider returned it
  • Graceful degradation: Always returns results if any provider works