Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Research Agent

A minimal agentic loop in one TypeScript file: you give it a research question, it searches the web (Tavily) in a loop until it's confident, then returns a synthesized answer with sources. Built to be read, not shipped — no framework, just the Anthropic SDK and fetch.

How it works

The whole agent is src/agent.ts:

  1. The question goes into a history array; the full history is resent every turn.
  2. The model is called with one custom tool, web_search(query).
  3. If the response contains a tool_use block, our code calls Tavily, appends a tool_result to history, and loops.
  4. If the response has no tool call, that's the final answer.
  5. Hard cap of 15 iterations — on the last one the tool is withheld and the model is told to synthesize from what it has.

The system prompt tells the model to break the question into sub-searches, cross-check claims across at least 2 sources, and answer in a fixed format (direct answer → detail → sources).

Setup

Requires Node 18+ (uses built-in fetch).

npm install
cp .env.example .env   # then fill in both keys

You need:

Run

npm run research -- "What caused the 2024 CrowdStrike outage and what changed since?"

Each step is logged to the console — which query it searched, how many results came back, and when it decided to stop — so you can watch the loop work.

Notes

  • Model: claude-sonnet-5 (adaptive thinking is on by default; the loop appends the full response.content back to history each turn, which keeps thinking and tool_use blocks intact as the API requires).
  • The Anthropic SDK retries rate limits and 5xx errors itself; Tavily calls get a small exponential-backoff wrapper.
  • A failed search is fed back to the model as an is_error tool result so it can adapt (rephrase the query) instead of crashing the run.

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages