docs/guides/example-projects/vercel-ai-sdk-deep-research.mdx
import RealtimeLearnMore from "/snippets/realtime-learn-more.mdx";
<Info title="Acknowledgements"> Acknowledgements: This example project is derived from the brilliant [deep research guide](https://aie-feb-25.vercel.app/docs/deep-research) by [Nico Albanese](https://x.com/nicoalbanese10). </Info>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.
<video controls className="w-full aspect-video" src="https://github.com/user-attachments/assets/aa86d2b2-7aa7-4948-82ff-5e1e80cf8e37"
</video>
Tech stack:
Features:
<Card title="View the Vercel AI SDK deep research agent repo" icon="GitHub" href="https://github.com/triggerdotdev/examples/tree/main/vercel-ai-sdk-deep-research-agent"
Click here to view the full code for this project in our examples repository on GitHub. You can fork it and use it as a starting point for your own project. </Card>
The research process is orchestrated through three connected Trigger.dev tasks:
deepResearchOrchestrator - Main task that coordinates the entire research workflow.generateReport - Processes research data into a structured HTML report using OpenAI's GPT-4o modelgeneratePdfAndUpload - Converts HTML to PDF using LibreOffice and uploads to R2 cloud storageEach task uses triggerAndWait() to create a dependency chain, ensuring proper sequencing while maintaining isolation and error handling.
The core research logic uses a recursive depth-first search approach. A query is recursively expanded and the results are collected.
Key parameters:
depth: Controls recursion levels (default: 2)breadth: Number of queries per level (default: 2, halved each recursion)Level 0 (Initial Query): "AI safety in autonomous vehicles"
│
├── Level 1 (depth = 1, breadth = 2):
│ ├── Sub-query 1: "Machine learning safety protocols in self-driving cars"
│ │ ├── → Search Web → Evaluate Relevance → Extract Learnings
│ │ └── → Follow-up: "How do neural networks handle edge cases?"
│ │
│ └── Sub-query 2: "Regulatory frameworks for autonomous vehicle testing"
│ ├── → Search Web → Evaluate Relevance → Extract Learnings
│ └── → Follow-up: "What are current safety certification requirements?"
│
└── Level 2 (depth = 2, breadth = 1):
├── From Sub-query 1 follow-up:
│ └── "Neural network edge case handling in autonomous systems"
│ └── → Search Web → Evaluate → Extract → DEPTH LIMIT REACHED
│
└── From Sub-query 2 follow-up:
└── "Safety certification requirements for self-driving vehicles"
└── → Search Web → Evaluate → Extract → DEPTH LIMIT REACHED
Process flow:
We use the useRealtimeTaskTrigger React hook to trigger the deep-research task and subscribe to it's updates.
Frontend (React Hook):
const triggerInstance = useRealtimeTaskTrigger<typeof deepResearchOrchestrator>("deep-research", {
accessToken: triggerToken,
});
const { progress, label } = parseStatus(triggerInstance.run?.metadata);
As the research progresses, the metadata is set within the tasks and the frontend is kept updated with every new status:
Task Metadata:
metadata.set("status", {
progress: 25,
label: `Searching the web for: "${query}"`,
});
useRealtimeTaskTrigger hook.