Strategy reference
Managed Claude source hooks run before tool results enter the transcript. They stand aside unless the current lane can retrieve the original. Source-hook behavior.
The Library
On by default:
| Strategy | What it does |
|---|---|
observation_mask | Retires stale tool observations behind a retrievable marker. |
code_graph | Keeps relevant symbols across multi-file reads. |
cache_optimizer | Stabilizes the request's start so providers reuse their cache. |
relevance_filter | Keeps only the relevant lines of a tool output. |
columnar_fold, repeat_factor and
client_spill_preview are on for every client.
command_digest is on in its lossless lane only: it folds repeated blocks in
fresh test output and changes nothing else.
content_census and cache_lint are also on. They only measure and never change a request.
content_census also reports the tokens a trim would have saved on a large pasted log.
Off by default
Enable these on a deployment you have measured. Each one changes what the model sees, or needs a client capability.
| Strategy | What it does |
|---|---|
command_digest (full digest) | Digests recognized dev-command output (test runs, grep, logs). |
thinking_trim | Removes re-sent copies of past reasoning. The current turn's thinking is untouched. |
semantic_cache | Serves a cached response for duplicate requests. |
image_ocr | Sends the text of a text-dense image or PDF instead of the file. |
Turn one on for everyone in the optimizer settings, for a team or
model with a per-target rule, or for a single
request with the x-anyray-optimization-kinds
header. A rule's disable always wins.
A client without retrieval can still receive lossless folds and cache optimization. App-state API
response schemas can also lose annotations under columnar_fold (details). For
verbatim input, start a fresh conversation with the
exact profile.
Lossless edits accepted under firstSightOnly: true keep their shortened bytes if the optimizer times
out, including on clients without retrieval. This replay applies on turns that allow tool calls.
Provider prompt caches bill only the new part of a request at full price; everything before
the cache_control breakpoints is a cheap cache read. Cache guards suppress unstable prefix edits. Replay-capable strategies may make a bounded,
pinned rewrite and replay it on later turns, refreshing any retrieval handle. The session gate measures whether that cost pays
back on the tenant's traffic. See it step by step.
Pricing switches
Every edit that can cost a cache rewrite or a read-back is priced in dollars before it is made, on
one token count, one horizon of later turns and one read-back chance per edit. An edit that does
not pay is skipped and its strategy reports why (strategyDeclines). The config's economics
block turns each part of that price on or off. enforceOpenLanes, horizonSlopes and
servedClassPriors default to false, the rest to true. A saved unifiedRuler is accepted and
ignored.
| Switch | On | Off |
|---|---|---|
tokenizer | Prices read real token counts of each message (the model's own tokenizer, or Claude's published vocabulary scaled to billed tokens) | Prices read the size estimate |
realTurnHorizon | The context-ceiling cap on later turns grows per real turn | It grows per exchange, which can count one turn twice |
measuredRetrieval | A tenant's measured read-back rate, for the same kind of content (source or output), raises the read-back chance | Built-in chances only |
servedClassPriors | With measured retrieval on, enough measured source or unknown class evidence replaces the built-in chance of relevance_filter and code_graph. No other strategy reads it | Served evidence can only raise the chance |
priceAllLanes | Edits after the cache breakpoint, repeat_factor's folds inside the cached prefix and thinking_trim's running-loop strips are priced | They run unpriced, as before |
enforceOpenLanes | observation_mask under context pressure, or on a route with no prompt cache, drops masks that do not pay | The price is reported and every mask goes out |
tailAdmission | An edit must also pay if the session ends early (the length three sessions in four reach) | The average session length decides alone; payback_tail is never reported |
freshTailGroups | Prices fresh-tail edits together and admits retrieval-tool activation when the suffix pays for it | Prices edits separately once retrieval tools are active; holds suffix tool activation |
quartileGrowth | The context-ceiling cap assumes later turns grow like a typical large turn (the upper quartile) | It assumes every later turn grows like the largest one so far |
markedHeaderRead | When the request marks its system prompt for caching, an edit to an earlier message prices the tools and system prompt as read from cache | On a route without a measured cache window, the edit also prices the tools and system prompt as re-written |
requestPlanning | Selects compatible edits across strategies and prices shared rewrite and retrieval setup costs once | Each strategy selects and prices its own edits |
subsetSelection | Searches smaller groups when the initial edit group fails; each group must pass the full price and enabled tail checks | Only removes costly edits from a group that already passes |
horizonSlopes | Caps main-thread gate and planner horizons, including explicit overrides, at a per-tool slope | Uses the existing horizon; defaults off pending a paired bench |
requestPlanning defaults to true: the optimizer chooses edits across strategies together
instead of one strategy at a time. Set economics.requestPlanning to false to restore
per-strategy selection, including its freshTailGroups and subsetSelection controls.
With request planning off, freshTailGroups defaults to true. Set it to false to price each edit separately. A group is
withheld if any required handle cannot be stored.
A rule's economics block replaces the fields it names for the requests it matches. Changing a
switch restarts the per-session gate's evidence for the
strategies it prices, keeping their current state.
Set subsetSelection to false to restore the previous selection algorithm.
{
"when": { "metadata": { "experiment": ["mean-admission"] } },
"economics": { "tailAdmission": false }
}
Reference
What each strategy edits and when it runs. Observe-only kinds, meaning meters and audits, are not listed.
observation_mask and relevance_filter stop a long scan when the request runs short of time and
keep the turn's settled edits. Set their midRunStandDown param to false to let the scan finish.
observation_mask
Replaces an old, large tool result with a one-line marker, so you stop paying for it every turn. The agent can fetch the original back when it needs it.
It never masks a failed tool call, the current turn, a source file the agent read, a file the agent is editing, or the latest completed exchange. It masks freely as a turn nears its context limit (the client's own limit when it declares one, else the model's window), and below that only where the payback check admits it.
Masking a result that is already in the provider's prompt cache forces a cache rewrite. Anyray masks it only when the saving pays for that rewrite plus a possible read-back. Later turns count toward the payback, so short sessions are left alone.
On a measured Bedrock rewrite region, each message keeps its cache-write TTL. A 1-hour system cache does not raise a 5-minute message rewrite to the 1-hour rate. If a message spans both TTLs, the estimate uses the higher rate for its retained bytes.
Native Claude requests also account for the gateway's resolved cache lifetime when pricing the current write.
mintAnchor: true reads live, hash-bound
cacheAnchorTails attestations from the
Anyray gateway. On an explicit Bedrock route, it can price a deep rewrite from the exact earlier
tail the gateway proves is still cached and place a marker there. This does not enable the
heuristic tail-lookback price. It defaults to false until a paired session bench passes;
mintWholePrefixPrice: true disables it.
Cache support, cached-token reporting, and safe mid-prefix rewrite pricing are separate capabilities. Anyray keeps a provider/model evidence matrix for all registered routes. Only a measured positive can enable region, tail-lookback, or anchor pricing; unmeasured and target-specific routes keep the whole-prefix price.
For an agent that re-sends tool output as an assistant message, such as LangGraph, add
assistant to its roles. It is off by default because it also masks the model's own long
replies on other agents. An assistant message at the very end of the request stays inline, and
system or developer messages are never masked.
command_digest
Recognizes known dev-command output and keeps what matters for that command. The full output stays retrievable.
- A test run keeps its failures and the count line. Each failure keeps its assertion (
expected,got,want, pytest'sElines), even under a long stack trace. grepoutput is grouped by file. Hits that differ only in a timestamp, duration, or client IP fold into one line with a count. Hits with a different path, id, or status code stay apart, so500and200never merge.- Repeated log lines collapse to
[×N].
Identical blocks inside one test output become references to the first copy, with no read-back
needed. A test log the agent saved to a file and read back with line numbers folds the same way,
and each reference names the line range it replaces. This is the only edit the shipped default
makes (firstSightOnly: true), and only on output that arrives this turn and is provably not
cached yet. Set firstSightOnly: false to add the lossy digests above, which edit older turns.
A digest of cached history has to pay for the cache rewrite it forces. Once a session sits idle
past its prompt-cache lifetime, the provider bills the whole prefix again whatever is sent, so the
rewrite costs nothing extra on that turn. The config's coldTurn.premiumKinds lists the strategies
that price a mint without the rewrite on a turn the gateway marks as cache-expired. It holds
observation_mask and relevance_filter by default; add command_digest to include it. A
possible read-back still counts, and later turns replay the same digest.
Two cases keep the usual price. One is a digest the agent cannot fetch back. The other is a request
where cache_optimizer places its own conversation breakpoint, because a new
digest would hold that breakpoint back for the turn.
The list replaces the default, so a rule that adds a strategy restates the two defaults. An empty
list turns the cold price off for every strategy it could name. coldTurn.writeCredit never
credits command_digest. There is no benchmark for it yet, so scope it to a test with a rule.
{
"when": { "metadata": { "experiment": ["cold-digest"] } },
"coldTurn": { "premiumKinds": ["observation_mask", "relevance_filter", "command_digest"] }
}
code_graph
When a request carries several source files the agent read, code_graph keeps the functions in
play and the functions they call. Other function bodies become a short marker, and their
signatures stay. Hidden bodies stay retrievable.
It maps which symbols use which across the files, and matches that map against the current turn, not against the last file read. A file the agent is editing, or one the turn names by path, stays whole, so edits always see real bytes. Fresh tool results and retrieved originals are never outlined.
On cached history it outlines a file only when the saving beats the cache rewrite, retrieval is available, and the original is stored. Later turns replay the same outline, so the cache stays stable.
Source-file results from Read, cat -n, or sed -n stay whole until eight later assistant
requests in that agent session. A later read or search of overlapping or adjacent lines also keeps
the result whole. Set sourceReadMinAge per strategy to change the age floor; zero turns it off.
freshTailMinLines is off by default. To outline a whole-file source read on the request that
first carries it, set a line count such as 150 and set sourceReadMinAge to zero. The age floor
otherwise keeps first-sight reads whole. This lane saves the cache write and later reads of hidden
bodies when the agent does not fetch them back.
The first-write saving uses the lowest proven rate in the edited message. Text beyond the last cache marker saves plain input; a 5-minute tail cannot claim the system prompt's 1-hour write rate.
coldTurn.premiumKinds works as it does for command_digest. With code_graph
in the list, an outline of cached history is priced without the cache rewrite on a cache-expired
turn. It is not in the list by default and has no benchmark yet.
Three things stay whole. A read that asked for a line range, because the agent wants those lines. A file the task names by path. And bodies of symbols the task names. Each outline the model fetches back makes the next one less likely, until the session makes no new ones.
The agent asked for that file and gets signatures plus markers like
[lines 1973-2036 · retrieve ctx_7c]. It has to call anyray_retrieve for a body it needs. Scope
it to a test with a rule before you turn it on widely.
{ "params": { "code_graph": { "freshTailMinLines": 150, "sourceReadMinAge": 0 } } }
relevance_filter
Keeps only the lines of a long tool output that matter to the latest message. It builds a query from that message, ranks every line, and keeps the top lines plus the first few for context. In a tool loop with no recent prose, it uses the first user message (the session task) and the latest tool-call arguments, including a call's description. Task matches take priority when the kept output reaches its size limit. When a recent query misses an output entirely, it can rank that output against the latest tool-call arguments. Removed lines stay retrievable, and the user's own words are never ranked or trimmed.
It edits older turns only, including the most recently completed one. It skips a source file that code_graph will outline,
because line-by-line trimming would break the structure code_graph reads.
Source-file tool results follow the same sourceReadMinAge and later-read checks described above.
Relevance filtering protects warm history by default. While the cache is warm, only confirmed new
messages can be filtered. Cached history becomes eligible after a confirmed cache expiry on a parent
conversation. Reversible edits require evidence that the retrieval tools are already present.
Earlier edits still replay. Set strategies[].params.warmCacheGuard to false on
relevance_filter to restore warm-history rewrites.
It also reads assistant messages. Some agent frameworks, LangGraph among them, trim a tool result to a short placeholder and re-send the real output as an assistant message on the next step. Settled ones get filtered. One at the very end of the request is left whole, because the model has not read it yet.
semantic_cache
When a request exactly repeats an earlier one, Anyray serves the stored response and skips the provider. A hit needs an exact match on the caller and on every field that can change the answer: model, system prompt, messages, tools, and sampling params.
A request that runs a guardrail or mutator is never served from it. It goes to the provider, so its guardrails check a real answer, and that answer is not stored for later requests.
It ships off because a coding agent never repeats a request: its transcript grows every turn. Over a month of fleet traffic it served 0.20% of requests, and none on Claude Code or Codex.
Turn it on for a workload that sends the same request again and again, such as a batch or SDK job with a fixed prompt.
columnar_fold
A tool that returns a list of records repeats the same field names in every record. columnar_fold
rewrites the list as one header row plus one row per record. Every value stays in its row, even a
field with the same value on every record, because a model builds its answer from the rows.
The first table in a folded result opens with a note, __anyray_note__, that tells the model what
it is reading: a lossless table form, nothing removed, the field names in __anyray_columns__ and
one record per entry of __anyray_rows__, no retrieval needed. When any table in the result uses
dotted, optional or keyed columns, the note says how each maps back. The note costs about 70
tokens once per result and is counted against the fold's saving.
It reads tool results. For an app tool loop (clientTool of langgraph, langchain or
sdk-agent) it does three more things:
- A nested object every record carries becomes dotted columns (
tenant.name), so its field names are sent once too. A nested field some records lack still folds, and reads back as missing, not null. - App state may arrive as the final assistant message. Providers that reject assistant prefills
may receive a final user message instead. Its text must be only an app-style
name state:label line and one JSON body. The name starts with a lowercase ASCII letter. Only whitespace may surround the body. A capitalized heading, prose around the JSON or a second body does not qualify. A reply the model wrote is never touched: an assistant message followed by a user turn or a tool result stays as it is, and so does one that is only JSON. - A large JSON object one message repeats, such as a sub-schema an API spec repeats in every
endpoint, is written once at the top of the message and each repeat becomes
{"$ref":"#/$defs/s1"}. Only objects of at least 500 characters are shared, so a request parameter stays where the model reads it.
App tool loops also get the one part of the fold that removes text, on by default. Some apps
write the OpenAPI operations an agent picked into a message before the step that builds the API
call. Each operation's response schemas lose their description and example annotations and
keep every field name and type. One line goes under the message's label so the model knows the
descriptions are gone and the listed endpoints are the only ones it may call:
Note: the response schemas below list the fields each endpoint returns, by name and type only; descriptions were removed. Only the endpoints listed here can be called.
It applies only to the app's own state message at the end of the request, never to a tool
result. Parameter and request-body values are unchanged, though a trimmed operation is re-sent as
compact JSON. Removed text cannot be retrieved, and it runs on a lane that cannot retrieve too.
The whole message stays unchanged unless every operation has closed responses: no open additionalProperties, patternProperties or $ref, and field lists for JSON successes.
To send specs unchanged, turn off Trim API response schemas on the Columnar fold card in
Console → Optimizer, or set params.specResponseDetail: "keep".
requireReversibleElision: true in the config also turns it off.
Apart from that trim, it drops nothing and stores nothing. Anyray unfolds the result and compares it to the original
first, and the message passes through unchanged if anything differs. It also leaves alone anything
the comparison cannot see: records with different keys, an object with a repeated key or a
__proto__ key, and a number JSON cannot carry exactly (a 64-bit database id, or a decimal with
more digits than a double holds). JSON followed by prose, and a message with more than one JSON
body, are not folded by default. In an app tool loop their repeated objects are still shared.
It runs on messages of at least 400 characters with at least 4 records, and skips a fold that saves under 120 characters or under 5% of the message. It also leaves alone any table with fewer than three columns, and any table whose fold removes under 1,000 characters (repeated field names, measured per table against the minified JSON so indentation does not count). For a fixed configuration the same input always folds to the same bytes.
It runs on every request. A result is folded on the request that first sends it, so it is smaller
while it is still fresh. When the result goes stale, observation_mask can
still replace it with a retrieval marker at its usual point, priced by the folded size. A retrieve
returns the original result, not the folded one. A result that first went out as written (a turn
the optimizer missed, or a session already running when the fold reached it) stays as written, and
so does one your client edits later. That keeps the fold from rewriting a result the provider has
already cached.
| Setting | Effect |
|---|---|
enabled: false | Off everywhere. |
default (params.scope: "all") | Every request, on any lane. |
params.scope: "app_harness_no_retrieve" | Only app tool loops (clientTool of langgraph, langchain or sdk-agent) on a lane that cannot retrieve, decided once per session. |
params.appStateMessages: false | App tool loops fold tool results only, not JSON the app wrote into state messages. |
params.flattenNested: false | App tool loops keep nested objects as cells. |
params.shareRepeatedObjects: false | App tool loops send every repeated object in full. |
params.specResponseDetail: "keep" | App tool loops send OpenAPI specs unchanged. The default, "names", drops the annotations from response schemas and adds the note. "drop" removes the responses, with no note. |
params.keyedRecords: false | Leaves an object keyed by id as written. By default one whose values share their fields ({"u1": {…}, "u2": {…}}) folds, with the key as the first column, __anyray_key__. |
params.jsonLines: false | Leaves JSON Lines as written. By default a result of one JSON object per line folds into one table, and text before the first line stays as written. |
params.valueDictionary: true | Experimental. A string of at least 48 characters that a result repeats at least 3 times is written once in a dictionary line at the top, and each copy becomes {"__anyray_value__":0}. |
params.prefixDictionary: true | Experimental. A start of at least 24 characters that at least 3 strings share (a URL or path root) is written once in the dictionary, and each string keeps the rest as {"__anyray_prefix__":0,"__anyray_tail__":"…"}. |
Changing its thresholds can refold results that are already cached, once, on a session the gateway does not pin.
The two dictionary settings are off by default and change what the model reads, so leave them off until a paired pilot shows they never make a session cost more. They apply only to a result the gateway proves is new on that request, after the fold, and only when the whole rewrite still clears the fold's 120-character and 5% floors. A result over 64 KiB after the fold, and results past the first 64 KiB a request examines, get no dictionary. The pin records which settings a result took, and every later turn sends that result's bytes unchanged, including after you turn the settings off. A result that arrived without a dictionary never gains one. The dictionary line comes after an app's label line, and the result decodes to the original JSON byte for byte.
repeat_factor
Long blocks of text repeat across tool results and pasted user context: the same licence header on
nine file reads, the same schema in three query results, or a quoted block carried into a follow-up.
repeat_factor keeps the first copy and replaces each later copy with a one-line marker.
Nothing is stored. The block the marker points to is still in the request, so the model reads it
there instead of calling a tool. The marker says so: it names the tool call that holds the first
copy, the line range inside it, and that nothing is missing. A tool result that repeats an earlier
one in full reads same output as the earlier search_issues call toolu_0: all 800 lines identical.
When either result has several text blocks, the marker names the block (text block 2 of 2) and
counts lines from it.
It never rewrites the first copy, or a span another strategy already changed.
If the agent repeats a call (same tool, same arguments) right after its result was replaced in full,
the new result goes out whole. That shows as a refetch_after_fold decline on the trace.
A block must be at least 8 lines and 400 characters. It scans up to 20,000 lines per request. By default it scans tool, function and user messages. Assistant messages stay unchanged.
client_spill_preview
opencode cuts any tool output over 2,000 lines or 50 KB (its tool_output limits), saves the full
output to a file, and sends a preview that ends with a note like
The tool call succeeded but the output was truncated. Full output saved to: <path>.
client_spill_preview keeps the first 20 preview lines (the last 20 when opencode kept the tail),
adds a line saying how many it left out, and keeps opencode's truncation line and note byte for
byte. Nothing is stored: the full output is the file opencode already wrote.
It only shortens a preview on the request that first sends it, so it never rewrites one the
provider already cached; later requests send the same shortened bytes. It matches opencode's whole
output format, so a model quoting the note, or a tool printing part of it, is left alone. It stands
aside when the model may not call a tool that can read the file on that request (read, grep,
bash, shell or task, after any forced tool_choice), which shows as a no_file_tool
decline on the trace.
| Param | Default | Effect |
|---|---|---|
keepLines | 20 | Preview lines kept, 1 to 200. |
minSavedChars | 2000 | The smallest cut worth making. |
roles | tool, function | Message roles checked for a spill. |
image_ocr
A screenshot of a log or a scanned page costs far more tokens as an image than as the words it
holds. image_ocr reads the text out of a text-dense image or PDF on the optimizer host and sends
that text in the file's place. The text starts with a line such as
[anyray: text read from an image (120 words)], so the model knows what it is reading.
It reads these blocks when they carry the file inline as base64:
| Model | Blocks |
|---|---|
| Claude | image (PNG, JPEG, WebP) and PDF document blocks, also inside a tool_result |
| OpenAI (GPT-4o, GPT-4.1, GPT-5, o1, o3, o4-mini) | image_url parts with a data: URL and detail: "high" |
On other models it changes nothing. GIFs, files sent by URL or Files API id, text documents,
OpenAI file PDFs and Responses API inputs stay as sent. OpenAI may read an image without
detail: "high" at low detail, which already costs less than its text, so those stay images too.
These stay an image:
- Charts, diagrams and photos, where the picture carries the meaning and the text is sparse.
- Text it cannot read with high confidence, such as a script other than Latin, Chinese or Hebrew.
- A PDF page it cannot read with high confidence. A PDF is read page by page: a page with its own text goes as that text, and a page with a chart or picture goes as its text plus that picture, cropped from the page as it looks. A letterhead or logo is left out. A scanned page it cannot read goes as a picture of the page, so one bad page does not keep the whole file. PDFs are replaced for Claude Haiku 5 and Sonnet 5 only, where the page cost is measured. A PDF sent to any other model stays as sent.
- Text under about 19 pixels tall, such as a downscaled browser screenshot. It cannot be read reliably, so the optimizer checks the size first and skips the read.
- A file whose text would not save enough tokens.
- An image Claude would refuse as too large: over 8000 px on a side, or over 2000 px in a request with more than 20 images.
The change is final for that request: the model sees the text, not the layout, and cannot fetch
the original. It changes a file only on the request that first sends it and sends the same text
on later requests, so it does not rewrite what the provider already cached. Every optimizer
replica sends that same text, because each replacement is kept, encrypted, in the optimizer's
context store for the store's retention period. Under content mode off it makes no
new replacements, and the ones already stored keep serving until they expire. Like every
strategy, it cannot help a request the gateway sends while the optimizer is down, on a gateway
replica that has not seen the conversation: that request sends the original file.
The stored copy is machine-only: the model never sees a handle to it, it is encrypted, it expires with the store's TTL, and erasing a user's data removes it. Its decision records only counts (blocks, pages, words, tokens); request traces follow your organization's content mode like any other request.
It needs about 1 GB more optimizer memory while it reads, so the 2 GB minimum is not enough. A page it reads unsurely goes to a second model, which loads the first time that happens and adds about 300 MB. It reads Hebrew pages end to end. Turn it on in the console: Optimizer, open Image OCR, switch it On. To limit it to a team or model, add a per-target rule.
Reading a file takes time. With it on, a request that sends a new image or PDF can take a few seconds longer (up to 20 seconds), while the gateway waits for the text. Other requests, including later ones that resend the same file, wait no longer than before.
thinking_trim
Agents re-send past thinking blocks on every turn, and you pay for them each time. thinking_trim
drops a past thinking block once that turn's visible output already covers it.
It only trims reasoning from finished user turns. The tool loop the model is working through keeps all its thinking. From finished turns it keeps the opening plan of each tool loop, the reasoning after a tool error, and the reasoning on a turn that edits a file.
Rewriting reasoning the provider has already cached costs the cache-write price (about 1.25x
input instead of 0.1x) and raised input cost 40-65% on replayed sessions. So it trims where nothing
is cached yet, and rewrites cached reasoning once only when the trim pays back over the rest of the
session. Trims it holds show as a warm_prefix decline on the trace.
A turn ends when you send the next message. Messages Claude Code adds on its own do not end it: a
loaded skill's instructions, Tool loaded., a Stop hook's feedback, a background-task notification.
An opt-in setting also trims inside the live tool loop. On Sonnet 5 with adaptive thinking, that made the model redo the reasoning it lost, costing about 1.3x the output tokens and more than no trimming. Turn it on only where an audited holdout shows a net saving.
Claude Fable and Mythos 5.1, Opus 5.5, Sonnet 5.5 and newer check every re-sent thinking block
against the exact prompt it was written for. The only removal they accept is dropping a block the
first time it is sent, which is always live-loop thinking. With default settings thinking_trim
saves nothing on those models.
observation_mask, relevance_filter and code_graph do edit history on those models by
default. On the first-party API the provider then drops every thinking block after the edit and
answers without that reasoning; Bedrock keeps them. The org setting protectThinkingBinding
(PUT /admin/optimizer/settings) holds those edits too, as a thinking_binding decline.
cache_optimizer
Providers give the cache discount only when a request starts with the same bytes as the last one.
cache_optimizer keeps that start stable: it sorts tools into a fixed order, adds Anthropic cache
breakpoints, and sets a prompt_cache_key on OpenAI models and on Mistral routes.
For app frameworks (langgraph, langchain, sdk-agent) it leaves the tool order alone, since
their code already sends the same order every turn. On OpenAI models it sets them no key either:
their steps share prompts OpenAI caches without one. Set sortTools: false to stop sorting for everyone.
On metered markerless Claude sessions, it can also mark the end of the latest
message once the full prompt clears the model's cache minimum. The gateway's
verified session history must show a follow-up inside the five-minute cache window.
It never edits prompt text. If your client already places its own cache breakpoints, it stands
aside and reports client_managed. Other no-action guards report fixed reasons through
strategyDeclines in the optimizer protocol. It runs last,
so it sees the final request after every other strategy.
If your agent places its own cache breakpoints
Anyray adds none of its own, which is what client_managed reports. A trim of history the provider
already cached forces a cache rewrite. When that rewrite costs more than the trim saves, the
strategy stands aside and reports payback_premium. Expect savings from large tool outputs the
first time they arrive, from turns that resume after the prompt cache
expired, and from long tool-heavy sessions. A short chat seldom has anything
worth trimming.