Daydreams Logo
Guides

Building a Twitter Agent

This guide will walk you through creating an AI agent that can interact with Twitter using DreamsAI.

Prerequisites

Before starting, make sure you have:

  1. A Twitter developer account
  2. The following environment variables set up:
    • GROQ_API_KEY: Your Groq API key

Creating the Agent

First, let's create a basic Twitter agent:

import { createGroq } from "@ai-sdk/groq";
import {
  createContainer,
  createDreams,
  LogLevel,
  twitter,
} from "@daydreamsai/core";
 
// Initialize Groq client
const groq = createGroq({
  apiKey: process.env.GROQ_API_KEY!,
});
 
// Create the agent
const agent = createDreams({
  logger: LogLevel.DEBUG,
  container: createContainer(),
  model: groq("deepseek-r1-distill-llama-70b"),
  extensions: [twitter],
});
 
// Start the agent
await agent.start();

How It Works

The Twitter agent is created using a few key components:

  1. Groq Integration: We use Groq's language model for processing and understanding Twitter interactions.

  2. Logger: Set to DEBUG level for detailed logging during development.

  3. Container: Manages dependencies and services.

  4. Twitter Extension: The twitter extension provides built-in capabilities for:

    • Monitoring mentions
    • Replying to tweets
    • Posting new tweets
    • Managing Twitter authentication

Next Steps

  • Set up Twitter authentication in your environment variables
  • Customize the agent's behavior by adding your own extensions
  • Implement specific use cases like auto-replies or content monitoring

For more examples and detailed API documentation, check out our API Reference.

On this page