Skip to main content
You can get the full code for this example by running:
And selecting the “Deep Research Agent” template.

Codewalk

This research agent runs multiple search iterations, extracts facts from sources, and evaluates when it has enough information to provide a comprehensive answer. It uses prompt chaining for sequential research steps and evaluator-optimizer patterns for quality assessment.
User
Your API
Agent
Tool
Business Logic
API Request
External Call
Response
Tool Result
Agent Response
API Response

Architecture Overview

The research agent runs up to 3 iterations of search, fact extraction, and evaluation. Each iteration plans new searches based on what information is still missing, then judges whether the collected facts are sufficient before continuing or generating a final summary.

Implementation

This example shows how to build research agents that improve their results through multiple iterations, using quality gates to determine when they have enough information.

Research Agent

This tool analyzes existing knowledge and identifies information gaps to generate targeted search queries for each iteration.
Executes web searches using OpenAI’s preview search tool with context-aware query optimization.
Extracts and cleans website content, converting it to structured markdown for fact extraction.
Extracts structured facts from content with relevance scoring and source attribution for comprehensive research tracking.
Implements quality gates at multiple stages to ensure comprehensive coverage and identify missing aspects for continued research.
Generates comprehensive, well-cited summaries that synthesize all collected facts into a coherent research report.

Key Features

Multiple Iterations: Runs up to 3 research cycles, planning each search based on what information is missing from previous rounds. Quality Gates: Uses the evaluator-optimizer pattern to judge whether collected facts are sufficient before continuing to the next iteration. Source Tracking: Prevents duplicate sources and maintains citation indexes throughout the research process. Gap-Based Planning: Each search iteration focuses on filling specific knowledge gaps rather than collecting redundant information.

Usage

This example combines prompt chaining for sequential research steps with evaluator-optimizer for quality assessment, showing how to build research agents that improve through iteration.