This example project is derived from the brilliant deep research
guide by Nico
Albanese.
Overview
This full-stack Next.js project is an intelligent deep research agent that autonomously conducts multi-layered web research, generates a comprehensive structured report, converts it to a PDF, and uploads it to cloud storage — all with real-time progress updates on the frontend. Tech stack:- Next.js — web application
- Vercel AI SDK — AI model integration and structured generation
- Trigger.dev — task orchestration, execution, and real-time progress
- OpenAI GPT-4o — query generation, content analysis, report writing
- Exa API — semantic web search with live crawling
- LibreOffice — HTML-to-PDF conversion
- Cloudflare R2 — stores the generated PDF reports
GitHub repo
View the deep research agent repo
Fork this repo to use it as a starting point for your own research agent.
How the agent works
Task orchestration
Three Trigger.dev tasks are chained together usingtriggerAndWait, each handling a distinct phase
of the pipeline:
deepResearchOrchestrator— coordinates the entire research workflowgenerateReport— converts accumulated research into a structured HTML report using GPT-4ogeneratePdfAndUpload— converts the HTML to PDF with LibreOffice and uploads to R2
src/trigger/deepResearch.ts
Recursive research algorithm
The core research logic uses a recursive depth-first approach. At each level the agent:- Generates multiple search queries from the current question using GPT-4o
- Searches the web via the Exa API
- Evaluates the relevance of each result
- Extracts key learnings and follow-up questions
- Recurses on the follow-up questions at the next depth level
Real-time progress with Trigger.dev Realtime
The frontend uses theuseRealtimeTaskTrigger hook to both trigger the task and subscribe to
progress updates without polling:
src/components/DeepResearchAgent.tsx
src/trigger/deepResearch.ts
Relevant code files
| File | Description |
|---|---|
src/trigger/deepResearch.ts | Core recursive research logic and orchestrator task |
src/trigger/generateReport.ts | Converts research data into a structured HTML report |
src/trigger/generatePdfAndUpload.ts | Converts HTML to PDF with LibreOffice and uploads to R2 |
src/components/DeepResearchAgent.tsx | Frontend form and real-time progress display |
Learn more
Trigger.dev Realtime
Subscribe to runs and stream live progress to your frontend
React hooks
Trigger a task and subscribe to its updates from a React component
Run metadata
Store and broadcast arbitrary data from inside a running task
triggerAndWait
Chain tasks together and wait for each to complete before continuing