-
Notifications
You must be signed in to change notification settings - Fork 1.5k
feat(evals): wire WebTailBench through verifier #2135
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
miguelg719
wants to merge
5
commits into
miguelgonzalez/verifier-06-offline-cli
Choose a base branch
from
miguelgonzalez/verifier-07-evals-adapter
base: miguelgonzalez/verifier-06-offline-cli
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
adca143
feat(evals): wire WebTailBench through verifier
miguelg719 986624e
fix(evals): normalize verifier rubric inputs
miguelg719 92afba0
fix(evals): validate verifier success mode
miguelg719 7652e32
docs(evals): remove rollout comments from verifier adapter
miguelg719 47dc1d5
fix(evals): align verifier adapter result API
miguelg719 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,177 @@ | ||
| /** | ||
| * verifierAdapter — runs a bench task through the verifier pipeline. | ||
| * | ||
| * Replaces the per-task ScreenshotCollector + V3Evaluator.ask() boilerplate | ||
| * with one call: | ||
| * | ||
| * const { evaluationResult, trajectory } = await runWithVerifier({ | ||
| * v3, | ||
| * agent, | ||
| * taskSpec: { id, instruction, initUrl, precomputedRubric? }, | ||
| * maxSteps: 50, | ||
| * }); | ||
| * | ||
| * Behavior: | ||
| * 1. Resolves the rubric from the task, cache, or evaluator. | ||
| * 2. Wraps agent.execute() with a TrajectoryRecorder subscribed to the bus. | ||
| * 3. Runs V3Evaluator.verify() on the recorded Trajectory. | ||
| * 4. Returns { trajectory, evaluationResult, agentResult }. | ||
| * | ||
| * Persistence and rubric caching are gated by env vars: | ||
| * VERIFIER_PERSIST_TRAJECTORIES — on locally, off in CI by default. | ||
| * VERIFIER_DISABLE_RUBRIC_CACHE — set to "1" to bypass the cache (forces | ||
| * fresh rubric generation every time). | ||
| */ | ||
| import { | ||
| V3Evaluator, | ||
| normalizeRubric, | ||
| type AgentInstance, | ||
| type AgentExecuteOptions, | ||
| type AgentResult, | ||
| type EvaluationResult, | ||
| type Rubric, | ||
| type TaskSpec, | ||
| type Trajectory, | ||
| type V3, | ||
| } from "@browserbasehq/stagehand"; | ||
|
|
||
| import { RubricCache } from "./rubricCache.js"; | ||
| import { TrajectoryRecorder } from "./trajectoryRecorder.js"; | ||
|
|
||
| export interface RunWithVerifierOptions { | ||
| v3: V3; | ||
| agent: AgentInstance; | ||
| taskSpec: TaskSpec; | ||
| /** | ||
| * Dataset name for rubric cache partitioning. Each task lives under | ||
| * `.rubric-cache/<dataset>/<task-id>.json`. | ||
| */ | ||
| dataset: string; | ||
| /** Agent execute options. `instruction` is filled from taskSpec.instruction. */ | ||
| agentOptions?: Omit<AgentExecuteOptions, "instruction">; | ||
| /** Override the run id (defaults to ISO timestamp). */ | ||
| runId?: string; | ||
| /** Override trajectory persistence root. */ | ||
| trajectoryRoot?: string; | ||
| } | ||
|
|
||
| export interface RunWithVerifierResult { | ||
| trajectory: Trajectory; | ||
| evaluationResult: EvaluationResult; | ||
| agentResult: AgentResult; | ||
| /** Resolved rubric (precomputed, cached, or freshly generated). */ | ||
| rubric: Rubric; | ||
| /** Where the trajectory was persisted (or would have been, if disabled). */ | ||
| trajectoryDir: string; | ||
| } | ||
|
|
||
| export async function runWithVerifier( | ||
| opts: RunWithVerifierOptions, | ||
| ): Promise<RunWithVerifierResult> { | ||
| const { v3, agent, taskSpec, dataset, agentOptions, runId, trajectoryRoot } = | ||
| opts; | ||
| const evaluator = new V3Evaluator(v3, { backend: "verifier" }); | ||
|
|
||
| // ── Resolve rubric ────────────────────────────────────────────────────── | ||
| let resolvedRubric: Rubric; | ||
| if (taskSpec.precomputedRubric) { | ||
| resolvedRubric = normalizeRubric(taskSpec.precomputedRubric)!; | ||
| } else if (process.env.VERIFIER_DISABLE_RUBRIC_CACHE === "1") { | ||
| resolvedRubric = await evaluator.generateRubric(taskSpec); | ||
| } else { | ||
| const cache = new RubricCache({ dataset }); | ||
| resolvedRubric = await cache.getOrGenerate(taskSpec, evaluator); | ||
| } | ||
|
|
||
| // Hand a fully-hydrated TaskSpec to the verifier so it doesn't regenerate. | ||
| const hydratedTaskSpec: TaskSpec = { | ||
| ...taskSpec, | ||
| precomputedRubric: resolvedRubric, | ||
| }; | ||
|
|
||
| // ── Record trajectory around agent.execute() ─────────────────────────── | ||
| const recorder = new TrajectoryRecorder({ | ||
| v3, | ||
| taskSpec: hydratedTaskSpec, | ||
| runId, | ||
| outputRoot: trajectoryRoot, | ||
| }); | ||
| recorder.start(); | ||
|
|
||
| let agentResult: AgentResult; | ||
| let recorderStatus: "complete" | "aborted" | "error" = "complete"; | ||
| try { | ||
| agentResult = await agent.execute({ | ||
| ...agentOptions, | ||
| instruction: taskSpec.instruction, | ||
| }); | ||
| } catch (e) { | ||
| recorderStatus = "error"; | ||
| const trajectory = await recorder.finish({ status: recorderStatus }); | ||
| // Re-throw after persisting so the bench task can decide how to report. | ||
| const wrapped = e instanceof Error ? e : new Error(String(e)); | ||
| Object.assign(wrapped, { trajectoryDir: recorder.directory, trajectory }); | ||
| throw wrapped; | ||
| } | ||
|
|
||
| const trajectory = await recorder.finish({ | ||
| status: recorderStatus, | ||
| finalAnswer: agentResult.message, | ||
| usage: agentResult.usage, | ||
| }); | ||
|
|
||
| // ── Verify ────────────────────────────────────────────────────────────── | ||
| const evaluationResult = await evaluator.verify(trajectory, hydratedTaskSpec); | ||
| await recorder.persistResult(evaluationResult); | ||
|
|
||
| return { | ||
| trajectory, | ||
| evaluationResult, | ||
| agentResult, | ||
| rubric: resolvedRubric, | ||
| trajectoryDir: recorder.directory, | ||
| }; | ||
| } | ||
|
|
||
| /** | ||
| * Decide bench task success from an EvaluationResult using the --success flag's | ||
| * semantics. | ||
| * | ||
| * `outcome` (default) — strict binary outcome. | ||
| * `process` — rubric process score ≥ threshold (default 0.8). | ||
| * `both` — both conditions must hold. | ||
| */ | ||
| export type EvalSuccessMode = "outcome" | "process" | "both"; | ||
|
|
||
| export function resolveEvalSuccessMode(mode: unknown): EvalSuccessMode { | ||
| if (typeof mode !== "string") return "outcome"; | ||
| const normalized = mode.trim().toLowerCase(); | ||
| if ( | ||
| normalized === "outcome" || | ||
| normalized === "process" || | ||
| normalized === "both" | ||
| ) { | ||
| return normalized; | ||
| } | ||
| return "outcome"; | ||
| } | ||
|
|
||
| export function evaluationResultToSuccess( | ||
| result: EvaluationResult, | ||
| mode: unknown = "outcome", | ||
| processThreshold = 0.8, | ||
| ): boolean { | ||
| const resolvedMode = resolveEvalSuccessMode(mode); | ||
| const outcomeOk = result.outcomeSuccess; | ||
| const processOk = | ||
| typeof result.processScore === "number" && | ||
| result.processScore >= processThreshold; | ||
| switch (resolvedMode) { | ||
| case "outcome": | ||
| return outcomeOk; | ||
| case "process": | ||
| return processOk; | ||
| case "both": | ||
| return outcomeOk && processOk; | ||
| } | ||
| } | ||
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
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
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
P2: If
recorder.finish()rejects inside the catch block, the original agent error is lost. Wrap the persistence call in its own try/catch so the original error is always rethrown.Prompt for AI agents