Open-source Python library for AI browser agents, plus Browser Use Cloud: stealth browsers and a hosted agent API.
Python ai-agentsai-toolsbrowser-agentbrowser-automationbrowser-usecdpcloud-browsercomputer-useheadless-browserllmmcpplaywrightpythonremote-browserstealth-browserweb-automationweb-scraping
Rename tokens to input_tokens in agent history tracking
Magnus Müller585464476732
diff --git a/browser_use/agent/service.py b/browser_use/agent/service.pyindex e843f1e6a..f4cd25fd5 100644--- a/browser_use/agent/service.py+++ b/browser_use/agent/service.py@@ -383,7 +383,7 @@ class Agent(Generic[Context]):step_number=self.state.n_steps,step_start_time=step_start_time,step_end_time=step_end_time,- tokens=self._message_manager.state.history.current_tokens,+ input_tokens=self._message_manager.state.history.current_tokens,)self._make_history_item(model_output, state, result, metadata)diff --git a/browser_use/agent/views.py b/browser_use/agent/views.pyindex 2ef3ff5e3..741719c11 100644--- a/browser_use/agent/views.py+++ b/browser_use/agent/views.py@@ -98,7 +98,7 @@ class StepMetadata(BaseModel):step_start_time: floatstep_end_time: float- tokens: int # Approximate tokens from message manager for this step+ input_tokens: int # Approximate tokens from message manager for this stepstep_number: int@property@@ -198,7 +198,7 @@ class AgentHistoryList(BaseModel):total += h.metadata.duration_secondsreturn total- def total_tokens(self) -> int:+ def total_input_tokens(self) -> int:"""Get total tokens used across all steps.Note: These are from the approximate token counting of the message manager.@@ -207,12 +207,12 @@ class AgentHistoryList(BaseModel):total = 0for h in self.history:if h.metadata:- total += h.metadata.tokens+ total += h.metadata.input_tokensreturn total- def token_usage(self) -> list[int]:+ def input_token_usage(self) -> list[int]:"""Get token usage for each step"""- return [h.metadata.tokens for h in self.history if h.metadata]+ return [h.metadata.input_tokens for h in self.history if h.metadata]def __str__(self) -> str:"""Representation of the AgentHistoryList object"""