Research Agent

This recipe builds a research agent that searches the web, fetches and reads pages, and synthesizes findings into a report. It demonstrates the core opentine workflow: run, save, inspect, and fork.

What It Does

  • Searches the web for relevant sources using search
  • Fetches and reads the most relevant pages using fetch
  • Synthesizes findings into a clear summary with citations
  • Saves the entire run tree to a .tine file for inspection and forking

Prerequisites

Terminal
export ANTHROPIC_API_KEY="sk-ant-..."

# Optional: set a search provider API key for better results
export TAVILY_API_KEY="tvly-..."    # or EXA_API_KEY or BRAVE_API_KEY

The search tool auto-selects a provider based on available API keys. Without a search provider key, it falls back to DuckDuckGo HTML scraping.

Full Example

research.py
1import asyncio
2from opentine import Agent
3from opentine.models.anthropic import Anthropic
4from opentine.tools.web import search, fetch
5
6agent = Agent(
7    model=Anthropic("claude-sonnet-4-20250514"),
8    tools=[search, fetch],
9    system="""You are a research assistant. Given a topic:
101. Search for recent, authoritative sources
112. Fetch and read the most relevant pages
123. Synthesize your findings into a clear summary
134. Cite your sources with URLs""",
14    max_steps=30,
15)
16
17async def main():
18    run = await agent.run("Research the latest advances in quantum computing")
19    print(run.final_output())
20    run.save("quantum_research.tine")
21
22asyncio.run(main())

How It Works

The agent is configured with the search and fetch tools from opentine.tools.web. The system prompt guides the agent through a structured research workflow. The max_steps=30 limit prevents runaway execution.

Every step the agent takes — searching, fetching, thinking, responding — is recorded in the run tree. After completion, the run is saved to a .tine file.

Running It

Terminal
python research.py

Inspecting the Run

Use the CLI to see every step the agent took:

Terminal
tine show quantum_research.tine

Example output:

Terminal
Run: quantum_research
Status: completed | Steps: 12 | Cost: $0.0341 | Duration: 18.7s

[think]  Planning research approach...
[tool]   search("quantum computing breakthroughs 2026")
[model]  Found 5 relevant results, fetching top 3...
[tool]   fetch("https://example.com/quantum-review")
[tool]   fetch("https://example.com/ibm-quantum-update")
[tool]   fetch("https://example.com/google-willow")
[model]  Synthesizing findings across 3 sources...
[done]   Research complete

Forking for a Different Angle

The real power of opentine: if the synthesis wasn't what you wanted, fork from an earlier step and try a different approach. The expensive search and fetch steps are reused — no wasted tokens.

fork_research.py
1from opentine import Run, Agent
2from opentine.models.anthropic import Anthropic
3from opentine.tools.web import search, fetch
4
5# Load the saved run
6run = Run.load("quantum_research.tine")
7
8# Fork from step 8 (before synthesis) to try a different angle
9forked = run.fork(from_step_id="step_abc123")
10
11# Create a new agent with a modified system prompt
12agent = Agent(
13    model=Anthropic("claude-sonnet-4-20250514"),
14    tools=[search, fetch],
15    system="Focus specifically on practical applications and commercial timelines.",
16)
17
18# Resume from the fork point — reuses the first 8 steps
19resumed = agent.resume(forked)
20resumed.save("quantum_research_v2.tine")

The forked run reuses all steps up to the fork point. Only the synthesis step runs again with the new prompt, saving both time and cost.

Next Steps