Skip to content

Conversation

@pirate
Copy link
Member

@pirate pirate commented Nov 18, 2025

why

Clarify where the execution flow goes when stagehand runs by showing more detailed logs.

image

what changed

Adds a log line printed at the beginning and end of each layer's execution:

  1. TASK: top-level user intent: when agent.execute('') is called (the initial entrypoint)
  2. STEP: any call to .act(...) .extract() or .observe()
  3. ACTION: any playwright or browser interaction api action dispatched, e.g. CLICK, HOVER, SCROLL, etc.
  4. CDP MSG: any CDP websocket message sent to the browser

Log lines are written to ./.browserbase/sessions/{sessionId}/{agent,stagehand,understudy,cdp}.log at runtime, and can be followed in a single unified screen by doing:

tail -f ./.browserbase/sessions/latest/*.log

test plan

Test by running pnpm tsx packages/core/examples/flowLoggingJourney.ts & tail -f ./.browserbase/sessions/latest/* (make sure OPENAI_API_KEY is in env).

@changeset-bot

This comment was marked as resolved.

@pirate pirate changed the title Add logging at all 4 levels: agent.execute, agent.act/observe/extract, CLICK/HOVER/SCROLL, and CDP [STG-1045] Add logging at all 4 levels: agent.execute, agent.act/observe/extract, CLICK/HOVER/SCROLL, and CDP Dec 4, 2025
@claude

This comment was marked as resolved.

@pirate

This comment was marked as resolved.

@claude

This comment was marked as resolved.

@claude

This comment was marked as resolved.

@pirate pirate changed the base branch from main to pr/4-test-infrastructure December 4, 2025 21:12
@pirate pirate changed the base branch from pr/4-test-infrastructure to main December 4, 2025 21:13
pirate and others added 18 commits December 5, 2025 18:11
- Add SessionFileLogger class that writes to session-specific directories
- Read BROWSERBASE_CONFIG_DIR from env (defaults to ./.browserbase)
- Create session directory structure: {configDir}/sessions/{sessionId}/
- Create convenience symlink: {configDir}/sessions/latest
- Write to 5 separate log files:
  - session.json (sanitized V3Options with secrets masked)
  - agent_events.log (TASK level - agent.execute)
  - stagehand_events.log (STEP level - act/observe/extract)
  - understudy_events.log (ACTION level - CLICK/HOVER/etc)
  - cdp_events.log (CDP MSG level)
- All filesystem operations are async, non-blocking, and fail silently
- Logs still also written to stdout via v3Logger for backwards compatibility
- Add .browserbase/ to .gitignore
- Update flowLoggingJourney example to show session log directory

Co-authored-by: Nick Sweeting <pirate@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants