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:

Terminal
# 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 automatically

If no API key is found, opentine falls back to DuckDuckGo HTML scraping. No configuration needed — it just works.

search

search_example.py
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, default 5) — Maximum number of results to return.

Returns

A formatted markdown string containing search results with titles, URLs, and snippets.

search_limited.py
# Limit to 3 results
result = await search("solid-state batteries 2026", max_results=3)

fetch

fetch_example.py
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, default 8000) — 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.

fetch_long.py
# Get more content from a long page
text = await fetch("https://example.com/long-article", max_chars=20000)

fetch_raw

fetch_raw_example.py
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.

web_agent.py
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