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

NameTypeRequiredDescription
name
stringRequiredTool function name.
arguments
objectRequiredJSON arguments payload.
call_id
stringRequiredUnique tool invocation ID.
status
stringpending | 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.