> For the complete documentation index, see [llms.txt](https://vity-toolkit.gitbook.io/vity-toolkit/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://vity-toolkit.gitbook.io/vity-toolkit/tools/reddit.md).

# Reddit

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.

<table><thead><tr><th>Details</th><th></th></tr></thead><tbody><tr><td>Supported Auth Type</td><td><pre><code>AuthType.API_KEY
</code></pre></td></tr></tbody></table>

## Quick Start

{% stepper %}
{% step %}
**Install the package.**

```bash
npm install vity-toolkit langchain @langchain/openai
```

{% endstep %}

{% step %}
**Initialize Vity Toolkit and Langchain.**

```typescript
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](https://vity-toolkit.gitbook.io/vity-toolkit/features/agent-authentication).
> {% endstep %}

{% step %}
**Add the tool.**

```typescript
const tools = toolKit.getTools({ apps: [App.SOLANA_WALLET] });
```

{% endstep %}

{% step %}
**Define the Agent.**

```typescript
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 });
```

{% endstep %}

{% step %}
**Execute the Agent.**

```typescript
const response = await agentExecutor.invoke({ input: "Fetch newest 1 post from solana on pump.fun and comment `GM` on that post." });
console.log(response);
```

{% endstep %}
{% endstepper %}

### Supported Actions

<table><thead><tr><th>Action</th><th>Description</th></tr></thead><tbody><tr><td><pre><code>Action.REDDIT_FILTER
</code></pre></td><td>Filter the posts in a subreddit by a query.</td></tr><tr><td><pre><code>Action.REDDIT_COMMENT
</code></pre></td><td>Comment on a post in a subreddit.</td></tr><tr><td><pre><code>Action.REDDIT_CREATE_POST
</code></pre></td><td>Create a new post in a subreddit.</td></tr><tr><td><pre><code>Action.REDDIT_DELETE_POST
</code></pre></td><td>Delete a post.</td></tr></tbody></table>
