Package com.tnsai.tools.social
Class RedditTools
java.lang.Object
com.tnsai.tools.social.RedditTools
Function-shape Reddit tools — read-only via the official OAuth2 API.
Replaces the legacy
RedditTool (single dispatched tool).
| Method | Endpoint | Idempotent |
|---|---|---|
redditSearch(java.lang.String, java.lang.String, java.lang.String, int) | GET /search | true |
redditSubredditPosts(java.lang.String, java.lang.String, int) | GET /r/{sub}/{sort} | true |
redditPostComments(java.lang.String, java.lang.String, java.lang.String) | GET /r/{sub}/comments/{id} | true |
Requires REDDIT_CLIENT_ID + REDDIT_CLIENT_SECRET. Create
an app at reddit.com/prefs/apps (pick "script" type for server-side).
Optional REDDIT_USER_AGENT (defaults to "TnsAI/1.0 (Java Agent
Framework)").
Token caching: a single access token is fetched on first call and cached until ~60s before its server-reported expiry. Subsequent calls reuse it. This avoids a token round-trip per tool call.
- Since:
- 0.5.7 (Phase 2 batch 16b — built-in tool migration to function shape, see #188)
-
Constructor Summary
ConstructorsConstructorDescriptionDefault constructor — picks REDDIT_CLIENT_ID / SECRET / USER_AGENT from env.RedditTools(String clientId, String clientSecret) Explicit-credentials constructor.RedditTools(String clientId, String clientSecret, String userAgent, okhttp3.OkHttpClient http, com.fasterxml.jackson.databind.ObjectMapper mapper) Full constructor for tests / shared HTTP. -
Method Summary
Modifier and TypeMethodDescriptionredditPostComments(String subreddit, String postId, String sort) redditSearch(String query, String subreddit, String sort, int limit) redditSubredditPosts(String subreddit, String sort, int limit)
-
Constructor Details
-
RedditTools
public RedditTools()Default constructor — picks REDDIT_CLIENT_ID / SECRET / USER_AGENT from env. -
RedditTools
Explicit-credentials constructor. -
RedditTools
public RedditTools(String clientId, String clientSecret, String userAgent, okhttp3.OkHttpClient http, com.fasterxml.jackson.databind.ObjectMapper mapper) Full constructor for tests / shared HTTP.
-
-
Method Details
-
redditSearch
@Tool(name="reddit_search", description="Search Reddit posts globally. Optional {subreddit} narrows to one community. {sort} is one of \"relevance\", \"hot\", \"top\", \"new\", \"comments\" (default \"relevance\"). {limit} clamps to [1, 100]. Returns the raw JSON listing.", keywords={"reddit","search","subreddit","post","social"}, idempotent=true) public String redditSearch(@ToolParam(description="Free-text search query") String query, @ToolParam(description="Optional subreddit name (without r/) to narrow the search",required=false,defaultValue="") String subreddit, @ToolParam(description="Sort order: relevance / hot / top / new / comments",required=false,defaultValue="relevance") String sort, @ToolParam(description="Max results (1..100); 0 \u2192 default 10",required=false,defaultValue="0") int limit) throws IOException - Throws:
IOException
-
redditSubredditPosts
@Tool(name="reddit_subreddit_posts", description="List posts in a subreddit. {sort} is \"hot\" / \"new\" / \"top\" / \"rising\" (default \"hot\"). {limit} clamps to [1, 100]. Returns the raw JSON listing.", keywords={"reddit","subreddit","posts","hot","new","top"}, idempotent=true) public String redditSubredditPosts(@ToolParam(description="Subreddit name (without r/)") String subreddit, @ToolParam(description="Sort: hot / new / top / rising",required=false,defaultValue="hot") String sort, @ToolParam(description="Max posts (1..100); 0 \u2192 default 10",required=false,defaultValue="0") int limit) throws IOException - Throws:
IOException
-
redditPostComments
@Tool(name="reddit_post_comments", description="Fetch the comment tree for a single Reddit post. {postId} is the base-36 post id (the \"abc123\" segment of the URL). {sort} is one of \"best\", \"top\", \"new\", \"controversial\", \"old\" (default \"best\"). Returns the raw JSON [post, comments] pair.", keywords={"reddit","comments","thread","post"}, idempotent=true) public String redditPostComments(@ToolParam(description="Subreddit name (without r/)") String subreddit, @ToolParam(description="Post id (base-36, e.g. \"abc123\")") String postId, @ToolParam(description="Comment sort: best / top / new / controversial / old",required=false,defaultValue="best") String sort) throws IOException - Throws:
IOException
-