All posts
May 3, 2026·9 min read
Agent MemoryState ManagementWorkflow DesignProduction

Agent Memory in Production: Building State-Aware Workflows That Don't Start From Scratch

Published: May 3, 2026

Every time a stateless AI agent runs, it starts from zero. It re-reads the codebase. It re-fetches the requirements. It re-derives context it derived identically in the last five runs. This isn't a model limitation — it's an architecture choice. And it's one of the biggest sources of unnecessary cost and latency in production agentic systems.

Memory isn't a single feature. It's a design layer that sits between your workflow nodes and your model calls. Get it right, and your agents behave like experienced teammates who remember what happened last week. Get it wrong, and you're paying full-price inference on work you've already paid for.

This post covers four production memory patterns, when to use each, and how to wire them into visual workflow designs.


Why Statelessness Is the Default — and Why It's a Problem

The default LLM call is stateless by design. You send a prompt, you get a response, nothing persists. This is correct for isolated tasks. It becomes expensive when:

  1. The same context is relevant across multiple runs — project structure, coding standards, team conventions
  2. Workflow steps accumulate results — each step builds on what the previous step discovered
  3. Long-running tasks exceed context window limits — you need to summarize and compress, not truncate

The cost impact compounds quickly. Consider a code review workflow that runs 20 times per day. If each run spends 4,000 tokens loading repo structure that hasn't changed, that's 80,000 tokens per day of pure overhead — before any actual review work begins. At frontier model prices, that's $0.40–$2.00/day in waste on one workflow alone. Across a team of 10 running multiple workflows, the overhead becomes non-trivial.

The solution isn't to stuff everything into a system prompt and hope. It's to apply the right memory pattern to each part of the workflow.


Pattern 1: Session Context — In-Memory State Within a Single Run

What it is: Data passed between workflow nodes within a single execution, without persisting to any external store.

When to use it: When context is relevant across multiple steps in one run, but has no value after the run completes.

How it works in a visual workflow:

Each node in your workflow can write to and read from a shared execution context object. In AgenticNode, this is the node data store — a typed key-value store that travels with the workflow execution.

```

[Input Node] → writes: { repo_url, branch, pr_number }

[Fetch PR Node] → reads: pr_number → writes: { diff, changed_files, pr_title }

[Classify Node] → reads: diff → writes: { risk_level, categories }

[Review Node] → reads: diff + risk_level → writes: { review_comments }

[Output Node] → reads: review_comments

```

Each node receives exactly what it needs — nothing more. The review node doesn't need to re-fetch the PR; it reads from context. The output node doesn't need to call the model again; it formats results from context.

What this eliminates: Redundant API calls, repeated model calls for data already in-hand, and the token cost of passing full context through every prompt when only a subset is needed.

Overhead: Near-zero. This is standard workflow data flow, not a new infrastructure component.


Pattern 2: External Memory Stores — Persistent Knowledge Across Runs

What it is: A database (vector store, key-value store, or structured DB) that agents can read from and write to across multiple workflow executions.

When to use it: When knowledge accumulates over time and is reusable across runs — project context, previously-resolved issues, coding conventions, team preferences.

Common implementations:

Store TypeBest ForExamples
Vector storeSemantic retrieval ("find relevant past fixes")Pinecone, pgvector, Chroma
Key-value storeFast lookup by known keyRedis, Supabase, Upstash
Relational DBStructured query ("all P0 issues in the last 30 days")Postgres, SQLite
Document storeRich structured contentSupabase jsonb, MongoDB

Workflow integration pattern:

A code review workflow with an external memory store might look like:

```

[Input Node]

[Memory Retrieval Node] — vector search: "past issues similar to this diff"

↓ returns: 3 most relevant historical reviews

[Review Node] — prompt includes: diff + retrieved historical context

[Memory Write Node] — stores: this review summary + resolution for future retrieval

[Output Node]

```

The key design principle: retrieval and write nodes are separate and explicit. Don't hide memory operations inside prompt engineering — make them visible workflow steps. This makes debugging easier and gives you granular cost visibility.

Token impact: A vector retrieval returning 3 relevant summaries (~500 tokens total) replaces potentially 10,000+ tokens of re-derived context. The retrieval call costs a few milliseconds and cents. The savings compounds across every run.

What this requires: A persistent store with write access, and a consistent schema for what you're storing. Define your memory schema before you need it — retrofitting is painful.


Pattern 3: Workflow Checkpoints — Long-Running Task Recovery

What it is: Serialized workflow state saved to persistent storage at defined intervals, enabling resumption after failure, timeout, or context window exhaustion.

When to use it: For workflows that run longer than a few minutes, use multiple model calls in sequence, or need to survive infrastructure interruptions.

The problem without checkpoints:

An agentic refactoring workflow running for 20 minutes hits a rate limit at step 14 of 20. Without checkpoints, you restart from step 1. With checkpoints, you resume from step 14. At $0.02+ per run for large workflows, this matters operationally.

How checkpoints work:

Every node execution result is serialized and stored with the workflow run ID and a step sequence number. On failure, the orchestrator reads the last successful checkpoint and resumes from the next step.

```json

{

"run_id": "review-pr-1847-20260503",

"step": 7,

"status": "completed",

"node": "implement-fixes",

"output": { "files_modified": 3, "patches": [...] },

"timestamp": "2026-05-03T09:14:22Z"

}

```

Context window management via checkpoints:

For workflows that exceed a single context window, checkpoints provide the natural break points for context compression. At each checkpoint, you can:

  1. Summarize completed steps into a compact progress object
  2. Clear the in-context history
  3. Re-initialize the next step with the compressed summary

This is how production agentic systems handle hours-long tasks — not by extending context infinitely, but by compressing and forwarding strategically.

Storage overhead: Checkpoint records are small (typically 1–10KB per step). At 1,000 workflow runs/day with 10 steps each, that's 10–100MB/day of checkpoint data — manageable with any standard database.


Pattern 4: Context Compression — Summarizing What You've Learned

What it is: A dedicated model call that distills accumulated context into a compact, high-signal summary before passing it to the next workflow stage.

When to use it: When context has grown large enough that passing it verbatim would be expensive or would exceed limits, but discarding it would lose important signal.

The naive approach vs. the compression approach:

Naive: Pass the full conversation history + all node outputs to every subsequent node. Context window grows linearly with workflow depth. Token cost explodes.

Compression: After every N steps (or when context exceeds a threshold), run a summarization node. The summarizer's job is to extract the key facts, decisions, and findings into a structured summary object.

```

[Steps 1-5: Analysis Phase]

[Summarizer Node]

prompt: "Summarize these findings into: risk_level, key_issues[],

decisions_made[], context_for_next_phase"

output: ~200 tokens of structured summary

[Steps 6-10: Implementation Phase]

receives: 200-token summary, not 3,000-token raw history

```

What to include in a good compression summary:

  • Decisions made — what was chosen and why (brief)
  • Blockers encountered — what was tried and failed, to prevent re-trying
  • Key findings — the output of analysis that informs subsequent steps
  • State facts — current file state, API responses, environmental context

What to omit: reasoning chains, intermediate attempts, redundant observations. The compressor should ask: "What does the next step actually need to proceed?"

Token math: A 3,000-token context compressed to 200 tokens, passed across 5 subsequent nodes, saves 14,000 tokens (3,000 - 200 × 5 additional loads). At Sonnet 4.6 input pricing, that's a non-trivial saving per run.


Combining the Patterns: A Production Code Review Workflow

Here's how all four patterns work together in a realistic workflow:

```

[Trigger: PR opened]

[Memory Retrieval] — external store: "project conventions, past similar issues"

↓ returns ~400 tokens of relevant context

[Fetch PR Node] — session context: stores diff, changed_files, pr_metadata

[Risk Classification] — reads: diff + retrieved context → writes: risk_level

[CHECKPOINT 1] — saves: retrieved_context, diff_summary, risk_level

[Review Node] — reads: diff + retrieved_context (from session, not re-fetched)

— prompt: ~1,800 tokens (compressed context, not 6,000)

[CHECKPOINT 2] — saves: review_comments

[Compressor Node] — distills review into 150-token structured summary

[Memory Write] — stores: compressed summary for future retrieval

[Output Node] — posts review comments to PR

```

Compare this to the naive implementation:

  • Naive: ~8,000 tokens per run (re-fetching everything, no compression)
  • Memory-optimized: ~2,400 tokens per run (retrieval, compression, no redundancy)
  • Saving: ~70% token reduction, faster runs, recoverable on failure

Making Memory Visible in Your Workflow Design

The single most important principle for production memory systems: make every memory operation an explicit node, not a hidden prompt trick.

When memory reads and writes are visible in your workflow graph, you get:

  • Debuggability: You can inspect exactly what was retrieved and stored at each step
  • Cost visibility: Memory operation nodes have their own timing and token counts
  • Testability: You can mock the memory store in test runs without changing the workflow logic
  • Iterability: You can tune retrieval parameters (top-k, similarity threshold) without touching the model prompts

When memory is buried inside prompt engineering — "always look up X in the system prompt" — debugging becomes guesswork. In a visual workflow editor, what's visible is what's maintainable.


Practical Starting Point

If you're adding memory to existing workflows, start with session context — it's zero infrastructure overhead and immediately reduces redundant model calls within a run. Move to external stores when you identify specific knowledge that's reused across multiple runs. Add checkpoints when workflow duration or cost makes restart-from-zero unacceptable.

The goal isn't to build the most sophisticated memory architecture. It's to eliminate the work your agents are currently redoing on every run. Start there, measure the token impact, and add complexity only where the numbers justify it.

Build your first agentic workflow

The visual workflow editor is live. Design, execute, and observe multi-agent pipelines — no framework code required.

Open Editor