From ec4a044b0b7e846fcd6a210a123ebf158dceab17 Mon Sep 17 00:00:00 2001 From: ciregenz Date: Fri, 31 Jul 2026 15:58:49 -0700 Subject: [PATCH] [eric] browser: strip the click-by-index element rows from anything a human reads --- backend/apps/agents/browser/browser_agent.py | 12 +++- .../agents/browser/humanize_element_rows.py | 69 +++++++++++++++++++ 2 files changed, 78 insertions(+), 3 deletions(-) create mode 100644 backend/apps/agents/browser/humanize_element_rows.py diff --git a/backend/apps/agents/browser/browser_agent.py b/backend/apps/agents/browser/browser_agent.py index 071b327c..afdae5e1 100644 --- a/backend/apps/agents/browser/browser_agent.py +++ b/backend/apps/agents/browser/browser_agent.py @@ -49,6 +49,7 @@ from backend.apps.agents.browser.browser_loop import ( stagnation_exhausted, ) from backend.apps.agents.browser.browser_validator import adjudicate_stuck +from backend.apps.agents.browser.humanize_element_rows import humanize_element_rows # Single actions the model could have folded into one BrowserBatch turn; reads, waits, and the batch tools themselves don't count toward the streak. P_BATCHABLE_ACTION_TOOLS = { @@ -2462,8 +2463,13 @@ async def run_browser_agents( final = [] for r in results: - if isinstance(r, Exception): + # gather(return_exceptions=True) hands back a cancelled child as a bare BaseException too, and that is not a result dict either. + if not isinstance(r, dict): final.append({"summary": f"Error: {str(r)}", "action_log": [], "final_screenshot": None}) - else: - final.append(r) + continue + # Last stop before the sub-agent's own words reach a parent agent or, on the fast path, the user verbatim. + for p_key in ("summary", "error"): + if isinstance(r.get(p_key), str): + r[p_key] = humanize_element_rows(r[p_key]) + final.append(r) return final diff --git a/backend/apps/agents/browser/humanize_element_rows.py b/backend/apps/agents/browser/humanize_element_rows.py new file mode 100644 index 00000000..5c600f08 --- /dev/null +++ b/backend/apps/agents/browser/humanize_element_rows.py @@ -0,0 +1,69 @@ +"""Rewrite the browser subsystem's internal element-index rows into plain prose. + +BrowserListInteractives hands the sub-agent rows like `[3]