Abstract
The ability to reason is one of the most fundamental capabilities of large language models (LLMs), enabling a wide range of downstream tasks through sophisticated problem-solving. A critical aspect of this is code reasoning, which involves logical reasoning with formal languages. In this paper, we enhance this capability of LLMs by exploring how an LLM agent can become progressively smarter in code reasoning with each solution it proposes, thereby achieving substantial cumulative improvement. Most existing research takes a static perspective, focusing on isolated problem-solving using frozen LLMs. In contrast, we adopt a cognitive-evolving perspective and propose a novel framework named Meta-Reflection with Cross-Referencing (MARCO) that enables the LLM to evolve dynamically during inference through self-improvement. We leverage both knowledge accumulation and lesson sharing, utilizing meta-reflection to capture experience for future problems and cross-referencing to incorporate feedback from peer agents. Experiments across various code reasoning datasets demonstrate the effectiveness of MARCO.
Introduction
Most current research treats Large Language Models (LLMs) as static tools: they receive a problem, provide an answer, and then "reset." When faced with a sequence of similar coding challenges, a standard LLM often suffers from a "Groundhog Day" effect, making the same logical errors repeatedly because it lacks a mechanism to carry over insights from one problem to the next. This is particularly evident in code reasoning tasks—induction, deduction, and abduction—where strict logical consistency is paramount.
MARCO (Meta-Reflection with Cross-Referencing) transforms LLMs from static solvers into evolving agents. By mimicking human cognitive development, MARCO allows models to learn from their own mistakes in real-time during the inference phase, rather than relying solely on static pre-training or expensive fine-tuning.
The MARCO Framework
MARCO facilitates evolution through two primary mechanisms designed to capture and share logical insights.
Meta-Reflection (Inter-Problem Learning)
After solving a problem, the agent reflects on its entire reasoning path. It identifies errors and successes, summarizing the experience into "key takeaways" (e.g., "Always consider both integers and float numbers"). These insights are stored in a Knowledge Bank. To prevent context bloat, a specialized "Knowledge Condenser" periodically distills these takeaways into concise, transferable rules that guide future problem-solving.
Cross-Referencing (Intra-Problem Learning)
To solve complex individual problems, MARCO employs multiple LLM agents. If one agent fails a test case, it shares that "lesson"—including the failed code and the interpreter's feedback—with its peer agents. This cross-referencing prevents the group from falling into the same logical traps and encourages a more diverse search for the correct solution.
Experimental Evaluation
We evaluated MARCO across eight datasets covering the three reasoning pillars:
- Inductive Reasoning: Synthesis of code from examples (ListFunction, MiniARC, RobustFill, DeepCoder).
- Deductive Reasoning: Predicting outputs (CRUXEval-O, LiveCodeBench-O).
- Abductive Reasoning: Predicting inputs (CRUXEval-I, LiveCodeBench-I).
Using backbones like GPT-4o-mini, LLaMA 3 70B, and Qwen 2.5 72B, MARCO consistently outperformed standard Chain-of-Thought (CoT) and other reflection-based baselines. For instance, on the ListFunction dataset using LLaMA 3 70B, MARCO achieved 52.60% accuracy, a significant jump from the 35.20% achieved by standard CoT.
Key Insights
- Inference-Time Evolution: Unlike fine-tuning, MARCO allows the model to "learn" during the inference phase. Analysis showed that MARCO's improvement over baselines was significantly higher in the second half of problem sets, proving successful knowledge accumulation.
- The Power of Condensation: Simply accumulating all past thoughts eventually degrades performance. The Knowledge Condenser is crucial for separating problem-specific noise from generalizable coding wisdom.
- Peer Collaboration: Cross-referencing between agents proved more effective than a single agent reflecting in isolation, as different agents explore different parts of the logic space.
Conclusion
MARCO demonstrates that LLMs do not have to remain static during inference. By implementing meta-reflection and cross-referencing, we can create agents that progressively improve their code reasoning capabilities. Future work will explore more sophisticated retrieval methods, such as RAG, to scale this transferable knowledge across thousands of problems without overwhelming the model's context window.
Summary updated