Skip to content

feat(evals): browser instructions, finish check and Anthropic prompt caching for the mastra harness - #3478

Open
AcnoSaga wants to merge 1 commit into
browserbase:mainfrom
AcnoSaga:mastra-harness-browser-defaults
Open

AcnoSaga wants to merge 1 commit into
browserbase:mainfrom
AcnoSaga:mastra-harness-browser-defaults

Conversation

@AcnoSaga

@AcnoSaga AcnoSaga commented Nov 17, 2026 •

Copy link
Copy Markdown

why

Mastra ships no system prompt, so the one line the eval adapter passes ("Use the available browser/web tools to complete the task.") is the agent's whole prompt. On anthropic/ models the adapter also never asks for prompt caching, which Anthropic only does on request, so every step pays full price for the history.

what changed

  • Prompt caching for anthropic/ models. A cache breakpoint on the instructions, which also covers the tool definitions, plus Anthropic's automatic caching for the conversation. Both go through providerOptions.anthropic.cacheControl. EVAL_MASTRA_PROMPT_CACHE=0 turns it off.
  • Browser instructions. mastraInstructions.ts replaces the one line with general browsing guidance: read the page before acting, meet every constraint, finish comparisons, prefer the site's own page, stop before irreversible steps, answer with specifics. EVAL_MASTRA_INSTRUCTIONS=minimal restores the one line.
  • Finish check. The first time the agent stops on its own with steps to spare, the adapter sends one follow-up asking it to re-read the task and either keep working or restate its answer. It continues the same conversation and shares the step budget. If the check errors, runs out of steps or adds no text, the first answer and its completed status stand. EVAL_MASTRA_FINISH_CHECK=0 turns it off.
  • harnessConfiguration records all three settings, and docs/harness-contract.md describes them.

All three are on by default. If you'd rather keep today's harness as the default and make these opt-in, that's a small change and I'm happy to flip it.

On how the finish check continues the run: it is a second agent.stream call built from response.dbMessages, Mastra's stored format. On Mastra 1.57 response.messages does not round-trip. Screenshot tool results come back as base64 text (one request went from 243 KB to 2.1 MB) and turns regroup, which misses the cache. The in-loop hooks didn't fit either: onIterationComplete drops its feedback once the model has stopped, and isTaskComplete adds its feedback as an assistant message, which current Claude models reject.

results

HardBench core set, 38 tasks x 2 trials per arm, this change on 6f2686d7. Judge google/gemini-3.5-flash, reached through OpenRouter (#3472). Browserbase with verified mode on and proxies off. "Old" is EVAL_MASTRA_INSTRUCTIONS=minimal EVAL_MASTRA_FINISH_CHECK=0. Prompt caching was on in every arm. Effective input counts cached tokens at 0.1x.

model old new defaults effective input per run
claude-sonnet-5-5 39/76 (51.3%) 56/76 (73.7%) 230k to 267k
gpt-6.1-sol 58/76 (76.3%) 61/76 (80.3%) 176k to 259k
  • Sonnet 5.5 gains 22 points, about three standard errors. 15 tasks did better and 4 did worse.
  • GPT-6.1 Sol gains 4 points, which is inside the noise (one standard error is about 7), and uses 47% more input to get there. On this model I can't show the finish check pays for itself.
  • Caching on Sonnet, same four tasks: with EVAL_MASTRA_PROMPT_CACHE=0, 0% of input was cached and a run used 754k effective tokens. With it on, 95% was cached and a run used 131k. That is 4 runs against 8, so the size is rough.
  • The four full arms sent about 11,200 model requests. The prompt prefix never changed between consecutive requests, check pass included, and no request failed because of this change.

Things to know before trusting these:

  • Model calls went through local model routes that are not part of this PR, so the absolute numbers are from our setup. Please re-measure on yours.
  • I did not separate the instructions from the finish check on this commit. On an October commit the instructions alone were worth 4 points on GPT-6.1 Sol, inside the noise.
  • I wrote the guidance after reading failed HardBench runs. It names no site, task or benchmark, and a test checks that, but it was not written blind to the benchmark.
  • One request in each Sonnet arm failed with Anthropic's "The final block in an assistant message cannot be thinking". It happens with the finish check off too, so it predates this change.

test plan

  • pnpm check, the evals unit tests (1223 passing) and the mastra package tests (44 passing)
  • new tests for the cache options, for the finish check (stored-message continuation and its ordering, shared step budget, summed usage, keeping the first answer when the check errors, adds no text or runs out of steps, and skipping it unless the model stopped with steps to spare), for the runner wiring and the three switches, and for the settings resolver
  • live: the four 76-run arms above, a 4-task Sonnet run with screenshots (120 requests, no errors, 96% of input cached), and a 4-task cache-off run

🤖 Generated with Claude Code


Summary by cubic

Improves the Mastra eval harness with browser instructions, a finish check, and Anthropic prompt caching, all on by default. Mastra ships no system prompt, so the harness's single instruction line was the entire agent prompt.

  • Replaces the one-line prompt with general browsing guidance; EVAL_MASTRA_INSTRUCTIONS=minimal restores the earlier line.
  • Sends one follow-up the first time the agent stops with steps to spare, asking it to re-read the task and either keep working or restate its answer; it continues the same conversation and never turns a finished run into a failed one. EVAL_MASTRA_FINISH_CHECK=0 turns it off.
  • Requests Anthropic prompt caching on anthropic/ models via a cache breakpoint on the instructions plus automatic conversation caching; EVAL_MASTRA_PROMPT_CACHE=0 turns it off.
  • harnessConfiguration records all three settings, and docs/harness-contract.md documents them.

Measured results (HardBench core set, 38 tasks × 2 trials per arm):

  • Sonnet 5.5 improved from 39/76 (51.3%) to 56/76 (73.7%).
  • GPT-6.1 Sol improved from 58/76 (76.3%) to 61/76 (80.3%), within noise.
  • Prompt caching cut effective input from 754k to 131k tokens per run on a small Sonnet sample.

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

View guided diff

…caching for the mastra harness

Mastra ships no system prompt, so the adapter's one line was the whole prompt,
and on anthropic/ models it never asked for prompt caching.

- Prompt caching for anthropic/ models: a cache breakpoint on the instructions
  plus Anthropic's automatic caching for the conversation.
- General browsing instructions in place of the one-line prompt.
- A finish check: one follow-up, the first time the agent stops on its own,
  asking it to re-read the task. It continues the same conversation from
  Mastra's stored messages and never turns a finished run into a failed one.

EVAL_MASTRA_PROMPT_CACHE=0, EVAL_MASTRA_INSTRUCTIONS=minimal and
EVAL_MASTRA_FINISH_CHECK=0 restore the earlier harness. harnessConfiguration
records all three.

Co-Authored-By: Claude <noreply@anthropic.com>
@changeset-bot

changeset-bot Bot commented Nov 17, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: a453f18

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

@github-actions

Copy link
Copy Markdown
Contributor

This PR is from an external contributor and must be approved by a stagehand team member with write access before CI can run.
Approving the latest commit mirrors it into an internal PR owned by the approver.
If new commits are pushed later, the internal PR stays open but is marked stale until someone approves the latest external commit and refreshes it.

@github-actions github-actions Bot added external-contributor Tracks PRs mirrored from external contributor forks. external-contributor:awaiting-approval Waiting for a stagehand team member to approve the latest external commit. labels Nov 17, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

external-contributor:awaiting-approval Waiting for a stagehand team member to approve the latest external commit. external-contributor Tracks PRs mirrored from external contributor forks.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant