Tavily Tools - Advanced Search Parameters

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

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?")

These domain, date, topic, and country options are forwarded by the ordinary search tool used here. Country boosts ranking; it is not a strict geographic filter. Keep enable_search_context=False for this example: the alternate context helper forwards only the query, search depth, and token limit.

Run the Example

Set up your virtual environment

uv venv --python 3.12
source .venv/bin/activate

Install dependencies

uv pip install -U agno openai tavily-python

Export your API keys

export OPENAI_API_KEY="your_openai_api_key_here"
export TAVILY_API_KEY="your_tavily_api_key_here"

Run the example

Save the code above as tavily_tools_advanced.py, then run:

python tavily_tools_advanced.py

Full source: cookbook/91_tools/tavily_tools_advanced.py