Build1 publisher2 min readPublished
Agent-cache's tool cache returns the first ticket's ID when the tool writes instead of reads
The library puts LLM completions, tool results and session state behind one Valkey or Redis connection. Its tool keys are a function name plus an argument hash, and the post says that breaks for tools that mutate state.
The Engineer · Build desk

What happened
- Agent-cache backs three cache tiers with Valkey or Redis, putting LLM responses, tool results and session snapshots behind a single connection.
- Version 0.1.0 shipped with Valkey 7+ and Redis 6.2+ support, and v0.2.0 added cluster mode the following day.
- The library ships adapters for LangChain, LangGraph and the Vercel AI SDK, with OpenTelemetry and Prometheus instrumentation wired in at the cache layer.
- Invalidation is manual: the library tracks no dependencies between entries, and cache.invalidate(pattern) takes Redis glob patterns the caller has to identify.
- If Valkey or Redis goes away, the default is graceful degradation straight to the LLM or tool, and the behaviour is configurable per tier.
Compiled by The EngineerSomething wrong?How this is made
Why it matters
- constraint A team still tuning prompts gets the least from tier 1, because every system-prompt edit and every temperature change resets the hit rate to zero until traffic reaccumulates.
- exposure Any tool that writes becomes a correctness risk the moment it is cached, since the second caller gets the first caller's record back instead of a new one.
- contradiction The post's cost case and its differentiation case point at different tiers. The two layers it adds beyond LangChain are left arguing on latency and resumability.
- cost Adoption presumes an existing Valkey or Redis deployment, so the price is another shared dependency in the agent's request path, paid by whoever carries the pager for it.
Under 1ms is the read time on an exact-match hit, measured against a call that would otherwise go to the API [5]. It describes the hit path. Whether it transfers to your agent depends on the hit rate, and the post does not report one, nor a measured token saving [18]. The LLM key is a hash of the prompt plus the model name, the temperature and the top-p [7]. Change any of those and every entry behind it is unreachable [7]. Exact-match caching rewards a frozen prompt, which is an odd thing to ask of a system you are still tuning.
The tool tier keys on the function name and a hash of the arguments object [8]. For a database lookup or a stable read API, the key is right [8]. For a write it is a defect: the post's own example is create_ticket(title, description), where a cached result comes back with the old ticket ID instead of creating a new ticket [8].
Each tier gets its own TTL strategy: LLM responses for hours when the model and prompt are stable, tool outputs sooner because the upstream data changes, session state only while the user session is active [10]. OpenTelemetry spans track hits, misses and errors, and Prometheus exposes hit rate, latency and connection pool health at the cache layer [13].
The LangGraph adapter is the piece I would adopt first. It implements BaseCheckpointSaver and persists checkpoints to Valkey instead of requiring Redis 8 with modules [14]. Checkpoints serialize as MessagePack to save space, while the LangChain path uses JSON for LLM responses [15].
The post positions tool and session caching as the layers other libraries skip, since LangChain caches completions and LangGraph persists checkpoints [4]. It also calls the LLM tier the biggest token saver when agents retry or loop over similar prompts [6]. Those two statements point in different directions. The token case sits in the tier LangChain already covers, so the two added tiers rest on latency and on checkpoints, user intent and execution state that can resume mid-flow [17][9].
The Vercel AI SDK adapter hooks streamText and generateText, and the post lists streaming support as roadmap, not shipped [14].
What to watch
- Whether tool entries gain a declared read/write flag so a mutating call cannot be cached by default.
- A published hit rate from a production agent loop. That number would decide whether tiers 2 and 3 pay for themselves.
- Whether LangGraph shops already running Redis 8 with modules move their checkpoints onto Valkey.