…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>
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
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.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.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.streamcall built fromresponse.dbMessages, Mastra's stored format. On Mastra 1.57response.messagesdoes 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:onIterationCompletedrops its feedback once the model has stopped, andisTaskCompleteadds 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. Judgegoogle/gemini-3.5-flash, reached through OpenRouter (#3472). Browserbase with verified mode on and proxies off. "Old" isEVAL_MASTRA_INSTRUCTIONS=minimal EVAL_MASTRA_FINISH_CHECK=0. Prompt caching was on in every arm. Effective input counts cached tokens at 0.1x.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.Things to know before trusting these:
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)🤖 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.
EVAL_MASTRA_INSTRUCTIONS=minimalrestores the earlier line.EVAL_MASTRA_FINISH_CHECK=0turns it off.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):
Written for commit a453f18. Summary will update on new commits.