DuckDuckGo Tools

Toggle DuckDuckGo search and news functions, plus WebSearchTools for other backends like Yandex.

duckduckgo_tools.py
"""
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-5.6-luna"),
    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-5.6-luna"),
    tools=[DuckDuckGoTools(enable_search=True, enable_news=True)],
)

# Example 3: Enable only news search
news_agent = Agent(
    model=OpenAIChat(id="gpt-5.6-luna"),
    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-5.6-luna"),
    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)

DuckDuckGoTools defaults to backend="duckduckgo"; an explicit backend argument can override it. The script only executes the first web-search agent. Uncomment the final examples to try news-only search or the Yandex-backed WebSearchTools agent.

Run the Example

Set up your virtual environment

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

Install dependencies

uv pip install -U agno ddgs openai

Export your OpenAI API key

export OPENAI_API_KEY="your_openai_api_key_here"

Run the example

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

python duckduckgo_tools.py

Full source: cookbook/91_tools/duckduckgo_tools.py