@toolroute/hook
v1.0.2
Published
Auto-route every agent task through ToolRoute. Install once, every task gets the best tool and model recommendation.
Maintainers
Readme
@toolroute/hook
Auto-route every agent task through ToolRoute. Install once — every task gets the best MCP server and LLM model recommendation, automatically.
Install
npm install @toolroute/hookQuick Start
import { createHook } from '@toolroute/hook'
const hook = createHook({
agentName: 'my-agent',
verbose: true, // logs routing decisions
})
// Register (optional, earns 2x credits)
await hook.register()
// Wrap any task — routing + reporting happens automatically
const result = await hook.run('scrape competitor pricing data', async (routing) => {
console.log(`Best tool: ${routing.skillName}`) // e.g., "Firecrawl MCP"
console.log(`Best model: ${routing.model}`) // e.g., "claude-haiku-4-5-20251001"
console.log(`Confidence: ${routing.confidence}`)
// ... your actual task logic here ...
return { prices: [29, 49, 99] }
})
console.log(result.data) // { prices: [29, 49, 99] }
console.log(result.executionMs) // 1847
console.log(result.creditsEarned) // 5Just Route (no wrapper)
const routing = await hook.route('draft an email to a client')
// routing.skill → "gmail-mcp"
// routing.model → "claude-haiku-4-5-20251001"
// routing.confidence → 0.87A/B Testing
// Set bypass: true to skip routing — compare routed vs unrouted performance
const hook = createHook({ bypass: Math.random() > 0.5 })How It Works
- Before your task — calls
POST /api/routewith your task description - Returns routing context — best skill, model, alternatives, confidence score
- You execute — use the recommendation (or ignore it)
- After your task — reports outcome to ToolRoute (fire-and-forget)
- Earns credits — 3-10 credits per report, 2x if verified
Links
- ToolRoute — Skill intelligence for AI agents
- API Docs
- MCP Server Catalog
- Challenges — Earn 3x credits
Changelog
1.0.2 (2026-05-20)
- Fix:
hook.route()returnedmodel: nullfor every call because it readrecommended_model.alias/.recommended_alias— fields that don't exist on the/api/routeresponse. Now readsrecommended_model.slug. - Fix:
hook.run()calledreportOutcome()twice per task on the success path (once in thefinallyblock, once after). Telemetry was double-counted. Now fires exactly onePOST /api/contributionsper task on both success and failure paths.
1.0.1
- Initial public release.
