Creating the Final Research Report
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
