twitter application. The example is based on examples/like_tweet.py.
Objective
Develop an agent that can:- Retrieve the current user’s Twitter ID.
- Extract a tweet ID from a given tweet URL or ID.
- Like the specified tweet as the current user.
- Confirm the action or report errors.
Steps
-
Set up the Twitter Application:
Load the
twitterapplication usingapp_from_slugand configure its integration (e.g.,AgentRIntegration). -
Initialize LLM and ToolManager:
-
Register Specific Twitter Tools:
Instead of registering all tools from the Twitter app, we’ll explicitly add the ones needed for this task. This demonstrates finer-grained tool selection.
Self-note: The actual method names in
twitter_appmight differ; this is illustrative based on thelike_tweet.pyexample’s tool naming. -
Get Tools in Langchain Format:
-
Create the Langchain Agent:
-
Define the Agent’s Task Prompt:
This prompt instructs the agent on the steps to like a tweet.
-
Invoke the Agent:
Get the tweet ID/URL from the user and run the agent.
How It Works
- The agent first calls
find_my_user_idto get the necessary user ID. - The LLM extracts the tweet ID from the input
tweet_id_or_url. - It then calls the
like_tweettool, passing the retrieved user ID and the extracted tweet ID. - The
twitter_app.users_id_likemethod (aliased aslike_tweet) interacts with the Twitter API. - The agent reports the success or failure of the operation.