> ## Documentation Index
> Fetch the complete documentation index at: https://phaseo.app/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# 工具调用（AI SDK）

> 使用 Vercel AI SDK 和 Phaseo 供应商进行函数/工具调用。

在 `generateText` 中使用 `tools`，即可通过类型化参数执行函数。

```ts theme={null}
import { phaseo } from "@phaseo/ai-sdk-provider";
import { generateText } from "ai";
import { z } from "zod";

const result = await generateText({
  model: phaseo("openai/gpt-5-nano"),
  prompt: "What is 17 + 25? Use the calculator tool.",
  tools: {
    calculator: {
      description: "Perform basic arithmetic",
      parameters: z.object({
        operation: z.enum(["add", "subtract", "multiply", "divide"]),
        a: z.number(),
        b: z.number(),
      }),
      execute: async ({ operation, a, b }) => {
        if (operation === "add") return a + b;
        if (operation === "subtract") return a - b;
        if (operation === "multiply") return a * b;
        return a / b;
      },
    },
  },
});

console.log(result.text);
```

## 说明

* 工具描述应准确，参数应严格。
* 在 `execute` 内验证外部副作用。
* 必要时为下游工具 API 添加重试和退避等待。


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.