-
Notifications
You must be signed in to change notification settings - Fork 75
Expand file tree
/
Copy pathtest-start-agent.mjs
More file actions
84 lines (70 loc) · 2.54 KB
/
test-start-agent.mjs
File metadata and controls
84 lines (70 loc) · 2.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#!/usr/bin/env node
/**
* 测试新的 startAgent 方法
*/
import { WebAgentManager } from './packages/core/dist/cli/webAgentManager.mjs';
console.log('🧪 测试 WebAgentManager.startAgent 方法...\n');
const webManager = new WebAgentManager();
try {
// 模拟一个Agent路径
const testAgentPath1 = '/tmp/test-agent-1';
const testAgentPath2 = '/tmp/test-agent-2';
console.log('📊 初始状态:');
console.log(`Agent数量: ${webManager.size()}`);
console.log(`Agent路径: ${JSON.stringify(webManager.getAgentPaths())}\n`);
console.log('🚀 测试启动Agent (禁用MCP和任务调度器)...');
// 测试启动第一个Agent
try {
const agent1 = await webManager.startAgent(testAgentPath1, {
enableMCP: false,
enableTaskScheduler: false,
});
console.log(`✅ Agent1启动成功: ${agent1.getConfig().name}`);
} catch (error) {
console.log(`❌ Agent1启动失败: ${error.message}`);
}
// 测试启动第二个Agent
try {
const agent2 = await webManager.startAgent(testAgentPath2, {
enableMCP: false,
enableTaskScheduler: false,
});
console.log(`✅ Agent2启动成功: ${agent2.getConfig().name}`);
} catch (error) {
console.log(`❌ Agent2启动失败: ${error.message}`);
}
console.log(`\n📊 启动后状态:`);
console.log(`Agent数量: ${webManager.size()}`);
console.log(`Agent路径: ${JSON.stringify(webManager.getAgentPaths())}`);
// 测试重复启动相同路径的Agent
console.log(`\n🔄 测试重复启动Agent1...`);
try {
const agent1Again = await webManager.startAgent(testAgentPath1);
console.log(`✅ 重复启动Agent1成功(应该复用实例)`);
console.log(`Agent数量保持不变: ${webManager.size()}`);
} catch (error) {
console.log(`❌ 重复启动Agent1失败: ${error.message}`);
}
// 获取Agent摘要
console.log(`\n📋 获取Agent摘要...`);
try {
const summaries = await webManager.getAgentSummaries();
console.log(`摘要数量: ${summaries.length}`);
summaries.forEach((summary, index) => {
console.log(` Agent${index + 1}: ${summary.config.name} (${summary.path})`);
});
} catch (error) {
console.log(`❌ 获取摘要失败: ${error.message}`);
}
console.log('\n✅ startAgent 方法测试完成!');
} catch (error) {
console.error('❌ 测试过程中发生错误:', error);
} finally {
// 清理资源
try {
await webManager.destroy();
console.log('🧹 资源清理完成');
} catch (error) {
console.error('清理资源时出错:', error);
}
}