Skip to main content
Use the built-in DuckDuckGoTools to search the web using DuckDuckGo. It provides text search, news search, and image search capabilities for your agent.

Installation

Install the required dependencies:
pip install ddgs

Usage

Import and use the DuckDuckGoTools:
from hypertic.agents import Agent
from hypertic.models import OpenAIChat
from hypertic.tools import DuckDuckGoTools

# Initialize DuckDuckGo tools
duckduckgo = DuckDuckGoTools(
    safesearch="off",
    region="us-en",
    time="d"
)

model = OpenAIChat(model="gpt-4o")
agent = Agent(
    model=model,
    tools=[duckduckgo],
)

response = agent.run("Search for 'Python programming language'")
print(response.content)

Configuration Options

Configure DuckDuckGoTools with these parameters:
  • safesearch - Safe search setting (“on”, “off”, or “moderate”)
  • region - Region for search results (e.g., “us-en”, “uk-en”, “de-de”)
  • time - Time filter for results (“d” for day, “w” for week, “m” for month, “y” for year)

Features

DuckDuckGoTools provides three search methods:
  • Text Search - Search the web for text results
  • News Search - Search for recent news articles
  • Image Search - Search for images

Example

from hypertic.agents import Agent
from hypertic.models import OpenAIChat
from hypertic.tools import DuckDuckGoTools

# Initialize DuckDuckGo tools
duckduckgo = DuckDuckGoTools(
    safesearch="off",
    region="us-en",
    time="d"
)

model = OpenAIChat(model="gpt-4o")
agent = Agent(
    model=model,
    tools=[duckduckgo],
)

# Text search
response = agent.run("Search for 'Python programming language'")
print(response.content)

# News search
response = agent.run("Search for recent news about 'artificial intelligence'")
print(response.content)

# Image search
response = agent.run("Search for images of 'cute puppies'")
print(response.content)
The agent can use DuckDuckGoTools to perform various types of web searches based on natural language requests.