diff --git a/run_agent.py b/run_agent.py index eb89e83cff..5c946591c2 100644 --- a/run_agent.py +++ b/run_agent.py @@ -10189,17 +10189,11 @@ class AIAgent: if final_response is None and ( api_call_count >= self.max_iterations or self.iteration_budget.remaining <= 0 - ) and not self._budget_exhausted_injected: - # Budget exhausted but we haven't tried asking the model to - # summarise yet. Inject a user message and give it one grace - # API call to produce a text response. - self._budget_exhausted_injected = True - self._budget_grace_call = True - _grace_msg = ( - "Your tool budget ran out. Please give me the information " - "or actions you've completed so far." - ) - messages.append({"role": "user", "content": _grace_msg}) + ): + # Budget exhausted — ask the model for a summary via one extra + # API call with tools stripped. _handle_max_iterations injects a + # user message and makes a single toolless request. + _turn_exit_reason = f"max_iterations_reached({api_call_count}/{self.max_iterations})" self._emit_status( f"⚠️ Iteration budget exhausted ({api_call_count}/{self.max_iterations}) " "— asking model to summarise" @@ -10209,14 +10203,6 @@ class AIAgent: f"\n⚠️ Iteration budget exhausted ({api_call_count}/{self.max_iterations}) " "— requesting summary..." ) - - if final_response is None and ( - api_call_count >= self.max_iterations - or self.iteration_budget.remaining <= 0 - ) and not self._budget_grace_call: - _turn_exit_reason = f"max_iterations_reached({api_call_count}/{self.max_iterations})" - if self.iteration_budget.remaining <= 0 and not self.quiet_mode: - print(f"\n⚠️ Iteration budget exhausted ({self.iteration_budget.used}/{self.iteration_budget.max_total} iterations used)") final_response = self._handle_max_iterations(messages, api_call_count) # Determine if conversation completed successfully