MCPcopy Create free account
hub / github.com/astercloud/aster / main

Function main

client-sdks/client-js/examples/agent-usage.ts:8–325  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

6import { AsterClient } from "@aster/client-js";
7
8async 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"],

Callers 1

agent-usage.tsFile · 0.70

Calls 15

logMethod · 0.80
listTemplatesMethod · 0.80
createFromTemplateMethod · 0.80
chatMethod · 0.80
chatStreamMethod · 0.80
getAggregatedStatsMethod · 0.80
cloneMethod · 0.80
activateBatchMethod · 0.80
createMethod · 0.45
listMethod · 0.45
getMethod · 0.45
updateMethod · 0.45

Tested by

no test coverage detected