Turning Trajectories into Memory: How AI Agents Learn from Experience

⭐️This is Day 11 of the JAPAN AI Advent Calendar 2025⭐️
Self Introduction
I’m Avinash, and I lead the JAPAN AI Lab team. Our job is to take what’s happening at the frontier of agentic AI research and figure out what actually can be incorporated into our platform and move the needle for customers.
Today I’d like to talk about memory for AI agents- one of the few levers we can tune without touching model weights, simply by changing what goes into the context window: system prompts, retrieval, tools, memory, and history. Lately, at JAPAN AI Lab we have focused on what makes a good memory for our agents and how to reuse past experience over time, drawing on ideas from reinforcement learning and neuroscience.
1. Introduction – Why Memory for AI Agents Is Hard
Almost everyone who has deployed an agent in production has seen the same pattern: sharp in the first few turns, increasingly forgetful as conversations and projects get longer. In enterprise settings, where projects span months and business logic changes constantly, an agent that forgets how your organization works creates real risk.
Scaling up context windows and just adding previous conversations/turns helps, but only to a point. LongMemEval shows that chat assistants can lose around 30% accuracy when operating over realistic multi‑session histories instead of short excerpts (Wu et al., 2024). At the same time, a growing ecosystem of memory systems - Mem0, Zep, MemGPT, ENGRAM, and others - publish strong benchmark numbers under different evaluation pipelines, making comparisons difficult.
For us at JAPAN AI, this is not abstract. In August 2025, we shipped Agent Memory (“エージェントメモリー”) as a feature of our AI agent products (JAPAN AI, 2025). It lets agents remember conversation contents, thought patterns, and work styles, and accumulate user insights as an organizational asset.
Building this feature forced us to confront three questions:
- What do we mean by “memory”? Is it just longer context, or something closer to human episodic, semantic, and procedural memory?
- How should we evaluate it? Benchmarks are valuable but fragile-small pipeline choices swing scores by double digits.
- How should enterprise platforms actually implement memory? We need systems that are observable, governable, and robust to real‑world constraints.
This post organizes that space: a taxonomy grounded in cognitive science (Section 2), why we focus on memory
extraction
rather than storage formats (Section 3), reflection‑style methods on a concrete task (Section 4), case‑based reasoning and learnable selectors (Section 5), and where we think agent memory is heading (Section 6).
2. A Simple Lens for Agent Memory
Most systems that claim “memory” are really just larger prompts or RAG over recent turns. We distinguish three timescales—ephemeral (current prompt), task‑level (a single episode), and cross‑task (survives across runs)—and this post focuses on cross‑task memory.


Within cross‑task memory, we separate what the memory contains. Building on Tulving’s taxonomy (Tulving, 1972), we use:
- Episodic → concrete trajectories (“what happened on this run”).
- Semantic → de‑contextualized facts (“approval chain is X → Y → Z”).
- Procedural → reusable playbooks (“for PDF→DOCX, do X, then Y, then Z”).
- Associative → cue–value links (user profiles, task similarity scores).
The card‑style example in Figure 2 shows how these ideas become a single structured memory item with playbook steps, rules, notes, and context metadata.


Where memory lives and who consumes it.
Parametric memory in the model weights gives broad priors but is hard to update. Our focus is external memory in stores that can be inspected, edited, and deleted. Planner components mainly consume cross‑task semantic and procedural items, executors use short‑term episodic context plus a few targeted procedures and rules, and teacher components read trajectories and write back new playbooks, rules, and notes.
The rest of the post focuses on how those teacher components produce structured memories from trajectories, how our retrieval policies choose which items to surface, and how this plays out on a concrete OfficeBench task (2‑7:0).
3. Our Focus: Memory Extraction
Benchmarks like LoCoMo and LongMemEval (Maharana et al., 2024; Wu et al., 2025) are useful stress tests for long‑term conversational memory. LoCoMo builds very long, persona‑grounded multi‑session chats from temporal event graphs and asks models to answer questions or summarize specific events scattered across them. LongMemEval implants hundreds of QA items and their supporting evidence into user–assistant histories, with filler sessions that create “needle‑in‑a‑haystack” retrieval and reasoning tasks. These settings mostly treat memory as recovering the right snippet from synthesized or heavily curated conversations; our agents spend most of their time on tool‑heavy workflows (editing documents, running scripts, orchestrating APIs) that are barely represented, and small pipeline changes can still swing scores by double digits—so we treat these benchmarks as regression tests, not scoreboards. Likewise, memory layers like Mem0, Zep, MemGPT/Letta, and ENGRAM solve important infrastructure problems, but the harder question for enterprise agents is not where you put memory but what you decide to store and why.
The rest of this post therefore focuses on memory extraction: turning noisy episodes into reusable procedures and failure patterns, selecting useful past episodes for the case‑based reasoning layer, and learning simple policies that choose which cases to surface from the case bank (Section 5). These techniques are largely orthogonal to the storage backend—you can implement them on top of most modern agent stacks.
4. Reflexion-Style Memory: Agents That Learn from Their Own Trajectories
So far, we have mostly discussed where agents store information and how long they keep it. Reflexion‑style methods ask instead how agents learn from their own trajectories.
In Reflexion (Shinn et al., 2023), once an agent finishes a task a separate “reflection” phase uses an LLM to analyze the trajectory (actions, thoughts, observations) and produce natural‑language feedback, with critiques such as “I wasted too many steps retrying the same tool; next time, verify the input format first.” The next episode conditions on this feedback, turning it into a form of verbal reinforcement learning.
In terms of our taxonomy, Reflexion operates at the task‑level and cross‑task scales: it turns episodic trajectories into procedural and semantic feedback, stores that feedback externally, and lets later planners and executors consume it without changing the base model.
4.1 A Running Example: OfficeBench PDF→DOCX
To make the rest of this section concrete, we will keep returning to a single Office‑style task from the OfficeBench benchmark:
Problem 2‑7:0: “Extract key points from paper.pdf, summarize them in paper.docx, and save it for reference.”
This task exercises exactly the failure modes that matter for enterprise workflows:
- Multi‑step tool use (shell → pdf → word → llm),
- Brittle error messages and malformed‑action loops
- A flaky PDF→Word conversion tool that sometimes raises a tool_execution_error
All of the reflection and memory experiments that follow reuse this same task as a running example: we will see how different teachers-Reflexion, Agent‑KB, and AgentDebug-write down different kinds of guidance from the same trajectories, and how those items change behavior when we actually retrieve and inject them.
4.2 From Trajectories to Structured Memories
In our experiments, the most useful artifacts are not free‑form critiques, but structured memories with a simple, human‑readable schema. We converge on three main fields:
- playbook (“do X, then Y, then Z”): a short, step‑by‑step procedure that should generally work for similar tasks.
- rules (“if you see A, avoid B, prefer C”): crisp constraints, failure modes, and guardrails extracted from what went wrong.
- notes (“optional hints and caveats”): looser observations and tips that do not rise to the level of a rule but are still worth surfacing.
Each memory item also carries
context
(task type, tools, domain, timestamps). Figure 3 shows how these items fit into a simple “Act → Review → Remember” learning loop.

This process gives us Agent‑KB–style memories: each playbook, rule, and note becomes a first‑class, inspectable object with natural‑language text, metadata, and links to source trajectories, similar to the artifacts produced in Reflexion‑style work (Shinn et al., 2023) and Agent‑KB / AgentDebug‑style procedures and failure‑mode reflections (AgentErrorTaxonomy / AgentErrorBench / AgentDebug, 2025). In our experiments, “playbook + rules + notes + context” has been expressive enough while staying easy to audit and edit, and it feeds both knowledge retrieval (for planners and executors) and learning (for selectors) without committing us to any specific storage backend.
On our running OfficeBench task (2‑7:0), a reflection‑only profile that uses this schema but does not feed anything back into the executor still populates the memory store with reusable procedure‑ and rule‑shaped objects for future runs on similar Office‑style tasks.
4.3 Offline Scheduling: Which Episodes Deserve Reflection?
Running reflection on every episode is usually too expensive, so we treat it as an offline job over recorded trajectories: agents log episodic traces with outcomes and basic metrics; a scheduler periodically samples failures, near‑misses, and surprising successes; and background jobs write new memory items and telemetry. This creates human‑readable artifacts (procedures and failure patterns) that are easier to audit than raw embeddings and gives us a natural hook for quality assurance via optional human review of individual memory items.
The next question is how to use these memories effectively at inference time. Before we turn to case‑based reasoning and learned selectors, it is helpful to look at how different teachers write down guidance for our running OfficeBench example, and what happens when we retrieve and inject that guidance.
4.4 Three Teachers on the Same Task
We apply three teacher templates-Reflexion, Agent‑KB, and AgentDebug-that all write to the same schema (playbook, rules, notes). For example, an Agent‑KB–style teacher extracted the following from a spreadsheet‑to‑document OfficeBench task:
Problem: Copy shopping items from shopping_list.xlsx to shopping_list.docx
Failure mode: Overwrote the original spreadsheet without backup.
Fix pattern: Always create a timestamped backup before read/write operations.
Together, these teachers produce procedures (recipes for success), rules (guardrails and failure modes), and playbooks (recovery narratives) that can be retrieved and shown to future agents.
4.5 A Concrete Office-Style Task: When Static Playbooks Are Not Enough
We then ran three variants of the same underlying agent policy on this OfficeBench problem, shown side‑by‑side in Figure 4.

- Baseline executor (no long‑term memory).
- The agent repeatedly issued malformed tool calls (for example, mis‑formatted llm.complete_text actions), got stuck in an error loop, and ultimately failed the task.
- The failure trace consumed 50,011 tokens with no usable paper.docx at the end.
- Executor + static playbooks and rules (no teacher replan).
- We enabled knowledge retrieval against a pool of Agent‑KB–style procedures seeded from prior Office‑like tasks. For this PDF‑summary problem, the agent retrieved five procedures with similarity 0.72–0.83 and reliability 0.85, and we injected their playbooks and rules into the executor’s prompt.
- Despite having these high‑quality suggestions available, the agent still fell into a malformed‑action loop and failed after 50 steps, consuming 100,761 tokens. Static guidance alone did not reliably change behavior.
- Executor + playbooks, rules, and a teacher‑style replan.
- In the full configuration, we kept the same knowledge retrieval and playbooks but added a Reflexion‑style teacher that could trigger another planning cycle when things went wrong. The teacher compared the original plan with the observed trajectory, generated additional rules and a revised playbook, and injected a second round of guidance before re‑executing.
- In this setup, the agent solved the task in 13 steps: it listed /testbed/data, opened paper.pdf, summarized it, created paper.docx, and wrote the summary. Total token usage: 23,805 (combined planner, executor, and replan)-a 4× reduction from the static-playbooks failure.
For us, this experiment reinforced two points:
- Playbooks and rules are necessary but not sufficient. Having good procedural memory does not guarantee good behavior if the agent cannot recognize that its current plan is failing.
- Teacher‑style replanning matters. A separate reflection stage that can revise the plan and re‑inject guidance-rather than only supplying static hints-was what actually changed the agent’s behavior and cost profile on this task.
The next section looks at how we layer case‑based reasoning and learnable memory selection on top of these reflection‑generated memories and our raw episodic logs.
5. From Case-Based Reasoning to Learnable Memory Selection
Once we have a pool of structured memories from reflection (playbooks, rules, notes) and a growing bank of raw episodes (state, action, reward), we still need to decide which pieces of history to surface for a new task. In our system, reflection and case‑based reasoning are separate: reflection runs offline and writes memories; at inference time, a case‑based layer reads from both stores and selects a small set of cases for the planner and executor.
The OfficeBench example showed that what we inject and whether we can replan both matter. In AppWorld‑style profiles we focus on the selection problem itself: given many past episodes and procedures, which few should guide the next plan, assuming reflection has already written whatever structured memories we care about?
5.1 Heuristic Case-Based Retrieval
Our case‑based reasoning layer treats each past episode as a “case” and each procedure as a “knowledge chunk.” Given a new task, we:
- embed the current task state and description into a vector;
- search a case bank of raw episodes (state, action, reward) and structured items, filtering candidates by coarse metadata (domain, tools, task type);
- score candidates by similarity (e.g., SimCSE cosine), recency, and reliability, then surface the top‑k as few‑shot episodes (for the planner/executor) and high‑level hints (from procedures and rules).

In the simplest, non‑parametric mode, we rank cases purely by embedding similarity and a few hand‑tuned weights for recency and reliability. This is cheap, easy to debug, and already avoids many repeated mistakes once failure‑mode cases exist in the bank.
5.2 Memento-Style Learned Selectors
Inspired by Memento (Agent‑on‑the‑Fly, 2025), we add an optional neural case‑selection policy on top of heuristic CBR. For each task, we know which cases (episodes, procedures, rules) were retrieved and which ones were actually helpful (for example, appeared in the context of a successful run or were echoed in reflections). We treat helpful cases as positives and unused or harmful cases as negatives, and train a small selector model (logistic regression or a shallow neural net) to estimate
Q(current_state, candidate_case) → “how helpful is this case?”
The selector never writes new memories or changes the base LLM; it only re‑ranks or gates heuristic CBR candidates (for example, as a parametric head on top of the non‑parametric SimCSE layer, or as a hard filter by learned Q‑value) before they reach the planner and executor.
5.3 Trade-offs
The learned selector helped surface rare but high‑impact failure modes that heuristics would have missed, and reduced false positives from cosmetically similar but structurally different episodes. At the same time, it introduced another model to train, deploy, and monitor-plus the usual risks of overfitting to early data.
For many workflows, we rely primarily on heuristic CBR + reflected procedures, reserving learned selection for domains with enough data and high mistake costs. The important point is that these knobs stay orthogonal: reflection writes procedures, CBR/Memento‑style selection chooses among them, and both can run independently or together.
6. Conclusion – Where Agent Memory Is Going
Memory for AI agents is not a single feature toggle. It is a design space spanning timescales, content types, storage locations, and roles in the agent loop-and the benchmarks and systems we have today are only a starting point.
Looking ahead, a few trends are already visible:
- Principled procedural memory. Agents that learn and reuse explicit playbooks and failure modes, not just scattered facts.
- Tighter reflection–learning integration. Reflexion‑style distillation and Memento‑style selection, without retraining base models.
- Governance and observability. Tools to inspect, edit, and delete memories-and clear answers to “what does this agent remember, and why?”
The OfficeBench 2‑7:0 case study in this post is small, but it makes these trends concrete: static playbooks and rules were not enough to fix malformed‑action loops, while a teacher‑style replan plus Agent‑KB procedures changed both behavior and cost (from 100k tokens and failure to 24k tokens and success). These are not leaderboard results, but they are exactly the kind of debuggable, reproducible evidence we are interested in exploring.