Skip to content

evals: declare the playwright_code agent mount - #2592

Merged
miguelg719 merged 1 commit into
stg-2671-v4-code-exposurefrom
stg-2671-playwright-code-exposure
Aug 9, 2026
Merged

evals: declare the playwright_code agent mount#2592
miguelg719 merged 1 commit into
stg-2671-v4-code-exposurefrom
stg-2671-playwright-code-exposure

Conversation

@shriyatheunicorn

@shriyatheunicorn shriyatheunicorn commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

The surface now owns its agent mount: prompt instructions (carried over
verbatim from the per-surface block inside the claude_code tool
adapter), a code_handles declaration, and captureEvidence() returning
the terminal screenshot, URL, and aria tree. Behavior is unchanged until
the adapter consumes mounts generically in #2596.

Part of the nondeterministic-evals stack (#2591#2611).


Summary by cubic

Make playwright_code agent-mountable so the v4 harness can consume it generically, with handle exposure, prompt wiring, runTool config, and best-effort evidence capture. No behavior change; supports STG-2671’s non-deterministic suite.

  • New Features
    • Added agentMount with handle access (page, context, browser), prompt instructions (incl. first-action guidance), and runTool config (async snippet scope: page, context, browser, startUrl, task, console; return JSON-serializable values; deny message references AGENT_RUN_TOOL_NAME).
    • Added captureEvidence typed as ProbeEvidence (screenshot, URL, ariaTree via page.represent({ includeIframes: true }) with best-effort per modality); track active page on "page" events; ensured initial page exists; unified cleanup.

Written for commit 9cf16fb. Summary will update on new commits.

Review in cubic

@changeset-bot

changeset-bot Bot commented Aug 5, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: 9cf16fb

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All reported issues were addressed across 1 file

Architecture diagram
sequenceDiagram
    participant Evals as Evals Framework
    participant Harness as External Harness
    participant PLC as prepareLLMExposure()
    participant Target as prepareCoreBrowserTarget()
    participant Browser as Playwright Browser
    participant Agent as Claude Code Agent
    participant TaskPlan as ExternalHarnessTaskPlan

    Note over Evals,Agent: NEW: playwright_code LLMExposure setup flow

    Harness->>PLC: prepareLLMExposure(plan, env, logger, startupProfile?)
    alt unresolved startupProfile
        PLC->>PLC: default: env === "BROWSERBASE" ? runner_provided_browserbase_cdp : runner_provided_local_cdp
    end
    alt invalid startupProfile
        PLC-->>Harness: throw EvalsError
    end

    PLC->>Target: prepareCoreBrowserTarget(env, "playwright_code", startupProfile)
    Target-->>PLC: { providedEndpoint, cleanup, metadata? }
    alt no providedEndpoint.url
        PLC-->>Harness: throw EvalsError
    end

    PLC->>Browser: chromium.connectOverCDP(url, headers)
    Browser-->>PLC: connectedBrowser
    PLC->>Browser: contexts()[0] ?? newContext()
    Browser-->>PLC: context
    PLC->>Browser: pages()[0] ?? newPage()
    Browser-->>PLC: page
    PLC->>PLC: log startup info

    Note over PLC,Agent: Build LLMExposure

    PLC-->>Harness: "LLMExposure { kind: 'code_handles', handles: { page, context, browser }, promptInstructions, runTool: { description, codeParamDescription, denyMessage, task }, captureFinalState, cleanup }"

    Note over Agent,TaskPlan: Agent uses runTool during task

    Agent->>Agent: Execute JavaScript with page/context/browser/startUrl/task in scope
    Agent-->>Harness: Result

    Note over PLC,Agent: End-of-task captureFinalState

    Harness->>PLC: captureFinalState()
    PLC->>Browser: page.screenshot()
    Browser-->>PLC: Buffer
    PLC->>Browser: page.url()
    Browser-->>PLC: string
    PLC-->>Harness: { screenshot, url }

    Note over PLC,Agent: Cleanup

    Harness->>PLC: cleanup()
    PLC->>Browser: browser.close()
    Browser-->>PLC: done
    PLC->>Target: targetCleanup()
    Target-->>PLC: done
    PLC-->>Harness: complete

    alt error during initialization
        PLC->>Browser: try close()
        PLC->>Target: targetCleanup()
        PLC-->>Harness: throw EvalsError
    end
Loading

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

Comment thread packages/evals/core/tools/playwright_code.ts Outdated
Comment thread packages/evals/core/tools/playwright_code.ts Outdated
@shriyatheunicorn
shriyatheunicorn force-pushed the stg-2671-playwright-code-exposure branch from 4ca3ae0 to 6d57e4f Compare August 5, 2026 07:14
@shriyatheunicorn
shriyatheunicorn force-pushed the stg-2671-playwright-code-exposure branch from 6d57e4f to bb41558 Compare August 5, 2026 08:12
@shriyatheunicorn
shriyatheunicorn force-pushed the stg-2671-playwright-code-exposure branch from bb41558 to 1dd8a47 Compare August 5, 2026 08:28
@shriyatheunicorn
shriyatheunicorn force-pushed the stg-2671-playwright-code-exposure branch from 1dd8a47 to 633fea7 Compare August 5, 2026 17:45
@shriyatheunicorn
shriyatheunicorn force-pushed the stg-2671-playwright-code-exposure branch from 633fea7 to d74e112 Compare August 5, 2026 19:06
@shriyatheunicorn
shriyatheunicorn force-pushed the stg-2671-playwright-code-exposure branch from d74e112 to 35c5cc6 Compare August 5, 2026 22:40
@shriyatheunicorn
shriyatheunicorn force-pushed the stg-2671-playwright-code-exposure branch from 35c5cc6 to 0156798 Compare August 6, 2026 02:16
@shriyatheunicorn
shriyatheunicorn force-pushed the stg-2671-playwright-code-exposure branch from 0156798 to 4bea251 Compare August 6, 2026 02:46
@miguelg719
miguelg719 force-pushed the stg-2671-playwright-code-exposure branch from 4bea251 to c1a91e1 Compare August 6, 2026 22:21
@shriyatheunicorn
shriyatheunicorn force-pushed the stg-2671-playwright-code-exposure branch from c1a91e1 to 6898f3d Compare August 6, 2026 23:12
@miguelg719
miguelg719 force-pushed the stg-2671-playwright-code-exposure branch from 6898f3d to 409de2a Compare August 6, 2026 23:27
@shriyatheunicorn
shriyatheunicorn force-pushed the stg-2671-playwright-code-exposure branch from 409de2a to 9cf16fb Compare August 8, 2026 04:49
@miguelg719 miguelg719 changed the title evals: declare the playwright_code LLMExposure evals: declare the playwright_code agent mount Aug 9, 2026
@miguelg719
miguelg719 merged commit b280f7d into v4-spike Aug 9, 2026
21 checks passed
miguelg719 added a commit that referenced this pull request Aug 9, 2026
Same shape as #2592 for the CDP surface: prompt instructions carried
over verbatim, code_handles declaration, captureEvidence() for the
terminal screenshot, URL, and aria tree. Behavior is unchanged until the
adapter consumes mounts generically in #2596.

Part of the nondeterministic-evals stack (#2591#2611).

<!-- This is an auto-generated description by cubic. -->
---
## Summary by cubic
Expose `cdp_code` as an `LLMExposure` with an agent-mountable `cdp`
runtime, clearer prompt instructions, and richer final-state evidence.
Linked to Linear STG-2671 (part 5/6). Requires the `LLMExposure`
contract (1/6).

- **New Features**
- Agent mount: `handles.cdp`; prompt includes `AGENT_RUN_TOOL_NAME`, a
first navigate/load recipe, run-tool description and code param, and a
deny message; `captureEvidence` collects screenshot, URL, and
`ariaTree`.
- Runtime: `send`/`browser` plus `on`/`off`/`once`/`waitForEvent`/`wait`
with session scoping, timeouts, safe teardown, and unhandled-rejection
guards; exposes `targetId`/`sessionId`; `createAgentRuntime(logger)`
initializes it.
- Representation: adds `representation` capability; `page.represent()`
returns the accessibility tree with metadata; evidence includes
`ariaTree`.
- Page management: `syncPages` keeps session pages current before
`listPages`/`activePage`; bootstrap only creates a target if none exist.

<sup>Written for commit e641edf.
Summary will update on new commits.</sup>

<a
href="https://cubic.dev/pr/browserbase/stagehand/pull/2595?utm_source=github"
target="_blank" rel="noopener noreferrer"
data-no-image-dialog="true"><picture><source
media="(prefers-color-scheme: dark)"
srcset="https://www.cubic.dev/buttons/review-in-cubic-dark.svg"><source
media="(prefers-color-scheme: light)"
srcset="https://www.cubic.dev/buttons/review-in-cubic-light.svg"><img
alt="Review in cubic"
src="https://www.cubic.dev/buttons/review-in-cubic-dark.svg"></picture></a>

<!-- End of auto-generated description by cubic. -->
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