Skip to main content

Official Repo for ToolGrad: Efficient Tool-use Dataset Generation with Textual “Gradients”

Project description

ToolGrad: Efficient Tool-use Dataset Generation with Textual "Gradients"

Open In Colab GitHub license Arxiv PyPI

TODOs: Dataset on HF Model on HF

This is an official repo for <ToolGrad: Efficient Tool-use Dataset Generation with Textual “Gradients”>.

Get Started: A Quick Demo

Step 0: Install packages

git clone https://github.com/zhongyi-zhou/toolgrad.git
cd toolgrad
conda env create -f environment.yml
conda activate toolgrad

Step 1: launch your first ToolGrad framework on a MCP service

export PYTHONPATH=./
python examples/mcp_filesystem.py

Reproduction of Dataset Generation

Step 0: ToolBench API Key

You need to first obtain a ToolBench API key by following their instruction:

Note: The API key is necessary for the following procedures.

Step 1: ToolBench Setups

export TOOLBENCH_KEY=YOURTOOLBENCHKEY

You also need to setup the ToolBench API database:

  • Unzip tools.zip (Google Drive) and it will show a tools/ folder.
  • add this path to the environ as follow
export TOOLBENCH_LIBRARY_ROOT=YOUR_PATH/TO/TOOLS

Step 2: Generate your first ToolGrad sample on the ToolBench API database

export PYTHONPATH=./
python examples/toolbench.py

You will then find a new json file under examples/outputs/. examples/example_outputs/seed=123__iter=5__num_apis=50.json is an example that we generated.

ToolGrad-5K is composed of 5k data generation sessions with different seed. It takes ~250 USD to generate the full 5K dataset, using gpt-4.1-mini.

Evaluation

First download the dataset from Google Drive and unzip it. You should be able see a folder structure as follows:

ToolGrad-5k  
├── data  
├── metadata  
├── prediction  
└── sft_data  

The prediction folder stores the prediction of three ToolGrad models on the test set. You can run the following command to perform evaluation with LLM judges:

python src/eval.py --pred_model toolgrad-1b --dataset ~/YOUR_DATASET_STORAGE_DIR/ToolGrad-5k/

You should see the following messages in CMD.

judge model: gpt-4.1
100%|████████████████████████████████████████████████████████████████████████████| 500/500 [00:00<00:00, 1384.60it/s]
               Recall  Success Rate     QoR
Model                                      
toolgrad-1b  0.987917      0.955482  93.702

This is an exact reproduction of our results.

If you wish to run the LLM judge again, run the following command (note this introduces costs on your OpenAI API):

python src/eval.py --pred_model toolgrad-1b \
  --dataset ~/YOUR_DATASET_STORAGE_DIR/ToolGrad-5k/ \
  --overwrite \
  --num_process 16 

You should be able to see a new result with similar values of ours. Note that you can adjust the num_process dependent on your OpenAI API RPM.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

toolgrad-0.1.1.tar.gz (439.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

toolgrad-0.1.1-py3-none-any.whl (451.3 kB view details)

Uploaded Python 3

File details

Details for the file toolgrad-0.1.1.tar.gz.

File metadata

  • Download URL: toolgrad-0.1.1.tar.gz
  • Upload date:
  • Size: 439.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.5

File hashes

Hashes for toolgrad-0.1.1.tar.gz
Algorithm Hash digest
SHA256 45efe9882dfc90fe541e27a16d64013d549d3cc53ce1cc2fc84119f851b0a6a9
MD5 3d1f339e19038a0dfa13c6de1aabf524
BLAKE2b-256 4592ad724db9acb18fb2fa9c2d91c6dc425ddfd1be6d7db07a2ffcbc807f877e

See more details on using hashes here.

File details

Details for the file toolgrad-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: toolgrad-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 451.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.5

File hashes

Hashes for toolgrad-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 33cbc50314157709fbdf4680c12a19540a990fee564897433c0e5938ec3bef01
MD5 57752bf80efb89180da924c65022eaaa
BLAKE2b-256 182e9570d7425a2842b0e2ac09fad4a2d1f3122192d35629e8573a47f52e58d0

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page