Skip to main content
Contributed by Ethan Ruhe on 2026-01-16
Deep research systems combine multiple agents with web retrieval to produce evidence-based reports. These tasks can involve dozens of searches and hundreds of documents, creating failure modes that Temporal’s durable execution helps protect against. This cookbook shows you how to build a deep research system with Temporal workflows and Braintrust observability. By the end of this cookbook, you’ll learn how to:
  • Build a multi-agent system with four specialized research agents
  • Use Temporal workflows for durable, resilient AI task execution
  • Add Braintrust tracing to debug and improve agent performance
  • Use structured outputs to ensure reliable communication between agents

The deep research architecture

The system uses four specialized agents, each implemented as a Temporal activity:
  1. Planning - Decomposes the research question into specific aspects with priorities
  2. Query generation - Creates optimized search queries for each aspect
  3. Web search - Retrieves and analyzes relevant documents
  4. Report synthesis - Combines findings into a comprehensive report
The workflow orchestrates these agents, executing searches in parallel and continuing with partial results if some fail.

Getting started

To get started, you’ll need: Set the required environment variables:
Clone the cookbook and install dependencies:

Running the example

This example requires three terminal tabs: Terminal 1 - Start the Temporal dev server:
Terminal 2 - Run the worker:
Terminal 3 - Start a research query:

Creating the data structures

We use Pydantic models to ensure information passes between agents in a structured way. The complete models are in agents/shared.py. The planning agent creates a ResearchPlan:
The query generation agent creates search queries:
The web search agent returns results with findings and citations:
The report synthesis agent creates the final report:

Building the agents

Each agent is implemented as a Temporal activity that calls OpenAI’s API. We use a shared invoke_model activity that handles API calls with Braintrust tracing.

Research planning agent

The research planning agent analyzes the query and creates a comprehensive strategy. It decomposes the question into 3-7 key aspects, identifies expected source types, and defines success criteria:
The complete implementation is in agents/research_planning.py.
Setting an appropriate start_to_close_timeout is critical. If it’s too short, the activity will fail with a timeout error, causing a retry loop. Response times for reasoning models can vary significantly depending on query complexity.

Query generation agent

The query generation agent converts the research plan into optimized web search queries. It targets different information types (factual data, expert analysis, case studies, and recent news) using varied query styles and temporal modifiers:
The complete implementation is in agents/research_query_generation.py.

Web search agent

The web search agent executes searches using OpenAI’s web search tool. It prioritizes authoritative sources like academic papers, government sites, and established news outlets, then extracts key findings with proper citations and relevance scores:
The complete implementation is in agents/research_web_search.py.

Report synthesis agent

The report synthesis agent combines all research findings into a comprehensive, well-cited report. It weighs authoritative sources more heavily, addresses contradictory findings transparently, and generates follow-up questions for deeper research:
The complete implementation is in agents/research_report_synthesis.py.

Creating the workflow

The DeepResearchWorkflow orchestrates the four-phase research process:
The workflow executes searches in parallel and continues with partial results if some fail:

Adding observability

Multi-agent systems like deep research are notoriously difficult to debug. When a report contains incorrect information, you need to trace back through the planning, query generation, and search phases to understand what went wrong. Did the planner miss a key aspect? Did a search query return irrelevant results? Did the synthesis agent misinterpret the findings? With the BraintrustPlugin, you get automatic tracing for every workflow and activity execution. It captures the full execution graph, including parallel searches and retries:
The invoke_model activity wraps the OpenAI client with Braintrust for detailed LLM call tracing:
In the Braintrust logs, you’ll see the complete trace for each research request, including:
  • The research plan generated by the planning agent
  • Each search query and its rationale
  • Web search results with relevance scores
  • The final synthesized report
Deep research trace in Braintrust This visibility is essential for improving agent performance over time. You can identify which types of queries produce low-relevance results, spot patterns in planning failures, and build evaluation datasets from real research traces to systematically improve each agent.

Next steps