CRAFT: Customizing LLMs by Creating and Retrieving from Specialized Toolsets

Lifan Yuan, Yangyi Chen, Xingyao Wang, Yi Fung, Hao Peng, Heng Ji

Introduction

CRAFT (Creating and Retrieving from Specialized Toolsets) is a framework that allows Large Language Models (LLMs) to "level up" by automatically building their own libraries of specialized tools. By generating, abstracting, and retrieving task-specific code snippets, CRAFT enables off-the-shelf LLMs to solve complex visual, tabular, and mathematical problems with significant accuracy gains—all without any fine-tuning.

The Challenge with Existing Tool Augmentation

While LLMs like GPT-4 are impressively versatile, they often hit a wall when faced with tasks requiring specialized "hands-on" capabilities, such as precise spatial reasoning in images or complex multi-step calculations. To solve this, researchers often augment LLMs with external tools (APIs).

However, existing tool-augmentation methods suffer from two main flaws:

  1. Rigidity: They rely on fixed, general-purpose APIs that might not be optimized for a specific, niche task.
  2. Unreliability: Some methods try to have the LLM create a tool on the fly during inference, which often leads to buggy, non-reusable code that fails to solve the problem.
Comparison of CRAFT against baselines like ViperGPT and CREATOR.

CRAFT addresses this by creating a "middle ground": a curated, validated, and reusable library of specialized tools created before the model ever sees a test query.

The CRAFT Framework

The CRAFT framework operates in two distinct phases: Toolset Creation (offline) and Tool Retrieval/Execution (online).

1. Toolset Creation

Instead of hand-coding APIs, CRAFT uses an automated pipeline:

  • Generation: The system prompts an LLM (like GPT-4) to solve a diverse set of training examples using Python code.
  • Abstraction: This is the "secret sauce." CRAFT takes a specific solution (e.g., "find the red ball") and instructs the LLM to turn it into a generic, reusable function (e.g., find_object_by_color(image, color)). It also generates a clear docstring for each tool.
  • Verification: Each abstract tool is tested back against the original training problems. If it doesn't produce the correct answer, it’s discarded.
  • Deduplication: To keep the toolset lean, similar tools are merged, keeping only the most comprehensive version.

2. Tool Retrieval and Inference

At inference time, when a user asks a question, CRAFT doesn't just guess which tool to use. It employs multi-view matching. It compares the user's query against three "views" in the toolset: the original problem the tool solved, the tool’s name, and its docstring. The most relevant tools are then injected into the LLM's prompt, allowing the model to write a simple script that calls these pre-validated functions to reach an answer.

Key Findings and Results

The authors evaluated CRAFT across three distinct domains: Vision-Language (GQA, OK-VQA, A-OKVQA), Tabular Processing (TabMWP), and Mathematical Reasoning (MATH algebra subset).

  • Substantial Performance Gains: CRAFT demonstrated significant improvements over strong baselines like ViperGPT and CREATOR. On VQA tasks, it achieved an average 43.16% relative improvement in F1 score over the best baselines. On the MATH algebra subset, CRAFT reached 68.1% accuracy, significantly outperforming vanilla tool-use (58.2%) and Chain-of-Thought prompting (50.9%).
  • The Power of Abstraction: The transition from "specific code" to "abstract tool" is what makes the system scalable. By generalizing variable names and wrapping logic into functions, a tool created for one problem becomes a Swiss Army knife for thousands of similar ones.
  • Multi-View Retrieval Matters: Matching the query to the function name was found to be the most critical part of retrieval. Removing the name-matching component drops performance significantly.
  • The "Scaling Law" of Tools: Performance consistently improves as the toolset grows and as the backbone model becomes more powerful. This suggests that "tool-making" is a viable path for continuing to improve LLM utility without massive retraining.
  • Efficiency: The framework is "plug-and-play." It allows a smaller or cheaper model (like GPT-3.5-Turbo) to perform at levels closer to much larger models by giving it access to the "wisdom" encoded in the GPT-4-generated toolset.

Limitations and Future Work

  • Code Dependency: Currently, CRAFT only works for tasks that can be solved via Python code. The authors suggest exploring pseudocode in the future to expand to non-coding domains.
  • Backbone Sensitivity: The system's success depends on the LLM's inherent ability to use tools. While CRAFT helps, very weak models still struggle to navigate the toolset effectively.
  • Cost: Building the initial toolset is computationally expensive (estimated at ~$2,500 for this paper), though this is a one-time cost that pays off during inference.

In summary, CRAFT moves us away from "one-size-fits-all" AI and toward a future where LLMs can be rapidly customized for any domain by simply "crafting" the right set of digital tools.

Summary updated

BibTeX
@inproceedings{yuan2024craft,
  author = {Lifan Yuan and Yangyi Chen and Xingyao Wang and Yi Fung and Hao Peng and Heng Ji},
  title = {{CRAFT: Customizing LLMs by Creating and Retrieving from Specialized Toolsets}},
  booktitle = {International Conference on Learning Representations},
  year = {2024},
  url = {https://openreview.net/forum?id=G0vdDSt9XM},
}
Figure