𝕏-Bot

An Autonomous AI-Powered Twitter/X Agent

"Intelligent content creation with personality-driven engagement"

Personal Project | 2025

The Problem

Why build an autonomous social media bot?

Time-Intensive

Consistent social media presence requires significant daily time investment

📊 Suboptimal Timing

Manual posting often misses optimal engagement windows

🌊 Content Overload

Engaging with relevant content is overwhelming at scale

🤖 AI Opportunity

Leverage LLMs for personality-consistent, high-quality content

The Solution

X Bot: Key Capabilities

Feature Description
🤖 Autonomous Posting Generates original tweets based on configurable personality
📖 Intelligent Reading Scans timeline, identifies posts matching interests
💡 Inspiration Engine Creates content inspired by curated interesting posts
🔔 Notification Handling Monitors mentions and replies for engagement
🧠 Memory System Avoids duplicate content using vector embeddings
📊 Web Dashboard Real-time monitoring, analytics, settings, and live control
💬 Reply Workflows Checks mentions/replies and queues notifications for processing

System Architecture

🕒

Scheduler

APScheduler

⚙️

Jobs Layer

Posting • Reading • Notifications • Replies • Inspiration

𝕏

X Automation

Selenium + undetected-chromedriver + stealth

🧩

LangChain + LangGraph

Generation, validation, reading, notifications workflows

🤖

LLM Providers

OpenRouter • OpenAI • Google • Anthropic

🧠

ChromaDB Memory

Embedding cache + duplicate detection (0.85)

💾

State Storage

JSON runtime state + SQLite analytics

🌐

FastAPI Dashboard

Jinja2 + HTMX + Chart.js + live settings reload

Personality System

Configurable bot personality via YAML

personality: tone: humorous style: conversational topics: - AI - technology - crypto - blockchain - web3 - memes min_tweet_length: 60 max_tweet_length: 280

Personality Enforces:

  • Brand alignment checking before posting
  • Tweet re-evaluation for quality control
  • Interest detection based on configured topics
  • Consistent voice across all generated content

Content Pipeline

From timeline reading to intelligent posting

📖 Read Timeline

Selenium extraction

🔍 Interest Check

LLM evaluation

⭐ Queue

Store interesting

💡 Generate

Inspiration batch

✅ Quality Check

Re-evaluation

📤 Post

Publish to X

Batch Processing: Interesting posts accumulate until threshold (25 posts), then the bot generates inspired content based on the collection.

Memory & Deduplication

ChromaDB vector storage for intelligent memory

🧠 ChromaDB Features
  • Every tweet embedded before storage
  • Cosine similarity for duplicate detection
  • Configurable threshold: 0.85
  • Metadata persisted: timestamps, provider, operation
  • Backed by data/chroma/ for persistence
Duplicate Prevention: Semantically similar content is blocked before posting
# Duplicate detection logic async def check_duplicate(text: str): embedding = await get_embedding(text) results = collection.query( query_embeddings=[embedding], n_results=1 ) if results["distances"][0][0] > 0.85: logger.warning("duplicate_detected") return True return False

Web Dashboard

Full monitoring and configuration interface

📊 Dashboard

Bot status, uptime, activity stats, rate limit progress

📝 Posts

Read, written, rejected, and interesting posts with tabs

💬 Chat

Interactive tweet generation with post-to-X option

📈 Analytics

Hourly token usage graph with Chart.js, provider breakdown

📋 Logs

Real-time log viewer with filtering and auto-scroll

⚙️ Settings

Live configuration editing with instant reload

Built with: FastAPI + Jinja2 + HTMX for dynamic partial loading • X.com-inspired dark/light themes

Rate Limits & Compliance

Enforced Limits

Limit Value
Max posts/day 15
Max replies/day 50
Reset time 00:00 UTC
Action delay 1-3 seconds (randomized)

Compliance Features

  • Rate limit enforcement per day
  • Human-like randomized delays
  • Cookie persistence (no repeated logins)
  • Bot disclosure in profile (🤖 AI Bot)
  • undetected-chromedriver to avoid detection
  • Stealth mode with User-Agent rotation

Current Status

Roadmap and repository snapshot

Phase 1: Scheduler & Reading Complete
Phase 2: Interest & Reactions Complete
🔶 Phase 3: Notifications & Reply Flow In Progress
Phase 4: Memory & Dashboard Complete
4
LLM Providers
6
Scheduler Jobs
5
Graph Workflows
8
Dashboard Templates

Live Demo

Dashboard walkthrough

1️⃣ Dashboard Overview

Bot status, uptime, rate limits, activity feed

2️⃣ Posts Tab

Read/written/rejected/interested posts with pagination

3️⃣ Analytics

Token usage graph, provider breakdown, hourly stats

4️⃣ Settings

Live configuration with instant scheduler reload

🖥️ Open Dashboard: http://localhost:8000

Tech Stack

Layer Technology
Language Python >= 3.13 with full type hints
AI Orchestration LangChain + LangGraph
Providers OpenRouter, OpenAI, Google, Anthropic
Configured Model x-ai/grok-4.1-fast (OpenRouter)
Embeddings text-embedding-3-small
Vector DB ChromaDB (persistent local storage)
Browser undetected-chromedriver + selenium-stealth
Scheduling APScheduler (background scheduler)
State & Analytics JSON state + SQLite (aiosqlite)
🌐 Web Layer
  • FastAPI backend
  • Jinja2 templates + HTMX partials
  • Chart.js token analytics
  • Pydantic v2 + pydantic-settings
Repo Facts: 6 scheduler jobs, 5 LangGraph workflows, and async I/O across state and database layers.

Challenges & Learnings

Challenge Solution
X/Twitter bot detection undetected-chromedriver + selenium-stealth
LLM provider reliability Multi-provider fallback (OpenRouter → OpenAI → Google)
Rate limiting enforcement Per-day counters with UTC reset logic
Duplicate content prevention Vector embeddings + cosine similarity threshold
Async complexity Full async/await architecture with aiosqlite
Configuration management YAML config + Pydantic validation + live reload

Future Roadmap

Planned enhancements

🔴 Intent Detection - Filter negative/toxic replies High Priority
🔴 Reply Generation - Respond to positive notifications High Priority
🟡 Trends Integration - Topic-aware content with compliance Medium
🟡 RSS Feed Ingestion - External content sources Medium
🟢 Multi-account Support - Manage multiple bots Low Priority
🟢 Cost Tracking - Per-provider API spend analytics Low Priority

Key Takeaways

🏗️ Modular Architecture

Clean separation of concerns with dedicated modules for each responsibility

🔒 Type Safety

Pydantic v2 models throughout for validation and documentation

🔄 Multi-Provider LLM

Resilient AI integration with automatic fallback between providers

👁️ Observable

Full dashboard with analytics, logs, and real-time status

Compliant

Rate limits, bot disclosure, human-like behavior patterns

🔌 Extensible

Easy to add new features, providers, and integrations

Questions?

Thank you for your attention!

📂 Source Code

Available on request

📧 Contact

Your contact info here