2026-07-10 17:21:38 +08:00

47 lines
1.3 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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';
import { knowledgeBase } from './knowledge/knowledge-base.js';
await registerHooks();
await knowledgeBase.load();
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();