Skip to content

Open-source Python library for AI browser agents, plus Browser Use Cloud: stealth browsers and a hosted agent API.

Populate Rust trace metadata

Magnus Müller5a6fd4abb06d
diff --git a/RUST_AGENT_INTEGRATION_FEATURES.md b/RUST_AGENT_INTEGRATION_FEATURES.md
index ed1a4e6f3..2b3528f91 100644
--- a/RUST_AGENT_INTEGRATION_FEATURES.md
+++ b/RUST_AGENT_INTEGRATION_FEATURES.md
@@ -1026,10 +1026,15 @@ Terminal core branch: `magnus/browser-use-rust-main-integration` at terminal mai
- Repeated step-end hook dispatch for the same history object is idempotent, preserving the run/follow-up finalization path while matching Browser Use's per-step hook cardinality.
- Proof: `test_rust_agent_invokes_on_step_end_for_each_terminal_turn`.
+203. Rust Agent trace metadata parity
+ - Rust-backed `get_trace_object()` now populates `browser_use_version` with Browser Use's version helper instead of leaving it empty.
+ - Trace payloads now include serialized `get_git_info()` metadata, matching Browser Use's trace contract while preserving the existing Rust-backed history and structured-output trace fields.
+ - Proof: `test_rust_agent_trace_metadata_matches_browser_use_helpers`.
+
## Current Verification
- `python3 -m py_compile browser_use/agent/service.py browser_use/rust/service.py browser_use/rust/__init__.py browser_use/__init__.py tests/ci/test_rust_agent.py examples/rust_agent/basic.py examples/rust_agent/real_v8_smoke.py`
-- `uv run pytest -q tests/ci/test_rust_agent.py` (171 tests)
+- `uv run pytest -q tests/ci/test_rust_agent.py` (172 tests)
- `cargo build -q -p browser-use-cli` on terminal branch `magnus/browser-use-rust-main-integration`
- `cargo test -q -p browser-use-cli run_codex_session_command_accepts_task_id_and_model -- --nocapture`
- `CARGO_INCREMENTAL=0 cargo test -q -p browser-use-agent selected_remote_cdp_mode_allows_remote_cdp_connect -- --nocapture`
diff --git a/browser_use/rust/service.py b/browser_use/rust/service.py
index d3bc97011..263a46726 100644
--- a/browser_use/rust/service.py
+++ b/browser_use/rust/service.py
@@ -58,7 +58,14 @@ from browser_use.tokens.service import TokenCost
from browser_use.tokens.views import ModelUsageStats, UsageSummary
from browser_use.tools.registry.views import ActionModel
from browser_use.tools.service import Tools
-from browser_use.utils import SignalHandler, URL_PATTERN, _log_pretty_path, check_latest_browser_use_version, get_browser_use_version
+from browser_use.utils import (
+ SignalHandler,
+ URL_PATTERN,
+ _log_pretty_path,
+ check_latest_browser_use_version,
+ get_browser_use_version,
+ get_git_info,
+)
Context = TypeVar('Context')
@@ -4036,6 +4043,7 @@ class Agent(Generic[Context, AgentStructuredOutput]):
trace_id = uuid7str()
timestamp = datetime.now().isoformat()
+ git_info = get_git_info()
structured_output = self.history.structured_output
structured_output_json = json.dumps(structured_output.model_dump(), default=json_default) if structured_output else None
final_result = self.history.final_result()
@@ -4048,8 +4056,8 @@ class Agent(Generic[Context, AgentStructuredOutput]):
'trace': {
'trace_id': trace_id,
'timestamp': timestamp,
- 'browser_use_version': None,
- 'git_info': None,
+ 'browser_use_version': get_browser_use_version(),
+ 'git_info': json.dumps(git_info, default=json_default) if git_info else None,
'model': self.model,
'settings': json.dumps(self.settings.model_dump(), default=json_default) if self.settings else None,
'task_id': self.task_id,
diff --git a/tests/ci/test_rust_agent.py b/tests/ci/test_rust_agent.py
index d4a67ddb8..690ff936c 100644
--- a/tests/ci/test_rust_agent.py
+++ b/tests/ci/test_rust_agent.py
@@ -6271,6 +6271,30 @@ async def test_rust_agent_trace_and_cloud_auth_helpers():
assert 'trace answer' in trace_object['trace_details']['complete_history']
+def test_rust_agent_trace_metadata_matches_browser_use_helpers(monkeypatch):
+ from browser_use.rust import Agent
+ import browser_use.rust.service as rust_service
+ from browser_use.rust.service import _history_from_events
+
+ monkeypatch.setattr(rust_service, 'get_browser_use_version', lambda: '9.9.9-test')
+ monkeypatch.setattr(rust_service, 'get_git_info', lambda: {'branch': 'trace-branch', 'commit_hash': 'abc123'})
+
+ agent = Agent(task='Trace metadata.', llm=type('LLM', (), {'model': 'gpt-test'})())
+ agent.history = _history_from_events(
+ [{'event_type': 'session.done', 'payload': {'result': 'trace metadata answer'}}],
+ model='gpt-test',
+ started=1.0,
+ finished=2.0,
+ output_model_schema=None,
+ process_error=None,
+ )
+
+ trace = agent.get_trace_object()['trace']
+
+ assert trace['browser_use_version'] == '9.9.9-test'
+ assert json.loads(trace['git_info']) == {'branch': 'trace-branch', 'commit_hash': 'abc123'}
+
+
async def test_rust_agent_saves_terminal_conversation(tmp_path, monkeypatch):
from browser_use.rust import Agent