安装
快速开始
创建您的第一个 Agent:添加工具
工具扩展了 Agent 超越文本生成的能力。下一步
- 多 Agent 系统 - 构建协作系统
- 工具 - 高级工具开发
- 记忆和状态 - 状态管理
构建简单的单步 Agent
npm install @ag-kit/agents @ag-kit/tools zod
import { Agent, OpenAIProvider } from '@ag-kit/agents';
const agent = new Agent({
name: 'my-assistant',
description: '一个有用的 AI 助手',
model: new OpenAIProvider({
apiKey: process.env.OPENAI_API_KEY!,
defaultModel: 'gpt-4o-mini'
}),
instructions: '你是一个有用的助手。'
});
const result = await agent.run('你好!');
console.log(result.output);
import { tool } from '@ag-kit/tools';
import { z } from 'zod';
const weatherTool = tool(
async (input: unknown) => {
const { location } = input as { location: string };
return { location, temperature: 72, condition: 'sunny' };
},
{
name: 'get_weather',
description: '获取某个位置的天气',
schema: z.object({
location: z.string().describe('城市名称')
})
}
);
const agent = new Agent({
tools: [weatherTool],
instructions: '当被问及天气时使用 get_weather 工具。'
});
此页面对您有帮助吗?