TPTU-v2: Boosting Task Planning and Tool Usage of Large Language Model-based Agents in Real-world Systems

Yilun Kong, Jingqing Ruan, Yihong Chen, Bin Zhang, Tianpeng Bao, Shiwei Shi, Guoqing Du, Xiaoru Hu, Hangyu Mao, Ziyue Li, Xingyu Zeng, Rui ZhaoarXiv 2023 · DOI

Abstract

While Large Language Models (LLMs) have demonstrated remarkable reasoning capabilities, their deployment as autonomous agents in real-world software environments remains challenging. These environments often feature massive API libraries, complex multi-step workflows, and ambiguous tool descriptions. This paper introduces TPTU-v2, a framework designed to bridge this gap through a three-pronged approach: a semantic API retriever, domain-specific supervised fine-tuning (SFT), and an adaptive demonstration selector. Experimental results show that TPTU-v2 significantly outperforms base models, achieving up to 96.67% accuracy in complex real-world scenarios.

1. Introduction

Transforming an LLM into a functional agent requires the model to interact with external tools via APIs. However, real-world systems present three primary bottlenecks that hinder performance:

  1. The Context Window Limit: Large-scale systems may contain thousands of APIs, making it impossible to include all documentation within a single prompt.
  2. Planning Complexity: Executing intricate workflows requires precise multi-step reasoning that base models often lack.
  3. API Ambiguity: Overlapping functionalities and similar naming conventions in specialized domains frequently lead to tool selection errors.

TPTU-v2 addresses these issues by filtering the toolset, enhancing the model's reasoning through targeted training, and providing context-aware demonstrations.

2. Methodology

The TPTU-v2 architecture is composed of three integrated components designed to optimize the agent's decision-making pipeline.

2.1 API Retriever

To overcome context limitations, the system employs a dual-stream Sentence-BERT architecture. This component converts user instructions and API descriptions into high-dimensional embeddings. By performing a semantic search, the retriever identifies and "recalls" only the top-K most relevant tools, effectively reducing the noise and token count passed to the LLM.

2.2 LLM Finetuner

The core reasoning engine (based on the InternLM model) underwent iterative Supervised Fine-Tuning (SFT). The researchers developed three versions of training data, with the final iteration (v3) focusing on robustness. This was achieved through heavy data augmentation, including shuffling API orders and intentionally inserting "irrelevant" APIs into the training prompts. This process trained the model to ignore distractions and maintain focus on the necessary tools for multi-step planning.

2.3 Demo Selector

To resolve API ambiguity, the Demo Selector dynamically retrieves successful historical examples of tool usage. These demonstrations are inserted into the prompt as in-context learning (ICL) examples, providing the LLM with a blueprint for how to distinguish between similar tools in specific scenarios.

3. Experimental Setup

The framework was evaluated across two distinct environments:

  • Commercial Security System: A real-world scenario featuring 45 APIs across 11 core functionalities. While the API count is smaller than open-source benchmarks, the tasks are highly complex, requiring trajectories of up to 9 steps (average 3.5 steps).
  • ToolBench: A massive open-source benchmark containing over 16,000 APIs across 49 categories, used to test the generalizability of the retriever and fine-tuning approach.

4. Key Results and Analysis

The integration of the three components led to a substantial performance increase over baseline models.

4.1 Performance Gains

In the real-world security system scenario, a base LLM without demonstrations achieved a meager 38.89% execution accuracy. The addition of the API Retriever and Demo Selector boosted this to 95.55%. When combined with the domain-specific fine-tuning of the TPTU-v2 framework, accuracy peaked at 96.67%. In the broader ToolBench environment, the framework improved performance from 76.67% to 86.7%.

4.2 The Importance of Robustness

A significant finding was that even an "Oracle" retriever (which provides the perfect set of APIs) is not a complete solution. LLMs exhibit a bias based on the order in which APIs are presented. TPTU-v2’s fine-tuning strategy, which included noisy and shuffled data, proved essential in mitigating this bias and ensuring the model could identify the correct tools regardless of prompt structure.

4.3 Retriever Efficiency

The Sentence-BERT retriever achieved a Recall@10 of 98.47% in the real-world scenario. However, in the hyper-dense ToolBench environment, recall dropped to 76.9%. This suggests that as API libraries grow in density and similarity, the retriever becomes a critical bottleneck; a single missed tool in a multi-step plan can lead to a cumulative error that causes the entire task to fail.

5. Conclusion and Future Work

TPTU-v2 demonstrates that high-accuracy tool usage in real-world systems requires more than just a powerful base model. It requires a coordinated system of retrieval, robust fine-tuning, and contextual guidance. Future research will focus on improving retriever recall in dense API environments and reducing the manual effort required to maintain the knowledge bases used by the Demo Selector. Scaling the framework to handle more open-ended environments where agents must discover tool usage autonomously remains a primary objective.

Summary updated

BibTeX
@misc{kong2023tptu,
  author = {Yilun Kong and Jingqing Ruan and Yihong Chen and Bin Zhang and Tianpeng Bao and Shiwei Shi and Guoqing Du and Xiaoru Hu and Hangyu Mao and Ziyue Li and Xingyu Zeng and Rui Zhao},
  title = {{TPTU-v2: Boosting Task Planning and Tool Usage of Large Language Model-based Agents in Real-world Systems}},
  year = {2023},
  eprint = {2311.11315},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2311.11315},
}
Figure