Introduction: Wrapping Up the Research Process

Welcome to the final lesson of the DeepResearcher course! Up to this point, you have learned how to set up the DeepResearcher project, generate search queries using OpenAI, filter and extract useful information from web pages, and refine your research through multiple search rounds.

Now, it’s time to bring everything together. In this lesson, you will learn how to create a final research report. This report is the end goal of all your previous work — it combines the user’s original question with all the relevant information you’ve gathered and uses AI to write a clear, well-structured summary. By the end of this lesson, you’ll know exactly how DeepResearcher produces a professional report from your research process.

Recall: From Contexts to Report

Let’s quickly remind ourselves of what you’ve already accomplished. In earlier lessons, you learned how to collect and store relevant information from web pages. Each time you found a useful piece of information, you added it to a list called contexts. This list is important because it holds all the key details that will be used to write your final report.

Think of contexts as a collection of research notes. Now, your task is to turn these notes into a polished report that answers the user’s original question.

How the Final Report Is Generated

The final report is created by a function called generate_final_report. This function takes two main inputs:

  • The user’s original research question (user_query)
  • The list of relevant information you gathered (contexts)

The function then combines these inputs and uses a prompt template to guide the AI in writing a detailed report. Let’s break down how this works, step by step.

Step 1: Preparing the Inputs

First, you need to combine all the gathered contexts into a single string. This is done by joining the list with newline characters so the AI can see all the information at once.

Here, contexts is your list of research notes, and context_combined is a single string containing all of them, separated by new lines.

Step 2: Setting Up the Variables for the Prompt

Next, you create a dictionary called variables that holds the user’s query and the combined contexts. This dictionary will be used to fill in the prompt template.

  • user_query is the original question or topic the user wants to research.
  • context_combined is the string of all relevant information you’ve gathered.
Step 3: Generating the Report with the AI

Now, you use the generate_response function to ask the AI to write the report. This function takes the names of the prompt templates and the variables you just prepared.

  • "report_writer_system" and "report_writer_user" are the names of the prompt files that guide the AI on how to write the report. You will write them in the practices.
  • variables provides the actual content for the AI to use.

The AI reads the prompt, sees the user’s question and all the gathered contexts, and writes a detailed report.

Example: Generating a Report in Code

Let’s look at a complete example of how to generate the final report. Here’s the relevant part of the code from your project:

Let’s break this down:

  1. The function takes the user’s query and the list of contexts.
  2. It prepares the variables for the prompt.
  3. It calls generate_response to get the AI-generated report.
  4. It prints the final report to the screen.

Example Output:

Suppose the user’s query is:

And the contexts list contains:

The output might look like:

This example shows how the function takes your research notes and turns them into a clear, well-organized report.

Summary And Congratulations

In this lesson, you learned how to generate a final research report by combining the user’s question with all the relevant information you gathered. You saw how to prepare the inputs, use prompt templates, and call the AI to write a detailed summary. This step completes the DeepResearcher workflow, turning your research process into a professional, readable report.

Congratulations on reaching the end of the DeepResearcher course! You now have all the skills needed to build and use your own AI-powered research tool. Take a moment to celebrate your progress, and get ready to apply what you’ve learned in the hands-on practice exercises that follow. Well done!

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