45 lines
1.3 KiB
TypeScript
45 lines
1.3 KiB
TypeScript
import { Agent } from './agents/index.js';
|
||
import { getOrchestratorTools } from './tools/registry.js';
|
||
import { PROMPTS } from './prompts/system.js';
|
||
import * as readline from 'node:readline/promises';
|
||
import { hooks } from './hooks/index.js';
|
||
import { registerHooks } from './hooks/registry.js';
|
||
|
||
await registerHooks();
|
||
|
||
const promptName = process.argv[2] || 'orchestrator';
|
||
const systemPrompt = PROMPTS[promptName as keyof typeof PROMPTS];
|
||
|
||
if (!systemPrompt) {
|
||
console.error(`未知提示词: ${promptName},可选: ${Object.keys(PROMPTS).join(', ')}`);
|
||
process.exit(1);
|
||
}
|
||
|
||
// 主 orchestrator Agent,拥有全部工具(包括 spawn_agent / run_conversation)
|
||
const mainAgent = new Agent({
|
||
name: 'Orchestrator',
|
||
systemPrompt,
|
||
tools: getOrchestratorTools(),
|
||
});
|
||
|
||
const rl = readline.createInterface({
|
||
input: process.stdin,
|
||
output: process.stdout,
|
||
});
|
||
|
||
console.log(`提示词模式: ${promptName},输入 "exit" 退出。\n`);
|
||
|
||
while (true) {
|
||
const userInput = await rl.question('我: ');
|
||
if (userInput.toLowerCase() === 'exit') break;
|
||
|
||
hooks.emit('agent:start', { userInput });
|
||
|
||
const reply = await mainAgent.run(userInput);
|
||
|
||
hooks.emit('agent:end', { userInput, reply });
|
||
// agent:end hook 会打印回复,这里不需要重复打印
|
||
}
|
||
|
||
rl.close();
|