30 lines
1.0 KiB
Markdown
30 lines
1.0 KiB
Markdown
# 将工具连接到您的代理
|
|
|
|
现在我们已经创建了工具,需要将其连接到我们的代理。回到您的 `agents/financial-agent.ts` 文件并更新它:
|
|
|
|
1. 导入工具:
|
|
|
|
```typescript
|
|
import { getTransactionsTool } from "../tools/get-transactions-tool";
|
|
```
|
|
|
|
2. 将工具添加到您的代理:
|
|
|
|
```typescript
|
|
export const financialAgent = new Agent({
|
|
name: "Financial Assistant Agent",
|
|
instructions: `角色定义
|
|
// ... 现有说明 ...
|
|
|
|
工具
|
|
- 使用 getTransactions 工具获取金融交易数据。
|
|
- 分析交易数据以回答用户关于其支出的问题。`,
|
|
model: openai("gpt-4o"),
|
|
tools: { getTransactionsTool }, // 在这里添加我们的工具
|
|
});
|
|
```
|
|
|
|
通过将工具添加到代理的配置中,您使其可供代理使用。代理现在将能够在需要访问交易数据时调用 `getTransactions` 工具。
|
|
|
|
同样重要的是更新代理的说明以包含有关工具的信息。这有助于代理理解何时以及如何使用工具来满足用户请求。
|