AG-Kit TS
简体中文
AG-Kit Agent 类型与核心能力
import { Agent, OpenAIProvider } from '@ag-kit/agents'; const modelProvider = new OpenAIProvider({ apiKey: process.env.OPENAI_API_KEY, defaultModel: 'gpt-4' }); // 定义带参数的工具 const weatherTool = { name: 'get_weather', description: '获取指定位置的当前天气', schema: z.object({ location: z.string().describe('城市名称或坐标'), unit: z.enum(['celsius', 'fahrenheit']).default('celsius') }), handler: async (input: { location: string; unit: string }) => { // 工具实现 return { temperature: 22, condition: 'sunny', unit: input.unit }; } }; const agent = new Agent({ name: 'my-agent', model: modelProvider, instructions: '你是一个可以获取天气信息的助手', tools: [weatherTool] }); const result = await agent.run('纽约的天气如何?'); console.log(result.data);
npm install @ag-kit/agents
此页面对您有帮助吗?