From 9fc8926975a36c84b7ee1f835612e23d60564396 Mon Sep 17 00:00:00 2001 From: kshitij <82637225+kshitijk4poor@users.noreply.github.com> Date: Tue, 4 Aug 2026 11:19:15 +0530 Subject: [PATCH] perf: reuse request_input_estimate instead of recomputing estimate_request_tokens_rough The output-cap error handler already computes request_input_estimate at line 4722 via estimate_request_tokens_rough(api_messages, tools=...). The new compression block ~50 lines below was calling the same function with the same inputs again. Reuse the existing local. --- agent/conversation_loop.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/agent/conversation_loop.py b/agent/conversation_loop.py index 4f4e57f8bf1f3..8848b64df2cb2 100644 --- a/agent/conversation_loop.py +++ b/agent/conversation_loop.py @@ -4775,7 +4775,7 @@ def run_conversation( _overflow_input = messages messages, active_system_prompt = agent._compress_context( messages, system_message, - approx_tokens=estimate_request_tokens_rough(api_messages, tools=agent.tools or None), + approx_tokens=request_input_estimate, task_id=effective_task_id, ) if messages is _overflow_input and compression_skipped_due_to_lock(agent):