Tool Use & Environment

Tool Result Caching

Cache the result of expensive deterministic tool calls keyed by their arguments so repeat calls within a session return immediately.

Problem

Repeat calls on identical arguments pay full latency and full per-call cost every time, even though the result has not changed and the tool author would gladly serve it from a cache. The agent's loop is structured one call at a time and has no awareness of caller history, so the same lookup gets re-fetched whenever a different reasoning step happens to need it. Caches written naively can leak results across users when caller identity is not part of the key.

Solution

Wrap deterministic tools in a cache layered on `(tool_name, normalised_args)`. Set TTLs by tool type. On cache hit, return immediately without invoking the underlying tool. Per-user scoping for tools that read user data; global for read-only public data. Cache keys must include the auth subject (caller identity), not just args; args-only keys leak data when callers change.

When to use

  • Agents re-call the same tool with the same arguments multiple times within a task.
  • Tools are deterministic enough to cache by normalised arguments.
  • TTL and per-user vs global scoping can be defined per tool.

Open the full interactive page

Diagram, neighbourhood map, code examples, related patterns and full provenance.

Related