# Tools An agent can use tools autonomously or with supervision. ## Define tools A tool is defined as a `ToolSpec` object with these fields: - `name` — unique identifier for the tool - `description` — what the tool does - `arguments` — schema of expected arguments - `type` — tool type (e.g., `"action"`, `"task"`) - `parallelCalls` — whether multiple instances can run in parallel - `execute` — async function that runs the tool logic - `canRun` — optional authorization callback Create a tool execution function: ```typescript async function get_current_weather(args: { location?: string }) { const location = args?.location ?? "unknown"; console.log("Running get_current_weather for", location); return { temp: 20.5, weather: "rain" }; } ``` Create a tool definition matching the `ToolSpec` interface: ```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: get_current_weather, }; ``` ## Configure an agent with tools Initialize an agent connected to an OpenRouter backend: ```typescript import { Lm, Agent } from "@agent-smith/agent"; const lm = new Lm({ name: "openrouter", serverUrl: "https://openrouter.ai/api/v1", apiKey: process.env.OPENROUTER_API_KEY, }); const agent = new Agent({ name: "weather-agent", lm, onToken: (t) => process.stdout.write(t), }); ``` Run the agent with tools: ```typescript const prompt = `I am landing in Barcelona soon: I plan to reach my hotel and then go for outdoor sport. How are the conditions in the city?`; const result = await agent.run(prompt, { params: { model: "qwen/qwen3-30b-a3b:free", temperature: 0.4, top_k: 40, top_p: 0.95, min_p: 0, max_tokens: 16384, }, debug: true, tools: [weatherTool], }); ``` The agent will autonomously call `get_current_weather` when it determines the tool is useful. Next: templates