feat: 添加 /agent 命令支持交互式切换 Agent 模式

- 在 AgentRegistry 添加 listPrimaryAgents() 方法
- 在 Agent 类添加 setAgentMode/getAgentMode 方法
- 在 TerminalUI 实现 /agent 命令:
  - /agent 显示当前模式和可用列表
  - /agent <name> 切换到指定 Agent
  - /agent default 切换回默认模式
- 提示符显示当前 Agent 模式(如 @plan You >)
- 为 build Agent 添加 prompt 配置
This commit is contained in:
2025-12-11 13:19:58 +08:00
parent 82f0a0ccde
commit bfe3bc63b3
4 changed files with 131 additions and 11 deletions
+34
View File
@@ -17,6 +17,7 @@ import {
type TokenUsage,
type CompressionConfig,
} from '../context/index.js';
import type { AgentInfo } from '../agent/types.js';
// Provider 工厂函数类型
type ProviderFactory = (apiKey: string) => (model: string) => LanguageModel;
@@ -53,6 +54,9 @@ export class Agent {
// 压缩管理器
private compressionManager: CompressionManager;
// 当前 Agent 模式(null 表示默认模式)
private currentAgentMode: AgentInfo | null = null;
constructor(config: AgentConfig, compressionConfig?: Partial<CompressionConfig>) {
this.config = config;
@@ -354,4 +358,34 @@ export class Agent {
type: result.type,
};
}
/**
* 切换 Agent 模式
*/
setAgentMode(agent: AgentInfo | null): void {
this.currentAgentMode = agent;
// 如果切换了 Agent,更新 system prompt
if (agent?.prompt) {
// 追加 Agent 的 prompt 到系统 prompt
this.config = {
...this.config,
systemPrompt: agent.prompt,
};
}
}
/**
* 获取当前 Agent 模式
*/
getAgentMode(): AgentInfo | null {
return this.currentAgentMode;
}
/**
* 获取当前 Agent 名称
*/
getAgentModeName(): string {
return this.currentAgentMode?.name ?? 'default';
}
}