Skip to content

Commit f5aa111

Browse files
tofarrTim O'Farrelltobitegemamoodi
authored
Fix: Bump max_iterations when resuming due to throttling (#3410)
* Fix: Reset iteration count when resuming due to throttling * Fix inadvertent additions * WIP * Changing max_iterations instead of iteration count * Now adjusting max_iterations or max_budget_per_task as appropriate * Fix check on iterations * Fix linter issues * AgentController: remember initial max_iterations and use it to extend state's iterations * increase task budget by initial value (not doubling it) --------- Co-authored-by: Tim O'Farrell <[email protected]> Co-authored-by: tobitege <[email protected]> Co-authored-by: mamoodi <[email protected]>
1 parent 0a3d46a commit f5aa111

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

openhands/controller/agent_controller.py

+17
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,8 @@ def __init__(
108108
self.max_budget_per_task = max_budget_per_task
109109
self.agent_to_llm_config = agent_to_llm_config if agent_to_llm_config else {}
110110
self.agent_configs = agent_configs if agent_configs else {}
111+
self._initial_max_iterations = max_iterations
112+
self._initial_max_budget_per_task = max_budget_per_task
111113

112114
# stuck helper
113115
self._stuck_detector = StuckDetector(self.state)
@@ -245,6 +247,21 @@ async def set_agent_state_to(self, new_state: AgentState):
245247
):
246248
# user intends to interrupt traffic control and let the task resume temporarily
247249
self.state.traffic_control_state = TrafficControlState.PAUSED
250+
# User has chosen to deliberately continue - lets double the max iterations
251+
if (
252+
self.state.iteration is not None
253+
and self.state.max_iterations is not None
254+
and self._initial_max_iterations is not None
255+
):
256+
if self.state.iteration >= self.state.max_iterations:
257+
self.state.max_iterations += self._initial_max_iterations
258+
if (
259+
self.state.metrics.accumulated_cost is not None
260+
and self.max_budget_per_task is not None
261+
and self._initial_max_budget_per_task is not None
262+
):
263+
if self.state.metrics.accumulated_cost >= self.max_budget_per_task:
264+
self.max_budget_per_task += self._initial_max_budget_per_task
248265

249266
self.state.agent_state = new_state
250267
if new_state == AgentState.STOPPED or new_state == AgentState.ERROR:

0 commit comments

Comments
 (0)