Skip to content

evals: document the stagehand_code exposure surface and batching guidance - #2639

Open
shriyatheunicorn wants to merge 11 commits into
wire-in-verifierfrom
evals-stagehand-code-exposure-contract
Open

evals: document the stagehand_code exposure surface and batching guidance#2639
shriyatheunicorn wants to merge 11 commits into
wire-in-verifierfrom
evals-stagehand-code-exposure-contract

Conversation

@shriyatheunicorn

@shriyatheunicorn shriyatheunicorn commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

Gives the stagehand_code exposure prompt an accurate, closed API contract and batching guidance.

With explicit contracts, there is a strong reduction in median turns per task.

Follow-up once #2608 lands: a short section introducing _experimental_batch usage.


Summary by cubic

Documents a closed API contract for stagehand_code by listing the exact page and page.locator methods and routing anything else through stagehand.act. Adds “always await” guidance, a recommended first step (page.goto(startUrl, { waitUntil: 'domcontentloaded' })), and batching advice; updates tests to assert the expanded surface (e.g., evaluate, scroll, setViewportSize, waitForSelector/waitForTimeout, and locator count/isVisible/textContent/inputValue).

Written for commit f981de5. Summary will update on new commits.

Review in cubic

shriyatheunicorn and others added 9 commits August 6, 2026 16:14
A uniform declaration of what a tool surface offers a coding agent:
code_handles (in-scope objects the agent writes code against, mounted by
the harness as a single local-MCP run tool), mcp_server, or cli — plus
the LLM_RUN_TOOL_SERVER/LLM_RUN_TOOL_NAME bindings the mount uses.
Types and constants only; no surface or adapter changes.

Part 1/4 of the #2473 port onto the current SDK generation.

<!-- This is an auto-generated description by cubic. -->
---
## Summary by cubic
Updates the tool-surface contract to include agent delivery
(`AgentMount`) and final-state evidence capture, keeping native
`CoreTool.surface` independent from how it’s delivered to the agent.
Types + tests only; supports STG-2671.

- **New Features**
- Types: `AgentMount` (`via: handles | mcp | cli` with
`promptInstructions`), `AgentRunToolSpec`; `ToolStartResult` gains
optional `agentMount` and `captureEvidence(): Promise<ProbeEvidence>`.
- Enums: `ToolSurface` adds `stagehand_code`; `CoreTool.family` adds
`stagehand`.
- Constants: `AGENT_RUN_TOOL_SERVER` ("stagehand_browser"),
`AGENT_RUN_TOOL_NAME` (`mcp__stagehand_browser__run`),
`AGENT_RUN_TOOL_RESERVED_HANDLES` (`startUrl`, `task`, `console`).
- Contract semantics: delivery is independent of native surface; CLI env
merges over harness env; reserved harness bindings;
capture-before-cleanup ordering.
- Tests: `tool-contract.test.ts` validates delivery independence, handle
mounts, and evidence capture.

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

<a
href="https://cubic.dev/pr/browserbase/stagehand/pull/2590?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. -->

---------

Co-authored-by: Miguel <36487034+miguelg719@users.noreply.github.com>
…ection

Per-step probe observations (url + screenshot through the exposure's own
surface) attach to run-tool steps for claude_code and bridge runs for codex,
and the harness-observed terminal artifact anchors the final observation —
parity with the Stagehand-driven TrajectoryRecorder path. Unverifiable
criteria are aggregated per (harness x surface x model) arm after each
batch; EVAL_MAX_UNVERIFIABLE_CRITERIA turns the report into a gate.
EVAL_HARNESS_OBSERVATIONS=none excludes a run from evidence collection.
Strict integer parsing for EVAL_MAX_UNVERIFIABLE_CRITERIA (malformed values
stay report-only); bridge probe callbacks can no longer hang a request or
flip a successful run to an error; a configured gate now fails loudly when
verifier-backed runs produced no graded arms instead of being silently
bypassed; codex observation attachment refuses to guess when recorded
bridge runs outnumber filter-matched steps — a gap grades safer than
misattributed evidence.
@changeset-bot

changeset-bot Bot commented Aug 7, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: f981de5

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 2 files

Architecture diagram
sequenceDiagram
    participant Agent as Coding Agent (LLM)
    participant Prompt as Prompt Instructions
    participant RunTool as run_snippet tool
    participant StagehandClient as Stagehand Client (stagehand)
    participant Page as Page Object
    participant Locator as page.locator()
    participant Backend as Browser Backend (CDP)

    Note over Agent,Backend: NEW: Tightened API surface & batching guidance

    Agent->>Prompt: Reads closed contract (page & locator methods)
    Prompt-->>Agent: Exact method list + batching guidance

    Agent->>RunTool: Invoke run() with snippet
    Note over Agent,RunTool: NEW: Prefer chaining multiple steps in one call

    RunTool->>StagehandClient: Execute snippet
    StagehandClient->>Page: Access page methods

    alt Deterministic Page Methods (new explicit list)
        Page->>Page: goto(), reload(), back(), forward()
        Page->>Page: url(), title()
        Page->>Page: screenshot(), setViewportSize()
        Page->>Page: waitForSelector(), waitForTimeout()
        Page->>Backend: async RPC to browser
        Backend-->>Page: Result
    else Locator Methods (new explicit list)
        Page->>Locator: .locator(selector)
        Locator->>Locator: count(), click(), hover()
        Locator->>Locator: fill(value), type(text)
        Locator->>Locator: isVisible(), textContent(), inputValue()
        Locator->>Backend: async RPC to browser
        Backend-->>Locator: Result
    else Unlisted Behavior
        Page->>StagehandClient: Fallback to stagehand.act()
        StagehandClient->>StagehandClient: act('describe the action')
    end

    StagehandClient-->>RunTool: Return final result (JSON-serializable)
    Note over RunTool,Agent: NEW: Return useful JSON for progress inspection

    alt Batching (NEW guidance)
        Agent->>RunTool: Chain act/observe/extract + page steps in one snippet
        RunTool->>StagehandClient: Execute batched sequence
        StagehandClient-->>RunTool: Return aggregated result
        RunTool-->>Agent: Single response with full outcome
    else Traditional (step-by-step)
        Agent->>RunTool: One action per call
        RunTool->>StagehandClient: Execute single step
        StagehandClient-->>RunTool: Partial result
        RunTool-->>Agent: Intermediate state
        Agent->>RunTool: Next action
    end

    Note over Agent,Backend: Batching reduces median turns per task
Loading

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

Re-trigger cubic

Comment thread packages/evals/core/tools/stagehand_code.ts Outdated
@shriyatheunicorn
shriyatheunicorn force-pushed the evals-stagehand-code-exposure-contract branch from a1332e0 to f981de5 Compare August 7, 2026 12:03
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