Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs.json
Original file line number Diff line number Diff line change
Expand Up @@ -7240,6 +7240,7 @@
"examples/tools/serper-tools",
"examples/tools/spider-tools",
"examples/tools/tavily-tools",
"examples/tools/tavily-tools-advanced",
"examples/tools/trafilatura-tools",
"examples/tools/web-tools",
"examples/tools/webbrowser-tools",
Expand Down
95 changes: 95 additions & 0 deletions examples/tools/tavily-tools-advanced.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
---
title: "Tavily Tools - Advanced Search Parameters"
description: "Scope Tavily web search by domain, recency, topic, and country."
source: cookbook/91_tools/tavily_tools_advanced.py
---

```python tavily_tools_advanced.py
"""
Tavily Tools - Advanced Search Parameters
=============================

Demonstrates scoping Tavily web search with the advanced parameters:
domain restriction, recency, topic, and country localization.
"""

from agno.agent import Agent
from agno.tools.tavily import TavilyTools

# ---------------------------------------------------------------------------
# Create Agent
# ---------------------------------------------------------------------------


# Domain-restricted research, limited to the last month, US-localized
research_agent = Agent(
tools=[
TavilyTools(
include_domains=[
"arxiv.org",
"github.com",
], # restrict results to these domains
exclude_domains=["reddit.com"], # drop results from these domains
time_range="month", # only results from the last month
country="united states", # boost results from this country
)
],
markdown=True,
)

# Recent news from the last few days (days applies to the news topic only)
news_agent = Agent(
tools=[
TavilyTools(
topic="news", # general, news, or finance
days=3, # only news from the last 3 days
)
],
markdown=True,
)

# ---------------------------------------------------------------------------
# Run Agent
# ---------------------------------------------------------------------------
if __name__ == "__main__":
research_agent.print_response(
"Find recent papers on mixture-of-experts language models"
)

news_agent.print_response("What are the latest developments in AI?")
```

## Run the Example

<Steps>
<Snippet file="create-venv-step.mdx" />

<Step title="Install dependencies">
```bash
uv pip install -U agno openai tavily-python
```
</Step>

<Step title="Export your API keys">
<CodeGroup>
```bash Mac/Linux
export OPENAI_API_KEY="your_openai_api_key_here"
export TAVILY_API_KEY="your_tavily_api_key_here"
```

```bash Windows
$Env:OPENAI_API_KEY="your_openai_api_key_here"
$Env:TAVILY_API_KEY="your_tavily_api_key_here"
```
</CodeGroup>
</Step>

<Step title="Run the example">
Save the code above as `tavily_tools_advanced.py`, then run:
```bash
python tavily_tools_advanced.py
```
</Step>
</Steps>

Full source: [cookbook/91_tools/tavily_tools_advanced.py](https://github.com/agno-agi/agno/blob/main/cookbook/91_tools/tavily_tools_advanced.py)
13 changes: 12 additions & 1 deletion tools/toolkits/search/tavily.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,24 @@ agent.print_response("Search tavily for 'language models'")
| `all` | `bool` | `False` | Enable all available functions in the toolkit. |
| `max_tokens` | `int` | `6000` | Maximum number of tokens to use in search results. |
| `include_answer` | `bool` | `True` | Whether to include an AI-generated answer summary in the response. |
| `search_depth` | `Literal['basic', 'advanced']` | `'advanced'` | Depth of search - 'basic' (1 credit) for faster results or 'advanced' (2 credits) for more comprehensive search. |
| `search_depth` | `Literal['basic', 'advanced', 'fast', 'ultra-fast']` | `'advanced'` | Depth of search - 'basic' (1 credit), 'advanced' (2 credits), 'fast', or 'ultra-fast'. |
| `extract_depth` | `Literal['basic', 'advanced']` | `'basic'` | Extraction depth - 'basic' (1 credit/5 URLs) or 'advanced' (2 credits/5 URLs). |
| `include_images` | `bool` | `False` | Include images in extracted content. |
| `include_favicon` | `bool` | `False` | Include favicon in extracted content. |
| `extract_timeout` | `Optional[int]` | `None` | Timeout in seconds for extraction requests. |
| `extract_format` | `Literal['markdown', 'text']` | `'markdown'` | Output format for extracted content. |
| `format` | `Literal['json', 'markdown']` | `'markdown'` | Output format - 'json' for raw data or 'markdown' for formatted text. |
| `topic` | `Optional[Literal['general', 'news', 'finance']]` | `None` | Search category - general, news, or finance. |
| `time_range` | `Optional[Literal['day', 'week', 'month', 'year', 'd', 'w', 'm', 'y']]` | `None` | Time window for results - day, week, month, year (or d/w/m/y). |
| `start_date` | `Optional[str]` | `None` | Only include results published after this date (YYYY-MM-DD). |
| `end_date` | `Optional[str]` | `None` | Only include results published before this date (YYYY-MM-DD). |
| `days` | `Optional[int]` | `None` | Number of days back to include results. Applies to the news topic only. |
| `include_domains` | `Optional[List[str]]` | `None` | Restrict results to these domains. |
| `exclude_domains` | `Optional[List[str]]` | `None` | Exclude these domains from results. |
| `country` | `Optional[str]` | `None` | Boost results from this country (e.g., 'united states'). |
| `auto_parameters` | `bool` | `False` | Let Tavily auto-tune search parameters. Explicitly set values (including the always-sent `search_depth` and `include_answer`) take precedence. |
| `chunks_per_source` | `Optional[int]` | `None` | Number of content chunks per source (1-3). Advanced search only. |
| `search_params` | `Optional[Dict[str, Any]]` | `None` | Additional parameters merged into web search requests. Overrides named parameters on key collision. |

## Toolkit Functions

Expand Down
Loading