Skip to content

Commit

Permalink
Fix: Bump max_iterations when resuming due to throttling (All-Hands-A…
Browse files Browse the repository at this point in the history
…I#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]>
  • Loading branch information
4 people authored Aug 20, 2024
1 parent 0a3d46a commit f5aa111
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions openhands/controller/agent_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,8 @@ def __init__(
self.max_budget_per_task = max_budget_per_task
self.agent_to_llm_config = agent_to_llm_config if agent_to_llm_config else {}
self.agent_configs = agent_configs if agent_configs else {}
self._initial_max_iterations = max_iterations
self._initial_max_budget_per_task = max_budget_per_task

# stuck helper
self._stuck_detector = StuckDetector(self.state)
Expand Down Expand Up @@ -245,6 +247,21 @@ async def set_agent_state_to(self, new_state: AgentState):
):
# user intends to interrupt traffic control and let the task resume temporarily
self.state.traffic_control_state = TrafficControlState.PAUSED
# User has chosen to deliberately continue - lets double the max iterations
if (
self.state.iteration is not None
and self.state.max_iterations is not None
and self._initial_max_iterations is not None
):
if self.state.iteration >= self.state.max_iterations:
self.state.max_iterations += self._initial_max_iterations
if (
self.state.metrics.accumulated_cost is not None
and self.max_budget_per_task is not None
and self._initial_max_budget_per_task is not None
):
if self.state.metrics.accumulated_cost >= self.max_budget_per_task:
self.max_budget_per_task += self._initial_max_budget_per_task

self.state.agent_state = new_state
if new_state == AgentState.STOPPED or new_state == AgentState.ERROR:
Expand Down

0 comments on commit f5aa111

Please sign in to comment.