-
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
11
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
11 commits
Select commit
Hold shift + click to select a range
5ded0aa
refactor(verifier): consolidate engine types
miguelg719 8b53f06
feat(evals): wire WebTailBench through verifier
miguelg719 101f801
fix(evals): normalize verifier rubric inputs
miguelg719 d92b311
fix(evals): validate verifier success mode
miguelg719 42a4da3
docs(evals): remove rollout comments from verifier adapter
miguelg719 f828f54
fix(evals): align verifier adapter result API
miguelg719 425285b
docs(evals): drop verifierAdapter file header
miguelg719 73e0bca
fix(evals): record verifier evidence via callbacks
miguelg719 c131a6f
style(evals): format verifier adapter
miguelg719 d92f3a5
fix(evals): verify recorded trajectory directly
miguelg719 9b5f22f
fix(evals): rely on recorder construction start
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
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,159 @@ | ||
| 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({ | ||
| taskSpec: hydratedTaskSpec, | ||
| runId, | ||
| outputRoot: trajectoryRoot, | ||
| }); | ||
| const { callbacks: userCallbacks, ...restAgentOptions } = agentOptions ?? {}; | ||
|
|
||
| let agentResult: AgentResult; | ||
| let recorderStatus: "complete" | "aborted" | "error" = "complete"; | ||
| try { | ||
| agentResult = await agent.execute({ | ||
| ...restAgentOptions, | ||
| instruction: taskSpec.instruction, | ||
| callbacks: { | ||
| ...userCallbacks, | ||
| onEvidence: async (event) => { | ||
| recorder.record(event); | ||
| await userCallbacks?.onEvidence?.(event); | ||
| }, | ||
| }, | ||
| }); | ||
| } 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); | ||
| 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