> ## 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.

# ScriptWriterAgent

> AI-powered video script generation agent

## Overview

The `ScriptWriterAgent` generates complete, production-ready video scripts based on content strategies. It creates structured scripts with hooks, introductions, main content, conclusions, and calls-to-action, following proven content templates.

## Constructor

<ParamField path="db" type="Database" required>
  Database instance for storing scripts
</ParamField>

<ParamField path="credentials" type="Credentials" required>
  Credentials manager for external services
</ParamField>

```javascript theme={null}
const { ScriptWriterAgent } = require('./agents/script-writer-agent');

const agent = new ScriptWriterAgent(db, credentials);
```

## Properties

<ResponseField name="templates" type="Object">
  Script templates for different content types (tutorial, explainer, list, review, story)
</ResponseField>

<ResponseField name="logger" type="Logger">
  Logger instance for tracking script generation
</ResponseField>

## Script Templates

The agent includes built-in templates for five content types:

<CodeGroup>
  ```javascript Tutorial theme={null}
  {
    structure: ['hook', 'introduction', 'problem', 'solution_steps', 
                'demonstration', 'recap', 'cta'],
    tone: 'educational',
    pacing: 'moderate'
  }
  ```

  ```javascript Explainer theme={null}
  {
    structure: ['hook', 'question', 'background', 'explanation', 
                'examples', 'implications', 'summary', 'cta'],
    tone: 'informative',
    pacing: 'steady'
  }
  ```

  ```javascript List theme={null}
  {
    structure: ['hook', 'introduction', 'list_items', 'bonus_item', 
                'summary', 'cta'],
    tone: 'engaging',
    pacing: 'quick'
  }
  ```

  ```javascript Review theme={null}
  {
    structure: ['hook', 'introduction', 'overview', 'pros', 'cons', 
                'comparison', 'verdict', 'cta'],
    tone: 'analytical',
    pacing: 'detailed'
  }
  ```

  ```javascript Story theme={null}
  {
    structure: ['hook', 'setup', 'conflict', 'journey', 'climax', 
                'resolution', 'lesson', 'cta'],
    tone: 'narrative',
    pacing: 'dynamic'
  }
  ```
</CodeGroup>

## Methods

### initialize()

Initializes the script writer agent.

<ParamField path="return" type="Promise<boolean>">
  Returns true when initialization is complete
</ParamField>

```javascript theme={null}
await agent.initialize();
```

### generateScript(strategy)

Generates a complete video script based on content strategy.

<ParamField path="strategy" type="Object" required>
  Content strategy object from ContentStrategyAgent
</ParamField>

<ParamField path="strategy.topic" type="string" required>
  Content topic
</ParamField>

<ParamField path="strategy.angle" type="string" required>
  Content angle/approach
</ParamField>

<ParamField path="strategy.contentType" type="string" required>
  Content type (Tutorial, Explainer, List, Review, Story)
</ParamField>

<ParamField path="strategy.keywords" type="Array<string>" required>
  SEO keywords
</ParamField>

<ParamField path="return" type="Promise<Object>">
  Complete script object
</ParamField>

<ResponseField name="script.title" type="string">
  Generated video title
</ResponseField>

<ResponseField name="script.hook" type="Object">
  Opening hook (0:00-0:05) with type and text
</ResponseField>

<ResponseField name="script.introduction" type="Object">
  Introduction section (0:05-0:20) with greeting, topic intro, value proposition, credibility
</ResponseField>

<ResponseField name="script.mainContent" type="Object">
  Main content sections with type-specific structure
</ResponseField>

<ResponseField name="script.conclusion" type="Object">
  Conclusion with recap and final thought
</ResponseField>

<ResponseField name="script.callToAction" type="Object">
  Call-to-action with subscribe, like, comment prompts
</ResponseField>

<ResponseField name="script.duration" type="string">
  Estimated video duration (MM:SS format)
</ResponseField>

<ResponseField name="script.fullScript" type="string">
  Formatted full script text ready for production
</ResponseField>

```javascript theme={null}
const strategy = {
  topic: 'JavaScript Promises',
  angle: 'The Ultimate Guide to JavaScript Promises',
  contentType: 'Tutorial',
  keywords: ['javascript', 'promises', 'async', 'programming'],
  targetAudience: 'Developers'
};

const script = await agent.generateScript(strategy);

console.log(script.title);
// 'How to JavaScript Promises: Step-by-Step Guide'

console.log(script.duration);
// '8:30'

console.log(script.hook);
// {
//   type: 'question',
//   text: 'Have you ever wondered how JavaScript Promises actually works?',
//   duration: '0:00-0:05'
// }
```

### generateTitle(strategy)

Generates an optimized video title.

<ParamField path="strategy" type="Object" required>
  Content strategy object
</ParamField>

<ParamField path="return" type="Promise<string>">
  Generated title
</ParamField>

```javascript theme={null}
const title = await agent.generateTitle(strategy);
// Content type specific:
// Tutorial: 'How to {topic}: Step-by-Step Guide'
// List: 'Top 10 {topic} Tips You Need to Know'
// Review: '{topic} Review: Is It Worth It?'
```

### generateHook(strategy)

Generates an attention-grabbing opening hook.

<ParamField path="strategy" type="Object" required>
  Content strategy
</ParamField>

<ParamField path="return" type="Promise<Object>">
  Hook object with type, text, and duration
</ParamField>

<ResponseField name="hook.type" type="string">
  Hook type: question, statistic, statement, challenge, or promise
</ResponseField>

<ResponseField name="hook.text" type="string">
  Hook text content
</ResponseField>

<ResponseField name="hook.duration" type="string">
  Time range for hook (0:00-0:05)
</ResponseField>

```javascript theme={null}
const hook = await agent.generateHook(strategy);
// {
//   type: 'statistic',
//   text: 'Did you know that 90% of people don\'t understand JavaScript Promises correctly?',
//   duration: '0:00-0:05'
// }
```

### generateIntroduction(strategy)

Generates the introduction section.

<ParamField path="strategy" type="Object" required>
  Content strategy
</ParamField>

<ParamField path="return" type="Promise<Object>">
  Introduction with greeting, topic intro, value proposition, credibility
</ParamField>

```javascript theme={null}
const intro = await agent.generateIntroduction(strategy);
// {
//   greeting: 'Hey everyone, welcome back to the channel!',
//   topicIntro: 'Today, we\'re diving deep into JavaScript Promises.',
//   valueProposition: 'By the end of this video, you\'ll understand exactly how to implement JavaScript Promises step by step.',
//   credibility: 'I\'ve spent months researching this topic',
//   duration: '0:05-0:20'
// }
```

### generateMainContent(strategy, template)

Generates structured main content based on template.

<ParamField path="strategy" type="Object" required>
  Content strategy
</ParamField>

<ParamField path="template" type="Object" required>
  Script template with structure array
</ParamField>

<ParamField path="return" type="Promise<Object>">
  Main content with sections array and total duration
</ParamField>

```javascript theme={null}
const template = agent.templates.tutorial;
const mainContent = await agent.generateMainContent(strategy, template);
// {
//   sections: [
//     { type: 'problem', title: 'The Challenge', content: [...], duration: 30 },
//     { type: 'solution_steps', title: 'The Solution', steps: [...], duration: 135 },
//     { type: 'demonstration', title: 'Live Demo', content: [...], duration: 120 }
//   ],
//   totalDuration: 285
// }
```

### generateSolutionSteps(strategy)

Generates step-by-step solution section for tutorials.

<ParamField path="strategy" type="Object" required>
  Content strategy
</ParamField>

<ParamField path="return" type="Promise<Object>">
  Solution steps section with 3-5 detailed steps
</ParamField>

```javascript theme={null}
const steps = await agent.generateSolutionSteps(strategy);
// {
//   type: 'solution_steps',
//   title: 'The Solution',
//   steps: [
//     {
//       number: 1,
//       title: 'Step 1: Research and Preparation',
//       description: 'This step involves understanding the key aspects...',
//       tip: 'Pro tip: Start small and scale gradually'
//     },
//     // ... more steps
//   ],
//   duration: 135
// }
```

### generateListItems(strategy)

Generates countdown list items for list-style content.

<ParamField path="strategy" type="Object" required>
  Content strategy
</ParamField>

<ParamField path="return" type="Promise<Object>">
  List items section with 5-10 items in countdown format
</ParamField>

```javascript theme={null}
const listItems = await agent.generateListItems(strategy);
// {
//   type: 'list_items',
//   title: 'Top 8 Things About JavaScript Promises',
//   items: [
//     {
//       number: 8,
//       title: 'The Hidden Power of JavaScript Promises',
//       description: 'This aspect is crucial because...',
//       impact: 'This alone can save you hours'
//     },
//     // ... countdown to #1
//   ],
//   duration: 240
// }
```

### generateConclusion(strategy)

Generates conclusion with recap and final thought.

<ParamField path="strategy" type="Object" required>
  Content strategy
</ParamField>

<ParamField path="return" type="Promise<Object>">
  Conclusion with recap points and final message
</ParamField>

```javascript theme={null}
const conclusion = await agent.generateConclusion(strategy);
// {
//   type: 'conclusion',
//   title: 'Wrapping Up',
//   recap: [
//     'So that\'s everything you need to know about JavaScript Promises.',
//     'We covered the key points:',
//     '- The fundamentals and why they matter',
//     '- Practical steps to get started',
//     '- Real-world applications and examples',
//     '- Tips for long-term success'
//   ],
//   finalThought: 'Remember, JavaScript Promises is a journey, not a destination. Keep learning and improving!',
//   duration: '30 seconds'
// }
```

### generateCTA(strategy)

Generates call-to-action section.

<ParamField path="strategy" type="Object" required>
  Content strategy
</ParamField>

<ParamField path="return" type="Promise<Object>">
  CTA with subscribe, like, comment, and next video prompts
</ParamField>

```javascript theme={null}
const cta = await agent.generateCTA(strategy);
// {
//   type: 'call_to_action',
//   subscribe: 'If you found this helpful, make sure to subscribe and hit the notification bell!',
//   like: 'Give this video a thumbs up if you learned something new.',
//   comment: 'Let me know in the comments: What\'s your experience with JavaScript Promises?',
//   nextVideo: 'Check out this related video for more insights.',
//   duration: '15 seconds'
// }
```

### formatFullScript(script)

Formats the complete script for production use.

<ParamField path="script" type="Object" required>
  Complete script object
</ParamField>

<ParamField path="return" type="string">
  Formatted script text with sections, timestamps, and metadata
</ParamField>

```javascript theme={null}
const formatted = agent.formatFullScript(script);
// Returns formatted text:
// TITLE: How to JavaScript Promises: Step-by-Step Guide
// ==================================================
// 
// [0:00-0:05] HOOK
// Have you ever wondered how JavaScript Promises actually works?
// 
// [0:05-0:20] INTRODUCTION
// ...
```

### estimateDuration(mainContent)

Calculates total video duration.

<ParamField path="mainContent" type="Object" required>
  Main content object with sections
</ParamField>

<ParamField path="return" type="string">
  Duration in MM:SS format
</ParamField>

```javascript theme={null}
const duration = agent.estimateDuration(script.mainContent);
// '8:30' (includes hook, intro, main content, conclusion, CTA)
```

## Usage Example

```javascript theme={null}
const { ScriptWriterAgent } = require('./agents/script-writer-agent');
const { ContentStrategyAgent } = require('./agents/content-strategy-agent');

// Generate strategy first
const strategyAgent = new ContentStrategyAgent(db, credentials);
const strategy = await strategyAgent.generateContentStrategy('Python Programming');

// Generate script
const scriptAgent = new ScriptWriterAgent(db, credentials);
await scriptAgent.initialize();

const script = await scriptAgent.generateScript(strategy);

console.log('Title:', script.title);
console.log('Duration:', script.duration);
console.log('Tone:', script.tone);
console.log('Pacing:', script.pacing);

// Access sections
console.log('Hook:', script.hook.text);
console.log('Main sections:', script.mainContent.sections.length);

// Get formatted script for production
const productionScript = script.fullScript;
fs.writeFileSync('script.txt', productionScript);
```

## Section Types

The agent generates different section types based on content template:

<Accordion title="problem">
  Identifies challenges and pain points related to the topic.
</Accordion>

<Accordion title="solution_steps">
  Provides 3-5 step-by-step instructions with pro tips.
</Accordion>

<Accordion title="demonstration">
  Live demo or walkthrough section with visual cues.
</Accordion>

<Accordion title="explanation">
  Deep dive into concepts with detailed breakdown.
</Accordion>

<Accordion title="examples">
  Real-world examples and case studies (usually 3).
</Accordion>

<Accordion title="list_items">
  Countdown-style list items (5-10 items).
</Accordion>

<Accordion title="pros / cons">
  Benefits and drawbacks for review content.
</Accordion>

<Accordion title="comparison">
  Comparative analysis with alternatives.
</Accordion>

## Best Practices

<Accordion title="Match Content Type to Topic">
  Choose appropriate content types: Tutorials for how-to topics, Lists for compilation content, Reviews for product/service evaluation.
</Accordion>

<Accordion title="Review Generated Scripts">
  While scripts are production-ready, always review for brand voice alignment and technical accuracy.
</Accordion>

<Accordion title="Customize Templates">
  Modify the built-in templates to match your channel's unique style and pacing preferences.
</Accordion>

<Accordion title="Use Duration Estimates">
  The estimated duration helps with production planning, but actual video length may vary based on delivery speed.
</Accordion>
