From 13cbf6429b7d8d66b62cb976c97f8bd18d8f71d2 Mon Sep 17 00:00:00 2001 From: ResearchForumOnline <116322650+ResearchForumOnline@users.noreply.github.com> Date: Fri, 31 Jul 2026 17:11:41 +0100 Subject: [PATCH] Bound local browser summary latency --- openzero/brain/app.py | 12 +++++++++++- openzero/tests/test_autonomous_runtime.py | 3 +++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/openzero/brain/app.py b/openzero/brain/app.py index 7810c62..1832013 100644 --- a/openzero/brain/app.py +++ b/openzero/brain/app.py @@ -1406,6 +1406,8 @@ def local_reply_token_budget(prompt: str, agent_mode: str = "chat") -> int: ) if any(marker in text for marker in concise_markers): return 96 + if "**[moltbot browser]**" in text: + return 192 return 1024 if str(agent_mode or "").lower() == "terminal" else 768 @@ -4911,6 +4913,14 @@ def voice_transcribe(): return jsonify(result) +def autonomous_checkpoint_tool_result(action: Dict[str, object]) -> str: + """Keep browser evidence useful without overflowing the local model context.""" + + result = str(action.get("result") or "") + if str(action.get("tool") or "") == "moltbot_browse" and len(result) > 5000: + return result[:5000].rstrip() + "\n...[browser result compacted for local summary]..." + return result + def deterministic_browser_inspection_reply(state: Dict[str, object]) -> str: """Return the initial read-only browser action without spending a model call.""" @@ -5309,7 +5319,7 @@ def execute_autonomous_run( state = AUTONOMOUS_RUN_STORE.checkpoint_action_result( run_id, - current_prompt=f"Tool proposal/result:\n{action_result}", + current_prompt=f"Tool proposal/result:\n{autonomous_checkpoint_tool_result(action)}", last_safe_result=action_result, usage_delta={ "tool_calls": 0 diff --git a/openzero/tests/test_autonomous_runtime.py b/openzero/tests/test_autonomous_runtime.py index a8ff19d..b2a0581 100644 --- a/openzero/tests/test_autonomous_runtime.py +++ b/openzero/tests/test_autonomous_runtime.py @@ -1121,6 +1121,9 @@ def test_plain_conversation_and_model_format_recovery_are_guarded(self): self.assertIn("def model_reply_retry_reason(", self.source) self.assertIn('"model_format_retry"', self.source) self.assertIn("def local_reply_token_budget(", self.source) + self.assertIn('if "**[moltbot browser]**" in text:', self.source) + self.assertIn("def autonomous_checkpoint_tool_result(", self.source) + self.assertIn("browser result compacted for local summary", self.source) self.assertIn("max_predict=local_reply_token_budget(prompt, agent_mode)", self.source) self.assertIn('"think": False', self.source) self.assertIn("The local model returned no visible answer.", self.source)