diff --git a/browser_use/agent/service.py b/browser_use/agent/service.py index ba1361921..5ee89c9fb 100644 --- a/browser_use/agent/service.py +++ b/browser_use/agent/service.py @@ -760,9 +760,6 @@ class Agent(Generic[Context, AgentStructuredOutput]): # Check again for paused/stopped state after getting model output await self._raise_if_stopped_or_paused() - # Increment step counter at the end of each step - self.state.n_steps += 1 - # Handle callbacks and conversation saving await self._handle_post_llm_processing(browser_state_summary, input_messages) @@ -879,6 +876,9 @@ class Agent(Generic[Context, AgentStructuredOutput]): ) self.eventbus.dispatch(step_event) + # Increment step counter after step is fully completed + self.state.n_steps += 1 + async def _handle_final_step(self, step_info: AgentStepInfo | None = None) -> None: """Handle special processing for the last step""" if step_info and step_info.is_last_step():