import type { AgentSession } from "@mariozechner/pi-coding-agent"; import type { McpServerConfig, McpServersStandardFormat } from "../mcp/index.js"; import type { Skill } from "./skills.js"; export interface AgentManagerOptions { agentDir?: string; workspace?: string; skillPaths?: string[]; skills?: Skill[]; } /** * Unified Agent Manager for both CLI and Gateway */ export declare class AgentManager { private sessions; /** 每个 session 最后被使用的时间戳,用于 LRU 淘汰 */ private sessionLastActiveAt; /** 每个 SessionAgent 当前最新的 compaction summary,关闭会话时写入向量库(infotype: compaction) */ private sessionLatestCompactionSummary; private agentDir; private workspaceDir; private skillPaths; private preLoadedSkills; constructor(options?: AgentManagerOptions); /** * Re-configure the manager */ configure(options: AgentManagerOptions): void; /** * Build system prompt with skills and browser tool description */ buildSystemPrompt(skills: Skill[]): string; /** * Get the initial context (prompt and skills) */ getContext(): Promise<{ systemPrompt: string; skills: Skill[]; }>; private createResourceLoader; /** * Resolve all relevant skill paths (Global, Project, Workspace) * @param workspaceDir 当前会话使用的工作区目录,不传则用 manager 默认 */ private resolveSkillPaths; /** * Get or create an agent session. * 缓存 key 为 sessionId + "::" + agentId,同一业务 session 下可切换 agent 且各自保留上下文。 * @param sessionId 业务会话 ID(桌面 UUID 或 channel:feishu:threadId 等) * @param options.agentId 当前使用的 agent,与 sessionId 组成复合 key,必传或默认 "default" * @param options.workspace 该会话绑定的工作区名(来自 agent 配置) * @param options.maxSessions 若提供且当前 session 数 >= 该值,按 LRU 淘汰 * @param options.targetAgentId 创建时绑定到 install_skill 工具 */ getOrCreateSession(sessionId: string, options?: { agentId?: string; workspace?: string; provider?: string; modelId?: string; apiKey?: string; maxSessions?: number; targetAgentId?: string; mcpServers?: McpServerConfig[] | McpServersStandardFormat; /** MCP 单次返回最大 token;不配置则不限制 */ mcpMaxResultTokens?: number; /** 自定义系统提示词(来自 agent 配置),会与技能等一起组成最终 systemPrompt */ systemPrompt?: string; /** 是否使用长记忆(memory_recall/save_experience);默认 true */ useLongMemory?: boolean; /** 在线搜索:启用时注册 web_search 工具 */ webSearch?: { enabled: boolean; provider: "brave" | "duck-duck-scrape"; apiKey?: string; timeoutSeconds?: number; cacheTtlMinutes?: number; maxResults?: number; /** 单次搜索返回最大 token;不配置则不限制;前端默认 64K */ maxResultTokens?: number; }; }): Promise; /** 按复合 key 获取(key = sessionId + "::" + agentId) */ getSession(compositeKey: string): AgentSession | undefined; /** 按业务 sessionId 查找一个 Session(取最近活跃的),用于 agent.cancel 等 */ getSessionBySessionId(sessionId: string): AgentSession | undefined; /** 删除一个 Agent Session(传入复合 key);关闭前将本 session 最新 compaction summary 写入向量库 */ deleteSession(compositeKey: string): Promise; /** 按业务 sessionId 删除该会话下所有 agent 的 Core Session(如删除会话时);关闭前将各 session 最新 compaction 写入向量库 */ deleteSessionsByBusinessId(sessionId: string): Promise; /** 按 agentId 删除该智能体下所有 Session(配置更新后使旧会话失效,下次请求会用新配置建新会话) */ deleteSessionsByAgentId(agentId: string): Promise; clearAll(): void; } export declare const agentManager: AgentManager;