将工具学习转化为代码生成,提升大模型复杂任务的执行能力
ToolCoder: A Systematic Code-Empowered Tool Learning Framework for Large Language Models
- 把自然语言指令转为带注释的Python函数模板,用编程思维拆解任务
- 在多个基准上任务完成率超基线方法,错误诊断准确率显著提升
- 适合需要高可靠执行、多步规划的自动化系统开发者
工具学习已成为大语言模型通过与外部工具交互解决复杂现实任务的关键能力。现有方法存在依赖手工设计提示、难以进行多步规划、缺乏精准错误诊断与反思机制等问题。我们提出ToolCoder,一种将工具学习重新构想为代码生成任务的新框架。受软件工程启发,ToolCoder将自然语言查询转换为结构化的Python函数骨架,并通过描述性注释系统性地分解任务,使大模型能利用编程范式进行复杂推理与规划。随后生成并执行函数实现以获得最终响应。此外,ToolCoder将成功执行的函数存入仓库促进代码复用,同时利用错误回溯机制实现系统化调试,从而提升执行效率与鲁棒性。实验表明,ToolCoder在任务完成准确率和执行可靠性方面均优于现有方法,验证了代码中心方法在工具学习中的有效性。
原文摘要 · Abstract (English)
Tool learning has emerged as a crucial capability for large language models (LLMs) to solve complex real-world tasks through interaction with external tools. Existing approaches face significant challenges, including reliance on hand-crafted prompts, difficulty in multi-step planning, and lack of precise error diagnosis and reflection mechanisms. We propose ToolCoder, a novel framework that reformulates tool learning as a code generation task. Inspired by software engineering principles, ToolCoder transforms natural language queries into structured Python function scaffold and systematically breaks down tasks with descriptive comments, enabling LLMs to leverage coding paradigms for complex reasoning and planning. It then generates and executes function implementations to obtain final responses. Additionally, ToolCoder stores successfully executed functions in a repository to promote code reuse, while leveraging error traceback mechanisms for systematic debugging, optimizing both execution efficiency and robustness. Experiments demonstrate that ToolCoder achieves superior performance in task completion accuracy and execution reliability compared to existing approaches, establishing the effectiveness of code-centric approaches in tool learning.
Thank you to arXiv for use of its open access interoperability. PaperDance 不是 arXiv 官方产品;中文卡片由大模型生成,请以原文为准。