Iterative Search: Refining Research Through Multiple Rounds

Introduction: Evolving DeepResearcher with Iterative Search

In the previous lesson, you learned how DeepResearcher could take a research question, generate search queries, and extract useful information from web pages—all in a single round. However, real research often requires digging deeper: using what you’ve found to guide further searching. In this lesson, we’ll focus on the key modifications that transform DeepResearcher from a single-pass tool into an iterative, multi-round research assistant.

Quick Recap: The Single-Round Approach

Previously, DeepResearcher worked as follows:

  • It generated a list of search queries from the user’s question.
  • It searched the web for each query and evaluated the usefulness of each page.
  • It extracted relevant information from useful pages.
  • All of this happened in just one round—no follow-up searches based on what was found.

While this approach works for simple questions, it often misses deeper or related information that only becomes apparent after reviewing initial results.

Step-by-Step: What’s New in the Iterative Version

Let’s walk through the key modifications that enable DeepResearcher to perform iterative, multi-round research.

1. Introducing the Iterative Search Loop

Before:
DeepResearcher performed all its work in a single pass.

Now:
A while loop has been added to the perform_iterative_research function. This loop allows the tool to repeat the search-extract-plan cycle multiple times, up to a user-defined limit.

def perform_iterative_research(user_query: str, new_search_queries: list, all_search_queries: list, iteration_limit: int):
    aggregated_contexts = []
    iteration = 0

    while iteration < iteration_limit:
        print(f"\n=== Iteration {iteration + 1} ===")
        iteration_contexts = []
        # ...search, extract, and plan...
        iteration += 1

    return aggregated_contexts

2. Aggregating Contexts Across Rounds

Before:
Extracted information was stored in a single list for one round.

Now:
A new list, aggregated_contexts, collects all useful information found across every round. Each iteration’s new findings are added to this master list, ensuring nothing is lost as the research progresses.

    # Inside the while loop
    if iteration_contexts:
        aggregated_contexts.extend(iteration_contexts)
    else:
        print("No useful context found this round.")
Sign up

Join the 1M+ learners on CodeSignal

Be a part of our community of 1M+ users who develop and demonstrate their skills on CodeSignal