0Pricing
AI Agents · Lesson

Deep Research Loop Pattern

Query → read → extract → synthesize → query again multi-hop research.

What Is the Deep Research Loop?

A deep research loop is an agent pattern where the agent iteratively searches, reads, identifies knowledge gaps, and searches again until it has gathered enough information to write a comprehensive answer.

Unlike a single search, this pattern mimics how a human researcher works: explore → learn → discover unknowns → dig deeper.

Loop Architecture Overview

The deep research loop has five phases that repeat:

  1. Initial query — search with the user's original question
  2. Read top results — extract key facts from the best 3 sources
  3. Identify gaps — what important questions remain unanswered?
  4. Follow-up queries — generate targeted searches for gaps
  5. Synthesize — combine all gathered facts into a final answer
def deep_research(question, max_iterations=3):
    all_facts = []
    queries_used = [question]

    for iteration in range(max_iterations):
        results = search_and_rank(queries_used[-1])
        facts = extract_facts(results, question)
        all_facts.extend(facts)

        gaps = identify_knowledge_gaps(question, all_facts)
        if not gaps:
            print(f'Research complete after {iteration + 1} iterations')
            break

        follow_up = generate_follow_up_query(gaps)
        queries_used.append(follow_up)
        print(f'Iteration {iteration + 1}: {follow_up}')

    return synthesize_answer(question, all_facts)

All lessons in this course

  1. Tavily and SerpAPI for Agent Search
  2. Ranking and Filtering Search Results
  3. Deep Research Loop Pattern
  4. Combining Web Search with RAG
← Back to AI Agents