TL;DR
Deploying Large Language Model (LLM) agents on-device for function calling is heavily restricted by strict memory and latency budgets. This paper introduces Dynamic Tool Dependency Retrieval (DTDR), a lightweight retrieval framework that selects relevant tools by conditioning on both the user's initial query and the evolving history of executed tools. By dynamically pruning the toolset during planning, DTDR improves function-calling success rates by up to 104% while drastically reducing prompt token overhead.
What Problem Does This Paper Address?
When LLM agents perform complex, multi-step tasks, they rely on external APIs (tools). On resource-constrained edge devices (like phones or laptops), stuffing descriptions of hundreds of available tools into an LLM prompt is impossible—it destroys latency, blows up the memory footprint, and confuses the model.
To solve this, researchers use tool retrievers to select a small subset of relevant tools before prompting the LLM. However, existing retrievers have a major flaw: they are static. They either look only at the initial user query (ignoring what tools have already been called) or look only at the very last tool executed (ignoring the overall task goal). As illustrated in Figure 1, this lack of joint awareness leads to suboptimal tool selection, causing agents to get stuck in repetitive loops or miss critical branching dependencies.
Methods
The authors propose Dynamic Tool Dependency Retrieval (DTDR), which models tool retrieval as a function of both the query ($q$) and the history of previously predicted functions ($f_{0:t-1}$). They design two highly efficient, lightweight variants that utilize historical demonstration trajectories:
- DTDR-Clustering (DTDR-C): An unsupervised approach. It uses a pre-trained embedding model and K-Means to cluster training queries. For each cluster, it constructs a weighted tool dependency graph (an $l$-ordered Markov Chain). At inference, the retriever finds the closest query cluster and traverses its specific dependency graph based on the tool history to predict the next tools.
- DTDR-Linear (DTDR-L): A supervised approach. It concatenates the query and the tool history as a single string, passes it through a frozen embedding model, and trains a single linear layer classifier using binary cross-entropy. Tools with probabilities above a threshold ($\alpha$) are retrieved.
Once the tools are retrieved, the paper evaluates different In-Context Learning (ICL) strategies to feed them to the LLM. The most effective strategy is Hard Masking, which completely removes irrelevant tools from the prompt, forcing the LLM to choose only from the dynamically retrieved subset (see Figure 2).
Datasets
The approach was benchmarked across four distinct function-calling datasets:
- TinyAgent: Represents tools commonly available on a typical device (17 tools, ~40k plans).
- TaskBench DailyLife APIs: Features daily-use tools but contains almost zero sequential tool dependencies.
- TaskBench HuggingFace: Domain-specific AI model tools (24 tools, ~5k plans).
- TaskBench Multimedia: Domain-specific multimedia processing tools (41 tools, ~4k plans).
Key Insights and Ideas
- Branching Context Matters: Relying only on the last executed tool creates a generic prior. For instance, after calling
summarize_pdf, the next correct tool depends entirely on whether the user's original intent was to email the summary or save it to a file. DTDR successfully resolves these branching paths. - Pruning Beats Prompting for Small Models: Smaller models (e.g., Qwen 3 0.6B or 1.7B) are easily overwhelmed by long contexts or raw text demonstrations. Directly pruning the toolset via Hard Masking yields the highest accuracy gains for these edge-scale models.
- Bridging the Edge-Cloud Gap: Remarkably, when DTDR-L is paired with smaller edge models like Qwen 3 4B or 8B, it allows them to outperform much larger models (like Qwen 3 14B or GPT-4o) running without retrieval.
Key Results
- Retrieval Accuracy: DTDR-L achieved a Mean Reciprocal Rank (MRR) of 0.93 on the TinyAgent dataset, vastly outperforming the static query-based baseline (0.53) and the history-only baseline (0.70).
- Downstream Success: On the Qwen 3 0.6B model, DTDR-L boosted Function Selection Accuracy (FSA) on TinyAgent from 23.2% (No ICL) to 46.1%.
- Prompt Efficiency: As shown in Figure 5, DTDR dramatically reduces the total prompt length by up to 73% and the variable portion by up to 48% compared to providing raw text demonstrations, saving significant prefill latency and compute costs.
Limitations and Future Work
The authors note several limitations:
- Out-of-Distribution (OOD) Sensitivity: DTDR-C's performance degrades on completely unseen tasks because its clustering and Markov modeling require sufficient training data coverage to map transitions reliably.
- Niche Vocabularies: If tool names are highly non-standard or domain-specific, pre-trained embeddings struggle to capture semantic similarity (though DTDR-L partially mitigates this through supervised training).
- Dependence on Expert Data: The framework assumes access to clean, ground-truth expert demonstrations. Future work will focus on learning from failed, incorrect, or unlabeled agent trajectories, as well as extending the method to multimodal tasks.
Summary updated