Skip to main content
A workflow step-result cache stores a step’s output keyed by its inputs, so a deterministic step reuses its answer instead of paying the full LLM cost on every run.
This caches entire step outputs inside the workflow, keyed by each step’s actual inputs. It is different from Prompt Cache Optimization, which caches prompt prefixes at the LLM provider.

Quick Start

1

Enable with True

Pass cache=True for a process-scoped LRU cache (default max_entries=128).
2

Tune the cache size

Pass an InMemoryStepCache instance to set capacity or share one cache across flows.
3

Bring your own cache

Any object with get() and set() works — back the cache with Redis, disk, or anything else.
InMemoryStepCache is not re-exported at the top level. Import it from praisonaiagents.workflows.step_cache.

When to Cache

Cache deterministic steps; skip steps that call tools with side effects, read a clock, or depend on randomness.

How It Works

On a miss the step runs and its output is stored; on a hit the cached output is returned without an LLM call. The key is a stable SHA-256 (first 32 hex chars) built from four fields:
Variable types are part of the key, so True and "True" (or 1 and "1") never collapse to the same entry. Two runs with the same prompt but different variables are different calls.

Correctness Guarantees

Nothing caches unless cache= is set. Agent steps are not always deterministic, so silent caching would be wrong.
Only successful steps are stored. Caching a failure would serve it again on every re-run, turning a transient error into a permanent one.
The linear executor and the pattern executor (used by Parallel, If, etc.) are both wrapped, so caching works regardless of where a step sits.
InMemoryStepCache caps at max_entries (default 128). An unbounded cache would be a memory leak on long-running flows.
InMemoryStepCache uses an internal lock, so it is safe to share across Parallel branches.
Values are deep-copied on set and on get, so a caller mutating a returned value cannot corrupt future hits.
On a cache hit, both output and the step’s output_variable (or {step_name}_output) are restored, so downstream {{step_name_output}} substitutions still resolve on a fully-cached re-run.

InMemoryStepCache Options

Public attributes: hits, misses. Public methods: get, set, clear, __len__. Accepted cache= values:

Seeing Cache Hits

Turn on verbose to print a line for each hit.

Best Practices

Formatters, lookups, and summarisers over unchanged text are safe. Their output depends only on their input.
Do not cache steps that call tools with side effects or read a clock — a cached answer would skip the effect the caller expected.
Create a single InMemoryStepCache and pass it to multiple AgentFlows to reuse results across pipelines.
Change a workflow variable when you want a fresh call — different variables produce a different key.
Set max_entries to the number of results you actually reuse; a larger cache only wastes memory.

Workflows

Build multi-step agent pipelines with AgentFlow.

Prompt Cache Optimization

Different layer — provider prompt-prefix caching.