Web & Search Tools
The opentine.tools.web module provides three async functions for web interaction: searching, fetching page content, and making raw HTTP requests.
Provider Auto-Selection
The search function automatically selects a search provider based on which API key is available in your environment. Set one of these and opentine handles the rest:
# Pick one — opentine auto-detects which key is available
export TAVILY_API_KEY="tvly-..." # Best quality
export EXA_API_KEY="exa-..." # Alternative
export BRAVE_API_KEY="BSA..." # Alternative
# No key? DuckDuckGo HTML fallback is used automaticallyIf no API key is found, opentine falls back to DuckDuckGo HTML scraping. No configuration needed — it just works.
search
1from opentine.tools.web import search
2
3# Auto-selects provider based on available env vars:
4# TAVILY_API_KEY → Tavily
5# EXA_API_KEY → Exa
6# BRAVE_API_KEY → Brave Search
7# (none) → DuckDuckGo HTML fallback
8
9result = await search("latest advances in quantum computing")
10print(result) # Formatted markdown with titles, URLs, and snippets
Parameters
- query (
str) — The search query string. - max_results (
int, default5) — Maximum number of results to return.
Returns
A formatted markdown string containing search results with titles, URLs, and snippets.
# Limit to 3 results
result = await search("solid-state batteries 2026", max_results=3)fetch
1from opentine.tools.web import fetch
2
3# Fetch a URL, strip HTML tags, return clean text
4text = await fetch("https://example.com/article")
5print(text) # Plain text content, up to 8000 chars
Parameters
- url (
str) — The URL to fetch. - max_chars (
int, default8000) — Maximum number of characters to return. HTML is stripped and the text is truncated to this limit.
Returns
A string containing the page content with HTML tags stripped.
# Get more content from a long page
text = await fetch("https://example.com/long-article", max_chars=20000)fetch_raw
1from opentine.tools.web import fetch_raw
2
3# Get the full HTTP response as a dict
4response = await fetch_raw("https://api.example.com/data")
5print(response["status"]) # 200
6print(response["headers"]) # {"content-type": "application/json", ...}
7print(response["body"]) # Raw response body as string
Parameters
- url (
str) — The URL to fetch.
Returns
A dictionary with three keys:
- status (
int) — The HTTP status code. - headers (
dict) — Response headers as key-value pairs. - body (
str) — The raw response body as a string.
Use fetch_raw when you need access to headers, status codes, or the unprocessed response body — for example, when working with JSON APIs.
Using with an Agent
Pass search and fetchdirectly to the agent's tool list. The agent will call them as needed during execution.
1from opentine import Agent
2from opentine.models.anthropic import Anthropic
3from opentine.tools.web import search, fetch
4
5agent = Agent(
6 model=Anthropic("claude-sonnet-4-20250514"),
7 tools=[search, fetch],
8 system="Search the web and summarize your findings.",
9)
10
11run = agent.run_sync("What happened at the latest AI conference?")
Next Steps
- File System tools — read, write, edit, and list files
- Shell & Python tools — run commands and execute code
- Research Agent recipe — a complete example using web tools