SearXNG Web Search
Privacy-respecting web search skill powered by SearXNG, a free metasearch engine
that aggregates results from 243+ search services without tracking users.
Rewritten from PulseBot's built-in web search skill to use SearXNG as the backend,
packaged as a standalone agentskills.io skill.
Prerequisites
- 1. A running SearXNG instance (self-hosted or accessible endpoint)
- JSON format must be enabled in your SearXNG
settings.yml:
CODEBLOCK0
- 3. Python
requests library installed
Configuration
The skill uses environment variables for configuration:
| Variable | Default | Description |
|---|
| INLINECODE2 | INLINECODE3 | SearXNG instance URL |
| INLINECODE4 |
10 | Maximum results to return |
|
SEARXNG_LANGUAGE |
all | Default search language (e.g.
en,
zh,
all) |
|
SEARXNG_SAFESEARCH |
0 | Safe search level: 0=off, 1=moderate, 2=strict |
|
SEARXNG_TIMEOUT |
15 | Request timeout in seconds |
|
SEARXNG_CATEGORIES |
general | Default categories (comma-separated) |
Usage
Run the search script:
CODEBLOCK1
With options:
CODEBLOCK2
Output Format
The script outputs JSON to stdout with the following structure:
CODEBLOCK3
If an error occurs, results will be empty and error will contain the message.
As a Python Module
You can also import and use the search function directly:
CODEBLOCK4
Integration with PulseBot
To register this skill in PulseBot, place it under skills/ and PulseBot
will discover it via SKILL.md frontmatter. The Python script can also be
called as a tool function by wrapping it:
CODEBLOCK5
Edge Cases
- - If SearXNG is unreachable, the script returns a structured error with
error field set - If no results are found,
results is an empty list (not an error) - Some engines may be unresponsive; check
unresponsive_engines in verbose mode - Rate-limited public instances may return 429; prefer self-hosted instances
- Queries with special characters are URL-encoded automatically
SearXNG Setup (Quick Start)
For details on deploying SearXNG, see references/REFERENCE.md.
CODEBLOCK6
Then edit /etc/searxng/settings.yml to add json to search.formats.
SearXNG 网络搜索
基于SearXNG的隐私保护网络搜索技能,SearXNG是一个免费元搜索引擎,能够聚合来自243+个搜索服务的结果,且不追踪用户。
从PulseBot内置的网络搜索技能重写而来,使用SearXNG作为后端,打包为独立的agentskills.io技能。
前置条件
- 1. 一个运行中的SearXNG实例(自托管或可访问的端点)
- 必须在SearXNG的settings.yml中启用JSON格式:
yaml
search:
formats:
- html
- json
- 3. 安装Python requests库
配置
该技能使用环境变量进行配置:
| 变量 | 默认值 | 描述 |
|---|
| SEARXNGBASEURL | http://localhost:8080 | SearXNG实例URL |
| SEARXNGMAXRESULTS |
10 | 返回的最大结果数 |
| SEARXNG_LANGUAGE | all | 默认搜索语言(例如 en、zh、all) |
| SEARXNG_SAFESEARCH | 0 | 安全搜索级别:0=关闭,1=中等,2=严格 |
| SEARXNG_TIMEOUT | 15 | 请求超时时间(秒) |
| SEARXNG_CATEGORIES | general | 默认类别(逗号分隔) |
使用方法
运行搜索脚本:
bash
python scripts/searxng_search.py 你的搜索查询
带选项运行:
bash
python scripts/searxng_search.py 最新AI新闻 \
--categories news \
--language en \
--time-range day \
--max-results 5
输出格式
脚本以JSON格式输出到标准输出,结构如下:
json
{
query: 搜索查询,
results: [
{
title: 结果标题,
url: https://example.com,
snippet: 来自页面的文本片段...,
engines: [google, bing],
score: 9.0,
category: general,
published_date: 2025-01-01T00:00:00
}
],
suggestions: [相关查询1, 相关查询2],
answers: [直接答案(如果有)],
total_results: 10,
error: null
}
如果发生错误,results将为空,error将包含错误信息。
作为Python模块使用
你也可以直接导入并使用搜索函数:
python
from scripts.searxng_search import SearXNGSearchTool
tool = SearXNGSearchTool(base_url=http://localhost:8080)
results = tool.search(量子计算, categories=science,it, max_results=5)
for r in results[results]:
print(f[{r[title]}]({r[url]}))
print(f {r[snippet]})
与PulseBot集成
要在PulseBot中注册此技能,将其放置在skills/目录下,PulseBot将通过SKILL.md的前置元数据自动发现它。Python脚本也可以通过包装作为工具函数调用:
python
from skills.searxngwebsearch.scripts.searxng_search import SearXNGSearchTool
tool = SearXNGSearchTool()
def websearch(query: str, categories: str = general, maxresults: int = 10) -> str:
使用SearXNG搜索网络。返回JSON格式结果。
result = tool.search(query, categories=categories, maxresults=maxresults)
return json.dumps(result, indent=2)
边界情况
- - 如果SearXNG无法访问,脚本返回带有error字段的结构化错误
- 如果未找到结果,results为空列表(不是错误)
- 某些引擎可能无响应;在详细模式下检查unresponsive_engines
- 受速率限制的公共实例可能返回429;建议使用自托管实例
- 包含特殊字符的查询会自动进行URL编码
SearXNG设置(快速入门)
关于部署SearXNG的详细信息,请参见references/REFERENCE.md。
bash
docker run -d --name searxng -p 8080:8080 \
-v $(pwd)/searxng:/etc/searxng \
searxng/searxng:latest
然后编辑/etc/searxng/settings.yml,在search.formats中添加json。