evals: document the stagehand_code exposure surface and batching guidance - #2639
Open
shriyatheunicorn wants to merge 11 commits into
Open
evals: document the stagehand_code exposure surface and batching guidance#2639shriyatheunicorn wants to merge 11 commits into
shriyatheunicorn wants to merge 11 commits into
Conversation
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.
|
Contributor
There was a problem hiding this comment.
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
Reply with feedback, questions, or to request a fix.
Re-trigger cubic
shriyatheunicorn
force-pushed
the
evals-stagehand-code-exposure-contract
branch
from
August 7, 2026 12:03
a1332e0 to
f981de5
Compare
shriyatheunicorn
force-pushed
the
wire-in-verifier
branch
from
August 8, 2026 04:49
83c982d to
88d32fd
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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_codeby listing the exactpageandpage.locatormethods and routing anything else throughstagehand.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 locatorcount/isVisible/textContent/inputValue).Written for commit f981de5. Summary will update on new commits.