Searxng Tools
Query a self-hosted SearxNG instance at localhost:53153 for web, news, and science results.
"""
Searxng Tools
=============================
Demonstrates searxng tools.
"""
from agno.agent import Agent
from agno.tools.searxng import SearxngTools
# ---------------------------------------------------------------------------
# Create Agent
# ---------------------------------------------------------------------------
# Initialize Searxng with your Searxng instance URL
searxng = SearxngTools(
host="http://localhost:53153",
engines=[],
fixed_max_results=5,
news=True,
science=True,
)
# Create an agent with Searxng
agent = Agent(tools=[searxng])
# Example: Ask the agent to search using Searxng
# ---------------------------------------------------------------------------
# Run Agent
# ---------------------------------------------------------------------------
if __name__ == "__main__":
agent.print_response("""
Please search for information about artificial intelligence
and summarize the key points from the top results
""")Use the current tool filter
In the saved example, replace the SearxngTools constructor with:
searxng = SearxngTools(
host="http://localhost:53153",
engines=[],
fixed_max_results=5,
include_tools=["search_web", "news_search", "science_search"],
)The current constructor does not accept news or science flags. Configure categories through include_tools. Your SearxNG server must allow the JSON search format; add json to search.formats in its settings.yml and restart it. The toolkit requests /search?format=json, so the HTML search page alone is insufficient. fixed_max_results=5 limits each tool response to five results.
Run the Example
Set up your virtual environment
uv venv --python 3.12
source .venv/bin/activateInstall dependencies
uv pip install -U agno openaiExport your OpenAI API key
export OPENAI_API_KEY="your_openai_api_key_here"Start SearxNG
Start a SearxNG instance at http://localhost:53153 before running the example.
Run the example
Save the code above as searxng_tools.py, then run:
python searxng_tools.pyFull source: cookbook/91_tools/searxng_tools.py