Dynamic Tool Dependency Retrieval for Lightweight Function Calling
DTDR leverages dynamic tool dependency modeling, boosting function calling success by 23%-104% through context-aware retrieval.
Key Findings
Methodology
This paper introduces DTDR, a framework that conditions tool retrieval on both user queries and the evolving sequence of tool calls, learned from demonstration data. It features two lightweight variants: DTDR-C, which constructs dependency graphs via clustering and graph traversal, and DTDR-L, a linear classifier trained to predict next tools based on context. The system encodes retrieved dependencies into prompts using hard or weighted masking, enabling the language model to sample appropriate tools iteratively. Extensive evaluation across multiple datasets and model sizes demonstrates significant improvements in retrieval metrics (e.g., MRR, F1), downstream task accuracy, and efficiency, validating the approach's effectiveness.
Key Results
- Across datasets like TinyAgent and TaskBench DailyLife APIs, DTDR-L achieved up to 104% higher function calling success rates compared to static retrieval baselines. On edge models such as Qwen 3 0.6B, success rates increased from 23% to over 65%, with F1 scores improving by 20%. The dynamic models consistently outperformed static counterparts in both retrieval accuracy and downstream task success, especially in multi-step, dependency-rich tasks.
- In experiments with models ranging from Qwen 3 0.6B to 14B and cloud models like GPT-4o, DTDR maintained high performance, demonstrating robustness and scalability. Prompt length analysis showed that weighted masking reduces prompt size, improving inference speed, particularly beneficial for resource-constrained devices. Ablation studies confirmed that incorporating full context and dependencies yields the best results.
- The study also found that the proposed dependency modeling significantly reduces irrelevant tool inclusion, leading to more precise function selection. The combination of demonstration learning and dependency-aware retrieval outperforms static or query-only baselines, establishing a new standard for lightweight, context-sensitive tool retrieval in autonomous agents.
Significance
This work addresses the critical challenge of dynamic, context-aware tool retrieval for on-device language agents, overcoming static limitations that hinder multi-step dependency modeling. By enabling real-time, adaptive tool selection, it enhances the accuracy and efficiency of function calling, crucial for practical deployment in edge devices, intelligent assistants, and automation systems. The approach bridges the gap between static knowledge and dynamic task requirements, paving the way for more robust, scalable AI systems capable of complex, multi-step reasoning with minimal resource overhead.
Technical Contribution
The core innovation lies in integrating demonstration-based learning of tool dependencies with lightweight, context-aware retrieval mechanisms. The two variants—clustering-based DTDR-C and linear classifier DTDR-L—offer flexible, resource-efficient solutions for real-time dependency inference. Unlike prior static or single-step models, DTDR dynamically adjusts its retrieval based on ongoing tool call sequences, capturing multi-step dependencies and task-specific nuances. This approach introduces a new paradigm for dependency-aware retrieval, with theoretical guarantees on relevance and efficiency, and practical benefits demonstrated through extensive empirical validation.
Novelty
This is the first framework to combine demonstration-driven learning with dynamic, context-sensitive tool dependency retrieval for lightweight agents. Unlike existing static or static-graph-based methods, DTDR models the evolving sequence of tool calls, enabling real-time, fine-grained dependency inference. Its dual variants provide practical, resource-efficient implementations suitable for on-device deployment, representing a significant step forward in adaptive, multi-step tool invocation systems.
Limitations
- The effectiveness depends heavily on the quality and diversity of demonstration data; limited or biased demonstrations can impair dependency learning.
- In highly complex or long-horizon tasks, the models may struggle to fully capture intricate dependencies, leading to potential errors.
- While designed for efficiency, the models still face challenges in extremely resource-constrained environments, especially regarding prompt length and inference latency.
Future Work
Future research could explore integrating reinforcement learning to optimize tool selection policies further. Extending the framework to multi-modal inputs, such as images or speech, could broaden application scenarios. Additionally, incorporating external knowledge bases or large-scale demonstrations may improve robustness and generalization, especially for unseen tasks or tools. Developing adaptive mechanisms to handle noisy or incomplete demonstration data remains an open challenge.
AI Executive Summary
In recent years, large language models (LLMs) have demonstrated remarkable capabilities in natural language understanding and generation, yet their ability to effectively invoke external tools for complex, multi-step tasks remains limited. Traditional approaches rely on static descriptions or demonstration data, which often fail to capture the dynamic dependencies between tools as tasks unfold. This leads to suboptimal tool selection, increased errors, and inefficiencies, especially in resource-constrained environments like edge devices.
To address these challenges, this paper introduces Dynamic Tool Dependency Retrieval (DTDR), a novel framework that conditions tool retrieval on both the initial user query and the evolving sequence of tool calls, learned from demonstration data. By modeling tool dependencies dynamically, DTDR enables the system to adapt its retrieval strategy as the task progresses, significantly improving the relevance and accuracy of selected tools. The framework features two lightweight variants: DTDR-C, which constructs dependency graphs via clustering and graph traversal, and DTDR-L, a linear classifier trained to predict next tools based on context.
The core technical innovation lies in integrating demonstration-based learning with real-time, context-aware retrieval. This approach allows the system to capture multi-step dependencies, branching behaviors, and task-specific nuances, which static methods overlook. The models encode retrieved dependencies into prompts using hard or weighted masking strategies, optimizing the balance between prompt length and relevance.
Extensive experiments across multiple datasets—including TinyAgent and TaskBench APIs—and model sizes demonstrate that DTDR achieves up to 104% improvement in function calling success rates over static baselines. In edge scenarios, success rates increase from 23% to over 65%, with notable reductions in prompt size and inference latency. The results confirm that dynamic, context-sensitive retrieval is essential for robust, efficient tool invocation in autonomous agents.
This work has broad implications for deploying intelligent systems on resource-limited devices, automating complex workflows, and enhancing multi-step reasoning. It bridges the gap between static knowledge and dynamic task demands, offering a scalable, adaptable solution for real-world AI applications. Future directions include integrating reinforcement learning, expanding to multi-modal inputs, and leveraging external knowledge bases to further improve dependency modeling and system robustness.
Deep Analysis
Background
近年来,大语言模型(LLMs)在自然语言处理领域取得了巨大突破,推动了智能问答、文本生成等多项应用的发展。早期工作如GPT-3、BERT等通过大规模预训练实现了强大的理解能力,但在实际应用中,调用外部工具以完成特定任务成为关键。工具调用技术如Toolformer(Schick et al., 2023)和Schick等(2023)提出了静态描述或示范学习的方法,能够在一定程度上实现工具调用,但多依赖静态信息,难以应对多步依赖和动态变化的任务场景。近年来,基于语义相似性和依赖关系的检索方法(如QTS、ToolNet)逐渐兴起,试图动态匹配工具,但仍存在静态性强、缺乏上下文适应性的问题。随着任务复杂度增加,静态检索难以捕获工具间的多步依赖关系,导致调用失误和效率降低。示范学习和依赖关系建模虽有所突破,但多依赖静态图或单步历史,不能充分反映任务的动态变化。本文在此背景下提出动态条件检索,旨在解决多步依赖捕获不足的问题。
Core Problem
核心问题在于现有静态检索方法无法动态适应任务上下文和工具调用轨迹,导致工具选择不准确。静态描述或单步历史忽略了多步依赖关系,容易引入无关工具或遗漏关键依赖,影响任务完成效率和准确性。尤其在边缘设备上,资源有限,模型需在保证低延迟的同时实现高精度检索。如何设计一种既轻量又能动态调整的工具依赖模型,成为亟待解决的难题。这关系到自动化系统的性能和用户体验,亟需创新解决方案。
Innovation
本研究的创新点包括:1)提出结合任务描述和工具调用历史的动态依赖关系建模框架,突破静态描述的限制;2)设计两种轻量级变体(DTDR-C和DTDR-L),实现实时、上下文感知的工具检索;3)引入示范学习机制,从示范中学习多步依赖关系,提升多任务适应性;4)优化工具在提示中的编码策略(硬掩码、加权掩码),增强模型的函数选择能力。这些创新使得工具检索更具上下文敏感性和多步依赖捕获能力,显著优于传统静态方法。
Methodology
- �� 输入:任务描述和工具调用历史。• 机制:
- 通过示范学习获取工具依赖关系模型。
- 设计两种变体:
- �� DTDR-C:利用聚类和图遍历,构建工具依赖图,动态推断下一步工具。
- �� DTDR-L:训练线性分类器,根据上下文预测工具子集。
- 输入任务描述和调用轨迹,输出相关工具子集。
- 将检索结果硬掩码或加权编码到提示中,供LLM采样下一工具。
- 迭代执行,直到任务完成或达到最大长度。• 训练:利用示范数据学习工具依赖关系,优化模型参数。• 评估:在多个数据集上测量检索指标(MRR、F1)、下游任务成功率和prompt长度。
Experiments
采用TinyAgent、TaskBench DailyLife APIs、TaskBench HuggingFace和Multimedia数据集,评估工具检索和函数调用成功率。对比静态检索(如ToolNet)和多种基线(BM25、QTS、LR),指标包括MRR、F1、函数选择准确率(FSA)和端到端成功率(SR)。模型涵盖Qwen 3系列(0.6B-14B)和云端模型(GPT-4o),测试不同任务复杂度和资源限制。通过消融实验验证不同编码策略(硬掩码、加权掩码)对性能的影响。
Results
动态检索(DTDR-L)在所有数据集上均优于静态方法,FSA提升最高达104%,MRR和F1指标也显著改善。特别是在边缘设备模型(Qwen 3 0.6B)中,成功率由静态方法的23%提升到65%以上。引入示范学习和多步依赖建模,有效减少无关工具引入,提升函数调用的准确性。硬掩码策略在小模型中表现优异,减少prompt长度,提升推理速度。整体结果验证了动态条件检索在多场景、多任务中的优越性。
Applications
该方法适用于边缘设备智能助手、自动化工作流、企业协作平台等场景,能显著提升工具调用的准确性和效率。依赖少、资源占用低,适合低延迟需求的实时系统。未来可结合多模态输入和强化学习,拓展多任务、多模态场景的应用范围,推动智能自动化的普及。
Limitations & Outlook
模型对示范数据的依赖较大,示范不足会影响性能。复杂长序列任务中依赖关系可能捕获不全,误差累积。在极端资源受限设备上,prompt长度和推理速度仍需优化,未来需结合模型剪枝和知识增强技术以提升鲁棒性。
Plain Language Accessible to non-experts
想象你在厨房做菜,手边有很多食材和工具。每次做菜都需要用不同的厨具,比如刀、锅、搅拌器。有时候,你会提前准备好所有工具,但有时也会根据菜的不同,临时决定用哪些工具。传统的方法就像提前把所有可能用到的厨具都放在桌子上,等你需要时再挑选。而本文提出的方法像是一个聪明的助手,它会根据你正在做的菜和你之前用过的工具,动态地帮你挑选最合适的厨具。这样,不仅节省空间,还能确保用到的工具正是你需要的,做菜也会变得更快更好。这种智能助手就像厨房里的神奇助手,能根据不同菜谱和你的习惯,灵活地帮你准备工具,让厨房变得更高效、更有趣。
ELI14 Explained like you're 14
想象你在学校里参加一个科学实验,你需要用到很多不同的工具,比如试管、显微镜、温度计。每次做不同的实验,所用的工具也不一样。有时候你会提前准备好所有可能用到的工具,但有时候你只知道大概需要哪些。传统的方法就像把所有工具都放在桌子上,等你用到时再找。而有个聪明的助手会根据你正在做的实验内容和你之前用过的工具,帮你动态挑选出最合适的工具。这样,你就不用一开始就准备所有工具,也不会用错工具。它就像一个会观察你、理解你需要什么的智能朋友,让你做实验变得更快、更顺利。未来,这样的助手还能帮你学习更多新技能,变得更聪明、更贴心!
Abstract
Function calling agents powered by Large Language Models (LLMs) select external tools to automate complex tasks. On-device agents typically use a retrieval module to select relevant tools, improving performance and reducing context length. However, existing retrieval methods rely on static and limited inputs, failing to capture multi-step tool dependencies and evolving task context. This limitation often introduces irrelevant tools that mislead the agent, degrading efficiency and accuracy. We propose Dynamic Tool Dependency Retrieval (DTDR), a lightweight retrieval method that conditions on both the initial query and the evolving tool calling plan. DTDR models tool dependencies from function calling demonstrations, enabling adaptive retrieval as plans unfold. We benchmark DTDR against state-of-the-art retrieval methods across multiple datasets and LLM backbones, evaluating retrieval precision, downstream task accuracy, and computational efficiency. Additionally, we explore strategies to integrate retrieved tools into prompts. Our results show that DTDR improves function calling success rates between $23\%$ and $104\%$ compared to state-of-the-art static retrievers.