An intelligent multi-agent assistant built on the Mastra framework, integrating RAG (Retrieval-Augmented Generation), data analysis, trending news, sports information, and more.
- Secretary Agent - Main coordinator for task routing and management
- Data Analyze Agent - MySQL database queries and analysis specialist
- Hot News Agent - Chinese platform trending topics (Zhihu, Weibo, Bilibili, etc.)
- Employee Rules Agent - RAG-powered HR policy and handbook assistant
- Hot News MCP - Trending news via Exa API
- 12306 MCP - China Railway train ticket queries (currently disabled)
- DBHub MCP - MySQL database connections
- BallDontLie MCP - Multi-league sports data (NBA/NFL/MLB/NHL/CBA)
- TODO MCP - Personal todo management via natural language (currently disabled)
- 📊 Database queries and SQL analysis
- 📰 Real-time trending news from Chinese platforms
- ⚽ Multi-league sports statistics
- 🚄 Train ticket search and trip planning
- 📖 RAG-based Q&A with Milvus vector database (Employee Handbook & Knowledge Book)
- 🤖 Intelligent Agent-to-Agent collaboration (A2A)
- 💾 Conversation memory with LibSQL
- ✅ Personal todo management (TODO MCP - currently disabled)
- Node.js >= 20.9.0
- MySQL (optional, for data analysis features)
- Milvus (for RAG features, can run via Docker)
- API Keys for various services (see configuration below)
npm installCopy env.example to .env:
cp env.example .envEdit .env with your configuration:
# OpenAI API Configuration
OPENAI_API_KEY=sk-your-actual-api-key
OPENAI_BASE_URL=https://api.openai.com/v1
# Milvus Vector Database (for RAG)
MILVUS_HOST=localhost
MILVUS_PORT=19530
EMPLOYEE_RULES_COLLECTION=employee_rules
MILVUS_COLLECTION=knowledge_book
# Redis Cache (optional, for query caching)
REDIS_HOST=localhost
REDIS_PORT=6379
# EXA API (Hot News) - Get from https://exa.ai
EXA_API_KEY=your-exa-api-key
# BallDontLie API (Sports) - Get from https://balldontlie.com
BALLDONTLIE_API_KEY=your-balldontlie-api-key
# MySQL Database Connection (optional)
MYSQL_DSN=mysql://username:password@host:port/database?sslmode=disable# Milvus Standalone
docker run -d \
--name milvus-standalone \
-p 19530:19530 \
-p 9091:9091 \
-p 2379:2379 \
-e ETCD_USE_EMBED=true \
-e COMMON_STORAGETYPE=local \
milvusdb/milvus:v2.4.4 \
milvus run standalone
# Redis (for caching)
docker run -d \
--name redis \
-p 6379:6379 \
redis:latestPlace your employee handbook in data/employee-rules.txt (or .pdf), then run:
npm run index-pdfPlace your knowledge book in data/dmbj.txt, then run:
npm run index-dmbjExpected output:
📘 员工手册索引工具 (Milvus)
📍 Milvus 地址: localhost:19530
📂 Collection: employee_rules
✂️ 分割成 28 个块
🧮 生成嵌入向量...
✅ 索引完成!
Development Mode
npm run devServer starts at http://localhost:4111
Production Build
npm run build
npm startWe provide a modern React-based web interface for interacting with the agents:
# Navigate to web directory
cd web
# Install dependencies (first time only)
npm install
# Start development server
npm run devFrontend runs at http://localhost:3000
Features:
- 💬 ChatGPT-style chat interface
- 🌓 Dark mode support
- 📱 Responsive design (mobile & desktop)
- ✨ Markdown message rendering
- ⌨️ Keyboard shortcuts (Enter to send, Shift+Enter for newline)
- 🔄 Real-time backend connection status
See web/README.md for detailed frontend documentation.
DataAnalyzeHelper/
├── src/
│ └── mastra/
│ ├── agents/ # Agent definitions
│ │ ├── secretary-agent.ts
│ │ ├── data-analyze-agent.ts
│ │ ├── hot-news-agent.ts
│ │ └── employee-ruler-agent.ts # RAG Agent
│ ├── mcp/ # MCP clients
│ │ ├── hot-news-client.ts
│ │ ├── 12306-client.ts
│ │ ├── mysql-client.ts
│ │ ├── sport-news-client.ts
│ │ └── mem0-client.ts
│ ├── config/ # Configuration
│ ├── tools/ # Custom tools
│ ├── workflows/ # Workflows
│ └── index.ts # Mastra instance
├── web/ # 🎨 Web Frontend (NEW!)
│ ├── src/
│ │ ├── api/client.ts # Mastra API client
│ │ ├── App.tsx # Main chat component
│ │ └── main.tsx # Entry point
│ ├── vite.config.ts
│ └── package.json
├── data/ # Documents for RAG
│ └── employee-rules.txt
├── scripts/ # Utility scripts
│ ├── index-pdf.ts # Document indexing
│ ├── test-mem0.ts # Test Mem0 integration
│ └── test-knowledge-book.ts # Test knowledge book agent
├── docs/ # Documentation
├── milvus-data/ # Milvus storage (if local, ignored)
├── env.example # Environment template
├── package.json
└── README.md
Main coordinator responsible for:
- Receiving and routing user requests
- Direct handling: train tickets, sports news
- Delegation: database analysis, trending news, HR policies
Professional data analyst capable of:
- Querying MySQL database schemas
- Executing SQL queries
- Analyzing data and generating insights
- Creating structured data reports
Fetches trending topics from:
- Zhihu Hot List
- Weibo Trending
- Bilibili Trending
- Douyin, Hupu, Douban, etc.
AI-powered HR assistant features:
- Vector Search: Semantic similarity search using Milvus
- Smart Caching: Redis-based query cache with similarity matching
- Query Optimization: Query rewriting and reranking for better accuracy
- Bilingual Support: Chinese and English queries
- Source Citations: Always quotes handbook references
User: What types of leave are available?
→ Secretary Agent → Employee Rules Agent → RAG Search → Returns 7 leave types with citations
User: NBA scores today
→ Secretary Agent → Sport News Tools → Returns today's NBA games
User: What's trending on Weibo?
→ Secretary Agent → Hot News Agent → Returns Weibo hot topics
User: Query sales data from tb_shop table
→ Secretary Agent → Data Analyze Agent → SQL Execution → Analysis Report
User: Beijing to Shanghai high-speed trains
→ Secretary Agent → 12306 Tools → Returns available trains
User Query
↓
Employee Rules Agent
↓
Query Input
↓
Redis Cache Check (Similarity-based)
↓ [Cache Miss]
Query Rewriting (Optional)
↓
Vector Search (Milvus)
↓
Reranking (Optional)
↓
Top-K Relevant Chunks
↓
GPT-4o-mini (Answer Generation)
↓
Structured Answer + Citations
↓
Cache Result
-
Smart Caching
- Redis-based query cache
- Similarity-based cache hits (cosine similarity > 0.95)
- TTL: 1 hour (configurable)
-
Query Rewriting (Optional)
- Generate multiple query variants
- Improves retrieval recall
- Configurable count (default: 2)
-
Reranking (Optional)
- Auto: Simple queries → embedding, complex → LLM
- Embedding: Fast cosine similarity reranking
- LLM: GPT-4o-mini semantic scoring
-
Smart Chunking
- Chunk size: 512 characters
- Overlap: 50 characters
- Preserves context continuity
-
Embedding Model
- Model:
text-embedding-3-small - Dimensions: 1536
- Provider: OpenAI
- Model:
All MCP configurations are in src/mastra/config/config.ts, using environment variables.
Supported services:
mcp-server-hotnews- News service (Exa)12306-mcp- Railway ticketsdbhub- MySQL databaseballdontlie- Sports data
- Location:
mastra.db(ignored in git) - Stores: Agent conversations, context, observability
- Docker container with persistent volumes
- Stores: Document embeddings (Employee Rules + Knowledge Book)
- Collections:
employee_rules,knowledge_book - Index: IVF_FLAT with L2 distance
- Docker container
- Stores: Query embeddings and results
- TTL: 1 hour per query
✅ DO:
- Use environment variables for all secrets
- Keep
.envfile out of version control - Use
env.exampleas a template - Regularly rotate API keys
❌ DON'T:
- Commit
.envto Git - Hardcode API keys in source code
- Share credentials in public repos
- Use production keys in development
- Place document in
data/directory (.txtor.pdf) - Update
employee-ruler-agent.tsfile path if needed - Run indexing:
npm run index-pdf - Restart server:
npm run dev
In src/mastra/agents/employee-ruler-agent.ts:
// Chunk size and overlap
maxSize: 512, // Increase for more context
overlap: 50, // Increase for better continuity
// Top-K results
topK: 5, // Number of chunks to retrieveMastra's A2A enables seamless delegation:
agents: {
secretaryAgent,
dataAnalyzeAgent,
hotNewsAgent,
employeeRulerAgent, // Auto-registered for A2A
}- Framework: Mastra - AI Agent Framework
- AI Model: OpenAI GPT-4o-mini
- Vector DB: Milvus
- Cache: Redis
- Embedding: OpenAI text-embedding-3-small
- Database: LibSQL (local), MySQL (analysis)
- Protocol: MCP (Model Context Protocol)
- Language: TypeScript
- Runtime: Node.js >= 20.9.0
# Check if Milvus is running
docker ps | grep milvus
# Restart Milvus
docker restart milvus-standalone
# Check Milvus logs
docker logs milvus-standalone# Check file exists
ls -la data/employee-rules.txt
ls -la data/dmbj.txt
# Check OpenAI API key
echo $OPENAI_API_KEY
# Re-run indexing
npm run index-pdf # Employee Rules
npm run index-dmbj # Knowledge Book# Check if collections exist (using Python)
from pymilvus import connections, utility
connections.connect(host='localhost', port='19530')
print(utility.list_collections())
# Re-index documents
npm run index-pdf
npm run index-dmbj# Check Redis connection
docker ps | grep redis
redis-cli -h localhost -p 6379 ping
# Clear cache
redis-cli -h localhost -p 6379 FLUSHDBISC
Issues and Pull Requests are welcome!
Please ensure:
- No sensitive data in commits
- Update both README.md and README.zh-CN.md
- Test RAG features after changes
Built with ❤️ using Mastra