Overview
Hyperbolic AgentKit provides comprehensive Twitter integration through custom Twitter actions built on the Twitter API v2. These tools enable AI agents to interact with Twitter, manage content, and engage with users.TwitterClient
TheTwitterClient class provides the core Twitter API integration:
custom_twitter_actions.py:21-31
Environment Configuration
Required environment variables for Twitter integration:Tweet Data Model
Tweets are represented using theTweet Pydantic model:
custom_twitter_actions.py:15-19
Core Twitter Operations
Get User ID
Retrieve a user’s Twitter ID from their username:custom_twitter_actions.py:33-42
LangChain Tool:
custom_twitter_actions.py:100-108
Get User Tweets
Fetch recent tweets from a specific user:custom_twitter_actions.py:44-67
LangChain Tool:
custom_twitter_actions.py:110-118
Delete Tweet
Delete a tweet by its ID:custom_twitter_actions.py:69-76
LangChain Tool:
custom_twitter_actions.py:90-97
Retweet
Retweet a tweet by its ID:custom_twitter_actions.py:78-85
LangChain Tool:
custom_twitter_actions.py:121-128
Adding Twitter Tools to Agent
Fromchatbot.py:342-359, Twitter tools are conditionally added:
CDP Twitter Integration
Coinbase AgentKit also provides Twitter capabilities through thetwitter_action_provider:
chatbot.py:61,470
Rate Limiting
The TwitterClient automatically handles rate limiting:Usage Examples
Check User’s Recent Tweets
Get User ID and Fetch Tweets
Delete a Specific Tweet
Retweet Content
Error Handling
All Twitter operations include error handling:- User not found
- Rate limit exceeded (handled automatically)
- Invalid credentials
- Insufficient permissions
- Tweet already deleted
Best Practices
API Credentials Security
- Store credentials in
.envfile - Never commit credentials to version control
- Use environment variables in production
- Rotate credentials regularly
Rate Limit Management
- Enable
wait_on_rate_limit=True - Monitor API usage in Twitter Developer Portal
- Implement backoff strategies for batch operations
- Cache user IDs when possible
Content Guidelines
- Follow Twitter’s automation rules
- Avoid spam-like behavior
- Implement appropriate delays between actions
- Respect user privacy and preferences
Twitter State Management
Track replied and reposted tweets to avoid duplicates:Next Steps
- Twitter Knowledge Base - Learn about tweet knowledge base and state management
- Blockchain Tools - Explore blockchain capabilities