Tools
Close the loop between model planning and deterministic function execution.
Tool Definition
TypeScript
const tools = [{
type: "function",
function: {
name: "get_weather",
description: "Return weather by city",
parameters: {
type: "object",
properties: { city: { type: "string" } },
required: ["city"],
},
},
}];Tool Call Item
| Name | Type | Required | Description |
|---|---|---|---|
name | string | Required | Tool function name. |
arguments | object | Required | JSON arguments payload. |
call_id | string | Required | Unique tool invocation ID. |
status | string | pending | executed | failed |
Execute + Return Result
tool-loop.ts
for (const item of result.items) {
if (item.type !== "tool_call") continue;
const output = await handlers[item.name](item.arguments);
await client.callModel({
...result.next_turn,
input: [{ type: "tool_result", call_id: item.call_id, output }],
});
}Validation first
Validate tool arguments against your schema before execution to prevent malformed or unsafe calls.