Skip to content

Commit b0ce123

Browse files
committed
Added docs
1 parent 3f2b748 commit b0ce123

File tree

3 files changed

+158
-59
lines changed

3 files changed

+158
-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: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
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+
<Info title="Acknowledgements">
11+
Acknowledgements: This example project is derived from the brilliant [deep research
12+
guide](https://aie-feb-25.vercel.app/docs/deep-research) by [Nico
13+
Albanese](https://x.com/nicoalbanese10).
14+
</Info>
15+
16+
## Overview
17+
18+
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.
19+
20+
**Tech stack:**
21+
22+
- **[Next.js](https://nextjs.org/)** for the web app
23+
- **[Vercel's AI SDK](https://sdk.vercel.ai/)** for AI model integration and structured generation
24+
- **[Trigger.dev](https://trigger.dev)** for task orchestration, execution and real-time progress updates
25+
- **[OpenAI's GPT-4o model](https://openai.com/gpt-4)** for intelligent query generation, content analysis, and report creation
26+
- **[Exa API](https://exa.ai/)** for semantic web search with live crawling
27+
- **[LibreOffice](https://www.libreoffice.org/)** for PDF generation
28+
- **[Cloudflare R2](https://developers.cloudflare.com/r2/)** to store the generated reports
29+
30+
**Features:**
31+
32+
- **Recursive research**: AI generates search queries, evaluates their relevance, asks follow-up questions and searches deeper based on initial findings.
33+
- **Real-time progress**: Live updates are shown on the frontend using Trigger.dev Realtime as research progresses.
34+
- **Intelligent source evaluation**: AI evaluates search result relevance before processing.
35+
- **Research report generation**: The completed research is converted to a structured HTML report using a detailed system prompt.
36+
- **PDF creation and uploading to Cloud storage**: The completed reports are then converted to PDF using LibreOffice and uploaded to Cloudflare R2.
37+
38+
## GitHub repo
39+
40+
<Card
41+
title="View the Vercel AI SDK deep research agent repo"
42+
icon="GitHub"
43+
href="https://github.com/triggerdotdev/examples/tree/main/vercel-ai-sdk-deep-research-agent"
44+
>
45+
Click here to view the full code for this project in our examples repository on GitHub. You can
46+
fork it and use it as a starting point for your own project.
47+
</Card>
48+
49+
## How the deep research agent works
50+
51+
### Trigger.dev orchestration
52+
53+
The research process is orchestrated through three connected Trigger.dev tasks:
54+
55+
1. `deepResearchOrchestrator` - Main task that coordinates the entire research workflow.
56+
2. `generateReport` - Processes research data into a structured HTML report using OpenAI's GPT-4o model
57+
3. `generatePdfAndUpload` - Converts HTML to PDF using LibreOffice and uploads to R2 cloud storage
58+
59+
Each task uses `triggerAndWait()` to create a dependency chain, ensuring proper sequencing while maintaining isolation and error handling.
60+
61+
### The deep research recursive function
62+
63+
The core research logic uses a recursive depth-first search approach. A query is recursively expanded and the results are collected.
64+
65+
**Key parameters:**
66+
67+
- `depth`: Controls recursion levels (default: 2)
68+
- `breadth`: Number of queries per level (default: 2, halved each recursion)
69+
70+
```
71+
Level 0 (Initial Query): "AI safety in autonomous vehicles"
72+
73+
├── Level 1 (depth = 1, breadth = 2):
74+
│ ├── Sub-query 1: "Machine learning safety protocols in self-driving cars"
75+
│ │ ├── → Search Web → Evaluate Relevance → Extract Learnings
76+
│ │ └── → Follow-up: "How do neural networks handle edge cases?"
77+
│ │
78+
│ └── Sub-query 2: "Regulatory frameworks for autonomous vehicle testing"
79+
│ ├── → Search Web → Evaluate Relevance → Extract Learnings
80+
│ └── → Follow-up: "What are current safety certification requirements?"
81+
82+
└── Level 2 (depth = 2, breadth = 1):
83+
├── From Sub-query 1 follow-up:
84+
│ └── "Neural network edge case handling in autonomous systems"
85+
│ └── → Search Web → Evaluate → Extract → DEPTH LIMIT REACHED
86+
87+
└── From Sub-query 2 follow-up:
88+
└── "Safety certification requirements for self-driving vehicles"
89+
└── → Search Web → Evaluate → Extract → DEPTH LIMIT REACHED
90+
```
91+
92+
**Process flow:**
93+
94+
1. **Query generation**: OpenAI's GPT-4o generates multiple search queries from the input
95+
2. **Web search**: Each query searches the web via the Exa API with live crawling
96+
3. **Relevance evaluation**: OpenAI's GPT-4o evaluates if results help answer the query
97+
4. **Learning extraction**: Relevant results are analyzed for key insights and follow-up questions
98+
5. **Recursive deepening**: Follow-up questions become new queries for the next depth level
99+
6. **Accumulation**: All learnings, sources, and queries are accumulated across recursion levels
100+
101+
### Trigger.dev Realtime progress updates
102+
103+
As each task is completed, the metadata is set and the frontend is updated:
104+
105+
**Task metadata**:
106+
107+
```typescript
108+
metadata.set("status", {
109+
progress: 25,
110+
label: `Searching the web for: "${query}"`,
111+
});
112+
```
113+
114+
**Frontend (React hook)**:
115+
116+
We use the [`useRealtimeTaskTrigger`](https://trigger.dev/docs/frontend/react-hooks/triggering#userealtimetasktrigger) hook to get the task metadata and update the frontend in real-time.
117+
118+
```typescript
119+
const triggerInstance = useRealtimeTaskTrigger<typeof deepResearchOrchestrator>("deep-research", {
120+
accessToken: triggerToken,
121+
});
122+
const { progress, label } = parseStatus(triggerInstance.run?.metadata);
123+
```
124+
125+
## Relevant code
126+
127+
- **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.
128+
- **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.
129+
- **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.
130+
- **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.
131+
- **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.
132+
133+
<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)