// Adapted from Malhar Ujawane’s agent-tool-router in Awesome Jev Apps · MIT. // Source: https://github.com/Justmalhar/awesome-jev-apps/blob/f4369cb415ddc6925cdd10d3a2c127b2458053c8/apps/ai-infrastructure/agent-tool-router/router.py // Retains the needs_tool question and criteria. The user turn moves into state and the example isolates the gate from the original two-stage tool selector. /* MIT License Copyright (c) 2026 Malhar Ujawane Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ // Setup: npm install @typesafe-ai/sdk@0.6.0 // Set TYPESAFE_API_KEY in your environment. Never put it in browser code. // Save as decision.ts; run with Node.js 24: node decision.ts // API calls incur provider charges. Not live-tested by Jev Directory. import { noul, TypeSafeClient, type JsonValue } from "@typesafe-ai/sdk"; // Illustrative input, not a recorded model test. const state: JsonValue = { "user_turn": "Which production services are failing right now?" }; const client = new TypeSafeClient(); try { const response = await client.systemOne({ model: "jev-latest", state, questions: { needs_tool: noul( "Does answering this turn require calling a tool at all?", { "true": "Requires fetching, changing, or acting on external state", "false": "Can be answered from conversation or general knowledge alone" } ) }, }); const probability = response.answers.needs_tool.noul; console.log({ probability, next: probability >= 0.5 ? "select_tool" : "answer_directly" }); } catch (error) { console.error("Decision unavailable; use your fallback or human review.", error); process.exitCode = 1; }