Skip to content

Commit 808c299

Browse files
authored
Added deep research example (#2166)
* Added docs * Improved docs and added video * Added upgrade badge
1 parent 498b9a2 commit 808c299

File tree

3 files changed

+168
-59
lines changed

3 files changed

+168
-59
lines changed

docs/docs.json

Lines changed: 13 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,7 @@
1010
},
1111
"favicon": "/images/favicon.png",
1212
"contextual": {
13-
"options": [
14-
"copy",
15-
"view",
16-
"claude"
17-
]
13+
"options": ["copy", "view", "claude"]
1814
},
1915
"navigation": {
2016
"dropdowns": [
@@ -39,11 +35,7 @@
3935
"pages": [
4036
{
4137
"group": "Tasks",
42-
"pages": [
43-
"tasks/overview",
44-
"tasks/schemaTask",
45-
"tasks/scheduled"
46-
]
38+
"pages": ["tasks/overview", "tasks/schemaTask", "tasks/scheduled"]
4739
},
4840
"triggering",
4941
"runs",
@@ -58,12 +50,7 @@
5850
"errors-retrying",
5951
{
6052
"group": "Wait",
61-
"pages": [
62-
"wait",
63-
"wait-for",
64-
"wait-until",
65-
"wait-for-token"
66-
]
53+
"pages": ["wait", "wait-for", "wait-until", "wait-for-token"]
6754
},
6855
"queue-concurrency",
6956
"versioning",
@@ -108,9 +95,7 @@
10895
},
10996
{
11097
"group": "Development",
111-
"pages": [
112-
"cli-dev"
113-
]
98+
"pages": ["cli-dev"]
11499
},
115100
{
116101
"group": "Deployment",
@@ -122,9 +107,7 @@
122107
"deployment/atomic-deployment",
123108
{
124109
"group": "Deployment integrations",
125-
"pages": [
126-
"vercel-integration"
127-
]
110+
"pages": ["vercel-integration"]
128111
}
129112
]
130113
},
@@ -177,12 +160,7 @@
177160
},
178161
{
179162
"group": "Using the Dashboard",
180-
"pages": [
181-
"run-tests",
182-
"troubleshooting-alerts",
183-
"replaying",
184-
"bulk-actions"
185-
]
163+
"pages": ["run-tests", "troubleshooting-alerts", "replaying", "bulk-actions"]
186164
},
187165
{
188166
"group": "Troubleshooting",
@@ -218,11 +196,7 @@
218196
},
219197
{
220198
"group": "Help",
221-
"pages": [
222-
"community",
223-
"help-slack",
224-
"help-email"
225-
]
199+
"pages": ["community", "help-slack", "help-email"]
226200
}
227201
]
228202
},
@@ -243,10 +217,7 @@
243217
},
244218
{
245219
"group": "Tasks API",
246-
"pages": [
247-
"management/tasks/trigger",
248-
"management/tasks/batch-trigger"
249-
]
220+
"pages": ["management/tasks/trigger", "management/tasks/batch-trigger"]
250221
},
251222
{
252223
"group": "Runs API",
@@ -292,9 +263,7 @@
292263
"groups": [
293264
{
294265
"group": "Introduction",
295-
"pages": [
296-
"guides/introduction"
297-
]
266+
"pages": ["guides/introduction"]
298267
},
299268
{
300269
"group": "Frameworks",
@@ -376,6 +345,7 @@
376345
"guides/example-projects/realtime-csv-importer",
377346
"guides/example-projects/realtime-fal-ai",
378347
"guides/example-projects/turborepo-monorepo-prisma",
348+
"guides/example-projects/vercel-ai-sdk-deep-research",
379349
"guides/example-projects/vercel-ai-sdk-image-generator"
380350
]
381351
},
@@ -407,9 +377,7 @@
407377
},
408378
{
409379
"group": "Migration guides",
410-
"pages": [
411-
"migration-mergent"
412-
]
380+
"pages": ["migration-mergent"]
413381
},
414382
{
415383
"group": "Community packages",
@@ -430,10 +398,7 @@
430398
"href": "https://trigger.dev"
431399
},
432400
"api": {
433-
"openapi": [
434-
"openapi.yml",
435-
"v3-openapi.yaml"
436-
],
401+
"openapi": ["openapi.yml", "v3-openapi.yaml"],
437402
"playground": {
438403
"display": "simple"
439404
}
@@ -608,4 +573,4 @@
608573
"destination": "/management/overview"
609574
}
610575
]
611-
}
576+
}
Lines changed: 143 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
1+
---
2+
title: "Deep research agent using Vercel's AI SDK"
3+
sidebarTitle: "Deep research agent"
4+
description: "Deep research agent which generates comprehensive PDF reports using Vercel's AI SDK."
5+
tag: "v4"
6+
---
7+
8+
import RealtimeLearnMore from "/snippets/realtime-learn-more.mdx";
9+
10+
import UpgradeToV4Note from "/snippets/upgrade-to-v4-note.mdx";
11+
12+
<UpgradeToV4Note />
13+
14+
<Info title="Acknowledgements">
15+
Acknowledgements: This example project is derived from the brilliant [deep research
16+
guide](https://aie-feb-25.vercel.app/docs/deep-research) by [Nico
17+
Albanese](https://x.com/nicoalbanese10).
18+
</Info>
19+
20+
## Overview
21+
22+
This full-stack project is an intelligent deep research agent that autonomously conducts multi-layered web research, generating comprehensive reports which are then converted to PDF and uploaded to storage.
23+
24+
<video
25+
controls
26+
className="w-full aspect-video"
27+
src="https://github.com/user-attachments/assets/aa86d2b2-7aa7-4948-82ff-5e1e80cf8e37"
28+
></video>
29+
30+
**Tech stack:**
31+
32+
- **[Next.js](https://nextjs.org/)** for the web app
33+
- **[Vercel's AI SDK](https://sdk.vercel.ai/)** for AI model integration and structured generation
34+
- **[Trigger.dev](https://trigger.dev)** for task orchestration, execution and real-time progress updates
35+
- **[OpenAI's GPT-4o model](https://openai.com/gpt-4)** for intelligent query generation, content analysis, and report creation
36+
- **[Exa API](https://exa.ai/)** for semantic web search with live crawling
37+
- **[LibreOffice](https://www.libreoffice.org/)** for PDF generation
38+
- **[Cloudflare R2](https://developers.cloudflare.com/r2/)** to store the generated reports
39+
40+
**Features:**
41+
42+
- **Recursive research**: AI generates search queries, evaluates their relevance, asks follow-up questions and searches deeper based on initial findings.
43+
- **Real-time progress**: Live updates are shown on the frontend using Trigger.dev Realtime as research progresses.
44+
- **Intelligent source evaluation**: AI evaluates search result relevance before processing.
45+
- **Research report generation**: The completed research is converted to a structured HTML report using a detailed system prompt.
46+
- **PDF creation and uploading to Cloud storage**: The completed reports are then converted to PDF using LibreOffice and uploaded to Cloudflare R2.
47+
48+
## GitHub repo
49+
50+
<Card
51+
title="View the Vercel AI SDK deep research agent repo"
52+
icon="GitHub"
53+
href="https://github.com/triggerdotdev/examples/tree/main/vercel-ai-sdk-deep-research-agent"
54+
>
55+
Click here to view the full code for this project in our examples repository on GitHub. You can
56+
fork it and use it as a starting point for your own project.
57+
</Card>
58+
59+
## How the deep research agent works
60+
61+
### Trigger.dev orchestration
62+
63+
The research process is orchestrated through three connected Trigger.dev tasks:
64+
65+
1. `deepResearchOrchestrator` - Main task that coordinates the entire research workflow.
66+
2. `generateReport` - Processes research data into a structured HTML report using OpenAI's GPT-4o model
67+
3. `generatePdfAndUpload` - Converts HTML to PDF using LibreOffice and uploads to R2 cloud storage
68+
69+
Each task uses `triggerAndWait()` to create a dependency chain, ensuring proper sequencing while maintaining isolation and error handling.
70+
71+
### The deep research recursive function
72+
73+
The core research logic uses a recursive depth-first search approach. A query is recursively expanded and the results are collected.
74+
75+
**Key parameters:**
76+
77+
- `depth`: Controls recursion levels (default: 2)
78+
- `breadth`: Number of queries per level (default: 2, halved each recursion)
79+
80+
```
81+
Level 0 (Initial Query): "AI safety in autonomous vehicles"
82+
83+
├── Level 1 (depth = 1, breadth = 2):
84+
│ ├── Sub-query 1: "Machine learning safety protocols in self-driving cars"
85+
│ │ ├── → Search Web → Evaluate Relevance → Extract Learnings
86+
│ │ └── → Follow-up: "How do neural networks handle edge cases?"
87+
│ │
88+
│ └── Sub-query 2: "Regulatory frameworks for autonomous vehicle testing"
89+
│ ├── → Search Web → Evaluate Relevance → Extract Learnings
90+
│ └── → Follow-up: "What are current safety certification requirements?"
91+
92+
└── Level 2 (depth = 2, breadth = 1):
93+
├── From Sub-query 1 follow-up:
94+
│ └── "Neural network edge case handling in autonomous systems"
95+
│ └── → Search Web → Evaluate → Extract → DEPTH LIMIT REACHED
96+
97+
└── From Sub-query 2 follow-up:
98+
└── "Safety certification requirements for self-driving vehicles"
99+
└── → Search Web → Evaluate → Extract → DEPTH LIMIT REACHED
100+
```
101+
102+
**Process flow:**
103+
104+
1. **Query generation**: OpenAI's GPT-4o generates multiple search queries from the input
105+
2. **Web search**: Each query searches the web via the Exa API with live crawling
106+
3. **Relevance evaluation**: OpenAI's GPT-4o evaluates if results help answer the query
107+
4. **Learning extraction**: Relevant results are analyzed for key insights and follow-up questions
108+
5. **Recursive deepening**: Follow-up questions become new queries for the next depth level
109+
6. **Accumulation**: All learnings, sources, and queries are accumulated across recursion levels
110+
111+
### Using Trigger.dev Realtime to trigger and subscribe to the deep research task
112+
113+
We use the [`useRealtimeTaskTrigger`](/frontend/react-hooks/triggering#userealtimetasktrigger) React hook to trigger the `deep-research` task and subscribe to it's updates.
114+
115+
**Frontend (React Hook)**:
116+
117+
```typescript
118+
const triggerInstance = useRealtimeTaskTrigger<typeof deepResearchOrchestrator>("deep-research", {
119+
accessToken: triggerToken,
120+
});
121+
const { progress, label } = parseStatus(triggerInstance.run?.metadata);
122+
```
123+
124+
As the research progresses, the metadata is set within the tasks and the frontend is kept updated with every new status:
125+
126+
**Task Metadata**:
127+
128+
```typescript
129+
metadata.set("status", {
130+
progress: 25,
131+
label: `Searching the web for: "${query}"`,
132+
});
133+
```
134+
135+
## Relevant code
136+
137+
- **Deep research task**: Core logic in [src/trigger/deepResearch.ts](https://github.com/triggerdotdev/examples/blob/main/vercel-ai-sdk-deep-research-agent/src/trigger/deepResearch.ts) - orchestrates the recursive research process. Here you can change the model, the depth and the breadth of the research.
138+
- **Report generation**: [src/trigger/generateReport.ts](https://github.com/triggerdotdev/examples/blob/main/vercel-ai-sdk-deep-research-agent/src/trigger/generateReport.ts) - creates structured HTML reports from research data. The system prompt is defined in the code - this can be updated to be more or less detailed.
139+
- **PDF generation**: [src/trigger/generatePdfAndUpload.ts](https://github.com/triggerdotdev/examples/blob/main/vercel-ai-sdk-deep-research-agent/src/trigger/generatePdfAndUpload.ts) - converts reports to PDF and uploads to R2. This is a simple example of how to use LibreOffice to convert HTML to PDF.
140+
- **Research agent UI**: [src/components/DeepResearchAgent.tsx](https://github.com/triggerdotdev/examples/blob/main/vercel-ai-sdk-deep-research-agent/src/components/DeepResearchAgent.tsx) - handles form submission and real-time progress display using the `useRealtimeTaskTrigger` hook.
141+
- **Progress component**: [src/components/progress-section.tsx](https://github.com/triggerdotdev/examples/blob/main/deep-research-agent/src/components/progress-section.tsx) - displays live research progress.
142+
143+
<RealtimeLearnMore />

docs/guides/introduction.mdx

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -43,17 +43,18 @@ Get set up fast using our detailed walk-through guides.
4343

4444
Example projects are full projects with example repos you can fork and use. These are a great way of learning how to encorporate Trigger.dev into your project.
4545

46-
| Example project | Description | Framework | GitHub |
47-
| :-------------------------------------------------------------------------------------- | :------------------------------------------------------------------------------------------------------------------------------------- | :-------- | :------------------------------------------------------------------------------------------------------------ |
48-
| [Batch LLM Evaluator](/guides/example-projects/batch-llm-evaluator) | Evaluate multiple LLM models and stream the results to the frontend. | Next.js | [View the repo](https://github.com/triggerdotdev/examples/tree/main/batch-llm-evaluator) |
49-
| [Claude thinking chatbot](/guides/example-projects/claude-thinking-chatbot) | Use Vercel's AI SDK and Anthropic's Claude 3.7 model to create a thinking chatbot. | Next.js | [View the repo](https://github.com/triggerdotdev/examples/tree/main/claude-thinking-chatbot) |
50-
| [Human-in-the-loop workflow](/guides/example-projects/human-in-the-loop-workflow) | Create audio summaries of newspaper articles using a human-in-the-loop workflow built with ReactFlow and Trigger.dev waitpoint tokens. | Next.js | [View the repo](https://github.com/triggerdotdev/examples/tree/main/article-summary-workflow) |
51-
| [OpenAI Agent SDK guardrails](/guides/example-projects/openai-agent-sdk-guardrails) | Use the OpenAI Agent SDK to create a guardrails system for your AI agents. || [View the repo](https://github.com/triggerdotdev/examples/tree/main/openai-agent-sdk-guardrails-examples) |
52-
| [Python web crawler](/guides/python/python-crawl4ai) | Use Python, Crawl4AI and Playwright to create a headless web crawler with Trigger.dev. || [View the repo](https://github.com/triggerdotdev/examples/tree/main/python-crawl4ai) |
53-
| [Realtime CSV Importer](/guides/example-projects/realtime-csv-importer) | Upload a CSV file and see the progress of the task streamed to the frontend. | Next.js | [View the repo](https://github.com/triggerdotdev/examples/tree/main/realtime-csv-importer) |
54-
| [Realtime Fal.ai image generation](/guides/example-projects/realtime-fal-ai) | Generate an image from a prompt using Fal.ai and show the progress of the task on the frontend using Realtime. | Next.js | [View the repo](https://github.com/triggerdotdev/examples/tree/main/realtime-fal-ai-image-generation) |
55-
| [Turborepo monorepo with Prisma](/guides/example-projects/turborepo-monorepo-prisma) | Use Prisma in a Turborepo monorepo with Trigger.dev. | Next.js | [View the repo](https://github.com/triggerdotdev/examples/tree/main/monorepos/turborepo-prisma-tasks-package) |
56-
| [Vercel AI SDK image generator](/guides/example-projects/vercel-ai-sdk-image-generator) | Use the Vercel AI SDK to generate images from a prompt. | Next.js | [View the repo](https://github.com/triggerdotdev/examples/tree/main/vercel-ai-sdk-image-generator) |
46+
| Example project | Description | Framework | GitHub |
47+
| :---------------------------------------------------------------------------------------- | :------------------------------------------------------------------------------------------------------------------------------------- | :-------- | :------------------------------------------------------------------------------------------------------------ |
48+
| [Batch LLM Evaluator](/guides/example-projects/batch-llm-evaluator) | Evaluate multiple LLM models and stream the results to the frontend. | Next.js | [View the repo](https://github.com/triggerdotdev/examples/tree/main/batch-llm-evaluator) |
49+
| [Claude thinking chatbot](/guides/example-projects/claude-thinking-chatbot) | Use Vercel's AI SDK and Anthropic's Claude 3.7 model to create a thinking chatbot. | Next.js | [View the repo](https://github.com/triggerdotdev/examples/tree/main/claude-thinking-chatbot) |
50+
| [Human-in-the-loop workflow](/guides/example-projects/human-in-the-loop-workflow) | Create audio summaries of newspaper articles using a human-in-the-loop workflow built with ReactFlow and Trigger.dev waitpoint tokens. | Next.js | [View the repo](https://github.com/triggerdotdev/examples/tree/main/article-summary-workflow) |
51+
| [OpenAI Agent SDK guardrails](/guides/example-projects/openai-agent-sdk-guardrails) | Use the OpenAI Agent SDK to create a guardrails system for your AI agents. || [View the repo](https://github.com/triggerdotdev/examples/tree/main/openai-agent-sdk-guardrails-examples) |
52+
| [Python web crawler](/guides/python/python-crawl4ai) | Use Python, Crawl4AI and Playwright to create a headless web crawler with Trigger.dev. || [View the repo](https://github.com/triggerdotdev/examples/tree/main/python-crawl4ai) |
53+
| [Realtime CSV Importer](/guides/example-projects/realtime-csv-importer) | Upload a CSV file and see the progress of the task streamed to the frontend. | Next.js | [View the repo](https://github.com/triggerdotdev/examples/tree/main/realtime-csv-importer) |
54+
| [Realtime Fal.ai image generation](/guides/example-projects/realtime-fal-ai) | Generate an image from a prompt using Fal.ai and show the progress of the task on the frontend using Realtime. | Next.js | [View the repo](https://github.com/triggerdotdev/examples/tree/main/realtime-fal-ai-image-generation) |
55+
| [Turborepo monorepo with Prisma](/guides/example-projects/turborepo-monorepo-prisma) | Use Prisma in a Turborepo monorepo with Trigger.dev. | Next.js | [View the repo](https://github.com/triggerdotdev/examples/tree/main/monorepos/turborepo-prisma-tasks-package) |
56+
| [Vercel AI SDK image generator](/guides/example-projects/vercel-ai-sdk-image-generator) | Use the Vercel AI SDK to generate images from a prompt. | Next.js | [View the repo](https://github.com/triggerdotdev/examples/tree/main/vercel-ai-sdk-image-generator) |
57+
| [Vercel AI SDK deep research agent](/guides/example-projects/vercel-ai-sdk-deep-research) | Use the Vercel AI SDK to generate comprehensive PDF reports using a deep research agent. | Next.js | [View the repo](https://github.com/triggerdotdev/examples/tree/main/vercel-ai-sdk-deep-research-agent) |
5758

5859
## Example tasks
5960

0 commit comments

Comments
 (0)