Learning API Functionality from In-Context Demonstrations for Tool-based Agents

📄 arXiv: 2505.24197v2 📥 PDF

作者: Bhrij Patel, Ashish Jagmohan, Aditya Vempaty

分类: cs.AI

发布日期: 2025-05-30 (更新: 2025-11-12)

备注: 19 Pages, 14 Figures, 7 Tables


💡 一句话要点

提出一种从上下文演示中学习API功能的方法,用于提升工具型Agent在无文档场景下的任务成功率。

🎯 匹配领域: 支柱九:具身大模型 (Embodied Foundation Models)

关键词: API学习 上下文学习 工具型Agent 无文档学习 自然语言处理 大型语言模型 函数调用

📋 核心要点

  1. 现有工具型Agent依赖API文档,但文档常缺失或不准确,限制了其可靠性和通用性。
  2. 提出从上下文演示中学习API功能,无需文档即可使Agent理解并使用API。
  3. 实验表明,明确的函数调用和自然语言评论能显著提升Agent的任务成功率。

📝 摘要(中文)

本文提出了一种新的研究方向:直接从上下文演示中学习API功能,以解决工具型Agent依赖API文档但文档缺失、过期、私有或不一致的问题。作者利用API基准,收集了来自专家Agent和自我探索的演示数据。通过研究演示数量以及LLM生成的摘要和评估对任务成功率的影响,深入理解了演示数据需要传递哪些信息才能成功完成任务。实验结果表明,即使对于最先进的LLM,从上下文演示中学习API功能仍然是一个具有挑战性的任务。明确的函数调用和自然语言评论能够显著提高Agent的任务成功率,这归功于更准确的参数填充。最后,作者分析了失败模式,识别了错误来源,并强调了未来在无文档、自改进、基于API的Agent领域中面临的关键开放性挑战。

🔬 方法详解

问题定义:论文旨在解决工具型Agent在缺乏API文档的情况下,如何理解和使用API的问题。现有方法严重依赖API文档,但实际应用中,文档经常缺失、过期、私有化或者前后不一致,导致Agent无法正常工作。这限制了Agent的通用性和可靠性。

核心思路:论文的核心思路是从上下文演示(in-context demonstrations)中学习API的功能。通过提供一系列API调用的示例,让Agent能够模仿这些示例,从而理解API的使用方法和参数含义。这种方法无需依赖显式的API文档,使得Agent能够在更广泛的场景下应用。

技术框架:整体框架包括以下几个主要步骤:1) 数据收集:收集API调用的演示数据,包括专家Agent的演示和Agent自我探索的演示。2) 上下文构建:根据任务需求,选择合适的演示数据作为上下文信息。3) API调用:Agent根据上下文信息,生成API调用请求。4) 结果评估:评估API调用的结果,并根据评估结果进行调整和优化。

关键创新:最重要的技术创新点在于提出了从上下文演示中学习API功能的新范式。与传统方法依赖API文档不同,该方法直接从数据中学习,具有更强的适应性和鲁棒性。此外,论文还研究了不同类型的演示数据(例如,包含明确函数调用和自然语言评论的演示)对Agent性能的影响。

关键设计:论文的关键设计包括:1) 演示数据的选择策略:如何选择最能帮助Agent理解API功能的演示数据。2) 上下文构建方法:如何将演示数据融入到Agent的输入中。3) 评估指标:如何评估Agent的API调用结果。论文发现,提供明确的函数调用和自然语言评论能够显著提高Agent的任务成功率,这表明这些信息对于Agent理解API功能至关重要。

🖼️ 关键图片

fig_0
fig_1
fig_2

📊 实验亮点

实验结果表明,从上下文演示中学习API功能仍然是一个具有挑战性的任务,即使对于最先进的LLM。但是,通过提供明确的函数调用和自然语言评论,Agent的任务成功率得到了显著提高。这表明,精心设计的演示数据对于Agent学习API功能至关重要。实验在3个数据集和6个模型上进行,验证了该方法的有效性。

🎯 应用场景

该研究成果可应用于智能助手、自动化运维、软件开发等领域。例如,在智能助手中,Agent可以自动学习新的API,从而扩展其功能。在自动化运维中,Agent可以自动诊断和修复系统问题。在软件开发中,Agent可以自动生成API调用代码,提高开发效率。该研究有助于构建更加智能、通用和可靠的工具型Agent。

📄 摘要(原文)

Digital tool-based agents, powered by Large Language Models (LLMs), that invoke external Application Programming Interfaces (APIs) often rely on documentation to understand API functionality. However, such documentation is frequently missing, outdated, privatized, or inconsistent-hindering the development of reliable, general-purpose agents. In this work, we propose a new research direction: learning of API functionality directly from in-context demonstrations. This task is a new paradigm applicable in scenarios without documentation. Using API benchmarks, we collect demonstrations from both expert agents and from self-exploration. To understand what information demonstrations must convey for successful task completion, we extensively study how the number of demonstrations and the use of LLM-generated summaries and evaluations affect the task success rate of the API-based agent. Our experiments across 3 datasets and 6 models show that learning functionality from in-context demonstrations remains a non-trivial challenge, even for state-of-the-art LLMs. We find that providing explicit function calls and natural language critiques significantly improves the agent's task success rate due to more accurate parameter filling. We analyze failure modes, identify sources of error, and highlight key open challenges for future work in documentation-free, self-improving, API-based agents.