sdk-python icon indicating copy to clipboard operation
sdk-python copied to clipboard

[FEATURE] Benchmark agent quality when keeping injected context for implicit-cache providers

Open jimbrub opened this issue 2 weeks ago • 0 comments

Human Overview

Left for a human to fill in. This issue was drafted by an AI agent, see team/AI_USAGE_POLICY.md.

Implicit caching is how some model providers address cache hits. Context Manager will inject todos/memories/environment facts that are ephermal. There are a few options to best utilize the benefits from cache hits that need to be benchmarked and tested with implicit caching models.

SDK Language

TypeScript (Python follows the result)

Problem Statement

Providers that cache only by exact prompt prefix (GPT and xAI on Bedrock Converse, OpenAI Chat Completions, Gemini implicit caching) read almost nothing from cache in a Strands agent loop. The SDK adds reminders (todos, environment) to the latest user message and drops the previous turn's reminder on the next call, so each request stops being a prefix of the next. GPT-6 Luna on Bedrock read 0% from cache on main.

#6175 fixes the cache by keeping earlier reminders in the request: Luna went from 0% to about 87% cache reads, and OpenAI Chat from 0% to about 87%. But it changes what the model reads. The model now sees every superseded todo list and date, plus one copy of the environment block (which includes AGENTS.md) per user turn. Cache numbers show the change saves money. They do not show whether the agent still works as well. #6175 is deferred until this benchmark answers that.

Proposed Solution

Measure agent quality and cost on implicit-cache routes for three variants, then pick the default for the implicit cache mode (#5126).

Variants

ID Behavior Code
A Earlier reminders dropped, only the latest is sent main
B Earlier reminders kept, unchanged #6175 head (d40355c12)
C Earlier reminders kept, and a new one is injected only when its text changed since the last one from that source Prototype: ContextInjector skips a render identical to its previous block

Routes

  • Implicit-cache: GPT-6 Luna on Bedrock Converse, Grok on Bedrock Converse, OpenAI Chat Completions (direct), Gemini 3-flash-preview on Vertex.
  • Control: Claude Haiku 4.5 on Bedrock with cacheConfig: auto. It uses SDK cache points, so it should show no difference.

Tasks (through createHarness defaults with Todos and environment on, each in a fresh temp working directory, each with an automatic grader)

  1. Fix failing tests: a small repo with 2 bugs. Passes when the test command exits 0.
  2. Rename across files: a function used in about 7 files. Passes when grep finds no old name and the build passes.
  3. Log analysis: a large log with a known answer. Passes on an exact match.
  4. Stale-plan trap: a multi-turn task whose todo list changes mid-run (items completed, then replaced). Counts tool calls or claims that act on already-completed items.
  5. Long session: 10+ user turns on one topic. Measures context growth and whether late answers stay correct.

Metrics per run

  • Task success (grader) and, for task 4, a stale-action count.
  • Model calls and tool calls.
  • Tokens: uncached input, cache read, cache write, output; cache-read share.
  • Cost: tokens × the model's published prices with its cache multipliers.
  • Wall-clock latency.
  • Prompt tokens on the final call.

Procedure

  1. Pilot: 1 run per route × variant × task, to check the graders and measure cost and time.
  2. Main runs: at least 10 runs per route × variant × task, interleaving variants (A, B, C, A, B, C…). Each run uses a fresh agent with no session reuse and the same prompts and model settings.
  3. Record commit SHAs, SDK and harness versions, region and date, and raw per-call usage (results.json), plus a summary (REPORT.md).

Decision rule

  • Adopt B or C as the implicit mode's default if its success rate is within 5 points of A, with no significant rise in stale actions, at lower cost. Prefer C over B at equal quality, since its context is smaller.
  • If both B and C hurt quality: keep A, and document that implicit-only providers trade cache hits for clean context.
  • If the control route shows a difference, the run is invalid.

Use Case

Decides whether unified auto caching (#5126) can turn implicit-cache providers from 0% cache reads to about 87% without making agents worse, and which variant #6175 becomes.

Alternatives Solutions

  • Ship #6175 as-is without measuring: rejected, since it changes what the model reads by default.
  • Keep main's behavior: implicit-cache providers keep missing the cache in agent loops.

Additional Context

  • Related: #4879, PR #6175 (deferred), #5126, #1140. Live cache numbers for every route are in the #6175 reviews.
  • Open choices: whether to include variant C (needs a small prototype), which OpenAI Chat model to use (the harness itself uses Responses), and a budget cap set after the pilot.

jimbrub avatar Nov 17 '26 16:11 jimbrub