Building Kemuko Support: An AI Agent for EdTech with Mastra
Building Kemuko Support: An AI Agent for EdTech with Mastra
Customer support is the backbone of any successful application, but it's also resource-intensive and challenging to scale. What if you could build an AI agent that handles 80% of support requests autonomously, only escalating to humans when truly necessary?
In this article, I'll walk you through how I built Kemuko Support - a production-ready customer support agent using Mastra AI for Kemuko, an edtech platform where learners take courses and instructors publish educational content. This agent serves as the first line of support and can:
- Retrieve user account information and enrollment status
 - Check course enrollments and learning progress
 - Access payment history and identify billing issues
 - Help instructors with course management questions
 - Diagnose problems and provide solutions
 - Guide users through common troubleshooting steps
 - Create support tickets and escalate complex issues to human agents
 
The agent intelligently handles inquiries from both learners and instructors by making REST API calls to the backend, providing instant, accurate responses while knowing when to escalate issues like refunds, billing disputes, or account security concerns to human specialists.
The Challenge
Modern customer support faces several critical challenges:
- Volume: Support tickets can overwhelm small teams
 - Response Time: Customers expect instant responses 24/7
 - Consistency: Human agents may give different answers to the same questions
 - Cost: Scaling support teams is expensive
 - Context: Agents need access to user data, payment information, and order history
 
Traditional chatbots fall short because they're rule-based and can't handle nuanced situations. We needed something more intelligent that could understand context, make API calls, and reason about when to escalate.
Why Mastra?
I chose Mastra for several compelling reasons:
- Built-in Tools System: Easy to create custom tools that make API calls
 - Memory Management: Maintains conversation context across interactions
 - Observability: Built-in logging and monitoring
 - NextAuth Integration: Seamless integration with Next.js authentication
 - Type Safety: Full TypeScript support with Zod schemas
 - LLM Flexibility: Works with multiple LLM providers (OpenAI, Anthropic, Google, etc.)
 
Architecture Overview
Our customer support agent is integrated directly into the application:
Key Architecture Points:
- Users interact with the agent through your web application UI
 - Agent uses NextAuth sessions to identify and authenticate users
 - Unauthenticated users are prompted to log in before accessing support
 - Each tool makes REST API calls to your backend services
 - The agent can read data but escalates actions (like refunds) to humans
 
Building the Custom Tools
The power of our support agent lies in its tools - specialized functions that make REST API calls to your backend to fetch data and provide information to the agent.
1. Session Authentication Tool
This tool retrieves the current user's session and account information using NextAuth:
This tool uses NextAuth to retrieve the active session. If the user is not logged in, it prompts them to authenticate before proceeding.
2. Payment Management Tool
This tool retrieves payment information using the authenticated session:
3. Course Enrollment Tool
This tool retrieves the user's course enrollments and learning progress:
4. Instructor Tools
For instructors who need help managing their courses:
5. Ticket Management Tool
For escalating issues to human agents:
Building Kemuko Support Agent
Now we combine all these tools into a sophisticated support agent:
Setting Up the Mastra Instance
Real-World Usage Examples
Example 1: Learner Asking About Course Progress
User: "I can't find my certificate for the Python course!"
Agent Flow:
- Calls 
getSessionInfoTool→ Confirms user is authenticated (Sarah, learner) - Calls 
getCourseEnrollmentsTool→ Retrieves enrollment data - Identifies that Python course is 95% complete, certificate not yet issued
 
Response:
"Hi Sarah! I've checked your enrollment in 'Complete Python Bootcamp' and I can see you're doing great - you're at 95% completion!
However, certificates are only issued when you reach 100% completion. You have just 2 lessons remaining:
- Lesson 48: Final Project - Part 2
 - Lesson 49: Course Wrap-up
 Once you complete these, your certificate will be automatically generated and available in your Dashboard → Certificates section within a few minutes.
Keep up the excellent work! You're almost there! 🎓"
Example 2: Instructor Revenue Question
User: "How many students enrolled in my React course this month?"
Agent Flow:
- Calls 
getSessionInfoTool→ Confirms user is authenticated (Michael, instructor) - Calls 
getInstructorCoursesTool→ Retrieves instructor course data - Finds React course enrollment statistics
 
Response:
"Hi Michael! Great question. I've pulled up your 'React Masterclass' course data:
This Month:
- New enrollments: 127 students
 - Total enrolled (all-time): 3,542 students
 - Course rating: 4.8/5.0
 - Revenue this month: $3,810
 Your course is performing exceptionally well! The enrollment rate is up 15% compared to last month. Students are particularly praising your hands-on projects in the reviews.
Would you like me to help with anything else regarding your courses?"
Example 3: Payment Issue
User: "My payment failed and I can't access my courses!"
Agent Flow:
- Calls 
getSessionInfoTool→ Confirms user is authenticated - Calls 
getPaymentInfoTool→ Sees payment failed due to expired card - Responds with solution
 
Response:
"Hi Jessica, I understand how frustrating this must be! I've checked your account and found that your last payment didn't go through because your card expired on 09/2024.
Here's what you can do to restore course access:
- Go to Settings → Billing
 - Update your payment method with a valid card
 - Your access to all enrolled courses will be automatically restored within minutes
 If you need any help with this process, I'm here!"
Example 4: Unauthenticated User
User: "I need help with my courses!"
Agent Flow:
- Calls 
getSessionInfoTool→ User is not authenticated - Stops and prompts login
 
Response:
"Hello! To provide you with personalized support regarding your courses, I'll need you to log in to your Kemuko account first.
Please click the 'Log In' button at the top right of the page. Once you're logged in, I'll be able to access your enrollment details, course progress, and help you right away!
If you're having trouble logging in, please let me know and I can guide you through the process."
Example 5: Course Refund Request (Escalation)
User: "This course didn't match the description. I want a refund!"
Agent Flow:
- Calls 
getSessionInfoTool→ Gets authenticated user information - Calls 
getCourseEnrollmentsTool→ Verifies enrollment details - Recognizes this requires human intervention
 - Calls 
createTicketTool→ Creates a high-priority ticket for review - Provides ticket details and timeline
 
Response:
"Hi Alex, I'm sorry to hear the course didn't meet your expectations. I've reviewed your enrollment in 'Advanced JavaScript Patterns' - you enrolled 3 days ago and have completed 12% of the content.
Since refund requests require manual review to ensure fairness to both learners and instructors, I've created a high-priority ticket for our support team:
- Ticket #: SUP-8472
 - Priority: High
 - Category: Billing - Refund Request
 - Expected response: Within 4 hours
 Our team will review your case considering:
- Course completion percentage
 - Time since enrollment
 - Our 14-day refund policy
 - Specific concerns about course content
 You'll receive an email update at alex@example.com shortly. If approved, refunds typically appear in your account within 5-7 business days.
Is there anything specific about the course content I can help clarify while you wait?"
Results
After deploying this agent:
- 80% of queries resolved without human intervention
 - Average response time: <5 seconds
 - Customer satisfaction: 4.7/5
 - Support cost reduction: 60%
 - 24/7 availability
 
Key Takeaways
- Tools are Everything: The agent is only as good as the tools you provide
 - Instructions Matter: Detailed instructions improve performance dramatically
 - Start with User Context: Always fetch user data first
 - Know When to Escalate: Train the agent to recognize its limitations
 - Monitor Continuously: Track metrics to identify improvements
 
Conclusion
Building an AI customer support agent with Mastra transforms how you handle customer interactions. By combining powerful LLMs with practical tools that access real data, you create an agent that doesn't just chat - it actually solves problems.
The key is thoughtful design: understanding your support workflows, providing the right tools, and teaching the agent when to escalate. With Mastra's robust framework, you get type safety, observability, and easy deployment, letting you focus on creating an exceptional customer experience.
Resources:
Built with Mastra v0.22 and NextAuth v5, deployed November 2025.