* 启动基础助手
(config: AgentConfig)
| 673 | * 启动基础助手 |
| 674 | */ |
| 675 | async function startBasicAssistant(config: AgentConfig) { |
| 676 | console.log(chalk.cyan('\n=== 🤖 智能助手 Agent ===')); |
| 677 | |
| 678 | const agent = new Agent(config); |
| 679 | await agent.init(); |
| 680 | |
| 681 | // 显示 Agent 状态 |
| 682 | const status = agent.getStatus(); |
| 683 | console.log( |
| 684 | chalk.gray(`Agent 状态: LLM=${status.llmProvider}, 组件数=${status.components.componentCount}`) |
| 685 | ); |
| 686 | |
| 687 | try { |
| 688 | // 智能问答 |
| 689 | console.log(chalk.yellow('\n问题: 什么是微服务架构?')); |
| 690 | const answer = await agent.ask('什么是微服务架构?请简洁地解释'); |
| 691 | console.log(chalk.green(`回答: ${answer}`)); |
| 692 | |
| 693 | // 代码生成 |
| 694 | console.log(chalk.yellow('\n请求: 生成快速排序算法')); |
| 695 | const code = await agent.generateCode('实现快速排序算法', 'python'); |
| 696 | console.log(chalk.green(`生成的代码:\n${code}`)); |
| 697 | |
| 698 | // 流式回答 |
| 699 | console.log(chalk.yellow('\n流式问答: 解释区块链技术')); |
| 700 | process.stdout.write(chalk.green('AI: ')); |
| 701 | |
| 702 | const messages: LLMMessage[] = [ |
| 703 | { role: 'user' as const, content: '请简单解释什么是区块链技术' }, |
| 704 | ]; |
| 705 | |
| 706 | await agent.streamChat(messages, chunk => { |
| 707 | process.stdout.write(chunk); |
| 708 | }); |
| 709 | console.log('\n'); |
| 710 | } catch (error) { |
| 711 | console.error(chalk.red('❌ 助手操作失败:'), error); |
| 712 | } |
| 713 | |
| 714 | await agent.destroy(); |
| 715 | console.log(chalk.green('\n✅ 智能助手演示完成')); |
| 716 | } |
no test coverage detected