SearxNG Search Tool Walkthrough - AG2

SearxNG Search Tool Walkthrough

This notebook demonstrates how to use the SearxNG Search Tool in AG2 to perform real-time web searches using a privacy-friendly, open-source metasearch engine.

Installation

No API key is required for public SearxNG instances. For private instances, consult your administrator.

# Import the SearxngSearchTool
from autogen.tools.experimental import SearxngSearchTool

Basic Usage

You can use the tool directly to perform a search and view results.

search_tool = SearxngSearchTool()
results = search_tool(query="open source search engine", max_results=3)
for r in results:
    print(r["title"], r["link"])

Using with AG2 Agents

You can register the tool with an AssistantAgent for LLM-driven search.

from autogen import AssistantAgent

search_tool = SearxngSearchTool()
assistant = AssistantAgent(name="assistant")
search_tool.register_for_llm(assistant)
response = assistant.run(
    message="What is SearxNG?",
    tools=assistant.tools,
    max_turns=2,
    user_input=False,
)
response.process()

Customizing Parameters

You can specify categories, language, or a custom SearxNG instance URL.

results = search_tool(query="AI news", max_results=2, categories=["news"], language="en-US")
for r in results:
    print(r["title"], r["link"])

Output Format

Each result is a dictionary with title, link, and snippet keys.

print(results[0])

Learn More