This package has been deprecated

Author message:

Please use @coinbase/agentkit and @coinbase/agentkit-langchain instead.

@coinbase/twitter-langchain
TypeScript icon, indicating that this package has built-in type declarations

0.0.12 • Public • Published

Twitter (X) Langchain Toolkit

Twitter integration with Langchain to enable agentic workflows using the core primitives defined in cdp-agentkit-core.

This toolkit contains tools that enable an LLM agent to interact with Twitter. The toolkit provides a wrapper around the Twitter (X) API, allowing agents to perform social operations like posting text.

Setup

Prerequisites

Installation

npm install @coinbase/twitter-langchain

Environment Setup

Set the following environment variables:

export OPENAI_API_KEY=<your-openai-api-key>
export TWITTER_API_KEY=<your-api-key>
export TWITTER_API_SECRET=<your-api-secret>
export TWITTER_ACCESS_TOKEN=<your-access-token>
export TWITTER_ACCESS_TOKEN_SECRET=<your-access-token-secret>
export TWITTER_BEARER_TOKEN=<your-bearer-token>

Usage

Basic Setup

import { TwitterAgentkit } from "@coinbase/cdp-agentkit-core";
import { TwitterToolkit } from "@coinbase/twitter-langchain";

// Initialize Twitter AgentKit
const agentkit = new TwitterAgentkit();

// Create toolkit
const toolkit = new TwitterToolkit(agentkit);

// Get available tools
const tools = toolkit.getTools();

Available Tools

The toolkit provides the following tools:

  1. account_details - Get the authenticated account details
  2. account_mentions - Get mentions for the account
  3. post_tweet - Post a tweet to the account
  4. post_tweet_reply - Post a reply to a tweet on Twitter

Using with an Agent

Additional Installations

npm install @langchain/langgraph @langchain/openai
import { ChatOpenAI } from "@langchain/openai";
import { createReactAgent } from "@langchain/langgraph/prebuilt";

// Initialize LLM
const model = new ChatOpenAI({
  model: "gpt-4o-mini",
});

// Create agent executor
const agent = createReactAgent({
  llm: model,
  tools,
});

// Example usage
const result = await agent.invoke({
  messages: [new HumanMessage("please post 'hello, world!' to twitter")],
});

console.log(result.messages[result.messages.length - 1].content);

Examples

Check out twitter-langchain/examples for inspiration and help getting started!

  • Chatbot Typescript: Simple example of a Node.js Chatbot that can interact on Twitter (X), using OpenAI.

Contributing

See CONTRIBUTING.md for detailed setup instructions and contribution guidelines.

Package Sidebar

Install

npm i @coinbase/twitter-langchain

Weekly Downloads

12

Version

0.0.12

License

none

Unpacked Size

12.5 kB

Total Files

8

Last publish

Collaborators

  • coinbase-owner
  • coinbase-npm