MemCollab: Cross-Model Memory Collaboration via Contrastive Trajectory Distillation
Organizations: Pennsylvania State University · AG2AI
Abstract
LLM agents increasingly rely on memory mechanisms to reuse knowledge from past problem-solving experiences. However, existing methods typically construct memory for a single agent and reuse it with the same underlying model, tightly coupling stored knowledge to model-specific reasoning styles. In heterogeneous deployments, where agents may be instantiated with backbone models of different sizes, architectures, or specializations, this raises a key question: can a single memory system be shared across agents with different backbone models? We find that naive cross-model memory transfer can degrade performance, because stored memories often entangle task-relevant knowledge with model-specific biases. To address this challenge, we propose MemCollab, a collaborative memory framework that builds shared cross-model memory by contrasting reasoning trajectories generated by different model-based agents on the same task. Through this contrastive process, MemCollab distills abstract reasoning constraints that capture shared task-level invariants while suppressing model-specific artifacts. We further introduce a task-aware retrieval mechanism that conditions memory access on task category, ensuring that only relevant constraints are retrieved at inference time. Experiments on mathematical reasoning and code generation benchmarks show that MemCollab consistently improves both accuracy and inference-time efficiency across diverse agents, including settings with different model families. These results demonstrate that collaboratively constructed cross-model memory can serve as a shared reasoning resource for heterogeneous LLM-based agents.
Figures & tables
| Backbone | Method | Accuracy (%) | ||||
|---|---|---|---|---|---|---|
| MATH500 | GSM8K | MBPP | HumanEval | Average | ||
| Qwen-2.5-7B | Vanilla | |||||
| Buffer of Thoughts | 57.6 | |||||
| Dynamic Cheatsheet | ||||||
| w/ Memory (7B) | ||||||
| w/ Memory (32B) | ||||||
| Backbone | Method | Accuracy (%) | ||||
| MATH500 | GSM8K | MBPP | HumanEval | Average | ||
| Llama-3-8B | Vanilla | |||||
| Buffer of Thoughts | ||||||
| Dynamic Cheatsheet | ||||||
| w/ Memory (8B) | ||||||
| w/ Memory (32B) | ||||||
| # Models | Qwen2.5-7B | Llama3-8B | Qwen2.5-32B |
|---|---|---|---|
| 1 | 52.2 | 27.4 | 58.0 |
| 2 | 67.0 | 42.4 | 73.8 |
| 3 | 66.8 | 43.2 | 75.0 |
Appendix figures & tables18 assets
Supplementary material from the paper’s appendix.
Appendix
| Model | Method | MATH500 | GSM8K | MBPP | HumanEval |
|---|---|---|---|---|---|
| Llama-3-70B | Vanilla | 58.0 | 93.2 | 54.8 | 64.6 |
| w/ Memory (self) | 59.6 | 93.5 | 56.3 | 68.6 | |
| w/ MemCollab | 65.2 | 93.6 | 63.0 | 74.4 |
| Model | Vanilla | w/ Memory (self) | w/ MemCollab |
|---|---|---|---|
| Gemma3-4B | 45.9 | 45.1 | 48.4 |
| Qwen2.5-7B | 47.9 | 50.2 | 50.8 |
| Model | Setting | MATH500 | GSM8K | MBPP | HumanEval |
|---|---|---|---|---|---|
| Qwen2.5-7B | Vanilla | 52.2 | 85.4 | 47.9 | 42.7 |
| w/ Memory (self) | 60.0 | 86.2 | 50.2 | 42.7 | |
| w/ MemCollab | 63.8 | 85.4 | 55.3 | 71.2 | |
| Llama-3-8B | Vanilla | 27.4 | 73.0 | 37.0 | 29.3 |
| w/ Memory (self) | 29.2 | 63.2 | 47.1 | 42.7 | |
| w/ MemCollab | 30.4 | 73.4 | 47.9 | 45.5 |
| Model | Setting | Accuracy |
|---|---|---|
| Llama-3-70B | Vanilla | 54.8 |
| w/ Memory (self) | 56.3 | |
| w/ MemCollab | 61.9 | |
| Qwen2.5-72B | Vanilla | 59.9 |
| w/ Memory (self) | 61.1 | |
| w/ MemCollab | 63.0 |
| Model | Method | Task Goal Completion | Scenario Goal Completion | ||||||
|---|---|---|---|---|---|---|---|---|---|
| Avg. | D1 | D2 | D3 | Avg. | D1 | D2 | D3 | ||
| GPT-5-nano | Vanilla | 4.8 | 11.1 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 |
| MemCollab | 26.7 | 44.4 | 26.7 | 0.0 | 10.0 | 0.0 | 20.0 | 0.0 | |
| GPT-5-mini | Vanilla | 47.7 | 66.7 | 55.3 | 0.0 | 30.0 | 66.7 | 20.0 | 0.0 |
| MemCollab | 63.3 | 66.7 | 66.7 | 50.0 | 50.0 | 66.7 | 40.0 | 50.0 | |
| Model | Vanilla | w/ MemCollab |
|---|---|---|
| Qwen2.5-7B | 15.4 | 21.3 |
| Qwen2.5-32B | 15.9 | 33.3 |
| Method | MBPP |
|---|---|
| Vanilla | 47.9 |
| MemCollab (default) | 57.6 |
| MemCollab (random) | 50.2 |
| MemCollab (reverse) | 52.9 |
| Target Model | Summarizer | HumanEval |
|---|---|---|
| Vanilla | – | 42.7 |
| w/ MemCollab | Qwen2.5-32B | 74.4 |
| Qwen2.5-7B | 65.9 | |
| Llama-3-8B | 63.4 |
| Prompt Change | HumanEval |
|---|---|
| No memory | 42.7 |
| Original prompt | 74.4 |
| Add instruction to numbered list | 74.4 |
| Add instruction to JSON format | 70.7 |
| Method | Wall Time (s) | Input Tokens | Output Tokens | Total Tokens |
|---|---|---|---|---|
| MemCollab | 38.3 | 812.42 | 117.50 | 929.90 |
| Self-Contrast | 50.4 | 828.90 | 121.56 | 950.50 |
| Self-Memory | 13.35 | 499.02 | 63.78 | 562.80 |
| Dataset | Vanilla | MemCollab |
|---|---|---|
| MATH500 | 2.7 | 2.2 |
| GSM8K | 1.8 | 1.6 |
| MBPP | 3.1 | 1.4 |
| HumanEval | 3.3 | 1.5 |
| Method | MATH500 | GSM8K | MBPP | HumanEval |
|---|---|---|---|---|
| Vanilla | ||||
| w/ MemCollab |
| Source Question : Determine the range of parameters for which a triangle exists. Summarized Un-preferred Trajectory : Explicitly writes triangle inequalities and solves the feasible range. Summarized Preferred Trajectory : Uses the same inequality-based feasibility reasoning before computation. Memory Guidance : When determining geometric feasibility, enforce triangle inequalities by converting them into explicit inequality constraints before solving. Invariants : Translate geometric existence into inequality constraints. Variants : One sets equations first, then simplifies; the other simplifies before imposing constraints. Source Question : How many intersection points are formed by a given number of circles? Summarized Un-preferred Trajectory : Identifies all diagonal pairs and counts only those that intersect, rather than enumerating points directly. Summarized Preferred Trajectory : Counts all circle pairs using and multiplies by the maximum possible intersections per pair. Memory Guidance : When dealing with combinatorial geometry problems involving intersections, enforce counting principles by first identifying all possible pairs of elements and then filtering based on intersection criteria; avoid direct enumeration without structured counting. When determining the probability of geometric events, enforce the calculation of favorable outcomes relative to total possible outcomes; avoid assuming uniform distribution without justification. Invariants : Decompose intersection problems into pairwise interactions with bounded intersection counts. Variants : One reasons at the geometric-object level (explicit intersection checks), while the other operates directly at the combinatorial level. One performs conditional filtering; the other applies a closed-form counting bound. Source Question :Determine a vector onto which multiple vectors have the same projection. Summarized Un-preferred Trajectory : Sets up dot-product equations equating scalar projections. Summarized Preferred Trajectory : Uses the same projection formula and explicitly enforces equality across vectors. Memory Guidance : When projecting multiple vectors onto the same vector and obtaining identical projections, enforce equality of scalar projection coefficients rather than treating each projection independently. Invariants : Equal projections imply a shared scalar projection constraint. Variants : One sets equations first, then simplifies; the other simplifies before imposing constraints. |
| Assistant Task 1. Core task summarization: Identify and describe the basic type and core challenges of the problem, such as classifying it as a mathematical problem (e.g., solving a quadratic equation), a data structure problem (e.g., array sorting), or an algorithmic problem (e.g., search algorithms). 2. Solution steps description: Outline the general solution steps, including how to define the problem, determine variables, list key equations or constraints, and choose appropriate solving strategies and methods. 3. General answer template: Based on the above analysis, propose a reusable template or approach that can be widely applied to this type of problem, including possible variables, functions, or class definitions. For programming problems, provide base classes or interfaces that can be instantiated to solve specific instances. Ensure the response is concise and structured so that instance-specific solutions can be generalized. Reusable Solution Skeleton 1. Define symbolic variables or core data structures. 2. Express the main constraints, equations, or problem conditions. 3. Convert the problem into a canonical or solvable form. 4. Apply the appropriate mathematical, algorithmic, or structural method. 5. Solve for the required variable(s) or compute the target quantity. 6. Verify or validate the result using the original constraints or expected outputs. |
| You are an expert analyst for extracting reusable REASONING MEMORY from contrastive multi-step mathematical reasoning trajectories. You are given multiple incorrect or partially correct reasoning traces or predicted outputs. Your goal is NOT to solve the problems. Your goal is NOT to correct the predictions. Your goal is to extract: 1) reusable failure-aware reasoning constraints, and 2) high-level reasoning strategies that characterize correct multi-step mathematical reasoning, expressed using abstract reasoning rules and high-level mathematical forms (rather than problem-specific calculations). Each extracted strategy must combine: - a trigger (when this strategy should be considered), and - an enforcement rule (what must be enforced or avoided). ANALYSIS SCOPE Analyze failures and near-misses at the reasoning level, focusing on: - explicit formalization of constraints and domains - correct construction and use of intermediate variables - alignment between mathematical structure and solution method - ordering of steps: formalize transform solve verify - separation between intermediate expressions and final solutions - handling of extraneous roots, boundary cases, and invalid domains Use high-level mathematical forms where appropriate, such as: - constraint systems: - canonical equations: , - optimization conditions: - modular forms: - geometric invariants: distance, angle, or area relations Do NOT focus on: - surface arithmetic mistakes without structural impact - numerical simplification details - stylistic presentation or verbosity - producing corrected solution chains or final answers STRICT CONSTRAINTS - Each strategy MUST be grounded in an observable pattern across trajectories. - Do NOT introduce speculative or unverifiable strategies. - Strategies MUST be abstract and reusable across different mathematical domains. REQUIRED OUTPUT Each strategy MUST: - be written as one sentence - optionally reference high-level mathematical forms or invariants - follow this format exactly: When … , enforce … ; avoid … At least: - 1 strategy MUST describe failure-prevention or constraint enforcement - 1 strategy MUST describe high-level reasoning structure or invariants Do NOT: - include explanations - reference specific problems, constants, or numeric values - include worked examples or derivations - add any text before or after the list |
| You are a mathematical problem classifier. Your task is to assign each math problem to exactly one subcategory within the given main category. You will be provided with: 1. The problem statement. 2. The main category (e.g., Algebra, Precalculus, Geometry, Number Theory). 3. A list of allowed subcategories for this category. Your output must be exactly one subcategory from the allowed list. CLASSIFICATION RULES 1. You MUST choose exactly one subcategory from the provided list. You may NOT output ‘‘None’’. You may NOT invent new categories. Only choose from the allowed subcategories provided. 2. If the problem clearly matches a subcategory definition, choose it, even if other superficial features appear. 3. If a problem fits multiple subcategories, choose the most specific one. 4. If a problem matches a special enforcement rule, you MUST apply that rule. These rules override all ambiguity. SPECIAL ENFORCEMENT RULES These rules override ambiguity and enforce consistent labeling: • Polar coordinates, polar--rectangular conversion, parametric coordinates Coordinate Systems . • Vector dot products, cross products, projections, vector angles, 3D line geometry Analytic Geometry (Vectors & Lines) . • Distance between points, midpoint, slope, basic coordinate geometry Analytic Geometry (Distance & Midpoints) . • Digit-restricted numbers or divisibility based on digit properties Modular Arithmetic & Digit Properties . • Proper divisors, prime factorization, number of divisors, GCD/LCM Divisibility & Prime Factorization . • Complex number rotation, geometric interpretation, roots of unity, transformations Complex Numbers (Geometry & Transformations) . • Equations involving radicals or exponentials (including logarithms) Radical & Exponential Equations . Exception: Compound interest or exponential growth/decay word problems Exponential & Logarithmic Equations . • Counting or arrangement problems with restrictions (e.g., adjacency constraints) Combinatorial Argument & Constraints . • Constructing polynomials from values or missing coefficients Polynomial Interpolation . • Equations involving functional constraints (e.g., , invariance) Functional Equations . OUTPUT FORMAT Your response must be ONLY the name of the chosen subcategory. No explanations. No justification. No additional text. INPUT FORMAT Problem: {PROBLEM} Main Category: {CATEGORY} Allowed Subcategories: {SUBCATEGORY_LIST} YOUR TASK Select exactly one subcategory from the list. |
Memory-Augmented Language Model Agents
Memory-augmented language model agents use persistent facts, interaction histories, and skills to support personalization and long-horizon tasks.
See all 428 papers