trading_agent.tools.web_search_tool
¶
The web_search tool: searches the web, or recent news, through the local SearXNG server.
SearXNG asks several search engines at once and merges their answers, so one engine failing does not stop a search. Results are labelled as data from the web, because a page's title or snippet may contain text written to mislead an AI model.
Typical usage example:
tool = WebSearchTool('http://127.0.0.1:4001', result_limit=8)
WebSearchArguments
¶
Bases: BaseModel
The arguments of web_search.
Attributes:
| Name | Type | Description |
|---|---|---|
query |
str
|
What to search for. |
category |
Literal['general', 'news']
|
"news" for news articles, "general" for the whole web. |
time_range |
Literal['day', 'week', 'month', 'year'] | None
|
Only results from the last day, week, month or year, or None for any time. |
WebSearchTool
¶
Bases: Tool
Searches through SearXNG.
Creates the tool.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
searxng_base_url
|
str
|
The SearXNG server's address. |
required |
result_limit
|
int
|
The most results to return. |
required |
transport
|
AsyncBaseTransport | None
|
What sends the requests; a test passes a fake one, and None means the network. |
None
|
Source code in src/trading_agent/tools/web_search_tool.py
run
async
¶
Runs the search, adding unfiltered results when the time range finds too few.
A time range makes SearXNG skip every engine that cannot filter by date, so a filtered news search can come back nearly empty while an unfiltered one finds plenty. The extra results are shown newest first, after a notice, so the model checks the dates itself.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
arguments
|
WebSearchArguments
|
The query and filters. |
required |
Returns:
| Type | Description |
|---|---|
ToolResult
|
One numbered entry per result, or an error when SearXNG cannot be reached. |