Reddit

Query subreddit posts, stats, and trends with RedditTools using praw script-app credentials.

Prerequisites

  1. Create or sign in to a Reddit account at reddit.com.
  2. Complete Reddit's Data API access process.
  3. Create a script app at reddit.com/prefs/apps.
  4. Copy the app's client ID and client secret.

RedditTools can perform read-only operations with the client ID and client secret. Set a username and password only for write operations.

from agno.agent import Agent
from agno.tools.reddit import RedditTools

# ---------------------------------------------------------------------------
# Create Agent
# ---------------------------------------------------------------------------

agent = Agent(
    instructions=[
        "Use your tools to answer questions about Reddit content and statistics",
        "Respect Reddit's content policies and NSFW restrictions",
        "When analyzing subreddits, provide relevant statistics and trends",
    ],
    tools=[RedditTools()],
)

# ---------------------------------------------------------------------------
# Run Agent
# ---------------------------------------------------------------------------
if __name__ == "__main__":
    agent.print_response("What are the top 5 posts on r/SAAS this week ?", stream=True)

This query only needs read access. In the saved example, use RedditTools(include_tools=["get_top_posts"]) to expose only the function needed to fetch the weekly top posts. Keep the client ID, client secret, and user agent configured; username and password are unnecessary for this example.

Run the Example

Set up your virtual environment

uv venv --python 3.12
source .venv/bin/activate

Install dependencies

uv pip install -U agno openai praw

Export required credentials

export REDDIT_CLIENT_ID="your_reddit_client_id"
export REDDIT_CLIENT_SECRET="your_reddit_client_secret"
export REDDIT_USER_AGENT="platform:app_id:version (by /u/username)"
export OPENAI_API_KEY="your_openai_api_key_here"

Run the example

Save the code above as reddit_tools.py, then run:

python reddit_tools.py

Full source: cookbook/91_tools/reddit_tools.py