Add real-time query handling: pre-search enrichment + routing fix
- router.py: add _MEDIUM_FORCE_PATTERNS to block weather/news/price queries from light tier regardless of LLM classification - agent.py: add _REALTIME_RE and _searxng_search_async(); real-time queries now run SearXNG search concurrently with URL fetch + memory retrieval, injecting snippets into medium system prompt - tests/use_cases/weather_now.md: use case test for weather queries Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
17
router.py
17
router.py
@@ -23,6 +23,16 @@ _LIGHT_PATTERNS = re.compile(
|
||||
re.IGNORECASE,
|
||||
)
|
||||
|
||||
# Queries that require live data — never answer from static knowledge
|
||||
_MEDIUM_FORCE_PATTERNS = re.compile(
|
||||
r"\b(weather|forecast|temperature|rain(ing)?|snow(ing)?|humidity|wind speed"
|
||||
r"|today.?s news|breaking news|latest news|news today|current events"
|
||||
r"|bitcoin price|crypto price|stock price|exchange rate|usd|eur|btc"
|
||||
r"|right now|currently|at the moment|live score|score now|score today"
|
||||
r"|open now|hours today|is .+ open)\b",
|
||||
re.IGNORECASE,
|
||||
)
|
||||
|
||||
# ── LLM classification prompt ─────────────────────────────────────────────────
|
||||
CLASSIFY_PROMPT = """Classify the message. Output ONLY one word: light, medium, or complex.
|
||||
|
||||
@@ -90,7 +100,12 @@ class Router:
|
||||
if force_complex:
|
||||
return "complex", None
|
||||
|
||||
# Step 0: regex pre-classification for obvious light patterns
|
||||
# Step 0a: force medium for real-time / live-data queries
|
||||
if _MEDIUM_FORCE_PATTERNS.search(message.strip()):
|
||||
print(f"[router] regex→medium (real-time query)", flush=True)
|
||||
return "medium", None
|
||||
|
||||
# Step 0b: regex pre-classification for obvious light patterns
|
||||
if _LIGHT_PATTERNS.match(message.strip()):
|
||||
print(f"[router] regex→light", flush=True)
|
||||
return await self._generate_light_reply(message, history)
|
||||
|
||||
Reference in New Issue
Block a user