
Deep Research Assistant with Mastra
This project implements an advanced AI deep research assistant using Mastra's workflows and agent capabilities. It creates an interactive, human-in-the-loop research system that allows users to explore topics, evaluate results, and generate comprehensive reports.
Implementation Approach
The research assistant is built on Mastra's workflows architecture for better orchestration and human interaction:
-
Workflow-Based Architecture:
mainWorkflow
: Coordinates the entire research processresearchWorkflow
: Handles the core research functionality with suspend/resume for user interaction- Human-in-the-loop experience with approval gates and iterative research
-
Research Agent with Custom Tools:
webSearchTool
: Searches the web using the Exa API for relevant informationevaluateResultTool
: Assesses result relevance to the research topicextractLearningsTool
: Identifies key learnings and generates follow-up questions
-
Report Generation:
reportAgent
: Transforms research findings into comprehensive markdown reports- Returns report content directly after user approval of research quality
Key Benefits of Mastra vNext Implementation
-
True Human-in-the-Loop Research: Users can guide the research process, approve findings, and iterate when needed
-
Suspend/Resume Capabilities: The workflow can pause at strategic points to collect user input and feedback
-
Structured Workflow: Clear separation between research, approval, and report generation phases
-
Resilient Operation: Robust error handling and fallback mechanisms when web searches fail
-
Modular Design: Each component (workflows, agents, tools) can be maintained and upgraded independently
How to Use
1# Install dependencies
2npm install
3
4# Run the research assistant
5npm run dev
Follow the interactive prompts:
- Enter your research topic
- Review the research findings
- Approve or reject the research results
- If approved, a comprehensive report will be returned as output
Required Environment Variables
Create a .env
file with:
1OPENAI_API_KEY=""
2EXA_API_KEY="your-exa-api-key"
Required Dependencies
@mastra/core
: Core Mastra functionality with vNext workflows@ai-sdk/openai
: OpenAI models integrationexa-js
: Exa API client for web searchzod
: Schema definition and validation for workflows