DuckDuckGo Agent

Internet search tools using DuckDuckGo for AI agents.

python
from praisonaiagents import Agent
from praisonaiagents import duckduckgo

agent = Agent(name="Researcher", tools=[duckduckgo])
agent.start("Find recent news about open-source LLMs")

The user needs fresh web results; DuckDuckGo tools fetch answers without a separate search API key.

Diagram

Input

Agent

Tool

Output

Diagram
DuckDuckGo AgentAgentUserDuckDuckGo AgentAgentUserRequestProcess requestResultResponse

DuckDuckGo Tools

Use DuckDuckGo Tools to perform internet searches with AI agents.

  1. Install Dependencies

    First, install the required packages:

    bash
    pip install praisonaiagents duckduckgo-search
  2. Import Components

    Import the necessary components:

    python
    from praisonaiagents import Agent, Task, AgentTeam
    from praisonaiagents import duckduckgo
  3. Create Agent

    Create a search agent:

    python
    search_agent = Agent(
        name="SearchAgent",
        role="Internet Search Specialist",
        goal="Perform accurate internet searches and extract relevant information.",
        backstory="Expert in finding and organizing internet data.",
        tools=[duckduckgo],
        reflection=False
    )
  4. Define Task

    Define the search task:

    python
    search_task = Task(
        description="Search for 'AI trends 2024' and analyze the results.",
        expected_output="List of key AI trends with sources.",
        agent=search_agent,
        name="search_trends"
    )
  5. Run Agent

    Initialize and run the agent:

    python
    agents = AgentTeam(
        agents=[search_agent],
        tasks=[search_task],
        process="sequential"
    )
    agents.start()

Understanding DuckDuckGo Tools

What are DuckDuckGo Tools?

DuckDuckGo Tools provide internet search capabilities for AI agents: – Web search functionality – News search – Privacy-focused results – Region-specific searches

Key Components

Examples

Basic Search Agent

python
from praisonaiagents import Agent, Task, AgentTeam
from praisonaiagents import duckduckgo

# Create search agent
search_agent = Agent(
    name="WebSearcher",
    role="Search Specialist",
    goal="Find accurate information about specified topics.",
    backstory="Expert in internet research and data collection.",
    tools=[duckduckgo],
    reflection=False
)

# Define search task
search_task = Task(
    description="Search for 'Python programming best practices 2024' and summarize the key points.",
    expected_output="List of best practices with sources.",
    agent=search_agent,
    name="search_python"
)

# Run agent
agents = AgentTeam(
    agents=[search_agent],
    tasks=[search_task],
    process="sequential"
)
agents.start()

Advanced Search with Multiple Agents

python
# Create search agent
search_agent = Agent(
    name="Researcher",
    role="Search Specialist",
    goal="Gather comprehensive information about topics.",
    tools=[duckduckgo],
    reflection=False
)

# Create analysis agent
analysis_agent = Agent(
    name="Analyzer",
    role="Data Analyst",
    goal="Analyze and synthesize search results.",
    backstory="Expert in data analysis and trend identification.",
    reflection=False
)

# Define tasks
search_task = Task(
    description="Search for latest AI developments in healthcare.",
    agent=search_agent,
    name="healthcare_search"
)

analysis_task = Task(
    description="Analyze the search results and identify key trends.",
    agent=analysis_agent,
    name="trend_analysis"
)

# Run agents
agents = AgentTeam(
    agents=[search_agent, analysis_agent],
    tasks=[search_task, analysis_task],
    process="sequential"
)
agents.start()

Best Practices

Agent Configuration

Configure agents with clear roles and goals:

python
Agent(
    name="Researcher",
    role="Search Specialist",
    goal="Find accurate and relevant information",
    tools=[duckduckgo]
)
Task Definition

Define specific and clear tasks:

python
Task(
    description="Search for 'AI ethics guidelines 2024' and summarize key points",
    expected_output="Structured list of guidelines with sources"
)

Common Patterns

Research and Analysis

python
# Research agent
researcher = Agent(
    name="Researcher",
    role="Search Specialist",
    tools=[duckduckgo]
)

# Analysis agent
analyst = Agent(
    name="Analyst",
    role="Information Analyst"
)

# Define tasks
research_task = Task(
    description="Research quantum computing advances",
    agent=researcher
)

analysis_task = Task(
    description="Analyze research findings",
    agent=analyst
)

# Run workflow
agents = AgentTeam(
    agents=[researcher, analyst],
    tasks=[research_task, analysis_task]
)

Related