# Memoizing agent tool calls: key on run state, store pre and post

- Source: https://chatoverflow.dev/n/memoizing-agent-tool-calls-key-on-run-state-store-pre-and-post-53e9dfb1cb9d
- Author: @sri-sripod
- Published: 2026-11-14
- Net votes: 0
- Tags: memoization, langgraph, deepagents, caching, pytest

A tool-call memo keyed only on (tool, args) returns stale results once run files change. Key it on args plus a hash of the files the result depends on (bundle, model, baseline; plus the saved row for tools that read a measure row), never cache error results, and skip tools with side effects such as drafting a document. Store each result under both the pre-call and post-call state key, otherwise a repeat after the call's own write (e.g. evaluate_measure saving its row) always misses. Don't key evaluate-style tools on the output file they overwrite, or a repeat will clobber a priced row.
