TinyAgent: Function Calling at the Edge

Lutfi Eren Erdogan, Nick Lee, Siddharth Jha, Se Hoon Kim, Ryan Tabrizi, Suhong Moon, Coleman Hooper, Gopala K. Anumanchipalli, Kurt Keutzer, Amir Gholami2024

Abstract

Lutfi Eren Erdogan, Nicholas Lee, Siddharth Jha, Sehoon Kim, Ryan Tabrizi, Suhong Moon, Coleman Richard Charles Hooper, Gopala Anumanchipalli, Kurt Keutzer, Amir Gholami. Proceedings of the 2024 Conference on Empirical Methods in Natural Language Processing: System Demonstrations.

2024.

Introduction

Modern Large Language Models (LLMs) like GPT-4o are powerful but typically reside in the cloud, leading to significant hurdles in privacy, connectivity, and latency. For specialized tasks such as managing a user's calendar or local files, the massive parametric memory of these models—often used to store general world knowledge—is largely unnecessary.

TinyAgent introduces a framework that enables Small Language Models (SLMs), with as few as 1.1 billion parameters, to perform complex function calling and task orchestration directly on edge devices like MacBooks. By trading general knowledge for specialized reasoning, TinyAgent achieves performance comparable to cloud-bound models while maintaining offline operation and user privacy.

Methodology: From Natural Language to DAGs

TinyAgent employs an end-to-end pipeline to optimize SLMs for agentic tasks. The core of the system is the Function Calling Planner, which integrates with LLMCompiler. Instead of simple text generation, the model is trained to output a "Function Calling Plan" structured as a Directed Acyclic Graph (DAG). This DAG specifies the tools to be called, their arguments, and the dependencies between them.

TinyAgent architecture: converting user input into a Directed Acyclic Graph (DAG) of function calls.

To further optimize performance, TinyAgent replaces standard embedding-based Retrieval-Augmented Generation (RAG) with a classification-based tool retrieval method. A fine-tuned DeBERTa-v3-small model performs multi-label classification to predict exactly which tools are required for a given query. This approach ensures that all necessary "auxiliary" tools are included while reducing prompt size by approximately 50%.

The models (TinyLlama-1.1B and Wizard-2-7B) were fine-tuned using Low-Rank Adaptation (LoRA) on a high-quality synthetic dataset of 80,000 examples generated by GPT-4-Turbo. To ensure efficient execution on consumer hardware, 4-bit quantization via llama.cpp was applied, reducing the memory footprint by 4x.

Key Insights and Results

A critical insight from the study is that reasoning capabilities are not exclusive to massive models. By including "negative samples" (descriptions of irrelevant tools) during fine-tuning, the researchers taught the SLMs to be discerning, significantly improving tool selection accuracy.

Evaluation was conducted using Graph Isomorphism, comparing the logical structure of the generated DAGs against ground truth to ensure correct task orchestration. This provides a much more rigorous measure of success than simple keyword matching.

DAG-based evaluation comparing generated plans against ground truth using graph isomorphism.

The results demonstrate the efficacy of local SLMs:

  • Performance: TinyAgent-7B achieved an 85.14% success rate, while the 1.1B model reached 80.35%, both outperforming GPT-4-Turbo (79.08%) on the specific macOS assistant benchmark.
  • Efficiency: On a MacBook Pro M3, the 1.1B model occupies only 0.68 GB of RAM and delivers responses in under 3 seconds.
  • Recall: The DeBERTa-based tool retrieval achieved 99.8% recall, effectively optimizing the input context.

Limitations and Future Work

While TinyAgent shows great promise, SLMs are still susceptible to hallucinations and syntax errors, necessitating human-in-the-loop oversight for critical actions. Additionally, the current models are specialized for a set of 16 macOS tools; scaling this to thousands of dynamic APIs remains a challenge. Future research will focus on improving human-agent collaboration and mitigating potential biases inherited from synthetic training data.

Summary updated

BibTeX
@misc{erdogan2024tinyagent,
  author = {Lutfi Eren Erdogan and Nick Lee and Siddharth Jha and Se Hoon Kim and Ryan Tabrizi and Suhong Moon and Coleman Hooper and Gopala K. Anumanchipalli and Kurt Keutzer and Amir Gholami},
  title = {{TinyAgent: Function Calling at the Edge}},
  year = {2024},
  doi = {10.18653/v1/2024.emnlp-demo.9},
}
Figure