"""
Complete Social Media Intelligence Agent
Built with Agno framework
"""
from pathlib import Path
from textwrap import dedent
from dotenv import load_dotenv
from agno.agent import Agent
from agno.models.openai import OpenAIChat
from agno.tools.x import XTools
from agno.tools.exa import ExaTools
# Load infrastructure secrets
load_dotenv(dotenv_path=Path(__file__).resolve().parents[1] / "infra" / "secrets" / ".env")
# Step 1: Choose the AI model
model = OpenAIChat(id="gpt-5-mini")
# Step 2: Configure tools
tools = [
XTools(
include_post_metrics=True,
wait_on_rate_limit=True,
),
ExaTools(
num_results=10,
include_domains=["reddit.com", "news.ycombinator.com", "medium.com"],
exclude_domains=["spam-site.com"],
)
]
# Step 3: Define instructions
complete_instructions = dedent("""
You are a Senior Social Media Intelligence Analyst specializing in cross-platform
brand monitoring and strategic analysis.
CORE METHODOLOGY:
DATA COLLECTION STRATEGY:
- Use X Tools to gather direct social media mentions with full engagement metrics
- Use Exa Tools to find broader web discussions, articles, and forum conversations
- Cross-reference findings between social and web sources for comprehensive coverage
ANALYSIS FRAMEWORK:
- Classify sentiment as Positive/Negative/Neutral/Mixed with detailed reasoning
- Weight analysis by engagement volume and author influence (verified accounts = 1.5x)
- Identify engagement patterns: viral advocacy, controversy, influence concentration
- Extract cross-platform themes and recurring discussion points
INTELLIGENCE SYNTHESIS:
- Detect crisis indicators through sentiment velocity and coordination patterns
- Identify competitive positioning and feature gap discussions
- Surface growth opportunities and advocacy moments
- Generate strategic recommendations with clear priority levels
REPORT FORMAT:
### Executive Dashboard
- **Brand Health Score**: [1-10] with supporting evidence
- **Net Sentiment**: [%positive - %negative] with trend analysis
- **Key Drivers**: Top 3 positive and negative factors
- **Alert Level**: Normal/Monitor/Crisis with threshold reasoning
### Quantitative Metrics
| Sentiment | Posts | % | Avg Engagement | Influence Score |
|-----------|-------|---|----------------|-----------------|
[Detailed breakdown with engagement weighting]
### Strategic Recommendations
**IMMEDIATE (≤48h)**: Crisis response, high-impact replies
**SHORT-TERM (1-2 weeks)**: Content strategy, community engagement
**LONG-TERM (1-3 months)**: Product positioning, market strategy
ANALYSIS PRINCIPLES:
- Evidence-based conclusions with supporting metrics
- Actionable insights that drive business decisions
- Cross-platform correlation analysis
- Influence-weighted sentiment scoring
- Proactive risk and opportunity identification
""")
# Step 4: Create the complete agent
social_media_agent = Agent(
name="Social Media Intelligence Analyst",
model=model,
tools=tools,
instructions=complete_instructions,
markdown=True,
show_tool_calls=True,
)
def analyze_brand_sentiment(query: str, tweet_count: int = 20):
"""Execute comprehensive social media intelligence analysis."""
prompt = f"""
Conduct comprehensive social media intelligence analysis for: "{query}"
ANALYSIS PARAMETERS:
- Twitter Analysis: {tweet_count} most recent tweets with engagement metrics
- Web Intelligence: Related articles, discussions, and broader context via Exa
- Cross-Platform Synthesis: Correlate social sentiment with web discussions
- Strategic Focus: Brand positioning, competitive analysis, risk assessment
METHODOLOGY:
1. Gather direct social media mentions and engagement data
2. Search for related web discussions and broader context
3. Analyze sentiment patterns and engagement indicators
4. Identify cross-platform themes and influence networks
5. Generate strategic recommendations with evidence backing
Provide comprehensive intelligence report following the structured format.
"""
return social_media_agent.print_response(prompt, stream=True)
if __name__ == "__main__":
# Test the complete agent
analyze_brand_sentiment("Agno OR AgnoAGI", tweet_count=25)