> ## Documentation Index
> Fetch the complete documentation index at: https://praison.ai/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Web Search Agent

> Learn how to create AI agents for intelligent web searching and information gathering.

Answer questions with real-time information by giving a single Agent a web search tool.

```python theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
from praisonaiagents import Agent
from praisonaiagents.tools import duckduckgo

agent = Agent(
    name="WebSearcher",
    instructions="You are a web search agent. Search and summarize findings.",
    tools=[duckduckgo],
)

agent.start("What are the latest AI developments in 2024?")
```

```mermaid theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
graph LR
    subgraph "Web Search Agent"
        User[📋 Query] --> Agent[🤖 Agent]
        Agent --> Search[🧠 Web Search]
        Search --> Result[✅ Summary]
    end

    classDef input fill:#6366F1,stroke:#7C90A0,color:#fff
    classDef process fill:#189AB4,stroke:#7C90A0,color:#fff
    classDef output fill:#10B981,stroke:#7C90A0,color:#fff

    class User,Agent input
    class Search process
    class Result output
```

Web search agent using DuckDuckGo for real-time information gathering.

## Quick Start

<Steps>
  <Step title="Simple Usage">
    Attach the search tool and ask a question.

    ```python theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
    from praisonaiagents import Agent
    from praisonaiagents.tools import duckduckgo

    agent = Agent(
        name="WebSearcher",
        instructions="You are a web search agent. Search and summarize findings.",
        tools=[duckduckgo],
    )

    agent.start("What are the latest AI developments in 2024?")
    ```
  </Step>

  <Step title="With Configuration">
    Return structured search results with a Pydantic schema.

    ```python theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
    from praisonaiagents import Agent, Task, AgentTeam
    from praisonaiagents.tools import duckduckgo
    from pydantic import BaseModel

    class SearchResult(BaseModel):
        summary: str
        sources: list[str]
        key_findings: list[str]

    agent = Agent(
        name="WebSearcher",
        instructions="Search the web and return structured results.",
        tools=[duckduckgo],
    )

    task = Task(
        description="Search for the latest AI developments in 2024",
        expected_output="Structured search results",
        agent=agent,
        output_pydantic=SearchResult,
    )

    AgentTeam(agents=[agent], tasks=[task]).start()
    ```
  </Step>
</Steps>

## How It Works

```mermaid theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
sequenceDiagram
    participant User
    participant Agent
    participant Search as Web Search

    User->>Agent: "Latest AI developments in 2024?"
    Agent->>Search: Execute DuckDuckGo query
    Search-->>Agent: Ranked results
    Agent-->>User: Summarised answer with sources
```

***

## Simple

**Agents: 1** — Single agent with search tool handles query and summarization.

### Workflow

1. Receive search query
2. Execute web search via DuckDuckGo
3. Filter and summarize results
4. Return formatted response

### Setup

```bash theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
pip install praisonaiagents praisonai duckduckgo-search
export OPENAI_API_KEY="your-key"
```

### Run — Python

```python theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
from praisonaiagents import Agent
from praisonaiagents.tools import duckduckgo

agent = Agent(
    name="WebSearcher",
    instructions="You are a web search agent. Search and summarize findings.",
    tools=[duckduckgo]
)

result = agent.start("What are the latest AI developments in 2024?")
print(result)
```

### Run — CLI

```bash theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
praisonai "What are the latest AI developments?" --web-search
```

### Run — agents.yaml

```yaml theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
framework: praisonai
topic: Web Research
roles:
  web_searcher:
    role: Web Search Specialist
    goal: Find and summarize web information
    backstory: You are an expert at finding information online
    tools:
      - duckduckgo
    tasks:
      search_task:
        description: Search for the latest AI developments in 2024
        expected_output: A summary of key AI developments with sources
```

```bash theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
praisonai agents.yaml
```

### Serve API

```python theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
from praisonaiagents import Agent
from praisonaiagents.tools import duckduckgo

agent = Agent(
    name="WebSearcher",
    instructions="You are a web search agent.",
    tools=[duckduckgo]
)

agent.launch(port=8080)
```

```bash theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
curl -X POST http://localhost:8080/chat \
  -H "Content-Type: application/json" \
  -d '{"message": "Search for Python 3.12 new features"}'
```

***

## Advanced Workflow (All Features)

**Agents: 1** — Single agent with memory, persistence, structured output, and session resumability.

### Workflow

1. Initialize session for resumable search context
2. Configure SQLite persistence for search history
3. Execute search with structured JSON output
4. Store results in memory for follow-up queries
5. Resume session to continue research

### Setup

```bash theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
pip install praisonaiagents praisonai duckduckgo-search pydantic
export OPENAI_API_KEY="your-key"
```

### Run — Python

```python theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
from praisonaiagents import Agent, Task, AgentTeam, Session
from praisonaiagents.tools import duckduckgo
from pydantic import BaseModel

# Structured output schema
class SearchResult(BaseModel):
    query: str
    summary: str
    sources: list[str]
    key_findings: list[str]

# Create session for resumability
session = Session(session_id="search-session-001", user_id="user-1")

# Agent with memory and tools
agent = Agent(
    name="WebSearcher",
    instructions="Search the web and return structured results.",
    tools=[duckduckgo],
    memory=True
)

# Task with structured output
task = Task(
    description="Search for the latest AI developments in 2024",
    expected_output="Structured search results",
    agent=agent,
    output_pydantic=SearchResult
)

# Run with SQLite persistence
agents = AgentTeam(
    agents=[agent],
    tasks=[task],
    memory=True
)

result = agents.start()
print(result)

# Resume later
session2 = Session(session_id="search-session-001", user_id="user-1")
history = session2.search_memory("AI developments")
```

### Run — CLI

```bash theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
# With memory and verbose
praisonai "Search for AI news" --web-search --memory --verbose

# Resume session
praisonai "Find more details" --web-search --memory --session search-001
```

### Run — agents.yaml

```yaml theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
framework: praisonai
topic: Web Research
memory: true
memory_config:
  provider: sqlite
  db_path: search.db
roles:
  web_searcher:
    role: Web Search Specialist
    goal: Find and summarize web information
    backstory: You are an expert at finding information online
    tools:
      - duckduckgo
    memory: true
    tasks:
      search_task:
        description: Search for the latest AI developments in 2024
        expected_output: Structured search results
        output_json:
          query: string
          summary: string
          sources: array
          key_findings: array
```

```bash theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
praisonai agents.yaml --verbose
```

### Serve API

```python theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
from praisonaiagents import Agent
from praisonaiagents.tools import duckduckgo

agent = Agent(
    name="WebSearcher",
    instructions="Search the web and return results.",
    tools=[duckduckgo],
    memory=True
)

agent.launch(port=8080)
```

```bash theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
curl -X POST http://localhost:8080/chat \
  -H "Content-Type: application/json" \
  -d '{"message": "Search for Python news", "session_id": "search-001"}'
```

***

## Monitor / Verify

```bash theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
praisonai "test search" --web-search --verbose
```

## Cleanup

```bash theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
rm -f search.db
```

## Features Demonstrated

| Feature           | Implementation                |
| ----------------- | ----------------------------- |
| Workflow          | Single-step web search        |
| DB Persistence    | SQLite via `memory_config`    |
| Observability     | `--verbose` flag              |
| Tools             | DuckDuckGo search             |
| Resumability      | `Session` with `session_id`   |
| Structured Output | Pydantic `SearchResult` model |

## Best Practices

<AccordionGroup>
  <Accordion title="Ask the agent to cite sources">
    Instruct it to include the URLs it used. Search answers without provenance are hard to verify and easy to distrust.
  </Accordion>

  <Accordion title="Summarise, don't dump">
    Tell the agent to synthesise findings into a concise answer rather than pasting raw snippets. Users want the takeaway, not ten links.
  </Accordion>

  <Accordion title="Enable memory for follow-up searches">
    Set `memory=True` so the agent builds on earlier queries instead of re-searching the same ground on each turn.
  </Accordion>

  <Accordion title="Escalate to Research for depth">
    For multi-source synthesis and long reports, hand off to the Research or Deep Research agents rather than a single search pass.
  </Accordion>
</AccordionGroup>

## Related

<CardGroup cols={2}>
  <Card icon="magnifying-glass-chart" href="/docs/agents/research">
    Synthesise multiple sources into a report.
  </Card>

  <Card icon="microscope" href="/docs/agents/deep-research">
    Provider-native deep research for in-depth analysis.
  </Card>
</CardGroup>
