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.

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.

3. Generating New Search Queries After Each Round

Before:
There was no way to generate new queries based on what had already been found.

Now:
After each round, DeepResearcher combines all the information it has gathered so far and asks the language model to suggest new search queries. This allows the tool to “think ahead” and refine its research path.

If the model returns an empty string, the loop stops—signaling that no further searching is needed.

4. Tracking All Search Queries

Before:
There was no record of which queries had already been used.

Now:
The all_search_queries list is updated with every new query generated. This prevents DeepResearcher from repeating the same searches and helps it keep track of its research history.

5. Improved Output and Error Handling

Before:
There was no indication of which round was running, and errors in query generation could cause issues.

Now:

  • The code prints the current iteration number at the start of each round.
  • It notifies the user if no useful context was found in a round.
  • It checks that new queries are valid lists and handles parsing errors gracefully.
Summary

With these modifications, DeepResearcher now:

  • Repeats the search-extract-plan cycle for multiple rounds.
  • Aggregates all useful information across rounds.
  • Uses accumulated knowledge to generate smarter, more targeted queries.
  • Tracks all queries to avoid repetition.
  • Provides clearer output and robust error handling.

These changes make DeepResearcher a much more powerful and flexible research tool, capable of digging deeper and adapting its strategy as it learns. In the next practice, you’ll get hands-on experience with this new iterative approach!

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