> ## 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.

# TavilySearch Tool

> Guide for using the TavilySearch tool with PraisonAI agents.

The TavilySearch tool lets an agent run AI-optimised web search through the Tavily API.

```mermaid theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
graph LR
    subgraph "Tavily Search"
        User[User] --> Agent[Agent]
        Agent --> Tool[TavilySearchResults]
        Tool --> API[Tavily API]
        API --> Result[Results]
    end

    classDef input fill:#8B0000,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 Tool,API process
    class Result output
```

## Overview

The TavilySearch tool is a tool that allows you to search the web using the TavilySearch.

```bash theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
pip install "langchain-community>=0.2.11" tavily-python
export TAVILY_API_KEY="${TAVILY_API_KEY:?Set TAVILY_API_KEY in your shell}"
```

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

def search_tool(query: str):
    tool = TavilySearchResults(
        max_results=5,
        search_depth="advanced",
        include_answer=True,
        include_raw_content=True,
        include_images=True
    )
    return tool.run(query)

data_agent = Agent(instructions="I am looking for the top google searches on AI tools of 2025", tools=[search_tool])
editor_agent = Agent(instructions="Analyze the data and rank the tools based on their popularity")

agents = AgentTeam(agents=[data_agent, editor_agent])
agents.start()
```

## How It Works

```mermaid theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
sequenceDiagram
    participant User
    participant Agent
    participant Tavily as TavilySearchResults
    participant API as Tavily API

    User->>Agent: "Search for X"
    Agent->>Tavily: run(query)
    Tavily->>API: HTTPS request
    API-->>Tavily: results + answer
    Tavily-->>Agent: parsed result
    Agent-->>User: final answer
```

## Getting Started

<Steps>
  <Step title="Simple Usage">
    1. Install dependencies (see **Overview** above)
    2. Set required API keys in your environment
    3. Run the agent example in **Overview**
  </Step>

  <Step title="With Configuration">
    Use the same tool with an agent — see the **Overview** example, or pass env vars from the sections above.
  </Step>
</Steps>

## Best Practices

<AccordionGroup>
  <Accordion title="Keep TAVILY_API_KEY in the environment">
    Set `TAVILY_API_KEY` in your shell or `.env`. The tool reads it automatically — never hard-code the key.
  </Accordion>

  <Accordion title="Cap max_results">
    `TavilySearchResults(max_results=5)` controls how many hits return. Lower it so the agent processes fewer tokens.
  </Accordion>

  <Accordion title="Enable include_answer for direct answers">
    Set `include_answer=True` when the agent needs a synthesised answer rather than raw links — it saves a follow-up LLM step.
  </Accordion>
</AccordionGroup>

## Related Tools

<CardGroup cols={2}>
  <Card title="Tavily" icon="book" href="/docs/tools/external/tavily">
    Tavily tool (praisonai-tools)
  </Card>

  <Card title="Exa Search" icon="book" href="/docs/tools/external/exa-search">
    Exa LangChain integration
  </Card>

  <Card title="DuckDuckGo" icon="book" href="/docs/tools/external/duckduckgo">
    Privacy-focused search
  </Card>
</CardGroup>
