> ## Documentation Index
> Fetch the complete documentation index at: https://mintlify.com/darkzOGx/youtube-automation-agent/llms.txt
> Use this file to discover all available pages before exploring further.

# SEO Optimizer Agent

> Discover how the SEO Optimizer Agent maximizes your video discoverability through intelligent metadata optimization

## Overview

The **SEO Optimizer Agent** is your YouTube search optimization expert. It analyzes your content and generates perfectly optimized titles, descriptions, tags, and metadata to maximize your video's discoverability in YouTube search, suggested videos, and Google results.

<Card title="What It Does" icon="magnifying-glass">
  The SEO Optimizer Agent creates search-optimized metadata including titles, descriptions, tags, hashtags, chapters, and category selection. Every element is designed to improve your video's ranking and click-through rate.
</Card>

## Key Features

<CardGroup cols={2}>
  <Card title="Title Optimization" icon="heading">
    Generates titles with power words, optimal length, and keyword placement
  </Card>

  <Card title="Smart Descriptions" icon="file-lines">
    Creates comprehensive descriptions with timestamps and keyword density
  </Card>

  <Card title="Tag Generation" icon="tags">
    Produces optimized tag sets within YouTube's 500-character limit
  </Card>

  <Card title="SEO Scoring" icon="chart-bar">
    Calculates SEO score (0-100) for quality assurance
  </Card>
</CardGroup>

## Core Methods

### optimize()

Main method that orchestrates the entire SEO optimization process.

```javascript seo-optimizer-agent.js theme={null}
async optimize(script, strategy) {
  this.logger.info(`Optimizing SEO for: ${script.title}`);
  
  // Generate optimized title
  const title = await this.optimizeTitle(script.title, strategy);
  
  // Generate description
  const description = await this.generateDescription(script, strategy);
  
  // Extract and optimize tags
  const tags = await this.generateTags(script, strategy);
  
  // Generate hashtags
  const hashtags = await this.generateHashtags(strategy);
  
  // Create chapters/timestamps
  const chapters = await this.generateChapters(script);
  
  // Generate end screen elements
  const endScreen = await this.generateEndScreenStrategy();
  
  // Calculate SEO score
  const seoScore = await this.calculateSEOScore(title, description, tags);
  
  const seoData = {
    title,
    description,
    tags,
    hashtags,
    chapters,
    endScreen,
    seoScore,
    metadata: {
      primaryKeyword: strategy.keywords[0],
      secondaryKeywords: strategy.keywords.slice(1, 5),
      targetLength: this.calculateOptimalLength(strategy.contentType),
      language: 'en',
      category: this.selectCategory(strategy)
    },
    createdAt: new Date().toISOString()
  };
  
  await this.db.saveSEOData(seoData);
  return seoData;
}
```

## Title Optimization

Titles are optimized using proven techniques:

### optimizeTitle()

```javascript seo-optimizer-agent.js theme={null}
async optimizeTitle(originalTitle, strategy) {
  let optimizedTitle = originalTitle;
  
  // Add power words if not present
  const powerWords = ['Ultimate', 'Complete', 'Essential', 'Proven', 
                      'Secret', 'Amazing', 'Powerful'];
  const hasPowerWord = powerWords.some(word => 
    originalTitle.toLowerCase().includes(word.toLowerCase())
  );
  
  if (!hasPowerWord && originalTitle.length < 60) {
    const randomPowerWord = powerWords[Math.floor(Math.random() * powerWords.length)];
    optimizedTitle = `${randomPowerWord} ${originalTitle}`;
  }
  
  // Add year if relevant and not present
  const currentYear = new Date().getFullYear();
  if (!optimizedTitle.includes(currentYear.toString()) && optimizedTitle.length < 70) {
    optimizedTitle = `${optimizedTitle} (${currentYear})`;
  }
  
  // Ensure primary keyword is in title
  const primaryKeyword = strategy.keywords[0];
  if (primaryKeyword && !optimizedTitle.toLowerCase().includes(primaryKeyword.toLowerCase())) {
    optimizedTitle = `${optimizedTitle} - ${primaryKeyword}`;
  }
  
  // Truncate if too long (YouTube limit: 100 characters)
  if (optimizedTitle.length > 100) {
    optimizedTitle = optimizedTitle.substring(0, 97) + '...';
  }
  
  return this.titleCase(optimizedTitle);
}
```

### Title Best Practices

<AccordionGroup>
  <Accordion title="Optimal Length: 60-70 Characters">
    This length displays fully in search results while leaving room for power words

    ```javascript theme={null}
    if (title.length >= 60 && title.length <= 70) score += 10;
    ```
  </Accordion>

  <Accordion title="Include Power Words">
    Words like "Ultimate", "Complete", "Secret" increase click-through rates by 15-20%

    ```javascript theme={null}
    const powerWords = ['Ultimate', 'Complete', 'Essential', 'Proven', 'Secret'];
    ```
  </Accordion>

  <Accordion title="Add Numbers">
    Titles with numbers perform 36% better in search results

    ```javascript theme={null}
    if (/\d/.test(title)) score += 5;
    ```
  </Accordion>

  <Accordion title="Use Current Year">
    Including the current year signals freshness and relevance

    ```javascript theme={null}
    if (title.includes(new Date().getFullYear().toString())) score += 5;
    ```
  </Accordion>
</AccordionGroup>

## Description Generation

Descriptions are comprehensive and SEO-optimized:

### generateDescription()

```javascript seo-optimizer-agent.js theme={null}
async generateDescription(script, strategy) {
  let description = '';
  
  // First 125 characters - most important for SEO
  const hook = `${script.title} - In this video, you'll discover ${strategy.angle.toLowerCase()}.`;
  description += hook + '\n\n';
  
  // Video overview
  description += '📺 WHAT YOU\'LL LEARN:\n';
  if (script.mainContent && script.mainContent.sections) {
    script.mainContent.sections.slice(0, 5).forEach(section => {
      description += `• ${section.title}\n`;
    });
  }
  description += '\n';
  
  // Timestamps/Chapters
  description += '⏱️ TIMESTAMPS:\n';
  description += '00:00 Introduction\n';
  let timestamp = 20;
  script.mainContent.sections.forEach(section => {
    const minutes = Math.floor(timestamp / 60);
    const seconds = timestamp % 60;
    description += `${minutes.toString().padStart(2, '0')}:${seconds.toString().padStart(2, '0')} ${section.title}\n`;
    timestamp += section.duration || 60;
  });
  
  // ... additional sections
  
  return description;
}
```

### Description Structure

<Steps>
  <Step title="Hook (First 125 Characters)">
    Most important for search rankings and preview text
  </Step>

  <Step title="What You'll Learn">
    Bulleted list of key takeaways for quick scanning
  </Step>

  <Step title="Timestamps">
    Improves user experience and enables YouTube chapters
  </Step>

  <Step title="About This Video">
    Keyword-rich paragraph for SEO (300-500 words)
  </Step>

  <Step title="Links & Resources">
    External links, social media, related videos
  </Step>

  <Step title="Tags & Hashtags">
    Additional keyword targeting
  </Step>
</Steps>

<Note>
  The first 125 characters appear in search results. The agent ensures this section contains your primary keyword and a compelling hook.
</Note>

## Tag Generation

Tags are generated using a sophisticated algorithm:

### generateTags()

```javascript seo-optimizer-agent.js theme={null}
async generateTags(script, strategy) {
  const tags = new Set();
  
  // Add primary keywords
  strategy.keywords.forEach(keyword => tags.add(keyword));
  
  // Add topic variations
  const topic = strategy.topic.toLowerCase();
  tags.add(topic);
  tags.add(topic.replace(/\s+/g, ''));
  tags.add(topic.replace(/\s+/g, '_'));
  
  // Add content type tags
  const contentTypeTags = {
    'Tutorial': ['how to', 'tutorial', 'guide', 'step by step', 'learn'],
    'Explainer': ['explained', 'what is', 'understanding', 'explanation'],
    'Review': ['review', 'comparison', 'vs', 'best', 'top'],
    'List': ['top 10', 'best', 'list', 'countdown'],
    'Story': ['story', 'journey', 'experience', 'case study']
  };
  
  const typeTags = contentTypeTags[strategy.contentType] || [];
  typeTags.forEach(tag => tags.add(tag));
  
  // Add long-tail keywords
  const longTailKeywords = this.generateLongTailKeywords(strategy);
  longTailKeywords.forEach(keyword => tags.add(keyword));
  
  // Ensure total doesn't exceed 500 characters
  const tagArray = Array.from(tags);
  const prioritizedTags = this.prioritizeTags(tagArray, strategy);
  
  let totalLength = 0;
  const finalTags = [];
  
  for (const tag of prioritizedTags) {
    if (totalLength + tag.length + 1 <= 500) {
      finalTags.push(tag);
      totalLength += tag.length + 1;
    }
  }
  
  return finalTags;
}
```

### Tag Types

<Tabs>
  <Tab title="Primary Keywords">
    Main topics and themes (highest priority)

    ```javascript theme={null}
    strategy.keywords.forEach(keyword => tags.add(keyword));
    ```
  </Tab>

  <Tab title="Topic Variations">
    Different formats of your main topic

    ```javascript theme={null}
    tags.add(topic);
    tags.add(topic.replace(/\s+/g, ''));  // "aitrends"
    tags.add(topic.replace(/\s+/g, '_')); // "ai_trends"
    ```
  </Tab>

  <Tab title="Content Type Tags">
    Format-specific tags

    ```javascript theme={null}
    'Tutorial': ['how to', 'tutorial', 'guide', 'step by step']
    ```
  </Tab>

  <Tab title="Long-Tail Keywords">
    Specific multi-word phrases

    ```javascript theme={null}
    `how to ${strategy.topic}`
    `${strategy.topic} for beginners`
    ```
  </Tab>
</Tabs>

## Chapter Generation

Automatic chapter/timestamp creation:

```javascript seo-optimizer-agent.js theme={null}
async generateChapters(script) {
  const chapters = [];
  let currentTime = 0;
  
  // Introduction
  chapters.push({
    time: '00:00',
    title: 'Introduction',
    seconds: 0
  });
  
  currentTime = 20; // Intro duration
  
  // Main content chapters
  script.mainContent.sections.forEach(section => {
    const minutes = Math.floor(currentTime / 60);
    const seconds = currentTime % 60;
    const timeString = `${minutes.toString().padStart(2, '0')}:${seconds.toString().padStart(2, '0')}`;
    
    chapters.push({
      time: timeString,
      title: section.title || 'Section',
      seconds: currentTime
    });
    
    currentTime += section.duration || 60;
  });
  
  return chapters;
}
```

<Note>
  YouTube chapters improve user experience and can boost watch time by allowing viewers to jump to relevant sections.
</Note>

## SEO Scoring System

The agent calculates a comprehensive SEO score:

```javascript seo-optimizer-agent.js theme={null}
async calculateSEOScore(title, description, tags) {
  let score = 0;
  
  // Title scoring (30 points max)
  if (title.length >= 60 && title.length <= 70) score += 10;
  else if (title.length >= 50 && title.length <= 100) score += 5;
  
  if (/\d/.test(title)) score += 5; // Contains number
  if (/[A-Z]/.test(title)) score += 5; // Proper capitalization
  if (title.includes(new Date().getFullYear().toString())) score += 5;
  if (['how', 'what', 'why', 'best', 'top'].some(word => 
      title.toLowerCase().includes(word))) score += 5;
  
  // Description scoring (40 points max)
  if (description.length >= 200) score += 10;
  if (description.length >= 500) score += 10;
  if (description.includes('TIMESTAMPS')) score += 5;
  if (description.includes('http')) score += 5;
  if (description.split('\n').length > 10) score += 5;
  if (description.substring(0, 125).includes(tags[0])) score += 5;
  
  // Tags scoring (30 points max)
  if (tags.length >= 10) score += 10;
  if (tags.length >= 15) score += 5;
  if (tags.some(tag => tag.split(' ').length > 2)) score += 5;
  if (tags.join('').length <= 500) score += 5;
  if (new Set(tags).size === tags.length) score += 5;
  
  return Math.min(100, score);
}
```

### Score Breakdown

<CardGroup cols={3}>
  <Card title="Title" icon="heading">
    Up to 30 points
  </Card>

  <Card title="Description" icon="file-lines">
    Up to 40 points
  </Card>

  <Card title="Tags" icon="tags">
    Up to 30 points
  </Card>
</CardGroup>

## Category Selection

Automatic YouTube category assignment:

```javascript seo-optimizer-agent.js theme={null}
selectCategory(strategy) {
  const categories = {
    'technology': 28,  // Science & Technology
    'gaming': 20,      // Gaming
    'education': 27,   // Education
    'business': 27,    // Education (closest match)
    'lifestyle': 22,   // People & Blogs
    'health': 26,      // Howto & Style
    'entertainment': 24 // Entertainment
  };
  
  const niche = this.identifyNiche(strategy);
  return categories[niche] || 22; // Default to People & Blogs
}
```

## Hashtag Generation

Strategic hashtag selection:

```javascript seo-optimizer-agent.js theme={null}
async generateHashtags(strategy) {
  const hashtags = [];
  
  // Primary hashtag
  hashtags.push(`#${strategy.topic.replace(/\s+/g, '')}`);
  
  // Content type hashtag
  hashtags.push(`#${strategy.contentType.toLowerCase()}`);
  
  // Niche-specific hashtags
  const niche = this.identifyNiche(strategy);
  const nicheHashtags = {
    'technology': ['#tech', '#technology', '#innovation'],
    'gaming': ['#gaming', '#gamer', '#games'],
    'education': ['#education', '#learning', '#study']
  };
  
  hashtags.push(...(nicheHashtags[niche] || []).slice(0, 2));
  
  // General engagement hashtags
  hashtags.push('#youtube', '#viral', '#trending');
  
  // Limit to 15 hashtags (YouTube recommendation)
  return hashtags.slice(0, 15);
}
```

<Note>
  YouTube recommends using no more than 15 hashtags. Using more can result in all hashtags being ignored.
</Note>

## Example SEO Output

```json theme={null}
{
  "title": "Ultimate AI Technology Trends (2026) - Complete Guide",
  "description": "Ultimate AI Technology Trends (2026) - Complete Guide - In this video, you'll discover ai technology trends: what nobody is telling you.\n\n📺 WHAT YOU'LL LEARN:\n• Deep Dive\n• Real-World Examples\n\n⏱️ TIMESTAMPS:\n00:00 Introduction\n00:20 Deep Dive\n01:50 Real-World Examples\n...",
  "tags": [
    "technology",
    "trends",
    "ai technology",
    "how to ai technology",
    "ai technology for beginners",
    "tutorial",
    "guide",
    "2026"
  ],
  "hashtags": [
    "#aitechnology",
    "#explainer",
    "#tech",
    "#technology",
    "#youtube",
    "#trending"
  ],
  "seoScore": 87,
  "metadata": {
    "primaryKeyword": "technology",
    "secondaryKeywords": ["trends", "artificial", "intelligence"],
    "targetLength": "5-10 minutes",
    "language": "en",
    "category": 28
  }
}
```

## Best Practices

<AccordionGroup>
  <Accordion title="Front-Load Keywords">
    Place your primary keyword in the first 60 characters of your title and first 125 characters of description
  </Accordion>

  <Accordion title="Use All Available Space">
    Maximize your tag character limit (500 chars) and description length (up to 5000 chars)
  </Accordion>

  <Accordion title="Include Timestamps">
    Always add timestamps - they enable YouTube chapters and improve user experience
  </Accordion>

  <Accordion title="Monitor SEO Score">
    Aim for scores above 80. Lower scores indicate optimization opportunities
  </Accordion>
</AccordionGroup>

## Performance Metrics

<CardGroup cols={3}>
  <Card title="Optimization Time" icon="clock">
    1-3 seconds
  </Card>

  <Card title="Average SEO Score" icon="star">
    85-95/100
  </Card>

  <Card title="Tag Count" icon="tags">
    15-25 tags
  </Card>
</CardGroup>

## Next Steps

<CardGroup cols={2}>
  <Card title="Publishing Agent" icon="calendar" href="/features/publishing-scheduler">
    See how optimized metadata is published
  </Card>

  <Card title="Analytics Agent" icon="chart-bar" href="/features/analytics-optimization">
    Track SEO performance and rankings
  </Card>

  <Card title="Script Writer" icon="pen" href="/features/script-writer">
    Learn how scripts influence SEO optimization
  </Card>

  <Card title="API Reference" icon="code" href="/api/agents/seo-optimizer">
    View complete API documentation
  </Card>
</CardGroup>
