Web

Enable agents to search the web and fetch page content

Web capabilities let agents search the internet and fetch page content to answer questions with up-to-date information.

python
from praisonaiagents import Agent

agent = Agent(
    name="News Agent",
    instructions="Answer with up-to-date web results",
    web="duckduckgo",  # search only — no API key
)
agent.start("What are today's AI headlines?")
Diagram

Web Capabilities

🤖 Agent

🔍 Search

📄 Fetch

📋 Results

📝 Content

✅ Answer

Quick Start

  1. Enable Web
    python
    from praisonaiagents import Agent
    
    agent = Agent(
        name="Web Agent",
        instructions="You search the web for information",
        web=True  # Enable web search and fetch
    )
    
    agent.start("What are the latest AI news today?")
  2. With Configuration
    python
    from praisonaiagents import Agent, WebConfig
    
    agent = Agent(
        name="Research Agent",
        instructions="You do thorough web research",
        web=WebConfig(
            search=True,                    # Enable search
            fetch=True,                     # Enable page fetch
            search_provider="duckduckgo",   # Search provider
            max_results=10,                 # Results per search
        )
    )

Web Features

Diagram

Features

Query

URL

🔍 Web Search
Find relevant pages

📄 Page Fetch
Get full content

📋 Search Results

📝 Page Content

Web Search

Find relevant pages for a query:

python
agent = Agent(
    instructions="You answer questions using web search",
    web=WebConfig(search=True)
)

agent.start("What is the current price of Bitcoin?")

Page Fetch

Retrieve full content from URLs:

python
agent = Agent(
    instructions="You analyze web pages",
    web=WebConfig(fetch=True)
)

agent.start("Summarize the content at https://example.com/article")

Configuration Options

python
from praisonaiagents import WebConfig

config = WebConfig(
    search=True,                    # Enable web search
    fetch=True,                     # Enable page fetch
    search_provider="duckduckgo",   # Search provider
    max_results=5,                  # Max results per search
    search_config={},               # Provider-specific config
    fetch_config={},                # Fetch-specific config
)
OptionTypeDefaultDescription
searchboolTrueEnable web search
fetchboolTrueEnable page fetch
search_providerstr"duckduckgo"Search provider
max_resultsint5Results per search
search_configdict{}Provider config
fetch_configdict{}Fetch config

Choosing the right form

Diagram
flowchart TD
    Start([Need web tools?]) --> Q1{Provider string?}
    Q1 -->|web="duckduckgo" etc.| SearchOnly[Search only]
    Q1 -->|web="fetch_only"| FetchOnly[Fetch only]
    Q1 -->|web=True| Both[Search + fetch]
    Q1 -->|WebConfig(...)| Custom[Explicit flags]

    classDef start fill:#6366F1,stroke:#7C90A0,color:#fff
    classDef choice fill:#F59E0B,stroke:#7C90A0,color:#fff
    classDef result fill:#10B981,stroke:#7C90A0,color:#fff

    class Start start
    class Q1 choice
    class SearchOnly,FetchOnly,Both,Custom result
FormSearchFetch
web="duckduckgo"✅❌
web="tavily"✅❌
web="google"✅❌
web="bing"✅❌
web="serper"✅❌
web="search_only"✅❌
web="fetch_only"❌✅
web=True or WebConfig(search=True, fetch=True)✅✅

Search Providers

Diagram

Providers

🦆 DuckDuckGo
Free, no API key

ProviderAPI KeyBest For
duckduckgo❌ Not neededGeneral use, free
google✅ RequiredComprehensive results
tavily✅ RequiredAI-optimized search
serper✅ RequiredGoogle results API
bing✅ RequiredMicrosoft ecosystem

Using Different Providers

python
# Provider string — search only (default for presets)
agent = Agent(web="duckduckgo")

# Search + fetch explicitly
agent = Agent(
    web=WebConfig(search=True, fetch=True, search_provider="duckduckgo")
)

# DuckDuckGo via WebConfig (search only unless fetch=True)
agent = Agent(
    web=WebConfig(search_provider="duckduckgo")
)

# Tavily (AI-optimized)
agent = Agent(
    web=WebConfig(
        search_provider="tavily",
        search_config={"api_key": "your-key"}
    )
)

# Google
agent = Agent(
    web=WebConfig(
        search_provider="google",
        search_config={
            "api_key": "your-key",
            "cx": "your-search-engine-id"
        }
    )
)

How It Works

Diagram
LLMFetchSearchAgentUserLLMFetchSearchAgentUseropt[Need full content]QuestionSearch queryURLs + snippetsFetch URLPage contentQuestion + contextAnswerResponse

Use Cases


Combining with Knowledge

Web search complements local knowledge:

python
agent = Agent(
    instructions="You answer using docs and web",
    knowledge=["docs/"],  # Local documents
    web=True,             # Web search fallback
)

# Agent checks local docs first, then searches web
Diagram

Found

Not found

❓ Query

Local Knowledge?

✅ Answer

🌐 Web Search


Best Practices

Use DuckDuckGo for simple needs

Free and requires no API key – good for basic search needs.

Use Tavily for AI applications

Tavily is optimized for AI agents with better structured results.

Limit results for speed

Lower max_results for faster responses when you don’t need many sources.

Combine with knowledge for best results

Use local knowledge for domain-specific info, web for current events.


Related