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-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
1
Set up your virtual environment
uv venv --python 3.12
source .venv/bin/activate
uv venv --python 3.12
.venv\Scripts\activate
2
Install dependencies
uv pip install -U agno ddgs openai
3
Export your OpenAI API key
export OPENAI_API_KEY="your_openai_api_key_here"
$Env:OPENAI_API_KEY="your_openai_api_key_here"
4
Run the example
Save the code above as
duckduckgo_tools.py, then run:python duckduckgo_tools.py