Skip to content

AI agent skill that researches any topic across Reddit, X, YouTube, HN, Polymarket, and the web - then synthesizes a grounded summary

Honor plan's explicit sources at quick depth (#664)

Bexr66691c21234c43
diff --git a/skills/last30days/scripts/lib/planner.py b/skills/last30days/scripts/lib/planner.py
index cbec8c11..fa75ffd7 100644
--- a/skills/last30days/scripts/lib/planner.py
+++ b/skills/last30days/scripts/lib/planner.py
@@ -545,7 +545,7 @@ def _trim_subqueries_for_depth(
limits = SOURCE_LIMITS.get(depth)
if not limits:
return subqueries
- priority_table = QUICK_SOURCE_PRIORITY if depth == "quick" else SOURCE_PRIORITY
+ priority_table = QUICK_SOURCE_PRIORITY
priority = priority_table.get(intent, priority_table["breaking_news"])
limit = limits.get(intent, 3)
ranked_sources = [source for source in priority if source in available_sources]
@@ -553,26 +553,34 @@ def _trim_subqueries_for_depth(
ranked_sources = list(available_sources)
trimmed = []
for subquery in subqueries:
- if depth in {"quick", "default"}:
- preferred_sources = ranked_sources[:limit]
- if requested_sources:
- requested = [
- source
- for source in requested_sources
- if source in available_sources and source in subquery.sources
- ]
- for source in requested:
- if source not in preferred_sources:
- preferred_sources.append(source)
- else:
- preferred_sources = [source for source in ranked_sources if source in subquery.sources][:limit]
- if len(preferred_sources) < limit:
- for source in ranked_sources:
- if source in preferred_sources:
- continue
+ # Quick depth only reaches this block. Honor the plan's explicit
+ # per-subquery sources: prefer priority-ranked plan sources first, then
+ # append any plan sources absent from the priority table (e.g.
+ # instagram). Explicit --search sources are user overrides, so they get
+ # first claim on the quick slots when present. The final list remains
+ # capped to the quick-depth limit.
+ plan_sources = [s for s in ranked_sources if s in subquery.sources]
+ for source in subquery.sources:
+ if source not in plan_sources:
+ plan_sources.append(source)
+ if not plan_sources:
+ plan_sources = ranked_sources[:limit]
+ preferred_sources: list[str] = []
+ if requested_sources:
+ for source in requested_sources:
+ if (
+ source in available_sources
+ and source in subquery.sources
+ and source not in preferred_sources
+ ):
preferred_sources.append(source)
if len(preferred_sources) >= limit:
break
+ for source in plan_sources:
+ if len(preferred_sources) >= limit:
+ break
+ if source not in preferred_sources:
+ preferred_sources.append(source)
trimmed.append(
schema.SubQuery(
label=subquery.label,
diff --git a/tests/test_planner_v3.py b/tests/test_planner_v3.py
index d9c39da3..a3512fcb 100644
--- a/tests/test_planner_v3.py
+++ b/tests/test_planner_v3.py
@@ -92,7 +92,7 @@ class PlannerV3Tests(unittest.TestCase):
self.assertEqual(1, len(plan.subqueries))
self.assertEqual(["reddit", "x"], plan.subqueries[0].sources)
- def test_quick_mode_preserves_explicit_requested_sources(self):
+ def test_quick_mode_prioritizes_explicit_requested_sources_within_cap(self):
raw = {
"intent": "product",
"freshness_mode": "balanced_recent",
@@ -111,10 +111,11 @@ class PlannerV3Tests(unittest.TestCase):
raw,
"AI coding agents",
["reddit", "youtube", "grounding", "digg"],
- ["reddit", "youtube", "grounding", "digg"],
+ ["digg", "reddit", "youtube", "grounding"],
"quick",
)
self.assertIn("digg", plan.subqueries[0].sources)
+ self.assertLessEqual(len(plan.subqueries[0].sources), 2)
def test_quick_mode_preserves_explicit_requested_sources_in_fallback_plan(self):
plan = planner.plan_query(