diff --git a/backend/apps/agents/browser/browser_map_reduce_read.py b/backend/apps/agents/browser/browser_map_reduce_read.py index a90a64ca..685dcf44 100644 --- a/backend/apps/agents/browser/browser_map_reduce_read.py +++ b/backend/apps/agents/browser/browser_map_reduce_read.py @@ -67,12 +67,17 @@ P_VALUE_LINE = ( ) +P_QUANTITY_RE = re.compile(r"\b(how much|how many|difference|by how)\b", re.I) + + def op_for(prompt: str) -> str: - """'difference' | 'sum' | '' from the request's own wording; '' = aux reduce as before.""" + """'difference' | 'sum' | '' from the request's own wording; '' = aux reduce as before. + Difference also requires a QUANTITY cue: a bare "which is taller?" wants a name, and a + number-only computed headline would answer the wrong question (caught in audit, not live).""" low = prompt or "" if P_SUM_RE.search(low): return "sum" - if P_DIFF_RE.search(low): + if P_DIFF_RE.search(low) and P_QUANTITY_RE.search(low): return "difference" return "" @@ -150,7 +155,7 @@ async def p_fetch_and_extract(client, aux_model: str, q: str, url: str, ask_valu return None -async def try_map_reduce_read(prompt: str, brief: str, settings, primary_api: str | None) -> str | None: +async def try_map_reduce_read(prompt: str, settings, primary_api: str | None) -> str | None: """Answer text for a multi-source public read, or None (caller falls to the browser leg). Any missing piece returns None, so it never half-answers.""" if not enabled(): diff --git a/backend/apps/agents/manager/run_browser_fast_path.py b/backend/apps/agents/manager/run_browser_fast_path.py index d8b59c79..5e24a2cc 100644 --- a/backend/apps/agents/manager/run_browser_fast_path.py +++ b/backend/apps/agents/manager/run_browser_fast_path.py @@ -56,7 +56,7 @@ async def run_browser_fast_path( # The single page couldn't answer it; a multi-source read (a difference, a compare) fans out to N concurrent single-page reads + one reduce, still no browser and still fail-open. from backend.apps.agents.browser import browser_map_reduce_read text = await browser_map_reduce_read.try_map_reduce_read( - prompt, brief, load_settings(), p_read_api, + prompt, load_settings(), p_read_api, ) or "" p_fp_path = "read-mapreduce" if text else "read->browser"