# Supervised Agent You can require user authorization before a tool is executed by defining a `canRun` callback on the tool definition. The `canRun` function receives the `ToolCallSpec` (the actual call the model wants to make) and returns a boolean. ## Define an authorization function Create a function that asks the user for permission: ```typescript import type { ToolCallSpec } from "@agent-smith/types"; import { createInterface } from "readline/promises"; import { stdin as input, stdout as output } from "process"; const rl = createInterface({ input, output, }); async function askUser(question: string): Promise { const answer = await rl.question(question); return answer.toLowerCase() === "y" || answer.toLowerCase() === "yes"; } async function canExecuteTool(tool: ToolCallSpec): Promise { const argsNames = Object.keys(tool.arguments ?? {}); const msg = `Execute tool ${tool.name} with arguments: ${argsNames.join(", ")}`; return await askUser(msg + " (y/n): "); } ``` ## Attach `canRun` to the tool definition Add the `canRun` callback to your `ToolSpec`: ```typescript const weatherTool = { name: "get_current_weather", description: "Get the current weather for a location", arguments: { location: { description: "The city and state, e.g. San Francisco, CA", type: "string", required: true, }, }, type: "action", parallelCalls: false, execute: async (args) => { const location = args?.location ?? "unknown"; return { temp: 20.5, weather: "rain" }; }, canRun: canExecuteTool, }; ``` ## How it works When the model generates a tool call: 1. The agent checks `tool.canRun(toolCallSpec)` before execution 2. If `canRun` returns `true`, the tool executes normally 3. If `canRun` returns `false`, the tool is skipped and an error message is logged 4. The agent continues with the next turn, potentially adjusting its approach This pattern is useful for safety-critical tools, expensive operations, or any scenario where human oversight is required before execution.