()
| 6 | import { AsterClient } from "@aster/client-js"; |
| 7 | |
| 8 | async function main() { |
| 9 | console.log("=".repeat(70)); |
| 10 | console.log("AsterClient Agent 功能演示"); |
| 11 | console.log("=".repeat(70)); |
| 12 | |
| 13 | // 初始化客户端 |
| 14 | const client = new AsterClient({ |
| 15 | baseUrl: "http://localhost:8080", |
| 16 | apiKey: process.env.ASTER_API_KEY, |
| 17 | }); |
| 18 | |
| 19 | // ======================================================================== |
| 20 | // 1. Agent 模板 |
| 21 | // ======================================================================== |
| 22 | console.log("\n📋 1. Agent 模板"); |
| 23 | console.log("-".repeat(70)); |
| 24 | |
| 25 | // 列出所有模板 |
| 26 | const templates = await client.agents.listTemplates(); |
| 27 | console.log(`✅ 可用模板: ${templates.length} 个`); |
| 28 | templates.forEach((template, i) => { |
| 29 | const icon = template.builtin ? "🔧" : "✨"; |
| 30 | console.log(` ${icon} ${i + 1}. ${template.name} (${template.type})`); |
| 31 | console.log(` ${template.description}`); |
| 32 | }); |
| 33 | |
| 34 | // ======================================================================== |
| 35 | // 2. 创建 Agent |
| 36 | // ======================================================================== |
| 37 | console.log("\n🤖 2. 创建 Agent"); |
| 38 | console.log("-".repeat(70)); |
| 39 | |
| 40 | // 从模板创建 |
| 41 | const assistant = await client.agents.createFromTemplate("assistant", { |
| 42 | name: "My Assistant", |
| 43 | description: "我的智能助手", |
| 44 | llmProvider: "anthropic", |
| 45 | llmModel: "claude-sonnet-4", |
| 46 | llmParams: { |
| 47 | temperature: 0.7, |
| 48 | maxTokens: 4096, |
| 49 | }, |
| 50 | }); |
| 51 | console.log("✅ 从模板创建 Agent:", assistant.id); |
| 52 | console.log(" 名称:", assistant.name); |
| 53 | console.log(" 状态:", assistant.status); |
| 54 | console.log(" LLM:", `${assistant.llmProvider}/${assistant.llmModel}`); |
| 55 | |
| 56 | // 直接创建 |
| 57 | const researcher = await client.agents.create({ |
| 58 | name: "Research Agent", |
| 59 | description: "AI 研究专家", |
| 60 | templateId: "researcher", |
| 61 | llmProvider: "openai", |
| 62 | llmModel: "gpt-4-turbo", |
| 63 | systemPrompt: "You are an expert AI researcher. Provide detailed, accurate information.", |
| 64 | tools: ["http_request", "web_scraper"], |
| 65 | middlewares: ["summarization", "cost_tracker"], |
no test coverage detected