Guides
AI Agent Integration
Give Claude or GPT Reddit intelligence
There are three ways to wire ReddGrow into an AI agent. Choose based on your architecture:
| Pattern | Best for |
|---|---|
| CLI mode | Shell-based pipelines, quick context injection |
| Direct API calls | Agents with tool use / function calling |
| MCP | Claude Desktop with persistent tool access |
Pattern 1 — CLI mode
The CLI's --mode agent flag outputs raw JSON with no formatting. This makes it easy to pipe directly into an agent's context.
# Inject subreddit context into a Claude prompt
CONTEXT=$(reddgrow subreddits about typescript --mode agent)
claude -p "You are a Reddit posting assistant. Here is context about r/typescript: $CONTEXT
Write a post title and body for sharing this article: https://example.com/ts-generics"Chain multiple lookups into a single context block:
ABOUT=$(reddgrow subreddits about typescript --mode agent)
RULES=$(reddgrow subreddits rules typescript --mode agent)
CONTEXT=$(jq -n \
--argjson about "$ABOUT" \
--argjson rules "$RULES" \
'{about: $about, rules: $rules}')
echo "$CONTEXT" | your-agent-scriptPattern 2 — Direct API calls in tool use
For agents that support tool use or function calling, call the ReddGrow API directly from within a tool handler.
Claude tool_use example
Define a tool that fetches subreddit info:
{
"name": "get_subreddit_info",
"description": "Fetch metadata, rules, and recent top posts for a subreddit before posting",
"input_schema": {
"type": "object",
"properties": {
"subreddit": {
"type": "string",
"description": "Subreddit name without the r/ prefix"
}
},
"required": ["subreddit"]
}
}Handle the tool call in your code:
async function handleToolCall(toolName, toolInput) {
if (toolName === "get_subreddit_info") {
const { subreddit } = toolInput;
const [about, rules] = await Promise.all([
fetch(`https://api.reddgrow.ai/agent/subreddits/${subreddit}/about`, {
headers: { "x-api-key": process.env.REDDGROW_API_KEY },
}).then((r) => r.json()),
fetch(`https://api.reddgrow.ai/agent/subreddits/${subreddit}/rules`, {
headers: { "x-api-key": process.env.REDDGROW_API_KEY },
}).then((r) => r.json()),
]);
return { about, rules };
}
}OpenAI function calling example
Define the function in the tools array:
const tools = [
{
type: "function",
function: {
name: "search_reddit",
description: "Search Reddit posts by keyword",
parameters: {
type: "object",
properties: {
query: {
type: "string",
description: "Search query",
},
subreddit: {
type: "string",
description: "Limit search to this subreddit (optional)",
},
limit: {
type: "number",
description: "Number of results, max 25",
},
},
required: ["query"],
},
},
},
];
// Handle the function call
async function callFunction(name, args) {
if (name === "search_reddit") {
const params = new URLSearchParams({
q: args.query,
...(args.subreddit && { subreddit: args.subreddit }),
limit: String(args.limit ?? 10),
});
const res = await fetch(
`https://api.reddgrow.ai/agent/search/posts?${params}`,
{ headers: { "x-api-key": process.env.REDDGROW_API_KEY } }
);
return res.json();
}
}Pattern 3 — MCP
If you use Claude Desktop, you can configure the ReddGrow CLI as an MCP server. This gives Claude persistent access to Reddit tools without any code.
See the MCP Integration guide for setup instructions.
Choosing a pattern
- Use CLI mode when you control the orchestration script and want the simplest setup
- Use direct API calls when your agent framework supports tool use and you want the agent to decide when to query Reddit
- Use MCP when you use Claude Desktop and want Reddit access available in every conversation without code