tool-prune

September 19, 2026 · View on GitHub

Calibrated tool selection and schema pruning for AI agents. Dual-engine: zero-dependency offline TurboQuant or TypeSafe System One.

Live Interactive Playground →

npm install tool-prune
# or
pip install tool-prune

# Optional: TypeSafe API key for cloud reasoning
export TYPESAFE_API_KEY="apikey_..."

Quick start

import prune from 'tool-prune';

const tools = {
  readFile: 'Read raw text from local filesystem path',
  runQuery: 'Execute SQL queries against database',
  webSearch: 'Search public web for documentation or articles'
};

// Works offline out of the box with TurboQuant:
const match = await prune('what tables exist in the db?', tools);
console.log(match.tool);   // 'runQuery'
console.log(match.engine); // 'turboquant'

prune() runs offline via TurboQuant by default, or routes to TypeSafe System One when TYPESAFE_API_KEY is present. That's the whole API.

Schema pruning for LLMs

Instead of dumping 100 MCP tool schemas into every prompt, prune them to the relevant candidates before calling your LLM:

const router = prune(tools);

// Auto-selects candidates dynamically based on confidence drop-off:
const topTools = await router.filter(userPrompt);

// Or pass fixed k:
// const topTools = await router.filter(userPrompt, { k: 5 });

const response = await llm.chat({
  tools: topTools,
  messages: [{ role: 'user', content: userPrompt }]
});

filter() automatically detects the optimal tool set based on score distribution, or accepts { k: 5 } for fixed top-K. Cuts prompt tokens by up to 92% and eliminates context confusion.

Fast-path direct dispatch

Bypass the LLM entirely when confidence clears your threshold:

const result = await router.dispatch('read ./package.json', {
  readFile: (query) => fs.readFileSync('package.json', 'utf8'),
  runQuery: (query) => db.query(query),
  fallback: (query, match) => callLLM(query)
});

Deterministic tool execution in under 160ms with zero LLM generation cost.

Dual engine

Select between offline vector search and cloud reasoning:

// Explicitly pick engine
const localMatch = await prune(query, tools, { engine: 'turboquant' });
const cloudMatch = await prune(query, tools, { engine: 'typesafe', apiKey: '...' });
  • turboquant: 100% offline, zero network, zero dependencies. Uses turboquant-search (WASM SIMD) in JS or turbovec (Rust SIMD) in Python if installed, with seamless built-in FWHT fallback.
  • typesafe: Cloud System One reasoning (Jev). 100% Top-1 accuracy on subtle distractors with calibrated probabilities.

Python

Identical API and zero required dependencies:

from tool_prune import prune, ToolPrune

# One-shot offline pruning
match = prune("what tables exist in the db?", tools)
print(match.tool, match.engine)

# Reusable router for LLM prompt pruning (auto-selects candidates)
router = ToolPrune(tools)
candidates = router.filter(user_prompt)  # or router.filter(user_prompt, k=5)

Berkeley Function Calling Leaderboard (BFCL v3)

Evaluated on Gorilla BFCL v3 multiple-tool benchmark:

EngineBackendDistractor Top-1100-Tool Top-5 PruneLatencyNetwork
TypeSafe (Jev)Cloud System One100.0%100.0%189 msCloud API
TurboQuantJS WASM (turboquant-search)86.7%85.0%16 msOffline
TurboQuantPython Rust (turbovec)85.0%82.5%0.018 msOffline
TurboQuantPure JS / Python (built-in)86.7%77.5%0.14 msOffline
BM25 (Baseline)Lexical search88.3%95.0%0.025 msOffline

End-to-End Agent Architecture Benchmark (60 Tools)

Evaluated with Claude Haiku 4.5 across 60 tool schemas and 79 queries:

ParadigmAccuracyLatency (P50)Tokens / TurnRoundtripsNotes
Tool-Prune Direct97.5%149 ms385 tokens0 LLM turnsLLM bypassed via calibrated fast-path (91% of queries)
Tool-Prune + LLM97.5%195 ms397 tokens1 turnDynamic Top-K candidate schema pruning (-72% tokens)
Full-Context LLM97.5%555 ms1,409 tokens1 turnAll 60 tool schemas dumped into prompt context
Tool-Search (BM25 + LLM)87.3%979 ms436 tokens2 turnsLexical retrieval bottleneck on ambiguous queries
Code Mode (search + eval)64.6%2,209 ms1,735 tokens1.9 turnsMulti-turn discovery drops target before sandbox execution

Run evaluations:

node bench/run.mjs --size 60
node bench/run_codemode_eval.mjs
node bench/run_bfcl_eval.mjs
uv run --with turbovec --with numpy python3 bench/run_turbovec_bench.py

License

MIT © Hemanth.HM