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)与外部工具相结合,已成为解决复杂问题的一种有前景的方法。然而,传统方法需要利用工具演示数据对LLM进行微调,这既成本高昂,又受限于预定义的工具集。近期的上下文学习范式缓解了这些问题,但有限的上下文长度仅允许提供少量示例,导致对工具的理解不够充分。此外,当有大量工具可供选择时,上下文学习可能完全失效。本文提出了一种替代方法——$\textbf{ToolkenGPT}$,它融合了上述两种方法的优势。我们的方法将每个$\underline{tool}$表示为一个$\underline{token}$($\textit{toolken}$),并学习其嵌入,从而能够以生成常规词token的方式调用工具。一旦触发某个toolken,LLM即被提示为工具执行所需参数。ToolkenGPT通过动态扩展toolken集合,能够灵活地接入任意数量的工具。此外,它允许利用大量演示数据学习toolken嵌入,从而提升工具使用效果。在数值推理、基于知识的问答以及具身化规划生成等多个领域,我们的方法有效地增强了LLM对工具的运用,并显著优于多种最新基线方法。ToolkenGPT展示了在复杂场景中从大型工具集中精准调用相关工具的潜力。