Skip to main content
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

from tools.curl_search_tool import CurlSearchTool

Extends

langchain_core.tools.BaseTool

Constructor

CurlSearchTool takes no configuration parameters.
tool = CurlSearchTool()

Methods

_run

Executes a curl subprocess call to the Wikipedia search API and returns formatted snippets.
def _run(self, query: str) -> str
query
str
required
The search query string. Passed as-is to the Wikipedia srsearch parameter.
returns
str
On success, up to 3 result lines joined by newlines, each in the format:
Result N (Title): snippet text
HTML tags are stripped from each snippet before formatting.

Error return values

All error conditions return a descriptive string rather than raising an exception:
ConditionReturn 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:
Mozilla/5.0 (Linux; U; Android 4.0.3; en-us; HTC Sensation Build/IML74K) AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0 Mobile Safari/534.30
curl is invoked with -s (silent), -L (follow redirects), and -A (custom User-Agent).
The tool depends on curl being available in the system PATH. It will fail with a CalledProcessError if curl is not installed or is not executable.

_arun

Async version. Delegates directly to _run.
def _arun(self, query: str) -> str
query
str
required
The search query string.
returns
str
Same output as _run.

Usage Example

from tools.curl_search_tool import CurlSearchTool

tool = CurlSearchTool()

# --- Direct call ---
result = tool._run("Large language models")
print(result)
# Result 1 (Large language model): large language model (LLM) is ...
# Result 2 (GPT-4): GPT-4 is multimodal large language model ...
# Result 3 (ChatGPT): ChatGPT is artificial intelligence chatbot ...

# --- Via LangChain invoke interface ---
result = tool.invoke("Transformer neural network architecture")
print(result)

# --- Pass to ExecutionAgent as a tool ---
from agents.execution_agent import ExecutionAgent

executor = ExecutionAgent(
    llm=llm,
    tools=[CurlSearchTool()],
)

output = executor.execute_step(
    "Find information about the history of the Eiffel Tower"
)
print(output)

Build docs developers (and LLMs) love