LogoLogo
TwitterWebsite
  • Getting Started
    • Introduction
    • Human UI
    • Examples
    • Monitoring
    • Workflows
    • Getting Help
  • Documentation
    • Humans
      • Introduction
      • Prompts
      • Tools
      • Knowledge
      • Memory
      • Storage
      • Structured Output
      • Reasoning
      • Teams
    • Models
      • Introduction
      • Open AI
      • Open AI Like
      • Anthropic Claude
      • AWS Bedrock Claude
      • Azure
      • Cohere
      • DeepSeek
      • Fireworks
      • Gemini
      • Gemini - VertexAI
      • Groq
      • HuggingFace
      • Mistral
      • Nvidia
      • Ollama
      • OpenRouter
      • Sambanova
      • Together
      • xAI
    • Tools
      • Introduction
      • Functions
      • Writing your own Toolkit
      • Airflow
      • Apify
      • Arxiv
      • AWS Lambda
      • BaiduSearch
      • Calculator
      • Cal.com
      • Composio
      • Crawl4AI
      • CSV
      • Dalle
      • DuckDb
      • DuckDuckGo
      • Email
      • Exa
      • Fal
      • File
      • Firecrawl
      • Giphy
      • Github
      • Google Calendar
      • Google Search
      • Hacker News
      • Jina Reader
      • Jira
      • Linear
      • Lumalabs
      • MLX Transcribe
      • ModelsLabs
      • Newspaper
      • Newspaper4k
      • OpenBB
      • Bitca
      • Postgres
      • Pubmed
      • Pyton
      • Replicate
      • Resend
      • Searxng
      • Serpapi
      • Shell
      • Slack
      • Sleep
      • Spider
      • SQL
      • Tavily
      • Twitter
      • Website
      • Yfinance
      • Zendesk
    • Knowledges
      • Introduction
      • ArXiv Knowledge Base
      • Combined KnowledgeBase
      • CSV Knowledge Base
      • CSV URL Knowledge Base
      • Docx Knowledge Base
      • Document Knowledge Base
      • JSON Knowledge Base
      • LangChain Knowledge Base
      • LlamaIndex Knowledge Base
      • PDF Knowledge Base
      • PDF URL Knowledge Base
      • S3 PDF Knowledge Base
      • S3 Text Knowledge Base
      • Text Knowledge Base
      • Website Knowledge Base
    • Chunking
      • Fixed Size Chunking
      • Agentic Chunking
      • Semantic Chunking
      • Recursive Chunking
      • Document Chunking
    • VectorDBS
      • Introduction
      • PgVector Agent Knowledge
      • Qdrant Agent Knowledge
      • Pinecone Agent Knowledge
      • LanceDB Agent Knowledge
      • ChromaDB Agent Knowledge
      • SingleStore Agent Knowledge
    • Storage
      • Introduction
      • Postgres Agent Storage
      • Sqlite Agent Storage
      • Singlestore Agent Storage
      • DynamoDB Agent Storage
      • JSON Agent Storage
      • YAML Agent Storage
    • Embeddings
      • Introduction
      • OpenAI Embedder
      • Gemini Embedder
      • Ollama Embedder
      • Voyage AI Embedder
      • Azure OpenAI Embedder
      • Mistral Embedder
      • Fireworks Embedder
      • Together Embedder
      • HuggingFace Embedder
      • Qdrant FastEmbed Embedder
      • SentenceTransformers Embedder
    • Workflows
      • Introduction
      • Session State
      • Streaming
      • Advanced Example - News Report Generator
  • How To
    • Install & Upgrade
    • Upgrade to v2.5.0
Powered by GitBook
LogoLogo

© 2025 Bitca. All rights reserved.

On this page
  • Prerequisites
  • ​Example
  • ​Toolkit Params
  • ​Toolkit Functions
Export as PDF
  1. Documentation
  2. Tools

Twitter

PreviousTavilyNextWebsite

Last updated 4 months ago

Prerequisites

The following example requires the tweepy library.

pip install tweepy

Get a Twitter API key and secret from .

export TWITTER_CONSUMER_KEY=***
export TWITTER_CONSUMER_SECRET=***
export TWITTER_ACCESS_TOKEN=***
export TWITTER_ACCESS_TOKEN_SECRET=***
export TWITTER_BEARER_TOKEN=***

Example

The following agent will use Twitter to get information about a user, send a message to a user, and create a new tweet.

cookbook/tools/twitter_tools.py

from bitca.agent import Agent
from bitca.tools.twitter import TwitterTools

# Initialize the Twitter toolkit
twitter_tools = TwitterTools()

# Create an agent with the twitter toolkit
agent = Agent(
    instructions=[
        "Use your tools to interact with Twitter as the authorized user @bitca",
        "When asked to create a tweet, generate appropriate content based on the request",
        "Do not actually post tweets unless explicitly instructed to do so",
        "Provide informative responses about the user's timeline and tweets",
        "Respect Twitter's usage policies and rate limits",
    ],
    tools=[twitter_tools],
    show_tool_calls=True,
)
agent.print_response("Can you retrieve information about this user https://x.com/bitca", markdown=True)

# Example usage: Reply To a Tweet
agent.print_response(
    "Can you reply to this post as a general message as to how great this project is:https://x.com/bitca",
    markdown=True,
)
# Example usage: Get your details
agent.print_response("Can you return my twitter profile?", markdown=True)

# Example usage: Send a direct message
agent.print_response(
    "Can a send direct message to the user: https://x.com/bitca assking you want learn more about them and a link to their community?",
    markdown=True,
)
# Example usage: Create a new tweet
agent.print_response("Create & post a tweet about the importance of AI ethics", markdown=True)

# Example usage: Get home timeline
agent.print_response("Get my timeline", markdown=True)
Parameter
Type
Default
Description

bearer_token

str

None

The bearer token for Twitter API authentication

consumer_key

str

None

The consumer key for Twitter API authentication

consumer_secret

str

None

The consumer secret for Twitter API authentication

access_token

str

None

The access token for Twitter API authentication

access_token_secret

str

None

The access token secret for Twitter API authentication

Function
Description

create_tweet

Creates and posts a new tweet

reply_to_tweet

Replies to an existing tweet

send_dm

Sends a direct message to a Twitter user

get_user_info

Retrieves information about a Twitter user

get_home_timeline

Gets the authenticated user’s home timeline

Toolkit Params

Toolkit Functions

here
​
​
​