trading_agent.tools.web_fetch_tool
¶
The web_fetch tool: downloads one web page and returns its main text, title and date.
The page is downloaded with a plain HTTP request and its article text is picked out with trafilatura. That works for most news sites in a fraction of a second. Sites that build the page with JavaScript, or that block automated requests, return no text or HTTP 403; the result then says so and suggests opening the page in the browser instead. Every address, including each redirect, must be on the public internet.
Typical usage example:
tool = WebFetchTool(timeout_seconds=20, maximum_characters=15000)
WebFetchArguments
¶
Bases: BaseModel
The arguments of web_fetch.
Attributes:
| Name | Type | Description |
|---|---|---|
url |
str
|
The page's address, starting with http:// or https://. |
WebFetchTool
¶
Bases: Tool
Fetches one page's main text.
Creates the tool.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
timeout_seconds
|
float
|
How long the download may take. |
required |
maximum_characters
|
int
|
How much of the page's text to return. |
required |
transport
|
AsyncBaseTransport | None
|
What sends the requests; a test passes a fake one, and None means the network. |
None
|
guard
|
AddressGuard | None
|
The address check, or None for the normal one. |
None
|
Source code in src/trading_agent/tools/web_fetch_tool.py
run
async
¶
Downloads the page and extracts its text.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
arguments
|
WebFetchArguments
|
The page's address. |
required |
Returns:
| Type | Description |
|---|---|
ToolResult
|
The title, date, address and text, or an error saying why the page could not be read. |