tool-prune
v0.3.0
Published
Fast, calibrated tool selection and schema pruning for AI agents using TypeSafe System One and TurboQuant vector search.
Maintainers
Readme
tool-prune
Calibrated tool selection and schema pruning for AI agents. Dual-engine: zero-dependency offline TurboQuant or TypeSafe System One.
npm install tool-prune
# Optional SIMD acceleration
npm install turboquant-search
# 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() narrows schemas 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
const router = prune(tools);
// Auto-selects candidate schemas dynamically (or pass { k: 5 }):
const topTools = await router.filter(userPrompt);
const response = await llm.chat({
tools: topTools,
messages: [{ role: 'user', content: userPrompt }]
});Cuts prompt tokens by up to 92% and eliminates context confusion without losing tools.
Fast-path direct dispatch
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)
});Runs deterministic handlers in under 160ms with zero token cost.
Dual 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) if installed, with built-in FWHT fallback. - typesafe: Cloud System One reasoning (Jev). 100% Top-1 accuracy on subtle distractors with calibrated probabilities.
Demo
npm run demoLicense
MIT © Hemanth.HM
