Skip to content

Lessons Learned: A Multi-Agent Framework for Code LLMs to Learn and Improve

Conference: NeurIPS 2025 arXiv: 2505.23946
Code: https://github.com/MITIBM-FastCoder/LessonL
Area: LLM Agent
Keywords: multi-agent collaboration, code optimization, lesson mechanism, mutual learning, performance optimization

TL;DR

This paper proposes the LessonL framework, enabling multiple small LLM agents to reflect on both successful and failed cases through mutually shared "lessons," collaboratively optimizing code performance. A combination of three 7Bโ€“14B models achieves code optimization results on par with GPT-4o and approaching o3.

Background & Motivation

Background: Code optimization is a critical component of software development, yet it has been largely overlooked in AI research. Existing work either focuses on code generation or relies on specialized HPC models.

Limitations of Prior Work: - LLMs exhibit complementary strengths on fine-grained tasks (e.g., Qwen7B outperforms GPT-4o by 2.5ร— on geometry tasks), but these advantages remain unexploited. - Multi-agent collaboration either adopts role-based division (planner/coder/debugger) or independent proposal aggregation. - There is a lack of interpretable knowledge-sharing mechanisms.

Key Challenge: How to leverage the complementary strengths of multiple small LLMs for code optimization while maintaining interpretability and cost efficiency.

Goal: Design a multi-agent learning framework that allows agents to learn from each other's successes and failures.

Key Insight: An analogy to peer-assisted learning โ€” learning from textbooks plus learning from classmates.

Core Idea: A three-phase iterative process โ€” lesson solicitation, lesson banking, and lesson selection โ€” enabling interpretable optimization experience sharing among agents.

Method

Overall Architecture

The core loop of LessonL: initial solution generation โ†’ lesson extraction โ†’ lesson banking โ†’ lesson selection โ†’ iterative refinement using selected lessons โ†’ repeat. Over \(T\) iterations, each of \(n\) agents generates one lesson per round, and \(k\) lessons are selected for the next round.

Key Designs

  1. Lesson Solicitation:

    • Function: Extract optimization experience in natural language form from code modification outcomes.
    • Mechanism: Four code modification scenarios yield distinct lesson types:
      • (a) Speedup: code is faster and correct โ†’ positive lesson (e.g., "reordering loops improves cache locality")
      • (b) Slowdown: code is correct but slower โ†’ warning lesson
      • (c) Functional error: fails tests โ†’ error lesson
      • (d) Syntax error: compilation failure โ†’ syntax lesson
    • Design Motivation: Learning not only from successes but also from failures to prevent repeated mistakes.
  2. Lesson Banking & Selection:

    • Function: Manage the lesson pool and select the most useful lessons for the next round.
    • Mechanism: A hybrid selection strategy โ€” top \(\lceil k/2 \rceil\) lessons by speedup (exploitation) + top \(\lfloor k/2 \rfloor\) lessons by relevance (CodeBERT cosine similarity).
    • Design Motivation: Selecting solely by speedup may cause trajectory fixation; the hybrid strategy introduces diversity.
  3. Dynamic Effectiveness Adjustment:

    • Function: Adjust lesson weights over time.
    • Mechanism: An adjustment factor \(f\) is defined such that when a lesson is applied in subsequent rounds, its actual speedup is compared to the original speedup, cumulatively updating \(f = c/n\).
    • Design Motivation: A lesson that is effective at creation may not remain so; adaptive downgrading is needed for lessons that underperform in practice.

Key Experimental Results

Main Results

Method ParEval Serial Correctness ParEval >2ร— Speedup Ratio ParEval Serial Speedup ParEval Parallel Speedup
Qwen14B Baseline 0.67 0.14 1.60ร— 2.28ร—
GPT-4o mini 0.77 0.14 1.57ร— 2.72ร—
GPT-4o 0.80 0.16 1.72ร— 2.93ร—
OpenAI o3 0.77 0.23 2.21ร— 3.55ร—
MapCoder (Qwen14Bร—3) 0.88 0.15 1.85ร— 3.43ร—
LessonL (Qwenร—3) 0.91 0.21 2.16ร— 3.46ร—

Ablation Study

Configuration ParEval S Correctness >2ร— Ratio Serial Speedup Parallel Speedup
Full LessonL 0.91 0.21 2.16ร— 3.46ร—
High-speedup lessons only 0.92 0.21 2.08ร— 3.20ร—
High-relevance lessons only 0.91 0.18 1.96ร— 3.40ร—
No speedup adjustment 0.92 0.21 2.05ร— 3.28ร—
Random lesson selection 0.91 0.19 2.03ร— 3.47ร—
No lessons 0.89 0.20 1.95ร— 3.01ร—

Key Findings

  • Emergent capability of small models: LessonL with three 7Bโ€“14B models reaches GPT-4o level and approaches o3, with parallel speedup of 3.46ร— vs. o3's 3.55ร—.
  • The hybrid selection strategy is optimal โ€” either high-speedup-only or high-relevance-only selection underperforms the hybrid.
  • Removing the lesson mechanism leads to a significant performance drop (parallel: 3.01ร— vs. 3.46ร—), validating its necessity.
  • Three agents is optimal; performance saturates or slightly degrades with six agents.
  • Clear cost advantage: LessonL lies on the Pareto frontier compared to MapCoder and MoA.

Highlights & Insights

  • Interpretable knowledge sharing: Lessons are human-readable optimization strategies (e.g., "parallelize using OpenMP"), offering greater pedagogical value than black-box embedding fusion.
  • Adaptive lesson weighting: Dynamic adjustment via the \(f\) factor prevents blind adoption of lessons with fixed weights.
  • Learning from failure: Negative lessons (error and slowdown cases) prevent repeated mistakes, a capability absent in MapCoder and MoA.
  • Fine-grained complementarity discovery: The framework automatically identifies each model's strengths without prior knowledge.

Limitations & Future Work

  • Lesson extraction and iterative rounds introduce latency, limiting applicability to real-time settings.
  • Validation is confined to function-level code; scaling to repository-level SWE tasks remains challenging.
  • Marginal gains from lessons diminish significantly after multiple rounds.
  • Automatically extracted lessons vary in quality and may contain LLM hallucinations.
  • vs. MapCoder/MoA: MapCoder aggregates independent proposals; MoA employs hierarchical aggregation. LessonL introduces an explicit lesson mechanism to fill the knowledge-sharing gap.
  • vs. Self-Refine/Reflexion: These rely on single-agent self-reflection; LessonL generalizes this to mutual learning among multiple agents.
  • vs. PIE/HPC-Coder: These use specialized fine-tuning or retrieval; LessonL provides lightweight, on-the-fly knowledge injection.

Rating

  • Novelty: โญโญโญโญโญ The lesson concept is novel, with an elegant and concise design.
  • Experimental Thoroughness: โญโญโญโญโญ Multiple benchmarks, six ablation conditions, cost analysis, and case studies.
  • Writing Quality: โญโญโญโญโญ Clear logical progression with vivid illustrative examples.
  • Value: โญโญโญโญโญ Offers a new perspective on multi-agent learning with a clear cost-effectiveness advantage.