Skip to main content
"""
Duckduckgo Tools
=============================

Demonstrates duckduckgo tools.
"""

from agno.agent import Agent
from agno.models.openai import OpenAIChat
from agno.tools.duckduckgo import DuckDuckGoTools
from agno.tools.websearch import WebSearchTools

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


# Example 1: Enable specific DuckDuckGo functions
agent = Agent(
    model=OpenAIChat(id="gpt-4o"),
    tools=[DuckDuckGoTools(enable_search=True, enable_news=False)],
)

# Example 2: Enable all DuckDuckGo functions (both search and news)
agent_all = Agent(
    model=OpenAIChat(id="gpt-4o"),
    tools=[DuckDuckGoTools(enable_search=True, enable_news=True)],
)

# Example 3: Enable only news search
news_agent = Agent(
    model=OpenAIChat(id="gpt-4o"),
    tools=[DuckDuckGoTools(enable_search=False, enable_news=True)],
)

# Example 4: Use WebSearchTools for other search backends (e.g., yandex)
# Note: DuckDuckGoTools always uses duckduckgo backend.
# For other backends, use WebSearchTools directly.
yandex_agent = Agent(
    model=OpenAIChat(id="gpt-4o"),
    tools=[WebSearchTools(enable_search=True, enable_news=False, backend="yandex")],
    add_datetime_to_context=True,
)

# Test the agents

# ---------------------------------------------------------------------------
# Run Agent
# ---------------------------------------------------------------------------
if __name__ == "__main__":
    agent.print_response("What's the latest about GPT-5?", markdown=True)
    # news_agent.print_response(
    #     "Find recent news about artificial intelligence", markdown=True
    # )
    # yandex_agent.print_response("What's happening in AI?", markdown=True)

Run the Example

# Clone and setup repo
git clone https://github.com/agno-agi/agno.git
cd agno/cookbook/91_tools

# Create and activate virtual environment
./scripts/demo_setup.sh
source .venvs/demo/bin/activate

python duckduckgo_tools.py