Build a Social Media Intelligence Agent with Agno, X Tools, and Exa
Create a professional-grade social media intelligence system using Agno.
In this tutorial, we will build a multi-agent intelligence system. It will monitor X (Twitter), perform sentiment analysis, and generate reports using Agno framework.We will be using the following components:
Agno - The fastest framework for building agents.
X Tools - Provides real-time, structured data directly from Twitter/X API with engagement metrics
Exa Tools - Deliver semantic web search for broader context discovery across blogs, forums, and news
GPT-5 Mini - OpenAI’s new model. Well suited for contextually-aware sentiment analysis and strategic pattern detection
This system will combine direct social media data with broader web intelligence, to provide comprehensive brand monitoring that captures both immediate social sentiment and emerging discussions before they reach mainstream attention.
mkdir social-intel && cd social-intelpython3 -m venv venvsource venv/bin/activate # If you are on Windows, use: venv\Scripts\activate
Install our Python dependencies:
Copy
Ask AI
# Install dependenciespip install "agno[infra]" openai exa_py python-dotenv4. Create a new project with [AgentOS](/agent-os/introduction):```bashag infra create # Choose: [1] agent-infra-docker (default)# Infra Name: social-intel
Which model should I use?: You can choose any model from our supported providers. Normally models are chosen based on costs and performance. In this case, we will be using OpenAI’s GPT-5 Mini.Why GPT-5 Mini?
Cost-effective: Better price/performance ratio than other GPT models
Tool usage: Excellent at deciding when and how to use tools
Complex reasoning: Can follow detailed analysis methodologies
Structured output: Reliable at generating formatted reports
Let’s first create the file where we will define our agent:
Copy
Ask AI
mkdir -p apptouch app/social_media_agent.py
Now let’s add the basic imports and model setup:
Copy
Ask AI
from pathlib import Pathfrom dotenv import load_dotenvfrom agno.models.openai import OpenAIChat# Load infrastructure secretsload_dotenv(dotenv_path=Path(__file__).resolve().parents[1] / "infra" / "secrets" / ".env")# Choose the AI model for your agentmodel = OpenAIChat(id="gpt-5-mini")print(f"Model selected: {model.id}")
We can now test our model setup:
Copy
Ask AI
# Quick test to verify model worksif __name__ == "__main__": test_response = model.invoke("Explain social media sentiment analysis in one sentence.") print(f"Model test: {test_response}")
This confirms your model is working, before we add more complexity.
Which tools should I use? We are adding XTools because we need direct Twitter/X data with engagement metrics, and ExaTools because we need broader web context that social media alone can’t provide.
Why XTools? Direct access to Twitter/X with engagement metrics is crucial for understanding influence patterns and viral content.
Copy
Ask AI
from agno.tools.x import XTools# Configure X Tools for social media datax_tools = XTools( include_post_metrics=True, # Critical: gets likes, retweets, replies for influence analysis wait_on_rate_limit=True, # Handles API limits gracefully)print("XTools configured with post metrics enabled")
Why ExaTools? Social media discussions often reference broader conversations happening across the web. ExaTools finds this context.
Copy
Ask AI
from agno.tools.exa import ExaTools# Configure Exa for broader web intelligenceexa_tools = ExaTools( num_results=10, # Comprehensive but not overwhelming include_domains=["reddit.com", "news.ycombinator.com", "medium.com"],)print("ExaTools configured for web search")
Why these specific domains?
Reddit: Early discussion indicators, community sentiment
HackerNews: Tech industry insights, developer opinions
Why do we need instructions? We need to describe the strategy that the agent should take to collect and analyze content. Without clear instructions, the agent won’t know how to use the tools effectively or what kind of analysis to provide.
from textwrap import dedent# Define how the agent should gather datadata_collection_strategy = dedent(""" 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""")print("Data collection strategy defined")
# Combine all instruction componentscomplete_instructions = f"""You are a Senior Social Media Intelligence Analyst specializing in cross-platformbrand monitoring and strategic analysis.CORE METHODOLOGY:{data_collection_strategy}{analysis_framework}{intelligence_synthesis}{report_format}{analysis_principles}"""print(f"Complete instructions created: {len(complete_instructions)} characters")
from agno.agent import Agent# Combine model, tools, and instructions into a complete agentsocial_media_agent = Agent( name="Social Media Intelligence Analyst", model=model, # The GPT-5 mini model we chose tools=tools, # The X and Exa tools we configured instructions=complete_instructions, # The strategy we defined markdown=True, # Enable rich formatting for reports show_tool_calls=True, # Show transparency in data collection)print(f"Agent created: {social_media_agent.name}")
def analyze_brand_sentiment(query: str, tweet_count: int = 20): """ Execute comprehensive social media intelligence analysis. Args: query: Brand or topic search query (e.g., "Tesla OR @elonmusk") tweet_count: Number of recent tweets to analyze """ # Create a detailed prompt for the agent 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. """ # Execute the analysis return social_media_agent.print_response(analysis_prompt, stream=True)print("Analysis function created")
def test_agent(): """Test the complete agent with a sample query.""" print("Testing social media intelligence agent...") analyze_brand_sentiment("Agno OR AgnoAGI", tweet_count=10)print("Test function ready")
Why API-first? The AgentOS infrastructure automatically exposes your agent as a REST API, making it ready for production integration without additional deployment work.Your agent is automatically available via the AgentOS API. Let’s test it!Find your API endpoint:
Copy
Ask AI
# Your AgentOS API is running on localhost:7777curl http://localhost:7777/v1/agents
Test with Postman or curl:
Copy
Ask AI
curl -X POST http://localhost:7777/v1/agents/social_media_agent/runs \ -H "Content-Type: application/json" \ -d '{ "message": "Analyze social media sentiment for: Tesla OR @elonmusk", "stream": false }'
You’ve built a comprehensive social media intelligence system that:
Combines direct social data with broader web intelligence
Provides weighted sentiment analysis with strategic recommendations
Serves insights via production-ready AgentOS API
Scales from development through enterprise deployment
This demonstrates Agno’s infrastructure-first approach, where your AI agents become immediately deployable services with proper monitoring, scaling, and integration capabilities built-in.