Introduction
If you're going to build agents effectively, you need to understand what AI is actually good at. Not the hype, not the fear—the reality.
Here's the thing: AI's strengths don't perfectly align with what people are great at doing. This means two important insights for builders:
-
Don't just replace human work. Some tasks that seem simple for humans (like drawing hands) are surprisingly hard for AI. Meanwhile, tasks we avoid because they're tedious (analyzing thousands of documents) can be trivial for AI.
-
Unlock new possibilities. When you understand AI's unique capabilities, you can design workflows that were never practical before—like generating personalized content for 10,000 users or analyzing competitor changes daily.
In this chapter, we'll cover the 10 core capabilities that every builder should understand. For each one, you'll see:
- What the capability actually means
- Real business examples
- Working TypeScript code you can use
- Common use cases for your projects
Let's start building your mental model of what AI can do.
The 10 Capabilities
These capabilities form the foundation of what AI agents can accomplish. Each one unlocks different use cases, and when combined, they enable sophisticated agentic workflows.
The 10 core AI capabilities for building agentic applications
🏷️ Classification
1. Classification
Classification is assigning data into predefined categories. It's probably the AI capability you've been benefiting from the longest—email spam filters have been using classification for decades, and they're so good now that you might not even check your spam folder anymore.
Modern LLMs make classification dramatically more flexible. Instead of training custom models for each use case, you can define categories in plain English and classify instantly. This opens up countless applications where traditional rule-based systems would be too rigid.
Expense Categorization
Imagine you're building a finance app. Users submit expense receipts, and you need to categorize them into Travel, Marketing, Engineering, Operations, or Other. With AI classification, you don't need to maintain complex rules—the agent understands context.
// @example expense-categorization import { Agent } from '@mastra/core'; import { openai } from '@ai-sdk/openai'; import { z } from 'zod'; // Define your classification categories const expenseCategories = [ 'Travel', 'Marketing', 'Engineering', 'Operations', 'Other' ] as const; const classificationSchema = z.object({ category: z.enum(expenseCategories), confidence: z.number().min(0).max(1), reasoning: z.string(), }); const expenseClassifier = new Agent({ name: 'Expense Classifier', instructions: `You are an expense categorization expert. Analyze the expense description and classify it into one of these categories: - Travel: flights, hotels, transportation, meals during travel - Marketing: ads, events, sponsorships, content creation - Engineering: software, tools, infrastructure, technical services - Operations: office supplies, utilities, administrative costs - Other: anything that doesn't fit the above Provide your classification with confidence (0-1) and brief reasoning.`, model: openai('gpt-4o-mini'), }); async function classifyExpense(description: string) { const result = await expenseClassifier.generate( [ { role: 'user', content: `Classify this expense: "${description}"`, }, ], { output: classificationSchema, } ); return result.object; } // Usage const expense = await classifyExpense( "Uber from airport to hotel in SF for product launch event" ); console.log(expense); // Output: { // category: "Travel", // confidence: 0.95, // reasoning: "Transportation during business travel" // }
Common Use Cases
- Customer support triage: Route tickets to the right team (billing, technical, sales)
- Content moderation: Flag inappropriate, spam, or policy-violating content
- Lead qualification: Classify leads as hot, warm, cold based on signals
- Document routing: Sort incoming documents (invoices, contracts, resumes) for processing
- Sentiment analysis: Categorize feedback as positive, negative, neutral
- Intent detection: Understand what users want (purchase, support, information)
💡 Pro Tip: For high-stakes classifications, request confidence scores and set thresholds. Route low-confidence items to human review.
📤 Extraction
2. Extraction
Extraction is pulling out specific, structured data from unstructured sources like text, PDFs, images, or web pages. Think of it as turning messy real-world data into clean, usable information.
Traditional extraction required rigid templates and broke whenever formats changed. AI-powered extraction is resilient—it understands context and can extract information even from documents with varying layouts, handwriting, or formats it's never seen before.
Invoice Processing
You receive invoices from hundreds of vendors in different formats. You need to extract due date, amount, vendor name, and line items to update your accounting system. AI extraction handles this variability effortlessly.
// @example invoice-extraction import { Agent } from '@mastra/core'; import { openai } from '@ai-sdk/openai'; import { z } from 'zod'; // Define the structure you want to extract const invoiceSchema = z.object({ vendor: z.string(), invoiceNumber: z.string(), date: z.string(), dueDate: z.string(), totalAmount: z.number(), currency: z.string(), lineItems: z.array(z.object({ description: z.string(), quantity: z.number(), unitPrice: z.number(), total: z.number(), })), }); const invoiceExtractor = new Agent({ name: 'Invoice Extractor', instructions: `Extract invoice data from the provided text. Be thorough and accurate. If a field is not found, use null or empty array. Ensure amounts are numbers, not strings. Parse dates in ISO format (YYYY-MM-DD) when possible.`, model: openai('gpt-4o'), }); async function extractInvoice(invoiceText: string) { const result = await invoiceExtractor.generate( [ { role: 'user', content: `Extract structured data from this invoice:\n\n${invoiceText}`, }, ], { output: invoiceSchema, } ); return result.object; } // Usage const invoiceText = ` ACME Corporation Invoice #INV-2024-0421 Date: January 15, 2024 Due: February 14, 2024 Items: - Web hosting (Jan 2024): 3 servers @ $150.00 = $450.00 - SSL certificates: 2 @ $99.00 = $198.00 - Support hours: 5 @ $120.00 = $600.00 Total: $1,248.00 USD `; const invoice = await extractInvoice(invoiceText); console.log(invoice); // Output: structured invoice object ready for your database
Common Use Cases
- Resume parsing: Extract skills, experience, education from diverse resume formats
- ID verification: Pull name, DOB, address from driver's licenses or passports
- Receipt processing: Capture merchant, date, amount, items for expense tracking
- Email intelligence: Extract meeting times, action items, or contract terms from emails
- Web scraping: Pull pricing, product details, reviews from competitor sites
- Form digitization: Convert handwritten or scanned forms to structured data
⚠️ Validation Matters: Always validate extracted data with schemas (like Zod). AI is powerful but can hallucinate or miss fields. Implement fallbacks and human review for critical data.
📝 Summarization
3. Summarization
Summarization condenses large amounts of text into concise, digestible summaries. It's one of AI's most practical capabilities because it saves humans from reading through walls of text to find what matters.
The key is that good summarization preserves the essential information while drastically reducing volume. Modern LLMs can summarize anything from meeting transcripts to documentation to entire research papers—and they can tailor the summary to your specific needs.
Meeting Notes
Your team records hour-long meetings. You need to turn 10,000-word transcripts into actionable 1-page summaries with key decisions, action items, and next steps. AI summarization makes this trivial.
// @example meeting-summary import { Agent } from '@mastra/core'; import { openai } from '@ai-sdk/openai'; import { z } from 'zod'; const summarySchema = z.object({ overview: z.string(), keyDecisions: z.array(z.string()), actionItems: z.array(z.object({ task: z.string(), owner: z.string().optional(), deadline: z.string().optional(), })), nextSteps: z.array(z.string()), openQuestions: z.array(z.string()), }); const meetingSummarizer = new Agent({ name: 'Meeting Summarizer', instructions: `Summarize meeting transcripts into actionable notes. Focus on: 1. High-level overview (2-3 sentences) 2. Key decisions made 3. Action items with owners and deadlines (if mentioned) 4. Next steps and follow-ups 5. Open questions or blockers Be concise but don't lose important context.`, model: openai('gpt-4o'), }); async function summarizeMeeting(transcript: string) { const result = await meetingSummarizer.generate( [ { role: 'user', content: `Summarize this meeting transcript:\n\n${transcript}`, }, ], { output: summarySchema, } ); return result.object; } // Multi-level summarization for long documents async function summarizeLongDocument(text: string, maxLength = 100000) { // If text is short enough, summarize directly if (text.length <= maxLength) { return await summarizeMeeting(text); } // For longer texts, chunk and summarize recursively const chunkSize = maxLength; const chunks: string[] = []; for (let i = 0; i < text.length; i += chunkSize) { chunks.push(text.slice(i, i + chunkSize)); } // Summarize each chunk const chunkSummaries = await Promise.all( chunks.map(chunk => summarizeMeeting(chunk)) ); // Combine and summarize the summaries const combined = chunkSummaries .map(s => s.overview) .join('\n\n'); return await summarizeMeeting(combined); } // Usage const summary = await summarizeMeeting(meetingTranscript); console.log(summary.actionItems); // Output: [{task: "Update pricing page", owner: "Sarah", deadline: "Friday"}]
Common Use Cases
- Newsletter digests: Condense multiple articles into daily briefings
- Research summaries: Turn academic papers into executive summaries
- Customer feedback: Aggregate hundreds of reviews into key themes
- Legal document review: Summarize contracts for quick review
- Video transcripts: Create show notes from podcast or video content
- Slack thread summaries: Catch up on long team discussions instantly
💡 Pro Tip: For very long documents (beyond context windows), use hierarchical summarization: chunk → summarize chunks → summarize summaries. This preserves important details better than truncation.
✍️ Writing
4. Writing
Writing is where AI shows both its power and its pitfalls. AI can generate everything from emails to blog posts to documentation—but the quality depends entirely on your inputs. Give it generic prompts and bad data, you get AI slop. Give it context, examples, and good guidelines, you get genuinely useful content.
The secret to good AI writing is treating it like working with a talented but inexperienced writer: provide clear briefs, show examples of your style, and give it access to relevant context.
Context-Aware Email Drafting
Your sales team needs to send personalized follow-up emails after demos. You want emails that reference the specific conversation, pain points discussed, and next steps—not generic templates. AI can write these with the right context.
// @example email-drafting import { Agent } from '@mastra/core'; import { createOpenAI } from '@ai-sdk/openai'; const openai = createOpenAI({ apiKey: process.env.OPENAI_API_KEY, }); const emailWriter = new Agent({ name: 'Email Drafter', instructions: `You are an expert sales email writer. Write personalized follow-up emails. Guidelines: - Reference specific points from the conversation - Keep tone professional but warm - Be concise (under 150 words) - Include clear next steps - Avoid generic pleasantries Study the examples provided to match the company's voice.`, model: openai('gpt-4o'), }); async function draftFollowUpEmail(context: { recipientName: string; companyName: string; meetingNotes: string; painPoints: string[]; proposedSolution: string; nextSteps: string; senderName: string; senderTitle: string; // Include example emails for style matching exampleEmails?: string[]; }) { const prompt = `Draft a follow-up email with this context: Recipient: ${context.recipientName} at ${context.companyName} Meeting Summary: ${context.meetingNotes} Key Pain Points Discussed: ${context.painPoints.map(p => `- ${p}`).join('\n')} Our Proposed Solution: ${context.proposedSolution} Next Steps: ${context.nextSteps} ${context.exampleEmails ? `\nStyle Examples:\n${context.exampleEmails.join('\n---\n')}` : ''} Write the email now.`; const result = await emailWriter.generate([ { role: 'user', content: prompt, }, ]); return result.text; } // Usage with context const email = await draftFollowUpEmail({ recipientName: "Sarah", companyName: "Acme Corp", meetingNotes: "Discussed their manual expense reporting process. Team spends 10 hours/week on categorization.", painPoints: [ "Manual expense categorization is error-prone", "Finance team drowning in receipts", "No visibility into spending patterns" ], proposedSolution: "AI-powered expense classifier that categorizes automatically with 95% accuracy", nextSteps: "Sarah will schedule a technical deep-dive with their CFO next week", senderName: "Alex", senderTitle: "Solutions Engineer", exampleEmails: [ // Previous emails from your team for style matching "Hi Jordan,\n\nGreat connecting yesterday about your data pipeline..." ] }); console.log(email);
Tips for High-Quality Outputs
- Provide examples: Show 2-3 examples of your desired output style
- Give context: The more relevant information, the better the output
- Set constraints: Word count, tone, structure requirements
- Include guidelines: Dos and don'ts for your use case
- Iterate: First drafts are rarely perfect—refine prompts based on results
- Human review: Always review AI-generated content before sending
Common Use Cases
- Social media content: Generate posts based on content briefs
- Product descriptions: Write compelling copy from specifications
- Documentation: Create user guides from technical notes
- Email campaigns: Personalized marketing emails at scale
- Blog posts: Draft articles from outlines and research
- Ad copy: Generate variations for A/B testing
⚠️ Quality Warning: AI writing quality varies dramatically based on input quality. Bad prompt + no context = generic slop. Good prompt + examples + context = useful drafts. Always provide rich context and review outputs.
🎨 Media Creation
5. Media Creation
Media creation—generating images, audio, and video—is one of AI's newest capabilities. Quality varies significantly: some tasks (realistic scenes) are surprisingly easy, while others (text in images, consistent faces) can be frustratingly hard.
For developers, media creation is most practical when integrated into workflows via APIs, not manual tools. You can generate images for marketing emails, create audio voiceovers, or produce visual assets—all programmatically.
Dynamic Social Media Assets
Your marketing team publishes daily tips. You want to auto-generate social media cards with the tip text and relevant imagery. AI can create these on-demand.
// @example media-creation async function generateSocialMediaCard( tipText: string, colorScheme?: string, size?: string ) { // Generate an image using OpenAI's gpt-image-1 model const imageResponse = await fetch('https://api.openai.com/v1/images/generations', { method: 'POST', headers: { 'Authorization': `Bearer ${process.env.OPENAI_API_KEY}`, 'Content-Type': 'application/json', }, body: JSON.stringify({ model: 'gpt-image-1', prompt: `Create a modern, minimalist social media background image for: ${tipText} Style: Clean gradients, professional, abstract shapes Colors: ${colorScheme || 'Blues and purples'} No text in the image Professional tech aesthetic`, size: size || '1536x1024', // landscape for social media quality: 'high', output_format: 'png', background: 'transparent', n: 1, }), }); const data = await imageResponse.json(); const imageB64 = data.data[0].b64_json; // Return base64 image data to overlay text on frontend return { imageData: imageB64, tipText, format: 'png', size: size || '1536x1024', usage: data.usage, }; } // Usage const card = await generateSocialMediaCard( "Tip: Use structured outputs with Zod schemas for reliable AI responses" ); console.log(`Generated image: ${card.size} ${card.format}`); console.log(`Tokens used: ${card.usage.total_tokens}`); // Image is returned as base64 data in card.imageData
Limitations and Best Practices
- Text in images: Still challenging—prefer overlaying text programmatically
- Consistency: Hard to generate consistent characters or styles across images
- Iteration: May need multiple attempts to get desired results
- Costs: Media generation is more expensive than text—optimize prompts
- Rights: Understand licensing for generated content in your use case
Common Use Cases
- Marketing assets: Social media cards, email headers, ad creatives
- Product mockups: Generate variants of product visuals
- Audio voiceovers: Narration for videos or podcasts
- Placeholder content: Generate realistic test images/audio
- Personalized visuals: Custom images based on user data
🔍 Research
6. Research
Research is one of AI's most powerful capabilities. Instead of manually Googling, opening 20 tabs, and synthesizing information, AI agents can query multiple sources, extract relevant facts, cross-reference claims, and deliver consolidated findings—all in seconds.
This unlocks workflows that were previously impractical: daily competitive analysis, real-time person dossiers before meetings, or keeping up with news across dozens of sources.
Pre-Meeting Dossier
You have a meeting with a potential customer. You want a quick briefing: who are they, what does their company do, any recent news, and common connections. AI can research and compile this in minutes.
// @example meeting-dossier import { Agent } from '@mastra/core'; import { createOpenAI } from '@ai-sdk/openai'; const openai = createOpenAI({ apiKey: process.env.OPENAI_API_KEY, }); const researcher = new Agent({ name: 'Research Agent', instructions: `You are a research assistant creating meeting briefings. Since you don't have access to live web search, create a realistic briefing based on the information provided and reasonable professional context. Include: 1. Person background (role, likely experience based on title) 2. Company overview (what they likely do based on name/industry) 3. Potential talking points and areas of interest 4. Suggested conversation starters Be thorough but concise.`, model: openai('gpt-4o'), }); async function createMeetingDossier( personName: string, companyName: string, additionalContext?: string ) { const result = await researcher.generate([ { role: 'user', content: `Create a pre-meeting briefing for: ${personName} at ${companyName} ${additionalContext ? `Additional context: ${additionalContext}` : ''} Please provide a comprehensive briefing to prepare for this meeting.`, }, ]); return result.text; } // Usage const dossier = await createMeetingDossier( "Sarah Chen", "Acme Corp", "VP of Engineering, interested in AI infrastructure" ); console.log(dossier); // Output: Comprehensive meeting briefing with talking points
Source Validation Strategies
- Require citations: Ask AI to cite sources for every claim
- Cross-reference: Check facts across multiple sources
- Date awareness: Prioritize recent information over outdated sources
- Authority: Weight official sources higher than random blogs
- Fact-check: For critical decisions, verify key facts manually
Common Use Cases
- Competitive intelligence: Track competitor products, pricing, features
- Market research: Gather industry trends and insights
- Due diligence: Research companies or individuals before partnerships
- News monitoring: Stay updated on specific topics or companies
- Customer research: Understand prospects before sales calls
- Academic research: Find and summarize relevant papers
💡 Pro Tip: Combine research with other capabilities: Research → Synthesis → Writing creates powerful content pipelines. Research competitor blog posts, synthesize themes, write your response—all automated.
🔗 Synthesis
7. Synthesis
Synthesis is combining information from multiple sources into unified, coherent insights. While humans do this naturally, AI can synthesize at massive scale—connecting dots across thousands of documents, data sources, or conversations that would take weeks manually.
The key difference from summarization: summarization condenses one source, synthesis combines many sources into something new. Think of it as research + analysis + connection-finding all at once.
Competitive Intelligence Dashboard
You're tracking 20 competitors across their blogs, press releases, product updates, and job postings. You want a weekly synthesis of strategic moves, new features, and market positioning shifts—not just summaries of individual sources.
// @example competitive-intel import { Agent } from '@mastra/core'; import { createOpenAI } from '@ai-sdk/openai'; import { z } from 'zod'; const openai = createOpenAI({ apiKey: process.env.OPENAI_API_KEY, }); const synthesisSchema = z.object({ keyTrends: z.array(z.object({ trend: z.string(), significance: z.string(), competitors: z.array(z.string()), })), strategicMoves: z.array(z.object({ move: z.string(), competitor: z.string(), implication: z.string(), })), marketImplications: z.string(), recommendations: z.array(z.string()), }); const analyzer = new Agent({ name: 'Competitive Analyst', instructions: `You are a competitive intelligence analyst. Analyze the provided competitive information and identify: - Key market trends - Strategic moves by competitors - Market implications - Actionable recommendations Be strategic and insightful.`, model: openai('gpt-4o'), }); async function analyzeCompetitiveIntel( competitors: string, market: string, competitiveData?: string, timePeriod?: string ) { const result = await analyzer.generate( [ { role: 'user', content: `Analyze this competitive intelligence data: Competitors: ${competitors} Market: ${market} Time Period: ${timePeriod || 'Last quarter'} ${competitiveData ? `Data:\n${competitiveData}` : ''} Provide strategic analysis and recommendations.`, }, ], { output: synthesisSchema, } ); return result.object; } // Usage const intel = await analyzeCompetitiveIntel( "CompanyA, CompanyB, CompanyC", "AI-powered analytics platforms", `CompanyA: Launched real-time dashboard, hired 10 ML engineers CompanyB: Partnership with DataCorp, raised $50M Series B CompanyC: New enterprise pricing tier, expanding to EU market`, "Q1 2024" ); console.log(intel); // Output: { // keyTrends: [...], // strategicMoves: [...], // marketImplications: "...", // recommendations: [...] // }
Common Use Cases
- Market research: Combine analyst reports, news, and social media into market insights
- Customer insights: Synthesize feedback across surveys, support tickets, and reviews
- Due diligence: Connect information from financials, news, and legal documents
- Content strategy: Analyze competitor content to identify gaps and opportunities
- Research synthesis: Combine academic papers into literature reviews
- Investment analysis: Connect company performance across multiple indicators
💡 Pro Tip: Synthesis works best when you provide diverse sources. The more varied your inputs (quantitative data, qualitative feedback, news, etc.), the richer your synthesis.
📊 Analysis
8. Analysis
Analysis is examining data to find patterns, anomalies, relationships, and insights. AI excels at spotting patterns humans might miss, especially in large datasets. Unlike traditional analytics (which follows predefined rules), AI can reason about what patterns mean and why they matter.
The power: AI combines pattern detection with contextual understanding. It doesn't just tell you "sales dropped 20%"—it can hypothesize why based on multiple factors.
Churn Prediction & Root Cause Analysis
You have user behavior data showing churn patterns. You want to understand not just who will churn, but why—and what specific behaviors predict churn for different user segments.
// @example churn-analysis import { Agent } from '@mastra/core'; import { openai } from '@ai-sdk/openai'; import { z } from 'zod'; const analysisSchema = z.object({ patterns: z.array(z.object({ pattern: z.string(), affectedSegment: z.string(), strength: z.enum(['strong', 'moderate', 'weak']), explanation: z.string(), })), rootCauses: z.array(z.object({ cause: z.string(), evidence: z.array(z.string()), impact: z.string(), })), recommendations: z.array(z.object({ action: z.string(), targetSegment: z.string(), expectedImpact: z.string(), })), anomalies: z.array(z.string()), }); const analyzer = new Agent({ name: 'Churn Analyzer', instructions: \`You are a data analyst specializing in user behavior and churn prediction. Analyze user behavior data to: 1. Identify patterns that predict churn 2. Determine root causes (not just correlations) 3. Segment users by behavior patterns 4. Recommend targeted interventions Be specific and actionable. Distinguish correlation from causation.\`, model: openai('gpt-4o'), }); async function analyzeChurn(data: { userData: Array<{ userId: string; segment: string; daysActive: number; featureUsage: Record<string, number>; supportTickets: number; lastLogin: string; churned: boolean; }>; aggregateMetrics: { overallChurnRate: number; churnBySegment: Record<string, number>; featureAdoption: Record<string, number>; }; }) { const prompt = \`Analyze this user behavior data to identify churn patterns and root causes: User Sample Data: \${JSON.stringify(data.userData.slice(0, 10), null, 2)} Aggregate Metrics: - Overall Churn Rate: \${data.aggregateMetrics.overallChurnRate}% - Churn by Segment: \${JSON.stringify(data.aggregateMetrics.churnBySegment)} - Feature Adoption: \${JSON.stringify(data.aggregateMetrics.featureAdoption)} Total Users Analyzed: \${data.userData.length} Identify patterns, root causes, and actionable recommendations.\`; const result = await analyzer.generate( [ { role: 'user', content: prompt, }, ], { output: analysisSchema, } ); return result.object; } // Usage const analysis = await analyzeChurn({ userData: [ // Your user data ], aggregateMetrics: { overallChurnRate: 15.2, churnBySegment: { enterprise: 8.1, smb: 22.3 }, featureAdoption: { analytics: 45, exports: 23, api: 12 } } }); console.log(analysis.patterns); // Output: Patterns like "Users who don't adopt analytics within 14 days have 3x higher churn"
When to Use AI Analysis vs Traditional Analytics
Use AI when:
- You need natural language explanations of patterns
- Data requires contextual interpretation
- You want hypothesis generation
- Patterns span multiple data types (quantitative + qualitative)
- You need root cause analysis, not just correlation
Use Traditional Analytics when:
- You need real-time dashboards with sub-second latency
- Calculations must be deterministic and auditable
- Cost is a concern for high-volume queries
- You're running statistical tests with strict methodologies
Common Use Cases
- Customer behavior: Identify what drives conversions, engagement, retention
- Anomaly detection: Spot unusual patterns in transactions, usage, or performance
- A/B test analysis: Interpret results and recommend next experiments
- Financial analysis: Analyze spending patterns and budget variances
- Quality assurance: Find patterns in bugs or support tickets
- Content performance: Understand what content resonates with different audiences
⚠️ Beware Hallucination: AI can see patterns that don't exist. Always validate insights with statistical tests or domain experts before making critical decisions.
✅ Grading & Evaluation
9. Grading & Evaluation
Grading is assessing quality, accuracy, or compliance against criteria. AI can evaluate everything from essay quality to code correctness to content compliance—at scale and with consistency that's hard for humans to maintain.
The key is being explicit about criteria. Good evaluation agents don't just say "this is bad"—they explain why based on specific rubrics.
Content Quality Checker
Your team publishes dozens of blog posts monthly. You want consistent quality checks for clarity, accuracy, SEO, and brand voice before publication—without bottlenecking on one editor.
// @example content-grading import { Agent } from '@mastra/core'; import { openai } from '@ai-sdk/openai'; import { z } from 'zod'; const evaluationSchema = z.object({ overallScore: z.number().min(0).max(100), passed: z.boolean(), dimensions: z.object({ clarity: z.object({ score: z.number().min(0).max(100), issues: z.array(z.string()), suggestions: z.array(z.string()), }), accuracy: z.object({ score: z.number().min(0).max(100), issues: z.array(z.string()), factCheckNeeded: z.array(z.string()), }), brandVoice: z.object({ score: z.number().min(0).max(100), issues: z.array(z.string()), }), seo: z.object({ score: z.number().min(0).max(100), issues: z.array(z.string()), recommendations: z.array(z.string()), }), }), blockers: z.array(z.string()), recommendations: z.array(z.string()), }); const contentGrader = new Agent({ name: 'Content Quality Evaluator', instructions: \`You are a content quality evaluator. Grade content across multiple dimensions. Grading Rubric: CLARITY (0-100): - 90-100: Crystal clear, scannable, well-structured - 70-89: Clear but could be more concise or better organized - 50-69: Some confusing sections, unclear structure - Below 50: Difficult to understand, poor structure ACCURACY (0-100): - Check for unsupported claims - Flag statements that need citations - Identify potential factual errors BRAND VOICE (0-100): - Matches company tone (professional but approachable) - Uses approved terminology - Avoids jargon or explains it SEO (0-100): - Has clear headings structure - Good keyword usage (natural, not stuffed) - Meta description worthy excerpts Content passes if overall score >= 80 and no critical blockers. Be constructive and specific in feedback.\`, model: openai('gpt-4o'), }); async function evaluateContent( content: string, metadata: { title: string; targetKeywords?: string[]; brandGuidelines?: string; } ) { const prompt = \`Evaluate this content for publication: Title: \${metadata.title} Target Keywords: \${metadata.targetKeywords?.join(', ') || 'None specified'} Content: \${content} ${metadata.brandGuidelines ? \`\nBrand Guidelines:\n\${metadata.brandGuidelines}\` : ''} Provide detailed evaluation and specific feedback.\`; const result = await contentGrader.generate( [ { role: 'user', content: prompt, }, ], { output: evaluationSchema, } ); return result.object; } // Usage const evaluation = await evaluateContent( "Your blog post content here...", { title: "10 Ways to Build Agentic Apps", targetKeywords: ["agentic apps", "AI agents", "autonomous systems"], } ); if (!evaluation.passed) { console.log("Blockers:", evaluation.blockers); console.log("Must fix before publishing"); } else { console.log(\`Ready to publish (Score: \${evaluation.overallScore}/100)\`); }
Consistency Considerations
Challenge: AI evaluation can drift over time or vary between runs.
Solutions:
- Use structured schemas: Force consistent output format
- Include examples: Show the AI what a "90" vs "70" looks like
- Temperature 0: Use deterministic settings for evaluation
- Calibration set: Periodically check against human-graded examples
- Human review: Sample AI evaluations and adjust prompts if drift occurs
Common Use Cases
- Code review: Check code quality, security, best practices
- Lead scoring: Grade leads based on fit and intent signals
- Resume screening: Evaluate candidates against job requirements
- Customer feedback: Score satisfaction and identify issues
- Compliance checking: Ensure content meets regulatory requirements
- Translation quality: Evaluate accuracy and naturalness of translations
💡 Pro Tip: For high-stakes evaluation, use multiple AI evaluators and compare scores. Disagreement often indicates edge cases that need human review.
🎓 Coaching & Guidance
10. Coaching & Guidance
Coaching provides personalized, interactive help to guide users through complex tasks or learning. Unlike static documentation, AI coaches adapt their explanation style, pace, and examples to each user's needs and current context.
Think of it as a patient expert who's always available, never judges, and can explain the same concept 10 different ways until it clicks.
Developer Onboarding Coach
New engineers join your team and need to learn your codebase, architecture, and practices. Instead of assigning a senior dev as a shadow for weeks, an AI coach provides personalized guidance based on what they're currently working on.
// @example dev-onboarding import { Agent } from '@mastra/core'; import { createOpenAI } from '@ai-sdk/openai'; const openai = createOpenAI({ apiKey: process.env.OPENAI_API_KEY, }); const coach = new Agent({ name: 'Onboarding Coach', instructions: `You are a developer onboarding coach helping new team members. Your role: - Answer questions about codebase architecture - Explain best practices - Guide developers through tasks - Provide code examples when helpful - Be encouraging and patient Tailor your responses to the developer's skill level.`, model: openai('gpt-4o'), }); async function askOnboardingCoach( question: string, currentTask?: string, skillLevel?: string, techStack?: string ) { const contextPrompt = `Developer Context: - Task: ${currentTask || 'Not specified'} - Skill Level: ${skillLevel || 'Unknown'} - Tech Stack: ${techStack || 'General web development'} Developer Question: ${question}`; const result = await coach.generate([ { role: 'user', content: contextPrompt, }, ]); return result.text; } // Usage const response = await askOnboardingCoach( "How do I add a new API endpoint? I've never done it in this codebase before.", "Add user preferences endpoint", "mid", "Next.js, TypeScript, Prisma" ); console.log(response); // Output: Personalized guidance with step-by-step instructions
Personalization Strategies
Adapt to skill level:
- Beginners: More explanation, simpler examples, step-by-step
- Advanced: Higher-level concepts, edge cases, trade-offs
Track progress:
- Remember what they've learned
- Adjust difficulty as they improve
- Celebrate milestones
Context awareness:
- Know what they're currently working on
- Reference their previous questions
- Anticipate next questions
Interactive:
- Ask clarifying questions
- Check understanding
- Encourage them to try before giving answers
Common Use Cases
- Customer support: Guide users through troubleshooting
- Product onboarding: Help new users learn your product
- Code debugging: Help developers find and fix issues
- Learning platforms: Adaptive tutoring for students
- Process guidance: Walk employees through complex procedures
- Sales coaching: Help reps handle objections and close deals
✨ Best Practice: Great coaching agents maintain conversation state and adapt over time. Store conversation history and user progress to provide increasingly personalized guidance.
Combining Capabilities
You've seen 10 capabilities in isolation, but the real power comes from combining them into multi-step workflows. This is where AI agents shine—they can chain together research, synthesis, analysis, and writing into sophisticated pipelines that replace entire workflows.
Example: Automated Competitive Intelligence Pipeline
Let's build a workflow that combines Research → Synthesis → Analysis → Writing:
import { Agent } from '@mastra/core'; import { openai } from '@ai-sdk/openai'; // Step 1: RESEARCH - Gather competitor data const researcher = new Agent({ name: 'Researcher', instructions: 'Research competitors across multiple sources', model: openai('gpt-4o'), tools: [webSearchTool, scrapeTool], }); // Step 2: SYNTHESIS - Combine findings const synthesizer = new Agent({ name: 'Synthesizer', instructions: 'Synthesize research into key trends and patterns', model: openai('gpt-4o'), }); // Step 3: ANALYSIS - Identify strategic implications const analyzer = new Agent({ name: 'Analyzer', instructions: 'Analyze competitive landscape and identify threats/opportunities', model: openai('gpt-4o'), }); // Step 4: WRITING - Generate executive brief const writer = new Agent({ name: 'Writer', instructions: 'Write clear, actionable competitive intelligence brief', model: openai('gpt-4o'), }); async function generateCompetitiveIntelligence(competitors: string[]) { // Research phase const researchResults = await Promise.all( competitors.map(competitor => researcher.generate( [ { role: 'user', content: \`Research \${competitor}'s recent product updates, press releases, and strategic moves\`, }, ], { maxSteps: 5, } ) ) ); // Synthesis phase const synthesis = await synthesizer.generate([ { role: 'user', content: \`Synthesize these research findings into key trends: \${researchResults.map(r => r.text).join('\n\n---\n\n')}\`, }, ]); // Analysis phase const analysis = await analyzer.generate([ { role: 'user', content: \`Analyze this competitive synthesis for strategic implications: \${synthesis.text} Identify: 1. Emerging threats to our position 2. Opportunities we should pursue 3. Market trends we need to respond to\`, }, ]); // Writing phase const brief = await writer.generate([ { role: 'user', content: \`Write an executive brief based on this analysis: \${analysis.text} Format: - Executive Summary (2-3 sentences) - Key Findings (bullet points) - Strategic Recommendations (3-5 items) - Next Actions (specific, time-bound) Keep it under 500 words. Be direct and actionable.\`, }); return { research: researchResults.map(r => r.text), synthesis: synthesis.text, analysis: analysis.text, brief: brief.text, }; } // Usage - fully automated weekly intelligence const intelligence = await generateCompetitiveIntelligence([ 'CompetitorA', 'CompetitorB', 'CompetitorC', ]); console.log(intelligence.brief); // Output: Ready-to-share executive brief
More Multi-Capability Patterns
Customer Feedback Loop:
- Classification: Route feedback by category
- Extraction: Pull key pain points
- Synthesis: Aggregate across all feedback
- Analysis: Identify root causes
- Writing: Generate response templates
Content Production Pipeline:
- Research: Gather information on topic
- Synthesis: Combine sources into outline
- Writing: Draft content
- Grading: Check quality and compliance
- Revision: Iterate based on feedback
Sales Intelligence:
- Research: Gather prospect information
- Analysis: Score lead quality
- Synthesis: Create briefing
- Writing: Draft personalized outreach
- Coaching: Guide rep on approach
The key: Each capability feeds into the next, creating workflows that are more than the sum of their parts.
What AI Struggles With
Understanding AI's limitations is just as important as knowing its capabilities. Here's what AI genuinely struggles with—and when you should reach for traditional code instead.
Math & Precise Calculations
The Problem: LLMs are trained to predict text, not compute. They can approximate, but they're unreliable for arithmetic.
Example failure:
// AI might get this wrong: "What's 347 * 892?" // AI: "About 309,000" (Actual: 309,524)
Solution: Use traditional code for anything requiring precision:
// Right approach const result = 347 * 892; // Always correct // Or give AI access to a calculator tool const calculatorTool = createTool({ id: 'calculate', description: 'Perform precise calculations', inputSchema: z.object({ expression: z.string(), }), execute: async ({ context }) => { return { result: eval(context.expression) }; // Use a safe eval in production }, });
Real-Time Data (Without Tools)
The Problem: LLMs have a knowledge cutoff. They don't know today's stock prices, weather, or news unless you give them tools to access that data.
Solution: Always provide tools for real-time information:
const stockPriceTool = createTool({ id: 'get-stock-price', description: 'Get current stock price', inputSchema: z.object({ ticker: z.string() }), execute: async ({ context }) => { const price = await fetchStockPrice(context.ticker); return { price, timestamp: new Date().toISOString() }; }, });
Complex Multi-Step Reasoning (Without Structure)
The Problem: LLMs can lose track of complex logical chains, especially without structure.
Example failure: "Given X, if Y then Z, but only when A and not B, unless C..." // AI might mix up the conditions
Solution: Break complex reasoning into steps:
// Instead of one complex prompt const step1 = await agent.generate([{ role: 'user', content: "Check condition X" }]); const step2 = await agent.generate([{ role: 'user', content: \`Given \${step1.text}, evaluate Y\` }]); const step3 = await agent.generate([{ role: 'user', content: \`Based on \${step2.text}, determine Z\` }]);
Or use structured approaches like ReAct (Reasoning + Acting) patterns.
Consistency & Determinism
The Problem: Same prompt can yield different results. This is usually a feature (creativity) but problematic when you need consistency.
Solutions:
- Set temperature to 0: Most deterministic setting
- Use structured outputs: Schemas force consistent format
- Add explicit constraints: "Always return exactly 3 recommendations"
- Validation: Check outputs match your requirements
// More consistent const agent = new Agent({ model: openai('gpt-4o', { temperature: 0 }), // ... });
Long-Context Reasoning
The Problem: Even with large context windows, AI performance degrades with very long inputs. It can "lose" information in the middle of long documents.
Solution: Use RAG (Retrieval-Augmented Generation) or hierarchical summarization:
// Instead of shoving 100k words into one prompt async function analyzeBook(bookText: string) { // 1. Split into chapters const chapters = splitIntoChapters(bookText); // 2. Summarize each chapter const summaries = await Promise.all( chapters.map(ch => agent.generate([{ role: 'user', content: \`Summarize: \${ch}\` }])) ); // 3. Synthesize summaries const fullAnalysis = await agent.generate([ { role: 'user', content: \`Analyze this book based on chapter summaries: \${summaries.join('\n\n')}\`, }, ]); return fullAnalysis.text; }
When to Use Traditional Code
Use traditional code for:
- ✅ Exact calculations (math, dates, currencies)
- ✅ Deterministic logic (if/else, state machines)
- ✅ High-frequency operations (< 100ms latency needs)
- ✅ Strict compliance requirements (auditable logic)
- ✅ Simple transformations (formatting, filtering, sorting)
Use AI for:
- ✅ Natural language understanding
- ✅ Ambiguous inputs
- ✅ Context-dependent decisions
- ✅ Creative generation
- ✅ Pattern recognition in unstructured data
Best approach: Combine both. Use traditional code for structure and deterministic logic, AI for understanding and decision-making within that structure.
Next Steps
You now understand the 10 core AI capabilities and their limitations. In the next chapter, we'll explore 50 practical use cases across different industries showing you exactly how to apply these capabilities to real business problems.
Ready to see these capabilities in action? Let's move on to real-world applications.
Get chapter updates & code samples
We’ll email diagrams, code snippets, and additions.