The X Trends Agent is an AI-powered conversational system designed to analyze trending topics on X (formerly Twitter). Built using the BeeAI framework for orchestration and the Agent Stack SDK, it specializes in identifying trending topics by country, researching the context behind each trend, and providing friendly, engaging summaries with emojis and source citations.
The agent is designed to run entirely locally using Ollama and the IBM Granite 4 model.
- Python: Version 3.11 or higher.
- Dependency Management:
uvis recommended for managing Python packages. - Ollama: Required for running the local LLM (
granite4:tiny-h).
Main packages used:
beeai-framework: For orchestrating the agent's reasoning flow and tool use.agentstack-sdk: For A2A protocol and server management.
-
Clone the repository:
git clone <repository-url> cd x_trends_agent
-
Install dependencies:
uv sync
-
Install Ollama and the model:
# Pull the required model ollama pull granite4:tiny-h
- Start the agent:
The agent will start and be ready on
uv run server
http://127.0.0.1:8000(configurable viaPORTenv var).
The agent uses a RequirementAgent (BeeAI) to process queries through a dynamic pipeline:
- Country Detection: Uses the LLM to identify if the user is asking about a specific region.
- Trend Retrieval: Scrapes
trends24.inspecifically for the target country (or global) to get the top 5 trending topics using the DuckDuckGoSearchTool. - Context Research: For each of the top 5 trends, it performs targeted web searches to find the "why" behind the trend.
- Friendly Synthesis: Generates a coherent report with emojis (💡, 📰, 🚀) and, most importantly, includes the source URLs of the news found.
- "What's trending in Mexico?"
- "Show me global trends on X today"
- "What's happening in Spain?"
src/beeai_agents/agent.py: Main logic of the agent, including the BeeAI agent definition and Agent Stack server.pyproject.toml: Dependency and script definitions.
This agent is built for demonstration purposes. Ensure you have Ollama running locally for the LLM to function properly.