fix: Improve Reddit search prompt to find actual discussions
- Add EXTRACT CORE KEYWORDS step to search for main subject, not full phrase
("killer features of clawdbot" → search "clawdbot")
- Remove hardcoded subreddit list that biased results toward design/dev subs
- Simplify search strategies and URL validation rules
- Make prompt more concise - GPT-5.2 responds better to clearer instructions
Before: 0 threads found for "killer features of clawdbot"
After: 7 threads found including r/LocalLLaMA (43pts), r/selfhosted (26pts)
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -22,51 +22,48 @@ DEPTH_CONFIG = {
|
|||||||
"deep": (50, 70),
|
"deep": (50, 70),
|
||||||
}
|
}
|
||||||
|
|
||||||
REDDIT_SEARCH_PROMPT = """Search Reddit for DISCUSSION THREADS about: {topic}
|
REDDIT_SEARCH_PROMPT = """Find Reddit discussion threads about: {topic}
|
||||||
|
|
||||||
DATE RANGE: Only include threads from {from_date} to {to_date} (last 30 days).
|
STEP 1: EXTRACT CORE KEYWORDS
|
||||||
|
Extract the main subject. Examples:
|
||||||
|
- "killer features of clawdbot" → search for "clawdbot"
|
||||||
|
- "best React hooks practices" → search for "React hooks"
|
||||||
|
Search for the CORE KEYWORD, not the full phrase.
|
||||||
|
|
||||||
SEARCH GUIDANCE:
|
STEP 2: SEARCH STRATEGIES (try multiple)
|
||||||
- Search for "site:reddit.com/r/ {topic}" to find subreddit discussions
|
1. "reddit [keyword]" - general Reddit search
|
||||||
- Look in subreddits like r/design, r/UI_Design, r/iOSProgramming, r/SwiftUI, r/Figma, r/webdev, r/userexperience, r/graphic_design, r/ClaudeAI, r/ClaudeCode
|
2. "reddit [keyword] discussion" - find discussions
|
||||||
- ONLY include URLs containing "/r/" and "/comments/" (actual discussion threads)
|
3. "[keyword] site:reddit.com/r/" - subreddit posts
|
||||||
- IGNORE: developers.reddit.com, business.reddit.com, reddit.com/user/
|
4. "reddit.com/r/ [keyword] comments" - thread URLs
|
||||||
|
|
||||||
CRITICAL DATE REQUIREMENT:
|
REQUIRED: URLs must contain BOTH "/r/" AND "/comments/"
|
||||||
- ONLY include threads posted AFTER {from_date}
|
Example valid URL: https://www.reddit.com/r/selfhosted/comments/abc123/title/
|
||||||
- Do NOT include threads older than {from_date}, even if they seem relevant
|
|
||||||
- If you cannot find enough recent threads, return FEWER results rather than older ones
|
|
||||||
- It is better to return 3 recent threads than 15 old ones
|
|
||||||
|
|
||||||
Find {min_items}-{max_items} relevant Reddit discussion threads from the last 30 days.
|
REJECT these URLs (not discussion threads):
|
||||||
|
- developers.reddit.com (Reddit apps, not discussions)
|
||||||
|
- business.reddit.com
|
||||||
|
- reddit.com/user/ (user profiles)
|
||||||
|
- Any URL missing "/comments/"
|
||||||
|
|
||||||
For EACH Reddit thread URL (containing /r/subreddit/comments/), extract:
|
DATE RANGE: {from_date} to {to_date} (last 30 days).
|
||||||
- Thread title
|
|
||||||
- Full Reddit URL
|
|
||||||
- Subreddit name
|
|
||||||
- Date (MUST be after {from_date}, otherwise do not include)
|
|
||||||
- Why it's relevant
|
|
||||||
|
|
||||||
Return ONLY valid JSON:
|
Find {min_items}-{max_items} discussion threads.
|
||||||
|
|
||||||
|
Return JSON:
|
||||||
{{
|
{{
|
||||||
"items": [
|
"items": [
|
||||||
{{
|
{{
|
||||||
"title": "Thread title",
|
"title": "Thread title from Reddit",
|
||||||
"url": "https://www.reddit.com/r/subreddit/comments/abc123/title/",
|
"url": "https://www.reddit.com/r/subreddit/comments/xyz/title/",
|
||||||
"subreddit": "subreddit_name",
|
"subreddit": "subreddit_name",
|
||||||
"date": "YYYY-MM-DD or null",
|
"date": "YYYY-MM-DD or null",
|
||||||
"why_relevant": "Relevance to {topic}",
|
"why_relevant": "Why this is relevant",
|
||||||
"relevance": 0.85
|
"relevance": 0.85
|
||||||
}}
|
}}
|
||||||
]
|
]
|
||||||
}}
|
}}
|
||||||
|
|
||||||
Rules:
|
IMPORTANT: Only return items with URLs containing /r/*/comments/*. If you cannot find any valid discussion threads, return {{"items": []}}."""
|
||||||
- ONLY URLs matching: reddit.com/r/*/comments/*
|
|
||||||
- ONLY threads from {from_date} to {to_date}
|
|
||||||
- relevance: 0.0-1.0
|
|
||||||
- Diverse subreddits preferred
|
|
||||||
- Fewer recent results is better than many old results"""
|
|
||||||
|
|
||||||
|
|
||||||
def search_reddit(
|
def search_reddit(
|
||||||
@@ -105,6 +102,8 @@ def search_reddit(
|
|||||||
# Adjust timeout based on depth
|
# Adjust timeout based on depth
|
||||||
timeout = 60 if depth == "quick" else 90 if depth == "default" else 120
|
timeout = 60 if depth == "quick" else 90 if depth == "default" else 120
|
||||||
|
|
||||||
|
# Note: allowed_domains accepts base domain, not subdomains
|
||||||
|
# We rely on prompt to filter out developers.reddit.com, etc.
|
||||||
payload = {
|
payload = {
|
||||||
"model": model,
|
"model": model,
|
||||||
"tools": [
|
"tools": [
|
||||||
|
|||||||
Reference in New Issue
Block a user