/pattern/working-memory/

04 · ProductionMemory ArchitectureScratchpadShort-Term StateTask State

Working Memory / Scratchpad.
Per-task notes the agent keeps while it reasons.

A temporary working state holds intermediate steps, variables, and open tasks during a single execution run.

In practiceA code-review agent writes intermediate findings — duplicate logic found, security issue noted — to a scratchpad state field, then collates all findings into a final report at the last step.

When to reach for it

  • Multi-step tasks require tracking intermediate states.
  • Tool results will be referenced later.
  • Reasoning must be traceable separately from execution.

When it backfires

  • The task is atomic.
  • Intermediate thoughts contain sensitive data that cannot be stored.
  • Persistence across runs is required.

The tradeoff

Better control during a single run is gained against the need for additional state management logic.

The effect

What it actually does.

A short-lived scratchpad held across the steps of one task.

scratchscratchpadreuse
Pitfalls

Two ways this pattern will hurt you.

Scratchpad leaks into the final answer

The model treats its own thinking notes as part of the response and emits the chain-of-thought to the user.

Fix · Hold scratchpad in a typed state field separate from the message channel. Render only the explicit final-answer field downstream.

Parallel branches clobber shared working state

Two fan-out branches write the same scratchpad key in one super-step. Last-writer-wins silently discards one branch's result and the run continues on half the data.

Fix · Give concurrent branches an append/reduce channel or per-branch namespaces, never a plain overwritten field; merge deterministically when they join.

Framework support

Where Working Memory / Scratchpad is native.

LangGraphLangGraph StateNative
OpenAI Agents SDKrun context objectNative
Microsoft Agent Frameworkthread stateNative
AutoGen / AG2shared agent stateNative
Google ADKsession stateNative

Search

Search patterns, frameworks, and pages.