arXiv:2504.11536cs.CLcs.AI2025-04被引 378

让大模型学会像人一样智能调用代码工具解题,提升数学推理能力。

ReTool: Reinforcement Learning for Strategic Tool Use in LLMs

  • 在推理过程中动态插入实时代码执行,实现自然语言与代码的混合思考。
  • 仅用400步训练就达到67%准确率,效率和性能均超越纯文本强化学习方法。
  • 模型能自主发现最佳调用时机并自我修正代码,适合复杂数学问题求解场景。

尽管基于强化学习(RL)训练的推理模型(如 DeepSeek R1)在文本推理方面表现优异,但在需要结构化求解的场景(如几何推理、简洁计算或复杂方程求解)中仍表现不足,而代码解释器(CI)在此类任务中具有明显优势。为此,我们提出 ReTool,通过引入工具集成学习来增强长序列推理能力,包含两项核心设计:(1)在自然语言推理过程中动态穿插实时代码执行;(2)采用自动化强化学习范式,支持多轮实时代码执行的策略推演,并根据任务结果反馈学习何时及如何调用工具。ReTool 采用系统化训练框架,首先生成合成冷启动数据以构建含代码的长序列推理轨迹,用于微调基础模型;随后利用任务结果作为奖励信号进行强化学习,迭代优化模型的工具使用策略,实现无需人工先验的自主探索最优调用模式。在挑战性 MATH 奥林匹克基准 AIME 上的实验表明,我们的 32B 模型仅需 400 步训练即达 67% 准确率,显著优于纯文本强化学习基线(40% 准确率,1080 步)。尤为突出的是,ReTool-32B 在扩展设置下达到 72.5% 准确率,超过 OpenAI o1-preview 27.9%。进一步分析揭示了代码自修正等涌现行为,标志着模型自主掌握适应性工具使用的‘顿悟’时刻。这些发现展示了结果驱动的工具融合在提升复杂数学推理方面的潜力,并为混合神经符号系统提供了新洞见。

原文摘要 · Abstract (English)

While reasoning models (e.g., DeepSeek R1) trained with reinforcement learning (RL), excel in textual reasoning, they struggle in scenarios requiring structured problem-solving, such as geometric reasoning, concise computation, or complex equation solving-areas where computational tools like code interpreters (CI) demonstrate distinct advantages. To bridge this gap, we propose ReTool, which enhances long-form reasoning with tool-integrated learning, including two key features: (1) dynamic interleaving of real-time code execution within natural language reasoning processes, and (2) an automated RL paradigm that allows policy rollouts with multi-turn real-time code execution and teaches the model in learning when and how to invoke tools based on outcome feedback. ReTool employs a systematic training framework, beginning with synthetic cold-start data generation to produce code-augmented long-form reasoning traces for fine-tuning base models. Subsequent RL training leverages task outcomes as rewards to iteratively refine the model's tool use strategy, enabling autonomous discovery of optimal tool invocation patterns without human priors. Experiments on the challenging MATH Olympiad benchmark AIME demonstrate ReTool's superiority: Our 32B model achieves 67% accuracy with 400 training steps, outperforming text-based RL baseline (40% accuracy, 1080 steps) in efficiency and performance. Remarkably, ReTool-32B attains 72.5% accuracy in extended settings, surpassing OpenAI's o1-preview by 27.9%. Further analysis reveals emergent behaviors such as code self-correction, signaling an ''aha moment'' in which the model autonomously masters adaptive tool use. These findings highlight the promise of outcome-driven tool integration for advancing complex mathematical reasoning and offer new insights into hybrid neuro-symbolic systems.

强化学习工具调用数学推理大模型

Thank you to arXiv for use of its open access interoperability. PaperDance 不是 arXiv 官方产品;中文卡片由大模型生成,请以原文为准。