Skip to main content

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

db
Database
required
Database instance for storing scripts
credentials
Credentials
required
Credentials manager for external services
const { ScriptWriterAgent } = require('./agents/script-writer-agent');

const agent = new ScriptWriterAgent(db, credentials);

Properties

templates
Object
Script templates for different content types (tutorial, explainer, list, review, story)
logger
Logger
Logger instance for tracking script generation

Script Templates

The agent includes built-in templates for five content types:
{
  structure: ['hook', 'introduction', 'problem', 'solution_steps', 
              'demonstration', 'recap', 'cta'],
  tone: 'educational',
  pacing: 'moderate'
}

Methods

initialize()

Initializes the script writer agent.
return
Promise<boolean>
Returns true when initialization is complete
await agent.initialize();

generateScript(strategy)

Generates a complete video script based on content strategy.
strategy
Object
required
Content strategy object from ContentStrategyAgent
strategy.topic
string
required
Content topic
strategy.angle
string
required
Content angle/approach
strategy.contentType
string
required
Content type (Tutorial, Explainer, List, Review, Story)
strategy.keywords
Array<string>
required
SEO keywords
return
Promise<Object>
Complete script object
script.title
string
Generated video title
script.hook
Object
Opening hook (0:00-0:05) with type and text
script.introduction
Object
Introduction section (0:05-0:20) with greeting, topic intro, value proposition, credibility
script.mainContent
Object
Main content sections with type-specific structure
script.conclusion
Object
Conclusion with recap and final thought
script.callToAction
Object
Call-to-action with subscribe, like, comment prompts
script.duration
string
Estimated video duration (MM:SS format)
script.fullScript
string
Formatted full script text ready for production
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.
strategy
Object
required
Content strategy object
return
Promise<string>
Generated title
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.
strategy
Object
required
Content strategy
return
Promise<Object>
Hook object with type, text, and duration
hook.type
string
Hook type: question, statistic, statement, challenge, or promise
hook.text
string
Hook text content
hook.duration
string
Time range for hook (0:00-0:05)
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.
strategy
Object
required
Content strategy
return
Promise<Object>
Introduction with greeting, topic intro, value proposition, credibility
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.
strategy
Object
required
Content strategy
template
Object
required
Script template with structure array
return
Promise<Object>
Main content with sections array and total duration
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.
strategy
Object
required
Content strategy
return
Promise<Object>
Solution steps section with 3-5 detailed steps
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.
strategy
Object
required
Content strategy
return
Promise<Object>
List items section with 5-10 items in countdown format
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.
strategy
Object
required
Content strategy
return
Promise<Object>
Conclusion with recap points and final message
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.
strategy
Object
required
Content strategy
return
Promise<Object>
CTA with subscribe, like, comment, and next video prompts
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.
script
Object
required
Complete script object
return
string
Formatted script text with sections, timestamps, and metadata
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.
mainContent
Object
required
Main content object with sections
return
string
Duration in MM:SS format
const duration = agent.estimateDuration(script.mainContent);
// '8:30' (includes hook, intro, main content, conclusion, CTA)

Usage Example

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:
Identifies challenges and pain points related to the topic.
Provides 3-5 step-by-step instructions with pro tips.
Live demo or walkthrough section with visual cues.
Deep dive into concepts with detailed breakdown.
Real-world examples and case studies (usually 3).
Countdown-style list items (5-10 items).
Benefits and drawbacks for review content.
Comparative analysis with alternatives.

Best Practices

Choose appropriate content types: Tutorials for how-to topics, Lists for compilation content, Reviews for product/service evaluation.
While scripts are production-ready, always review for brand voice alignment and technical accuracy.
Modify the built-in templates to match your channel’s unique style and pacing preferences.
The estimated duration helps with production planning, but actual video length may vary based on delivery speed.