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 graph 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.search import search
5from opentine.tools.web import fetch
6
7agent = Agent(
8    model=Anthropic("claude-sonnet-4-20250514"),
9    tools=[search, fetch],
10    system="""You are a research assistant. Given a topic:
111. Search for recent, authoritative sources
122. Fetch and read the most relevant pages
133. Synthesize your findings into a clear summary
144. Cite your sources with URLs""",
15    max_steps=30,
16)
17
18async def main():
19    run = await agent.run("Research the latest advances in quantum computing")
20    print(run.steps[-1].outputs or run.steps[-1].inputs)
21    run.save("quantum_research.tine")
22
23asyncio.run(main())

How It Works

The agent is configured with the search and fetch tools from opentine.tools.search and 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 graph. 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.search import search
4from opentine.tools.web import fetch
5
6# Load the saved run
7run = Run.load("quantum_research.tine")
8
9# Fork from the inspected step before synthesis to try a different angle.
10# Use tine show to choose the exact traversal position for your run.
11fork_point = run.steps[7].id
12forked = run.fork(from_step_id=fork_point)
13
14# Create a new agent with a modified system prompt
15agent = Agent(
16    model=Anthropic("claude-sonnet-4-20250514"),
17    tools=[search, fetch],
18    system="Focus specifically on practical applications and commercial timelines.",
19)
20
21# Resume from the fork point with an explicit continuation prompt.
22resumed = agent.resume_sync(
23    forked,
24    prompt="Synthesize again with emphasis on practical applications and commercial timelines.",
25)
26resumed.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