Skip to content

DuckDuckGoSearchTool

autogen.tools.experimental.DuckDuckGoSearchTool #

DuckDuckGoSearchTool()

Bases: Tool

DuckDuckGoSearchTool is a tool that uses DuckDuckGo to perform a search.

This tool allows agents to leverage the DuckDuckGo search engine for information retrieval. DuckDuckGo does not require an API key, making it easy to use.

Initializes the DuckDuckGoSearchTool.

Source code in autogen/tools/experimental/duckduckgo/duckduckgo_search.py
def __init__(self) -> None:
    """
    Initializes the DuckDuckGoSearchTool.
    """

    def duckduckgo_search(
        query: Annotated[str, "The search query."],
        num_results: Annotated[int, "The number of results to return."] = 5,
    ) -> list[dict[str, Any]]:
        """
        Performs a search using the DuckDuckGo Search API and returns formatted results.

        Args:
            query: The search query string.
            num_results: The maximum number of results to return. Defaults to 5.

        Returns:
            A list of dictionaries, each containing 'title', 'link', and 'snippet' of a search result.
        """
        return _duckduckgo_search(
            query=query,
            num_results=num_results,
        )

    super().__init__(
        name="duckduckgo_search",
        description="Use the DuckDuckGo Search API to perform a search.",
        func_or_tool=duckduckgo_search,
    )

name property #

name

description property #

description

func property #

func

tool_schema property #

tool_schema

Get the schema for the tool.

This is the preferred way of handling function calls with OpeaAI and compatible frameworks.

function_schema property #

function_schema

Get the schema for the function.

This is the old way of handling function calls with OpenAI and compatible frameworks. It is provided for backward compatibility.

realtime_tool_schema property #

realtime_tool_schema

Get the schema for the tool.

This is the preferred way of handling function calls with OpeaAI and compatible frameworks.

register_for_llm #

register_for_llm(agent)

Registers the tool for use with a ConversableAgent's language model (LLM).

This method registers the tool so that it can be invoked by the agent during interactions with the language model.

PARAMETER DESCRIPTION
agent

The agent to which the tool will be registered.

TYPE: ConversableAgent

Source code in autogen/tools/tool.py
def register_for_llm(self, agent: "ConversableAgent") -> None:
    """Registers the tool for use with a ConversableAgent's language model (LLM).

    This method registers the tool so that it can be invoked by the agent during
    interactions with the language model.

    Args:
        agent (ConversableAgent): The agent to which the tool will be registered.
    """
    if self._func_schema:
        agent.update_tool_signature(self._func_schema, is_remove=False)
    else:
        agent.register_for_llm()(self)

register_for_execution #

register_for_execution(agent)

Registers the tool for direct execution by a ConversableAgent.

This method registers the tool so that it can be executed by the agent, typically outside of the context of an LLM interaction.

PARAMETER DESCRIPTION
agent

The agent to which the tool will be registered.

TYPE: ConversableAgent

Source code in autogen/tools/tool.py
def register_for_execution(self, agent: "ConversableAgent") -> None:
    """Registers the tool for direct execution by a ConversableAgent.

    This method registers the tool so that it can be executed by the agent,
    typically outside of the context of an LLM interaction.

    Args:
        agent (ConversableAgent): The agent to which the tool will be registered.
    """
    agent.register_for_execution()(self)

register_tool #

register_tool(agent)

Register a tool to be both proposed and executed by an agent.

Equivalent to calling both register_for_llm and register_for_execution with the same agent.

Note: This will not make the agent recommend and execute the call in the one step. If the agent recommends the tool, it will need to be the next agent to speak in order to execute the tool.

PARAMETER DESCRIPTION
agent

The agent to which the tool will be registered.

TYPE: ConversableAgent

Source code in autogen/tools/tool.py
def register_tool(self, agent: "ConversableAgent") -> None:
    """Register a tool to be both proposed and executed by an agent.

    Equivalent to calling both `register_for_llm` and `register_for_execution` with the same agent.

    Note: This will not make the agent recommend and execute the call in the one step. If the agent
    recommends the tool, it will need to be the next agent to speak in order to execute the tool.

    Args:
        agent (ConversableAgent): The agent to which the tool will be registered.
    """
    self.register_for_llm(agent)
    self.register_for_execution(agent)