Augmenting large language models (LLMs) with external tools has emerged as a promising approach to solving complex problems. However, traditional methods, which finetune LLMs with tool demonstration data, can be both costly and restricted to a predefined set of tools. Recent in-context learning paradigm alleviates these issues, but the limited context length only allows for a few shots of demonstrations, leading to suboptimal understandings of the tools. Moreover, when there are numerous tools to choose from, in-context learning could completely fail to work. In this paper, we propose an alternative approach, $\textbf{ToolkenGPT}$, which combines the benefits of both sides. Our approach represents each $\underline{tool}$ as a to$\underline{ken}$ ($\textit{toolken}$) and learns an embedding for it, enabling tool calls in the same way as generating a regular word token. Once a toolken is triggered, the LLM is prompted to complete arguments for the tool to execute. ToolkenGPT offers the flexibility to plug in an arbitrary number of tools by expanding the set of toolkens on the fly. In addition, it improves tool use by allowing extensive demonstration data for learning the toolken embeddings. In diverse domains, including numerical reasoning, knowledge-based question answering, and embodied plan generation, our approach effectively augments LLMs with tools and substantially outperforms various latest baselines. ToolkenGPT demonstrates the promising ability to use relevant tools from a large tool set in complex scenarios.
翻译:增强大型语言模型(LLMs)的外部工具使用能力已成为解决复杂问题的有效途径。然而,传统方法通过工具演示数据微调LLMs,不仅成本高昂,且受限于预定义的工具集合。近期提出的上下文学习范式虽缓解了这些问题,但有限的上下文长度仅支持少量演示样本,导致模型对工具的理解不够充分。更严重的是,当面临大量工具选择时,上下文学习可能完全失效。本文提出一种融合双方优势的替代方案$\textbf{ToolkenGPT}$。该方法将每个$\underline{工具}$表示为$\underline{标记}$($\textit{toolken}$),学习其嵌入向量,使得工具调用如同生成常规词元般自然。一旦触发工具标记,LLM便通过提示生成该工具执行所需的参数。ToolkenGPT可通过动态扩展工具标记集合灵活插入任意数量工具;同时,通过海量演示数据学习工具嵌入,有效提升工具使用效能。在数值推理、知识问答、具身规划生成等多元领域,本方法显著增强了LLMs的工具运用能力,其表现全面优于多种最新基线模型。ToolkenGPT充分证明了在复杂场景下从庞杂工具库中精准调用相关工具的卓越潜力。