<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Osher Elhadad on Medium]]></title>
        <description><![CDATA[Stories by Osher Elhadad on Medium]]></description>
        <link>https://medium.com/@osherelhadad?source=rss-c1a40339b47d------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*mCuBIhzfH3I1QLIfSLGBAQ.png</url>
            <title>Stories by Osher Elhadad on Medium</title>
            <link>https://medium.com/@osherelhadad?source=rss-c1a40339b47d------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Thu, 03 Dec 2026 15:01:56 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@osherelhadad/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[ContextGuru — Carry less, pay less — cutting the cost of AI agents]]></title>
            <link>https://medium.com/@osherelhadad/contextguru-carry-less-pay-less-cutting-the-cost-of-ai-agents-770f099aedd2?source=rss-c1a40339b47d------2</link>
            <guid isPermaLink="false">https://medium.com/p/770f099aedd2</guid>
            <category><![CDATA[kv-cache]]></category>
            <category><![CDATA[llm]]></category>
            <category><![CDATA[claude-code]]></category>
            <category><![CDATA[context-engineering]]></category>
            <category><![CDATA[ai-agent]]></category>
            <dc:creator><![CDATA[Osher Elhadad]]></dc:creator>
            <pubDate>Sun, 08 Nov 2026 17:39:11 GMT</pubDate>
            <atom:updated>2026-11-08T18:29:45.643Z</atom:updated>
            <content:encoded><![CDATA[<h4>Context Guru optimizes your AI agent’s cache and context. How we cut AI agent costs by 20% in our own production at IBM Research.</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Oy6ZCkhDE8es1eEkpkmSHA.png" /><figcaption>ContextGuru — Overview</figcaption></figure><p>Coding agents send a lot of the same context to the model on every request: instructions, tool definitions, conversation history, and tool outputs. Prompt caching makes that much cheaper, but only while the cache is warm. Once it expires, the next request has to write the context again, which can cost 25 times more on the Claude models we measured.</p><p>Picture an ordinary afternoon. An agent is fixing a bug, and its session has grown to 800,000 tokens.</p><p>It hands the change to a reviewer, a second agent started for that one job. The review takes 20 minutes. Then the agent runs a test suite that takes 10.</p><p>The provider keeps the part of every request that repeats (instructions, tools and the whole conversation so far) in a cache, but only for five minutes after it was last used.</p><p>If the reviewer had answered at minute four, the next request would have read that cache for <strong>$0.16</strong> on Claude Opus 5.5. It took half an hour, the cache had expired, and the agent paid <strong>$4.00</strong> to build it again.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qW5zon-KuJ7HL1NXBj2FOQ.png" /><figcaption>List prices per million tokens. A five-minute cache write costs 25 times a cache read.</figcaption></figure><p>Writing the five-minute cache costs 25 times as much as reading it, on both models. Most of this post follows from that one ratio.</p><p><strong>What Context Guru is.</strong> Context Guru is an open-source library that watches your agent’s traffic between your harness and the model provider. We provide plugins for all major harnesses. You can install it with a built-in local proxy, so your data stays on your machine, or use a shared proxy. It reduces unnecessary context and manages prompt caches so agents don’t repeatedly pay to rebuild them.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*FB9CNyDVnOVBS3X0TuToHA.png" /></figure><p><strong>How much will you save?</strong> It depends on how you work. On our own teams, the product’s dashboard shows <strong>$183.80 saved in the last 24 hours, 20% of what the work would have cost</strong>.</p><h3>Prefer to watch? The whole story in two and a half minutes</h3><p>The bag, the four things Context Guru does, our team’s dashboard and our best session.</p><p><a href="https://youtu.be/2ZKkDnml6is">https://youtu.be/2ZKkDnml6is</a></p><h3>What Context Guru does</h3><p>Context Guru sits between your agent harness and the model provider.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*BW7dlJMsdPkanxUcyO2nLA.png" /><figcaption>Context Guru sits between your agent harness and the model provider.</figcaption></figure><p>Context Guru does four things. Three make the bag smaller, and one makes what is left cheaper to carry.</p><p>You choose how much it trims with a <strong>preset</strong>. The default, off, trims nothing and only manages the cache. The others are conservative, medium, high and xhigh, the deepest.</p><p><strong>Smaller tool outputs.</strong> Test logs, search results and shell output are full of clutter, like colour codes, the same file path over and over, and repeated lines. Context Guru strips it out before the agent sends that output back to the model on its next request.</p><p><strong>Tools and skills you never use.</strong> Every request lists every tool the agent could call, whether it uses it or not. That includes MCP tools (plug-ins that connect outside services) and skills (saved instructions for particular jobs). Context Guru can leave out the ones the agent never touches.</p><p><strong>Compaction at the right moment.</strong> Compaction shrinks a long conversation by cutting what the agent no longer needs. Context Guru prepares the cut while the cache is still warm, then applies it on the first request after the cache goes cold, since the whole prompt has to be written again at that point anyway. The cut adds no cost, and every later turn (one round of the agent asking and the model answering) is smaller.</p><p>Its gentlest cut is the <strong>sweep</strong>. During a ping, while the cache is cheap to read, it asks a model which old tool output the agent no longer needs. It removes that output and leaves a marker, so the agent can fetch the text back.</p><p><strong>Smart cache management.</strong> While you are away, or while the agent waits for a long test run or for another agent, Context Guru decides whether the cache is worth keeping warm. If it is, it sends a <strong>ping</strong>: a tiny request that reads the cache and restarts its five-minute clock. One ping costs a twenty-fifth of a rewrite.</p><p>Pings work on Anthropic models (direct, Bedrock and Vertex), and on recent OpenAI models through the Responses API, where the cache lasts longer.</p><h3>A real session: 12 minutes away, $0.04 instead of $1.09</h3><p>In the 90-second video below, we recorded a Claude Code session from install to dashboard. Watch the <strong>band</strong>, the status line above the prompt. It shows what your next message will cost with a warm cache and with a cold one, what you have saved so far, and how long the cache has left.</p><p><a href="https://youtu.be/8WR9yBYMAXw">https://youtu.be/8WR9yBYMAXw</a></p><p>We stepped away for 12 minutes on purpose. Pings kept the cache warm, so the next message cost $0.04 instead of $1.09.</p><p>The band after a 12-minute pause: the next message costs $0.04 warm and $1.09 cold.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1zzu45GUNAtEBhPEtZB_lA.png" /><figcaption>The band after a 12-minute pause: the next message costs $0.04 warm and $1.09 cold.</figcaption></figure><h3>What it saved our teams: $183.80 in one day</h3><p>Our IBM Research teams use Context Guru every day on Claude Code. Over the week this post covers, 20 accounts sent traffic and about 10 to 16 were active on a working day. Here is the product’s own dashboard for our deployment over the last 24 hours (November 4, 11:54 to November 5, 11:54 UTC):</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*E4PQGOHkGfkkKKBCKtrlaA.png" /><figcaption>Our deployment’s dashboard, last 24 hours: $183.80 saved out of $911.57, 20%.</figcaption></figure><p>Without Context Guru that day would have cost <strong>$911.57</strong>. Our teams spent <strong>$727.77</strong>, pings included.</p><p>Most of the saving, <strong>$144.53</strong>, came from keeping caches warm while people were away: on 146 requests, the cache was read instead of written again. Another <strong>$39.27</strong> came from trimming old tool output and compacting.</p><p>Every developer saved something, from 10% to 36%:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*iyYEZ93q0iMSdZTEmI9qPw.png" /><figcaption>Every developer saved something, from 10% to 36% of what their work would have cost.</figcaption></figure><p>One caveat before you compare. Our teams chose xhigh, the deepest preset; yours starts at off. The tools-and-skills filter was off, so it saved nothing.</p><h4>Our best session: a third saved over five days</h4><p>This session ran on Opus 5.5, on and off over five days, and grew to 839,000 tokens. Without Context Guru it would have cost <strong>$205</strong>. It cost <strong>$137</strong>, so <strong>$68 saved, a third</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_evkgjWYDdtzEgoLMwPMnA.png" /><figcaption>Our best session, over five days: $205 without Context Guru, $137 with it.</figcaption></figure><p>The session had 59 long pauses. Here is what happened in them:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*p09fz3NHRWaCnYdUNoZVtw.png" /><figcaption>What happened in the session’s 59 long pauses, and what each outcome cost or saved.</figcaption></figure><h4>Not every session wins</h4><p>Our best session saved a third. A typical one saves about an eighth. Here is one: an Opus session that ran most of a working day and grew to 457,000 tokens.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Tw6TwvgohBhJ-ZGAtTm-MQ.png" /><figcaption>A typical session: 13% saved over a working day.</figcaption></figure><p>Context Guru kept the cache warm through 17 pauses, and each time the next turn read it for a few cents instead of rewriting it for one or two dollars. Twelve pauses still went cold and cost $17.40. Six of those were waits of six to nine minutes that got no ping, just past the cache’s five-minute life. The session cost $201 instead of $231.</p><p>Across all sessions the spread is wide.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qixX0cFwz4rMpPW0gEospg.png" /><figcaption>Most of the money sits in sessions that save 5 to 20%; 13 of 81 sessions lost money.</figcaption></figure><p>We looked at the 81 sessions that cost at least $5, which hold almost all the money. Eleven saved more than a fifth, 33 saved between 5% and 20%, and 24 saved up to 5%. Thirteen lost money, $54 in all.</p><blockquote>The winners are long sessions with one agent and plenty of breaks.</blockquote><p>The losers are swarms of short-lived subagents that finish before any pause begins, so any pings sent their way buy nothing.</p><h4>Our deployment is also our lab</h4><p>Because we run the deployment ourselves, we can change the ping strategy from one day to the next and see what each one is worth in dollars.</p><p>The main thing we learned is that how long an agent waits depends on <em>why</em> it stopped. An agent waiting for its own test run is back in minutes, while a person who went to a meeting may not be back today. So we now set the number of pings by what the agent is waiting for: up to eight for its own tool, five for background work, three for a person. A first replay said this would save 16% more. When we replayed the code we actually shipped, it did no better than the plan it replaced and sent three times as many pings, so we now replay the real code before we ship it.</p><h3>Subagents keep caches small, pings keep them warm</h3><p>What follows comes from two of our own sessions on a laptop and from the hosted deployment our department uses. We also wrote about it <a href="https://www.linkedin.com/posts/davidamid_aiagents-claudecode-contextengineering-share-7523106838612094976-x4Ic/">on LinkedIn</a>.</p><p>The <strong>main agent</strong> is the one you talk to. It plans and decides, and it starts subagents, helper agents that each take on one task. Its context is large: about 860 messages and 180,000 tokens in these two sessions. A subagent does one task. Almost everything it does is run commands (854 of 856 calls in one session): it builds, tests, and opens or fixes a pull request. Its context is smaller, about 300 messages and 95,000 tokens, mostly tool output. Its long pauses come from its own commands, a test run or a remote build. It seldom waits for the main agent.</p><p>Because each subagent’s context is small and focused, its cache is cheap to keep warm. Context Guru does that while the subagent waits for its command, sending a ping at about four minutes. The ping reads the cache for one to three cents and saves a rewrite that would cost 20 to 70 cents when the result comes back. In one session, $2.76 of pings saved the subagents <strong>$15.39</strong>.</p><p><strong>Where it still cost us money.</strong> Three things got in the way. We have since changed two of them, and an earlier fix took care of the third.</p><ul><li><em>Small subagents were never pinged.</em> Context Guru skipped pings for any cache under 80,000 tokens, on the theory that small caches are cheap to rewrite. But subagents are small by design, so their caches went cold. The rule blocked the ping in 47 of the 51 subagent pauses that went cold unpinged. The limit is now 20,000 tokens. Side calls (the small background requests an agent makes without using any tool) are no longer pinged at all.</li><li><em>Two pings were too few for the long waits.</em> When the main agent waited for background work or for a person, two pings ran out too early. Extra pings paid off on our laptop, which led to the wait-aware plan above.</li><li><em>A finished subagent looked like it was still working.</em> A subagent hands in its final answer through a special tool call, and Context Guru read that as “waiting for a tool”. On the hosted deployment, 226 finished subagents were pinged for nothing. That is fixed (<a href="https://github.com/rossoctl/context-guru/issues/857">#857</a>, <a href="https://github.com/rossoctl/context-guru/pull/859">#859</a>).</li></ul><p>Across the whole deployment, subagent pings lost money in late October, mostly on those finished subagents. Since the fixes they cost about three cents each and roughly break even. One idea did not work out. For subagents, the one-hour cache (the pricier write option, $8.00 per million tokens on Opus 5.5) costs more than pings and leaves the sweep almost nothing to do.</p><h3>Where the rest of the money goes: one dollar in five is a cold cache</h3><p>After all of that, where does the remaining bill go? We split every dollar our teams spent from October 28 to November 3, $2,225 in all.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1WbkyPM4p6JCRAfYQvUSWw.png" /><figcaption>Of every $100 we still pay, $21 goes to cache rewrites and $14 to side calls with no tools.</figcaption></figure><p>The biggest slice, 27%, is reading the context that is already cached. That is the cost of carrying a big bag, and only a smaller bag shrinks it. Output, the model’s own answers, is another 20%, and we leave it alone.</p><p>The slice we care about most is <strong>cache rewrites after a pause: $365, 16% of the bill</strong>. Add the rewrites when a new agent starts its conversation and after a changed prompt, and cold caches take $470 of the $2,225, about one dollar in five. (The middle column in the figure is the same split for November 4 alone.) Rewrites for any reason other than time, such as a changed tool list or a switched model, were only 1%. Waiting is what empties the cache.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jYOktF6ez9md59RwHVKGAA.png" /><figcaption>After a 5 to 15 minute break, a ping turns a cold return into a warm one.</figcaption></figure><p>Pings help on short breaks. After a break of 5 to 15 minutes, 6% of pinged returns (the first request after the break) found a cold cache, against 89% when no ping was sent.</p><p>This was not a controlled test, but the gap holds for small, medium and large contexts alike (329 such breaks on November 1, 2 and 4). Past fifteen minutes, most returns are cold either way.</p><p>The bigger the context, the more a cold return hurts.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2xfn8rSmJliF_A2SY3vpWA.png" /><figcaption>The bigger the context, the more a cold return costs.</figcaption></figure><p>Past 400,000 tokens, a warm turn costs about 12 cents and one cold return costs $2.44, the price of 21 warm turns at that size.</p><h3>Does it hurt accuracy?</h3><p>Cache management never changes what the model reads. A ping is a separate request, and the agent’s own requests pass through untouched. We checked 93 requests, and all 93 came out byte for byte the same.</p><p>The other three trim and compact, so they do change what the model sees. We tested the conservative preset on coding tasks and saw no loss. In 32 of 32 runs with long pauses the answer was correct, 48 of 48 short bug fixes were solved (as they are without Context Guru), and 18 of 18 long sessions that we stopped and resumed ended with the full test suite green. The samples are small, so read this as no sign of harm rather than proof.</p><p>We have not run the same tests on the deeper presets that our own teams opted in to. That is why trimming is opt-in, while cache management is on by default. The dashboard shows every edit Context Guru made, request by request, and /context-guru:save-more shows you what a setting would have done on your own sessions before you turn it on.</p><h3>Two things that surprised us</h3><p>Two things we did not expect, from our own deployment (October 28 to November 4, priced at list).</p><p><strong>1. A 95% cache-hit rate can hide a big bill.</strong> Think of a café that sells 95 coffees and 5 steaks: the steaks are where the money is. On our deployment, 95% of prompt tokens were read from the cache. Yet one dollar in five went to rewriting a cold cache, and for the biggest sessions it was nearly half.</p><blockquote>A token that misses the cache costs 25 times one that hits, so the 5% of prompt tokens that miss the cache set the bill.</blockquote><p>Track the dollars spent on rewrites instead of the hit rate. The band and the heatmap below both do.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*dCv_XBYAw1I15ZWAiR6K9g.png" /><figcaption>The real cache-miss heatmap from our deployment, November 1 and 2 (UTC): 556 misses cost about $281.</figcaption></figure><p><strong>2. When you cut matters more than what you cut.</strong> Across the deployment, simple rules that trim tool output as it arrives saved $8 over six days. The sweep, which cuts when the cache has gone cold and the rewrite is paid for anyway, saved $64. (The $19 in the best session came from the deep preset’s cuts, a third kind.) Get the timing right first.</p><h3>What we’re working on now</h3><p><strong>First: cache control for the models you run yourself.</strong> vLLM and llm-d already reuse cached prefixes and route requests to where the cache lives. What we did not find is a way for the agent’s side to say how long a cache should live, or to compact on the server. We want to help add both.</p><p><strong>Cortex as our proxy, and a much bigger experiment.</strong> <a href="https://github.com/rossoctl/cortex">Cortex</a> is an open-source proxy for coding agents, built in the same organisation as Context Guru. You install one program on your laptop, point your agent at it, and watch every model call, tool call and dollar the agent spends, live. It already connects to Claude Code, OpenCode, Codex, IBM Bob and Pi, and to any agent that can use an HTTPS proxy. Your traffic stays on your machine: Cortex decrypts it with a certificate made locally, passes it through a chain of plugins, and sends it on to the server your agent asked for.</p><p>That plugin chain is where Context Guru fits. Cortex already ships an opt-in Context Guru plugin that trims an agent’s requests before they leave the machine, and we are building the rest of Context Guru into it (<a href="https://github.com/rossoctl/context-guru/issues/619">#619</a>). The two divide the work well. Cortex handles the connection to each harness and shows people what they spend. Context Guru decides what to carry and when to keep the cache warm. The same Cortex binary also runs as a sidecar on Kubernetes, so the setup that runs on a laptop can run for a whole team.</p><p>With Cortex as the front door, we want to take the experiment in this post from our own teams to a much larger group across IBM Research and Red Hat. More people and more kinds of work will show which of these savings hold up, which strategies to change, and where the next dollar is.</p><p><strong>More agent harnesses.</strong> Most of what you read here was measured on Claude Code. We are now adding integrations for more harnesses. <a href="https://opencode.ai/">OpenCode</a> is an open-source agent that is common at Red Hat. IBM Bob is IBM’s own coding agent, where every saving goes straight back to IBM’s bill. The cache rules differ from one harness to the next, so each integration brings its own lessons, and we will report them as we go.</p><p><strong>A like-for-like comparison of context tools.</strong> <a href="https://github.com/rtk-ai/rtk">RTK</a>, <a href="https://github.com/headroomlabs-ai/headroom">Headroom</a>, <a href="https://github.com/JuliusBrussee/caveman">caveman</a>, Context Guru and others each report savings on their own workloads, and we found no like-for-like comparison. We are building a library that runs them all on the same recorded sessions and tasks and measures what each feature is worth, in dollars and in accuracy.</p><p><strong>A cache-aware router for reasoning effort.</strong> Reasoning effort is how long the model thinks before it answers. Thinking harder costs output tokens, and many turns do not need it. Some current models now let you change effort mid-conversation without losing the cache. On the Claude API this is a beta setting on some models, and OpenAI documents a similar path. Changed the usual way, effort starts the cache over. We are building a router that lowers effort when it can, only through the cache-safe path, with as little effect on accuracy as possible.</p><h3>Try it</h3><p>In Claude Code:</p><pre>/plugin marketplace add rossoctl/context-guru<br>/plugin install context-guru@context-guru<br>/reload-plugins<br>/context-guru:install</pre><p>Other setups, including Codex and your organisation’s hosted instance, are in the <a href="https://github.com/rossoctl/context-guru#install">install guide</a>. Work as usual for a few days, then run /context-guru:insights to see what happened. Not sure which setting to pick? /context-guru:save-more replays your own sessions before you change anything.</p><p>If your sessions look different from ours, we want to know how. Open an issue, and if Context Guru saved you money, <a href="https://github.com/rossoctl/context-guru">star the repo</a>.</p><p><em>Written with David Amid, Itay Nakash, David Boaz, Vitaly Zabershinsky, Guy Uziel and Ateret Anaby-Tavor, the Context Guru team at IBM Research.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=770f099aedd2" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>