Dual-Polarity Procedural Memory with Periodic Maintenance¶
Maintain separate failure and success procedural memory pools under periodic maintenance when recurring tool-use streams justify extra token cost for broader coverage.
Dual-polarity procedural memory separates lessons from local failures and local successes into two capacity-bounded pools updated in periodic batches (Tianmai M. Zhang et al., 2026). Use both pools only when recurring multi-step tool-use tasks fit inside a small injected context and broader tool coverage justifies 2.31 times the weighted token cost of running without memory. Choose success-only memory when execution efficiency and cost matter more than marginal recall, where final-answer accuracy did not differ significantly among memory-on modes (all p >= .17). On longer streams, retain raw episodes and gate consolidation to limit rewrite erosion (Dylan Zhang et al., 2026).
How the workflow runs¶
Dual-Polarity Memory with Periodic Maintenance (DualPM) splits an ordered task stream into blocks of b episodes (b = 20 on TRAJECT-Bench, b = 5 on EvoMemBench) and cycles through three phases (Tianmai M. Zhang et al., 2026).
graph TD
A[Task block<br>frozen M_k-1] -->|visible trajectories| B[Reflect and draft<br>2 LLM calls/episode]
B -->|success drafts D+| C[Maintain success pool<br>cap m units]
B -->|failure drafts D-| D[Maintain failure pool<br>cap m units]
C -->|M_k+| E[Combined context M_k<br>next block]
D -->|M_k-| E
Each phase boundary uses a fixed handoff contract (Tianmai M. Zhang et al., 2026):
- Task execution runs every episode in block
kagainst one frozen combined poolM_{k-1}appended to the system prompt. Block 1 cold-starts with no memory. - Reflection and drafting runs two sequential LLM calls per episode over only the model-visible trajectory (task, instructions, actions, tool responses, and final answer, with no gold calls or evaluator scores). Any trajectory can produce both polarities: "A successful trajectory may contain local failures worth avoiding or improving, while a failed trajectory may contain effective behaviors worth reusing." The drafting call emits up to
dJSON lessons per polarity (d = 2) with six fields:memory_type,title,content,evidence,applicability(<phase>: <observable trigger>), andconfidence. - Periodic maintenance runs one separate LLM call per polarity over the prior pool and that block's same-polarity drafts. The maintainer returns the full updated pool capped at
munits (m = 10, up toe = 3evidence items each) via preserve, revise, merge, split, create, or remove operations. On GPT-5.5, those caps hold each pool to around 5,000 tokens.
Polarity trade-offs and measured results¶
Tianmai M. Zhang et al. (2026) tested a 2×2 polarity design on TRAJECT-Bench parallel-hard across 720 evaluated episodes per condition (GPT-5.5 backbone, four user profiles, nine prequential evaluation blocks of 20 tasks, answer accuracy judged by DeepSeek-V3.2):
| Memory setting | Discovery recall | Selection recall | Usage recall | Usage precision | Turns | Answer accuracy | Weighted tokens/episode |
|---|---|---|---|---|---|---|---|
| No memory | 75.2% | 68.0% | 66.0% | 50.5% | 6.1 | 68.1% | 70.4k |
| Failure only | 81.0% | 73.9% | 71.9% | 49.0% | 6.3 | 71.0% | 153.6k |
| Success only | 78.7% | 72.2% | 70.5% | 56.2% | 5.4 | 72.2% | 131.7k |
| Both on | 81.1% | 74.5% | 72.4% | 53.7% | 5.5 | 73.2% | 162.3k |
Every memory-on condition beat no memory on all three recall metrics (p <= .001) and answer accuracy (p <= .015). Failure-only beat success-only on discovery recall (p = .002) and selection recall (p = .018), whereas success-only beat failure-only on usage precision and turns (both p < .001). Combining both pools beat success-only on all three recall metrics (p <= .002) with slightly lower precision (p < .001) and comparable turns (p = .27). Compared with failure-only, both-on raised usage precision and cut turns (both p < .001) (Tianmai M. Zhang et al., 2026).
Two limits qualify those numbers (Tianmai M. Zhang et al., 2026):
- Accuracy differences among failure-only, success-only, and both-on were not statistically significant (all
p >= .17). - Weighted token spend per episode (uncached input + 0.1 times cached input + 6 times output, including reasoning tokens) rose from 70.4k (no memory) to 131.7k for success-only (79.9k task + 51.8k DualPM), 153.6k for failure-only (97.3k + 56.3k), and 162.3k for both on (105.1k + 57.2k). Both-on costs 2.31 times no memory and 1.23 times success-only.
Three follow-up studies check scope, transfer, and portability (Tianmai M. Zhang et al., 2026):
- Multi-stage lessons beat discovery-only lessons on user U2: accuracy reached 69.4% (55.3% usage precision) versus 64.4% (51.3% precision) when restricted to tool discovery and 56.7% with no memory.
- Cross-domain transfer between the least-overlapping profiles (U1 and U4) lifted accuracy from 72.0% to 75.0% when frozen (precision dipped from 49.1% to 48.2%; turns rose from 6.2 to 6.4). Adaptive transfer reached 78.5% accuracy and 5.6 turns, matching from-scratch memory (78.0% accuracy, 5.6 turns).
- On EvoMemBench-CrossEp-Tool with DeepSeek-V3.2 (four domains of 50 tasks, three runs,
b = 5, un-tunedd = 2, m = 10, e = 3), retrieval-free DualPM averaged 69.8% success rate versus 45.0% without memory and 68.5% for retrieval-based ReasoningBank. DualPM beat ReasoningBank on File System (67.3% vs 64.0%), Vehicle Control (84.0% vs 82.0%), and Travel Booking (47.3% vs 42.0%), and trailed on Trading Bots (80.7% vs 86.0%).
Why it works¶
Dual-polarity memory applies separation of concerns to procedural recall. Paired trajectory analysis in Tianmai M. Zhang et al. (2026) showed that "failure memories operated primarily as coverage-and-recovery checklists that encouraged continued pursuit of incomplete subtasks." By contrast, "success memories operated more as routing guidance that organized parallel work into a more compact execution trajectory." Decomposing implicit requests into subtask-specific tool_search queries lowered mean best rank of gold tools from 7.7 without memory to 5.5 with both pools active. Separate capacity-bounded pools keep either signal from crowding out the other under a fixed limit m. The authors note one methodological limit: "the polarity of a source trajectory and the procedural guidance derived from it are coupled in our design; we did not isolate their respective contributions" (Tianmai M. Zhang et al., 2026).
When this backfires¶
Skip dual-polarity periodic maintenance or pick a lighter design in these cases:
- Cost- or latency-sensitive workloads: the authors note that "success-only is preferable when prioritizing execution efficiency and cost, whereas dual-polarity memory is preferable when maximizing coverage and performance" (Tianmai M. Zhang et al., 2026). Both-on costs 23.2% more weighted tokens than success-only (162.3k vs 131.7k) with no statistically significant accuracy gain over success-only (
p >= .17). - Long-horizon streams without raw-episode grounding: repeated LLM consolidation is a lossy rewrite where "memory utility first rises, then degrades, and can fall below the no-memory baseline" (Dylan Zhang et al., 2026). DualPM tested 10 stationary blocks without distribution shift or transcript verification; Dylan Zhang et al. (2026) recommend keeping raw episodes and gating consolidation explicitly.
- Frontier models under rigid recording rules: on the CL-Bench database task, a rule to "record only failures" cut memory gain by 0.234 on Opus 5 and 0.150 on Opus 4.7; Anthropic recommends letting stronger models judge salience and checking notes offline against transcripts (Anthropic, 2026).
- Same-task coding repair retries: on bug-revealing tests across 181 failed
gpt-5.4-miniBugsInPy attempts, failure memory gave no statistically significant pass-rate gain over plain retries (+5.5 to +9.9 points over 29.8%), and "a model-written lesson showed no advantage over the transcript it summarises" (Ye et al., 2026). - Broad tool catalogs or short streams: injecting roughly 10,000 tokens of static memory (around 5,000 per polarity) into every prompt scales poorly as domains grow without retrieval or lazy loading, and cold-starting block 1 penalizes short streams (Tianmai M. Zhang et al., 2026).
- Uninformative or misleading tool responses: DualPM's reflection reads only model-visible tool responses without ground-truth labels, and its maintenance prompt notes that evidence quality and semantic support are not locally validated (Tianmai M. Zhang et al., 2026).
Example¶
In TRAJECT-Bench (user U1, block 8, task 142), a user requested three classroom items in one prompt: a fact about number 42, diversity, equity, and inclusion (DEI) learning resources, and a usage example for "excellent" (Tianmai M. Zhang et al., 2026).
Before — no memory (single broad tool_search query):
Query: "web search internet search retrieve links snippets definitions dictionary"
Result: retrieved a dictionary tool only; made no further searches, answered from prior knowledge, and invented plausible links to DEI resources.
After — dual-polarity memory (three subtask tool_search queries):
Query 1: "Numbers trivia fact number 42"
Query 2: "DEI learning resources page links"
Query 3: "dictionary definition word excellent usage"
Result: obtained tools for all three subtasks.
Two verbatim memory units from TRAJECT-Bench Appendix C show how the two pools encode distinct control signals (evidence arrays omitted for brevity) (Tianmai M. Zhang et al., 2026):
# Success pool entry (routing heuristic)
memory_type: success_memory
title: "Search by concrete output needs"
applicability: "tool search: required external lookup, generation, ranking, filtering, scoped-source, or fact capability is not already loaded"
content: "When the needed capability is not already loaded, search using the requested operation, entity/input type, source family, hard constraint, identifier, locale, and desired output fields rather than a broad topic. Prefer purpose-built endpoints that accept the exact code, number, date, rank, range, reading, market, nationality, ID, chapter, or field the user named; if discovery exposes a wrong-scope default, refine before calling."
# Failure pool entry (coverage-and-recovery checklist)
memory_type: failure_memory
title: "Target missing fields"
applicability: "tool usage: considering extra calls after a valid, sparse, false-positive, autocomplete-only, image-only, incomplete, failed, or already-sufficient response"
content: "After a broad, sparse, false-positive, autocomplete-only, facet-only, image-only, metadata-only, incomplete, failed, or indirect response, decide which missing field would materially improve the answer before calling more tools. Refine within the user's intended source, identity, product class, structure, or evidence type-exact match, stable ID, product rows, prices, stores, offer URLs, expiry, policies, reviews, roles, evolutions, definitions, finish/color options, or decision fields. Do not drift to adjacent metadata or issue extra post-success calls unless tied to a specific unresolved field."
Key Takeaways¶
- Pick success-only memory when token budget and turn count dominate; add a separate failure pool only when higher discovery and selection recall justify 1.23 times success-only weighted token spend (2.31 times no memory).
- Extract both polarities from local steps within any trajectory without waiting for episode-level labels, and consolidate each pool independently under a fixed cap so one polarity cannot evict the other.
- Allow lessons across planning, discovery, usage, and response stages rather than restricting reflection to tool discovery alone.
- Keep raw trajectories and gate consolidation on long or shifting streams, because repeated ungrounded LLM rewrites can fall below a no-memory baseline.
- Test purpose-only salience steering with transcript validation before imposing fixed recording rules on frontier models, and do not assume model-written lessons will beat raw transcripts on same-task bug-repair retries.
Related¶
- Steering Agent Memory: Judge Salience, Then Correct with Dreaming — model-judged salience and offline transcript validation, the main alternative to fixed polarity pools on frontier models
- Memory Synthesis: Extracting Lessons from Execution Logs — the broader spectrum from passive log recording to structured lessons and pruning strategies
- Tiered Memory Architecture: Episodic-to-Semantic Consolidation — separating raw episode storage from a curated semantic tier promoted on re-use
- Memory Transfer Learning: Cross-Domain Memory Reuse — how abstraction level controls cross-domain reuse and negative transfer
- Failure Memory on Agent Retry — empirical counter-evidence in same-task coding repair retries where model-written lessons did not beat raw transcripts