Overview
TheContentStrategyAgent analyzes YouTube trends, competitor channels, and historical performance to generate optimized content strategies. It identifies trending topics, selects optimal publishing times, and creates data-driven content recommendations.
Constructor
Database
required
Database instance for storing and retrieving content data
Credentials
required
Credentials manager with YouTube API access
Properties
Database
Database connection instance
Credentials
YouTube API credentials manager
Logger
Logger instance for tracking agent operations
Array
Array of currently trending topics with scores and sources
Array
Analysis data from competitor channels
Array
Scheduled content calendar entries
Methods
initialize()
Initializes the agent, loads historical data, and analyzes current trends.Promise<boolean>
Returns true when initialization is complete
generateContentStrategy(requestedTopic)
Generates a comprehensive content strategy for a topic.string
Specific topic to create strategy for. If not provided, selects optimal trending topic.
Promise<Object>
Complete content strategy object
string
Selected content topic
string
Unique content angle generated for the topic
string
Identified target audience demographic
string
Content type (Tutorial, Explainer, List, Review, Story)
Array<string>
Extracted keywords for SEO optimization
number
Predicted view count based on topic score
string
ISO timestamp for optimal publishing time
Array
Insights from competitor analysis
fetchYouTubeTrends()
Fetches trending videos from YouTube API.Promise<Array>
Array of trending video data
analyzeCompetitors()
Analyzes competitor channels specified in environment variables.Promise<Array>
Competitor analysis data including top topics and performance metrics
getChannelVideos(channelId)
Retrieves recent videos from a specific channel.string
required
YouTube channel ID to analyze
Promise<Array>
Array of video details with statistics
analyzeVideoPerformance(videos)
Analyzes performance metrics for a collection of videos.Array
required
Array of video objects with statistics
Object
Performance analysis including top topics, average views, and upload frequency
Array
Top 10 performing topics with average views
number
Average view count across all videos
number
Number of videos analyzed
extractKeywords(text)
Extracts meaningful keywords from text by filtering stop words.string
required
Text to extract keywords from
Array<string>
Array of extracted keywords (words > 3 characters, excluding stop words)
selectOptimalTopic()
Selects the best topic from trending topics using scoring algorithm.Object
Selected topic with score
identifyTargetAudience(topic)
Identifies the target audience for a given topic.string
required
Content topic
Promise<string>
Target audience description
selectContentType(topic)
Determines the optimal content type based on topic keywords.string
required
Content topic
string
Content type: Tutorial, List, Review, Explainer, News, or Story
calculateBestPublishTime()
Calculates the optimal publishing time based on historical performance.string
ISO timestamp for next optimal publish time
Environment Variables
string
default:"US"
YouTube region code for trending videos
string
Comma-separated list of competitor channel IDs to analyze
Usage Example
Error Handling
The agent implements comprehensive error handling:Best Practices
Optimize Trend Analysis
Optimize Trend Analysis
Call
initialize() periodically (e.g., daily) to refresh trending topics and competitor analysis. The agent caches data to minimize API calls.Configure Competitors
Configure Competitors
Set
COMPETITOR_CHANNELS environment variable with relevant channel IDs in your niche for better strategy recommendations.Monitor Historical Performance
Monitor Historical Performance
The agent learns from historical content performance. Ensure you’re saving analytics data back to the database for improved predictions.
Topic Rotation
Topic Rotation
The agent automatically avoids repeating topics within 7 days. This prevents content fatigue and maintains audience interest.