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:
- Initial query — search with the user's original question
- Read top results — extract key facts from the best 3 sources
- Identify gaps — what important questions remain unanswered?
- Follow-up queries — generate targeted searches for gaps
- 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
- Tavily and SerpAPI for Agent Search
- Ranking and Filtering Search Results
- Deep Research Loop Pattern
- Combining Web Search with RAG