duckduckgo.py


Overview

The duckduckgo.py file provides an integration component for performing search queries using the DuckDuckGo search engine through the duckduckgo_search Python library. It is designed as a tool within a larger agent or AI assistant framework (likely InfiniFlow), enabling privacy-focused web and news searches. The component supports configurable parameters, such as search query keywords and search channel (general web or news), and returns structured search results for downstream consumption.

Key features:


Classes, Methods, and Functions

Class: DuckDuckGoParam

Defines and validates input parameters specific to the DuckDuckGo search component.

Description

DuckDuckGoParam extends the base parameter class ToolParamBase to specify the configuration schema and validation for the DuckDuckGo search tool.

Properties

Methods

Usage Example

param = DuckDuckGoParam()
param.top_n = 5
param.channel = "news"
param.check()  # Validates parameters
input_form = param.get_input_form()
print(input_form)

Class: DuckDuckGo

Main DuckDuckGo search tool component extending ToolBase and implementing an abstract base class.

Description

DuckDuckGo encapsulates the logic to perform DuckDuckGo searches, handle retries, parse results, and output them in usable formats.

Class Attributes

Methods


Implementation Details and Algorithms


Interaction with Other Parts of the System


Mermaid Class Diagram

classDiagram
    class DuckDuckGoParam {
        +meta: ToolMeta
        +top_n: int
        +channel: str
        +__init__()
        +check()
        +get_input_form() dict
    }

    class DuckDuckGo {
        +component_name: str
        +_invoke(**kwargs) str
        +thoughts() str
    }

    DuckDuckGoParam <|-- ToolParamBase
    DuckDuckGo <|-- ToolBase
    DuckDuckGo ..|> ABC

Summary

The duckduckgo.py file implements a privacy-focused search tool component that integrates DuckDuckGo's web and news search capabilities into an AI assistant framework. It provides a well-defined parameter structure, robust invocation logic with retries and timeouts, and structured output formatting. This component is fundamental for enabling external knowledge retrieval in applications prioritizing user data privacy and real-time information access.