Guide to use reddit tool on your AI agent using Vity Toolkit
Reddit is a social news and discussion website where users can share and vote on content, and participate in communities called subreddits.
Details
Supported Auth Type
AuthType.API_KEY
Quick Start
1
Install the package.
npm install vity-toolkit langchain @langchain/openai
2
Initialize Vity Toolkit and Langchain.
import { ChatOpenAI } from "@langchain/openai";
import { App, LangchainToolkit } from "vity-toolkit";
import { createOpenAIFunctionsAgent, AgentExecutor } from "langchain/agents";
import { ChatPromptTemplate } from "@langchain/core/prompts";
const llm = new ChatOpenAI({ model: "gpt-4o" });
const toolKit = new LangchainToolkit({
appPrivateKey: "<app-wallet-private-key>",
userPrivateKey: "<user-wallet-private-key>",
});
Make sure that you already have integrated and connected the app.
3
Add the tool.
const tools = toolKit.getTools({ apps: [App.SOLANA_WALLET] });
4
Define the Agent.
const prompt = ChatPromptTemplate.fromMessages([
["system", `You are an AI agent responsible for taking actions on Reddit on users' behalf.
You need to take action on Reddit using Reddit APIs. Use correct tools to run APIs from the given tool-set.`],
["placeholder", "{chat_history}"],
["human", "{input}"],
["placeholder", "{agent_scratchpad}"],
]);
const agent = await createOpenAIFunctionsAgent({
llm,
tools,
prompt,
});
const agentExecutor = new AgentExecutor({ agent, tools, verbose: true });
5
Execute the Agent.
const response = await agentExecutor.invoke({ input: "Fetch newest 1 post from solana on pump.fun and comment `GM` on that post." });
console.log(response);
Supported Actions
Action
Description
Action.REDDIT_FILTER
Filter the posts in a subreddit by a query.
Action.REDDIT_COMMENT
Comment on a post in a subreddit.
Action.REDDIT_CREATE_POST
Create a new post in a subreddit.
Action.REDDIT_DELETE_POST
Delete a post.
Last updated