CurlSearchTool is a LangChain BaseTool that delegates web search to the system curl binary. It targets the Wikipedia OpenSearch API, strips HTML tags from the returned snippets, and surfaces the top 3 results as plain text. It can be passed directly to an ExecutionAgent as a tool.
Tool name: curl_search
Import
Extends
langchain_core.tools.BaseTool
Constructor
CurlSearchTool takes no configuration parameters.
Methods
_run
Executes a curl subprocess call to the Wikipedia search API and returns formatted snippets.
The search query string. Passed as-is to the Wikipedia
srsearch parameter.On success, up to 3 result lines joined by newlines, each in the format:HTML tags are stripped from each snippet before formatting.
Error return values
All error conditions return a descriptive string rather than raising an exception:| Condition | Return value |
|---|---|
| No search results | "No results found for query: '<query>'" |
curl non-zero exit | "Curl command failed with error: <stderr>" |
| Invalid JSON response | "Failed to parse search results. Raw output: <first 200 chars>..." |
| Any other exception | "An unexpected error occurred: <exception>" |
Implementation notes
The tool spoofs an Android 4.0.3 mobile
User-Agent string to avoid simple bot-detection blocks on the Wikipedia API. The full agent string is:curl is invoked with -s (silent), -L (follow redirects), and -A (custom User-Agent)._arun
Async version. Delegates directly to _run.
The search query string.
Same output as
_run.