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.
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
-
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
# Install dependencies
npm install
# Run the research assistant
npm run devFollow 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
Create a .env file with:
OPENAI_API_KEY=""
EXA_API_KEY="your-exa-api-key"
@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