Skip to content

SearxngSearchTool

autogen.tools.experimental.SearxngSearchTool #

SearxngSearchTool(base_url='https://searxng.site/search')

Bases: Tool

SearxngSearchTool is a tool that uses SearxNG to perform a search.

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

Initializes the SearxngSearchTool. Args: base_url (str): The SearxNG instance URL.

Source code in autogen/tools/experimental/searxng/searxng_search.py
def __init__(self, base_url: str = "https://searxng.site/search") -> None:
    """
    Initializes the SearxngSearchTool.
    Args:
        base_url (str): The SearxNG instance URL.
    """
    self.base_url = base_url
    super().__init__(
        name="searxng_search",
        description="Use the SearxNG API to perform a search.",
        func_or_tool=self.searxng_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.

base_url instance-attribute #

base_url = base_url

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)
searxng_search(query, max_results=5, categories=None, language=None)

Performs a search using the SearxNG API and returns formatted results. Args: query: The search query string. max_results: The maximum number of results to return. Defaults to 5. categories: List of categories to search in. language: Language code. Returns: A list of dictionaries, each containing 'title', 'link', and 'snippet' of a search result.

Source code in autogen/tools/experimental/searxng/searxng_search.py
def searxng_search(
    self,
    query: Annotated[str, "The search query."],
    max_results: Annotated[int, "The number of results to return."] = 5,
    categories: Annotated[Optional[List[str]], "List of categories to search in."] = None,
    language: Annotated[Optional[str], "Language code (e.g., 'en-US')."] = None,
) -> list[dict[str, Any]]:
    """
    Performs a search using the SearxNG API and returns formatted results.
    Args:
        query: The search query string.
        max_results: The maximum number of results to return. Defaults to 5.
        categories: List of categories to search in.
        language: Language code.
    Returns:
        A list of dictionaries, each containing 'title', 'link', and 'snippet' of a search result.
    """
    return _searxng_search(
        query=query,
        max_results=max_results,
        categories=categories,
        language=language,
        base_url=self.base_url,
    )