feat(evals): browser instructions, finish check and Anthropic prompt caching for the mastra harness
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 throughproviderOptions.anthropic.cacheControl.EVAL_MASTRA_PROMPT_CACHE=0turns it off. - Browser instructions.
mastraInstructions.tsreplaces 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=minimalrestores 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=0turns it off. harnessConfigurationrecords all three settings, anddocs/harness-contract.mddescribes 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=minimalrestores 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=0turns it off. - Requests Anthropic prompt caching on
anthropic/models via a cache breakpoint on the instructions plus automatic conversation caching;EVAL_MASTRA_PROMPT_CACHE=0turns it off. harnessConfigurationrecords all three settings, anddocs/harness-contract.mddocuments 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.