Learning Hierarchical Procedural Memory for LLM Agents through Bayesian Selection and Contrastive Refinement

Saman Forouzandeh, Wei Peng, Parham Moradi, Xinghuo Yu, Mahdi Jalili · DOI

TL;DR

This paper introduces MACLA, a novel framework for LLM agents that decouples reasoning from learning by using a frozen LLM and an external hierarchical procedural memory. MACLA achieves state-of-the-art performance across multiple benchmarks with significantly reduced training time and computational cost by learning reusable skills and refining them through Bayesian selection and contrastive analysis.

What Problem Does This Paper Address?

Large Language Models (LLMs) have shown promise in complex, interactive tasks, but current approaches often involve expensive fine-tuning of the entire LLM. This process is computationally intensive, prone to catastrophic forgetting, and doesn't easily support online adaptation during inference. Existing methods struggle with efficiently learning and reusing "how-to" knowledge, often requiring agents to replan from scratch even for similar tasks. Furthermore, learning from trajectories often treats them as monolithic units, neglecting valuable intermediate steps and failing to distinguish between correct substeps and overall failure. This paper aims to address these limitations by creating sample-efficient, interpretable LLM agents that can continuously learn and adapt without modifying the core LLM parameters.

Methods

MACLA's core innovation lies in its decoupling of reasoning and learning. The LLM is kept frozen, acting as a stable semantic reasoner for tasks like parsing instructions, segmenting trajectories, and abstracting actions. All learning and adaptation happen in an external, structured procedural memory. This memory is hierarchical and comprises two main components:

  • Procedural Memory: Stores reusable skills as structured procedures, each with a natural-language goal, precondition patterns, an abstracted action sequence, and postcondition patterns. These procedures are embedded in a semantic space for efficient retrieval.
  • Meta-Procedural Memory: Stores compositions of frequently co-occurring procedures, forming "playbooks" with conditional control policies for long-horizon tasks.

MACLA employs three key mechanisms:

  1. Bayesian Procedure Selection: Each procedure has a Beta posterior distribution over its success rate. Actions are selected based on an expected-utility score that balances contextual relevance, success probability, failure risk, and information gain, enabling principled exploration-exploitation.
  2. Contrastive Refinement: When a procedure accumulates sufficient successes and failures, MACLA uses contrastive analysis to compare these contexts. This allows for explicit refinement of preconditions, action schemas, and postconditions, improving procedure accuracy and robustness without requiring new expert demonstrations.
  3. Meta-Procedural Composition: MACLA automatically discovers and learns hierarchical compositions of procedures, enabling agents to tackle long-horizon tasks by chaining skills with learned control policies.

Datasets

MACLA was evaluated on four challenging interactive agent benchmarks:

  • ALFWorld: A text-based embodied environment with six household tasks.
  • WebShop: Simulates e-commerce search requiring multi-step navigation and filtering.
  • TravelPlanner: Involves multi-day itinerary planning under constraints.
  • InterCodeSQL: Benchmarks interactive text-to-SQL generation.

The paper does not introduce new benchmarks but uses existing ones to demonstrate MACLA's generalization capabilities.

Key Insights and Ideas

  • Frozen LLM + External Memory is Powerful: Decoupling LLM reasoning from memory-based learning is highly effective, leading to sample-efficient agents without costly LLM fine-tuning.
  • Bayesian Uncertainty is Crucial for Exploration: Using Beta posteriors and expected utility for procedure selection allows agents to intelligently balance exploiting known good procedures with exploring uncertain ones, leading to faster learning and better generalization.
  • Contrastive Learning for Refinement is Key: Learning from both successes and failures, rather than just terminal outcomes, allows for precise refinement of procedures, making them more robust and applicable.
  • Hierarchy Enables Compositional Generalization: Meta-procedures are essential for tackling complex, long-horizon tasks by enabling agents to chain and conditionally execute learned skills.
  • Procedural Memory Scales Efficiently: MACLA demonstrates significant compression of trajectories into reusable procedures, drastically reducing memory footprint and training time.
  • Task Structure Matters: MACLA excels in domains with high action reusability, hierarchical structure, and consistent semantics (like ALFWorld), but faces challenges in highly structured, less compositional domains (like SQL).

Key Results

  • State-of-the-Art Performance: MACLA achieved an average performance of 78.1% across four benchmarks, outperforming all baselines, including those using much larger LLMs.
  • Exceptional Generalization: On ALFWorld unseen tasks, MACLA reached 90.3% performance with a +3.1% positive generalization gap, indicating strong compositional transfer.
  • Massive Speedup: Memory construction took only 56 seconds, which is 2,800 times faster than state-of-the-art LLM parameter-training baselines.
  • Efficient Compression: 2,851 trajectories were compressed into 187 procedures (a 15:1 ratio), demonstrating effective knowledge distillation.
  • Minimal LLM Usage: The framework significantly reduces LLM calls during inference by leveraging retrieved procedures.

Limitations and Future Work

  • Threshold Sensitivity: Several thresholds (e.g., for duplicate detection, confidence, meta-procedure formation) were determined empirically and lack strong theoretical justification, though theoretical foundations are proposed.
  • Memory Capacity Saturation: Performance plateaus around 150-200 procedures, suggesting an optimal capacity and potential for redundant storage or retrieval noise with overcapacity.
  • Task-Specific Effectiveness: MACLA's performance is highly dependent on the task's structure, excelling in domains with high reusability and hierarchy but struggling with highly structured, less compositional tasks like SQL.
  • Potential for Catastrophic Forgetting: The fixed memory capacity and utility-based pruning might lead to forgetting rare but important skills.
  • Future Work: The authors suggest exploring dynamic memory expansion, hierarchical memory structures, importance-weighted retention, and improving performance on structured query tasks through schema-aware abstraction and compositional query building.

Summary updated

BibTeX
@misc{forouzandeh2025learning,
  author = {Saman Forouzandeh and Wei Peng and Parham Moradi and Xinghuo Yu and Mahdi Jalili},
  title = {{Learning Hierarchical Procedural Memory for LLM Agents through Bayesian Selection and Contrastive Refinement}},
  year = {2025},
  eprint = {2512.18950},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2512.18950},
}
Figure