X (Twitter) AI Agent is an AI web agent that interacts with tweets, built using Browser Use and Browserbase.
https://storage.googleapis.com/audio_bucket_studiaai/demo.mp4
- 🤖 Autonomous - Auto-reply to tweets on X
- 🌐 It's free - Literally all free tools (Browser-use and Browserbase) with limits
- 📱 Simple-to-use UI - Even your grandma can use it lol
- 🔄 Observation - See your agent in action with agent browsing session playback
The project is divided into two main components:
A modern web application built with:
- Next.js 15 - React framework with server-side rendering
- TypeScript - For type safety and better developer experience
- Tailwind CSS - For styling and responsive design
- Radix UI - Accessible UI components
- Zustand - State management
- Framer Motion - For animations and transitions
A Python backend built with:
- FastAPI - High-performance web framework for building APIs
- Browser-use - Library for browser automation with LLMs
- Browserbase - Browser infrastructure for reliable web automation
- LangChain - Framework for developing applications powered by language models
- Playwright - Under-the-hood browser automation library
- You enter your X login credentials and click login, which creates a context (identified by the context id) for the agent to perform the login task (go to X.com and enter credentials and login).
- The first login step is provided in order to save login info (via cookies) for future agent tasks.
- Next the user will click the run agent button, this will initiate an agent run (with saved context data, i.e auth) that will perform the task of commenting on a post on your For You page on X.
- After the agent has performed the task, you will be able to view the session recording to see how the agent has performed the tasks.
- Please note that all data (agent session data and agent context id) has been stored locally for privacy.
- (free) Browserbase API key + Browserbase Project ID (Get them at https://www.browserbase.com/settings)
- (free) OpenAI API (Get one at https://platform.openai.com/api-keys)
- Navigate to the client directory:
cd client- Install dependencies:
npm install
# or
pnpm install- Configure environment variables (optional - can be done on the interface):
# Copy example env file
cp .env.example .env
# Then edit the .env file with your values:
OPENAI_API_KEY=
BROWSERBASE_API_KEY=
BROWSERBASE_PROJECT_ID=
NEXT_PUBLIC_BROWSERBASE_API_KEY=
NEXT_PUBLIC_BROWSERBASE_PROJECT_ID=
NEXT_PUBLIC_OPENAI_API_KEY=- Start the development server:
npm run dev
# or
pnpm dev- The client will be available at http://localhost:3000
- Navigate to the server directory:
cd server- Create and activate a virtual environment using uv:
# Install uv if you don't have it
pip install uv
# Create and activate virtual environment
uv venv
source .venv/bin/activate # On Windows, use .venv\Scripts\activate- Install dependencies with uv (faster):
uv pip install -r requirements.txt- Configure environment variables (optional - if you've configured them on the frontend):
# Copy example env file
cp .env.example .env
# Then edit the .env file with your values:
BROWSERBASE_API_KEY=your_browserbase_api_key
OPENAI_API_KEY=your_openai_api_key
BROWSERBASE_PROJECT_ID=your_browserbase_project_id- Start the FastAPI server:
uv run main.py- The server will be available at http://localhost:8000
- Open your browser and navigate to http://localhost:3000
- Enter your Browserbase API key, project ID and Open AI key
- Click "Run Agent" to start a browser automation session
- Watch the session recording after task is completed (default task for AI agent is to reply to only 1 tweet - this can be changed)
- Customise the agent at utils.py in the server's api folder
The server provides several API endpoints:
POST http://localhost:8000/api/run-agent- Run an automation agent with specified keysPOST http://localhost:8000/api/login-x- Run an automation agent to login to X (only needed once at the start)POST http://localhost:3000/api/session- Get session recording for sessionPOST http://localhost:3000/api/live-view- Get live view url for session (expires after session ends)
Contributions are welcome! Please feel free to submit a Pull Request.
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add some amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
This project is licensed under the GPL License - see the LICENSE file for details. Please note the client directory has it's sub license (MIT) from Agent-UI.
- Browserbase for browser infrastructure
- Browser-use for browser automation with LLMs
- Agent-UI for agent's UI interface