Key Concepts
| Concept | Description |
|---|---|
| Sentiment Classification | Categorizes tweets as positive, negative, neutral, or mixed |
| Engagement Patterns | Detects viral advocacy, controversy, and influence concentration |
| Brand Health Score | 1-10 rating based on sentiment and engagement metrics |
| Theme Extraction | Identifies recurring topics and pain points |
Prerequisites
- Python 3.12+
- OpenAI API key
- X (Twitter) API credentials
Setup
1
Clone the repository
2
Create and activate virtual environment
3
Install dependencies
4
Get X API credentials
- Go to the X Developer Portal
- Create a project and app
- Generate API keys and access tokens
5
Set environment variables
Run the Agent
Brand Analysis
Analyze sentiment for a brand:- Retrieving tweets for a brand
- Sentiment classification
- Brand health scoring
Competitor Comparison
Compare sentiment across brands:- Multi-brand analysis
- Comparative sentiment metrics
- Competitive positioning insights
Trending Topic
Analyze a trending topic:Agent Configuration
| Parameter | Purpose |
|---|---|
model | GPT for sentiment analysis and synthesis |
output_schema | Structured report with sentiment data |
XTools | X API integration for tweet retrieval |
include_post_metrics | Get likes, retweets, replies |
wait_on_rate_limit | Handle API rate limits gracefully |
ReasoningTools | Plan analysis approach |
How It Works
Analysis Workflow
Sentiment Classification
| Category | Indicators |
|---|---|
| Positive | Praise, recommendations, satisfaction |
| Negative | Complaints, frustration, criticism |
| Neutral | Information sharing, questions, news |
| Mixed | Contains both positive and negative |
Brand Health Score
| Score | Meaning |
|---|---|
| 9-10 | Overwhelmingly positive, strong advocacy |
| 7-8 | Mostly positive, minor issues |
| 5-6 | Mixed sentiment, notable concerns |
| 3-4 | Predominantly negative, significant issues |
| 1-2 | Crisis level negativity |
Troubleshooting
X API authentication failed
X API authentication failed
Verify all four environment variables are set:
Rate limit errors
Rate limit errors
The agent is configured with
wait_on_rate_limit=True. For high-volume analysis, consider spacing requests or using X API premium tiers.Limited results for niche brands
Limited results for niche brands
Some brands may have fewer tweets. The agent will analyze available data and note limitations in the report.