0PricingLogin
AI Agents · Lesson

Multi-Step Research Loop Design

Plan → search → read → extract → synthesize → repeat until sufficient depth.

What is a Research Loop?

A research loop is an agentic pattern where an LLM plans, searches, reads, extracts, identifies gaps, and repeats until the research goal is satisfied.

Unlike a single-shot search, the loop adapts based on what it finds — following unexpected leads and discarding dead ends.

Phase 1: Question Decomposition

The first step is breaking the research question into sub-questions. This creates a directed search plan and prevents the agent from aimlessly browsing.

import openai, json

client = openai.OpenAI(api_key='YOUR_OPENAI_KEY')

def decompose_question(question: str) -> list[str]:
    prompt = (
        f'Break this research question into 3-5 focused sub-questions.\n'
        f'Each sub-question should be independently searchable.\n'
        f'Question: "{question}"\n'
        f'Return JSON: {{"sub_questions": ["..."]}}'
    )
    resp = client.chat.completions.create(
        model='gpt-4o',
        messages=[{'role': 'user', 'content': prompt}],
        response_format={'type': 'json_object'}
    )
    return json.loads(resp.choices[0].message.content)['sub_questions']

questions = decompose_question('What are the main causes of inflation in 2024?')
print(questions)

All lessons in this course

  1. Multi-Step Research Loop Design
  2. Source Verification and Citation
  3. Structured Report Generation
  4. Fact-Checking and Hallucination Prevention
← Back to AI Agents