🤯 LobeHub - Super-Agents on Your Team. Add super-agents to the chats your team already uses.They take on work by themselves and get better every week.
TypeScript agentagent-collaborationagent-harnessloop-engineeringmcppersonal-assistantproactive-agentskillssuper-agenttask-management
🌐 chore: translate non-English comments to English in AgentRuntime module (#11429)
LobeHub Botd95125c6cf2f
diff --git a/src/server/modules/AgentRuntime/AgentRuntimeCoordinator.ts b/src/server/modules/AgentRuntime/AgentRuntimeCoordinator.tsindex f870ad7c969..fc2ea742562 100644--- a/src/server/modules/AgentRuntime/AgentRuntimeCoordinator.ts+++ b/src/server/modules/AgentRuntime/AgentRuntimeCoordinator.ts@@ -9,27 +9,27 @@ const log = debug('lobe-server:agent-runtime:coordinator');export interface AgentRuntimeCoordinatorOptions {/**- * 自定义状态管理器实现- * 默认根据 Redis 可用性自动选择实现+ * Custom state manager implementation+ * Defaults to automatic selection based on Redis availability*/stateManager?: IAgentStateManager;/**- * 自定义流式事件管理器实现- * 默认根据 Redis 可用性自动选择实现+ * Custom stream event manager implementation+ * Defaults to automatic selection based on Redis availability*/streamEventManager?: IStreamEventManager;}/*** Agent Runtime Coordinator- * 协调 AgentStateManager 和 StreamEventManager 的操作- * 负责在状态变更时发送相应的事件+ * Coordinates operations between AgentStateManager and StreamEventManager+ * Responsible for sending corresponding events when state changes occur*- * 默认行为:- * - Redis 可用时使用 Redis 实现- * - Redis 不可用时自动回退到内存实现(本地开发模式)+ * Default behavior:+ * - Uses Redis implementation when Redis is available+ * - Automatically falls back to in-memory implementation when Redis is unavailable (local development mode)*- * 支持依赖注入,可以传入自定义实现+ * Supports dependency injection, allowing custom implementations to be passed in*/export class AgentRuntimeCoordinator {private stateManager: IAgentStateManager;@@ -41,7 +41,7 @@ export class AgentRuntimeCoordinator {}/**- * 创建新的 Agent 操作并发送初始化事件+ * Create a new Agent operation and send initialization event*/async createAgentOperation(operationId: string,@@ -52,14 +52,14 @@ export class AgentRuntimeCoordinator {},): Promise<void> {try {- // 创建操作元数据+ // Create operation metadataawait this.stateManager.createOperationMetadata(operationId, data);- // 获取创建的元数据+ // Get the created metadataconst metadata = await this.stateManager.getOperationMetadata(operationId);if (metadata) {- // 发送 agent runtime init 事件+ // Send agent runtime init eventawait this.streamEventManager.publishAgentRuntimeInit(operationId, metadata);log('[%s] Agent operation created and initialized', operationId);}@@ -70,16 +70,16 @@ export class AgentRuntimeCoordinator {}/**- * 保存 Agent 状态并处理相应事件+ * Save Agent state and handle corresponding events*/async saveAgentState(operationId: string, state: AgentState): Promise<void> {try {const previousState = await this.stateManager.loadAgentState(operationId);- // 保存状态+ // Save stateawait this.stateManager.saveAgentState(operationId, state);- // 如果状态变为 done,发送 agent runtime end 事件+ // If status changes to done, send agent runtime end eventif (state.status === 'done' && previousState?.status !== 'done') {await this.streamEventManager.publishAgentRuntimeEnd(operationId, state.stepCount, state);log('[%s] Agent runtime completed', operationId);@@ -91,18 +91,18 @@ export class AgentRuntimeCoordinator {}/**- * 保存步骤结果并处理相应事件+ * Save step result and handle corresponding events*/async saveStepResult(operationId: string, stepResult: StepResult): Promise<void> {try {- // 获取之前的状态用于检测状态变化+ // Get previous state for detecting state changesconst previousState = await this.stateManager.loadAgentState(operationId);- // 保存步骤结果+ // Save step resultawait this.stateManager.saveStepResult(operationId, stepResult);- // 如果状态变为 done,发送 agent_runtime_end 事件- // 这确保 agent_runtime_end 在所有步骤事件之后发送+ // If status changes to done, send agent_runtime_end event+ // This ensures agent_runtime_end is sent after all step eventsif (stepResult.newState.status === 'done' && previousState?.status !== 'done') {await this.streamEventManager.publishAgentRuntimeEnd(operationId,@@ -118,28 +118,28 @@ export class AgentRuntimeCoordinator {}/**- * 获取 Agent 状态+ * Get Agent state*/async loadAgentState(operationId: string): Promise<AgentState | null> {return this.stateManager.loadAgentState(operationId);}/**- * 获取操作元数据+ * Get operation metadata*/async getOperationMetadata(operationId: string): Promise<AgentOperationMetadata | null> {return this.stateManager.getOperationMetadata(operationId);}/**- * 获取执行历史+ * Get execution history*/async getExecutionHistory(operationId: string, limit?: number): Promise<any[]> {return this.stateManager.getExecutionHistory(operationId, limit);}/**- * 删除 Agent 操作+ * Delete Agent operation*/async deleteAgentOperation(operationId: string): Promise<void> {try {@@ -155,14 +155,14 @@ export class AgentRuntimeCoordinator {}/**- * 获取活跃操作+ * Get active operations*/async getActiveOperations(): Promise<string[]> {return this.stateManager.getActiveOperations();}/**- * 获取统计信息+ * Get statistics*/async getStats(): Promise<{activeOperations: number;@@ -174,14 +174,14 @@ export class AgentRuntimeCoordinator {}/**- * 清理过期操作+ * Clean up expired operations*/async cleanupExpiredOperations(): Promise<number> {return this.stateManager.cleanupExpiredOperations();}/**- * 关闭连接+ * Close connections*/async disconnect(): Promise<void> {await Promise.all([this.stateManager.disconnect(), this.streamEventManager.disconnect()]);diff --git a/src/server/modules/AgentRuntime/AgentStateManager.ts b/src/server/modules/AgentRuntime/AgentStateManager.tsindex 4a21bb80a63..869c47249f1 100644--- a/src/server/modules/AgentRuntime/AgentStateManager.ts+++ b/src/server/modules/AgentRuntime/AgentStateManager.ts@@ -42,7 +42,7 @@ export class AgentStateManager {}/**- * 保存 Agent 状态+ * Save Agent state*/async saveAgentState(operationId: string, state: AgentState): Promise<void> {const stateKey = `${this.STATE_PREFIX}:${operationId}`;@@ -51,7 +51,7 @@ export class AgentStateManager {const serializedState = JSON.stringify(state);await this.redis.setex(stateKey, this.DEFAULT_TTL, serializedState);- // 更新元数据+ // Update metadataawait this.updateOperationMetadata(operationId, {lastActiveAt: new Date().toISOString(),status: state.status,@@ -59,7 +59,7 @@ export class AgentStateManager {totalSteps: state.stepCount,});- // 状态变更事件通过 saveStepResult 中的 events 数组记录+ // State change events are recorded through the events array in saveStepResultlog('[%s] Saved state for step %d', operationId, state.stepCount);} catch (error) {@@ -69,7 +69,7 @@ export class AgentStateManager {}/**- * 加载 Agent 状态+ * Load Agent state*/async loadAgentState(operationId: string): Promise<AgentState | null> {const stateKey = `${this.STATE_PREFIX}:${operationId}`;@@ -92,17 +92,17 @@ export class AgentStateManager {}/**- * 保存步骤执行结果+ * Save step execution result*/async saveStepResult(operationId: string, stepResult: StepResult): Promise<void> {const pipeline = this.redis.multi();try {- // 保存最新状态+ // Save latest stateconst stateKey = `${this.STATE_PREFIX}:${operationId}`;pipeline.setex(stateKey, this.DEFAULT_TTL, JSON.stringify(stepResult.newState));- // 保存步骤历史+ // Save step historyconst stepsKey = `${this.STEPS_PREFIX}:${operationId}`;const stepData = {context: stepResult.nextContext,@@ -114,19 +114,19 @@ export class AgentStateManager {};pipeline.lpush(stepsKey, JSON.stringify(stepData));- pipeline.ltrim(stepsKey, 0, 199); // 保留最近 200 步+ pipeline.ltrim(stepsKey, 0, 199); // Keep most recent 200 stepspipeline.expire(stepsKey, this.DEFAULT_TTL);- // 保存步骤的事件序列到 agent_runtime_events+ // Save step event sequence to agent_runtime_eventsif (stepResult.events && stepResult.events.length > 0) {const eventsKey = `${this.EVENTS_PREFIX}:${operationId}`;pipeline.lpush(eventsKey, JSON.stringify(stepResult.events));- pipeline.ltrim(eventsKey, 0, 199); // 保留最近 200 步的事件+ pipeline.ltrim(eventsKey, 0, 199); // Keep events from most recent 200 stepspipeline.expire(eventsKey, this.DEFAULT_TTL);}- // 更新操作元数据+ // Update operation metadataconst metaKey = `${this.METADATA_PREFIX}:${operationId}`;const metadata: Partial<AgentOperationMetadata> = {lastActiveAt: new Date().toISOString(),@@ -152,14 +152,14 @@ export class AgentStateManager {}/**- * 获取执行历史+ * Get execution history*/async getExecutionHistory(operationId: string, limit: number = 50): Promise<any[]> {const stepsKey = `${this.STEPS_PREFIX}:${operationId}`;try {const history = await this.redis.lrange(stepsKey, 0, limit - 1);- return history.map((item) => JSON.parse(item)).reverse(); // 最早的在前面+ return history.map((item) => JSON.parse(item)).reverse(); // Earliest first} catch (error) {console.error('Failed to get execution history:', error);return [];@@ -167,7 +167,7 @@ export class AgentStateManager {}/**- * 获取操作元数据+ * Get operation metadata*/async getOperationMetadata(operationId: string): Promise<AgentOperationMetadata | null> {const metaKey = `${this.METADATA_PREFIX}:${operationId}`;@@ -198,7 +198,7 @@ export class AgentStateManager {}/**- * 创建新的操作元数据+ * Create new operation metadata*/async createOperationMetadata(operationId: string,@@ -222,7 +222,7 @@ export class AgentStateManager {userId: data.userId,};- // 序列化复杂对象+ // Serialize complex objectsconst redisData: Record<string, string> = {createdAt: metadata.createdAt,lastActiveAt: metadata.lastActiveAt,@@ -247,7 +247,7 @@ export class AgentStateManager {}/**- * 更新操作元数据+ * Update operation metadata*/private async updateOperationMetadata(operationId: string,@@ -278,7 +278,7 @@ export class AgentStateManager {}/**- * 删除 Agent 操作的所有数据+ * Delete all data for Agent operation*/async deleteAgentOperation(operationId: string): Promise<void> {const keys = [@@ -298,7 +298,7 @@ export class AgentStateManager {}/**- * 获取所有活跃操作+ * Get all active operations*/async getActiveOperations(): Promise<string[]> {try {@@ -312,7 +312,7 @@ export class AgentStateManager {}/**- * 清理过期的操作数据+ * Clean up expired operation data*/async cleanupExpiredOperations(): Promise<number> {try {@@ -327,7 +327,7 @@ export class AgentStateManager {const now = Date.now();const hoursSinceActive = (now - lastActiveTime) / (1000 * 60 * 60);- // 清理超过 2 小时未活跃的操作+ // Clean up operations inactive for more than 2 hoursif (hoursSinceActive > 2) {await this.deleteAgentOperation(operationId);cleanedCount++;@@ -344,7 +344,7 @@ export class AgentStateManager {}/**- * 获取统计信息+ * Get statistics*/async getStats(): Promise<{activeOperations: number;@@ -397,7 +397,7 @@ export class AgentStateManager {}/**- * 关闭 Redis 连接+ * Close Redis connection*/async disconnect(): Promise<void> {await this.redis.quit();diff --git a/src/server/modules/AgentRuntime/InMemoryAgentStateManager.ts b/src/server/modules/AgentRuntime/InMemoryAgentStateManager.tsindex c8e09b75a68..6940abcf7dc 100644--- a/src/server/modules/AgentRuntime/InMemoryAgentStateManager.ts+++ b/src/server/modules/AgentRuntime/InMemoryAgentStateManager.ts@@ -8,7 +8,7 @@ const log = debug('lobe-server:agent-runtime:in-memory-state-manager');/*** In-Memory Agent State Manager- * 内存实现,用于测试和本地开发环境+ * In-memory implementation for testing and local development environments*/export class InMemoryAgentStateManager implements IAgentStateManager {private states: Map<string, AgentState> = new Map();@@ -17,10 +17,10 @@ export class InMemoryAgentStateManager implements IAgentStateManager {private events: Map<string, any[][]> = new Map();async saveAgentState(operationId: string, state: AgentState): Promise<void> {- // 深拷贝以避免引用问题+ // Deep clone to avoid reference issuesthis.states.set(operationId, structuredClone(state));- // 更新元数据+ // Update metadataconst existingMeta = this.metadata.get(operationId);if (existingMeta) {existingMeta.lastActiveAt = new Date().toISOString();@@ -39,15 +39,15 @@ export class InMemoryAgentStateManager implements IAgentStateManager {}log('[%s] Loaded state (step %d)', operationId, state.stepCount);- // 返回深拷贝以避免外部修改影响内部状态+ // Return deep clone to prevent external modifications from affecting internal statereturn structuredClone(state);}async saveStepResult(operationId: string, stepResult: StepResult): Promise<void> {- // 保存最新状态+ // Save latest statethis.states.set(operationId, structuredClone(stepResult.newState));- // 保存步骤历史+ // Save step historylet stepHistory = this.steps.get(operationId);if (!stepHistory) {stepHistory = [];@@ -63,14 +63,14 @@ export class InMemoryAgentStateManager implements IAgentStateManager {timestamp: Date.now(),};- // 在开头插入(最新的在前面)+ // Insert at beginning (newest first)stepHistory.unshift(stepData);- // 保留最近 200 步+ // Keep most recent 200 stepsif (stepHistory.length > 200) {stepHistory.length = 200;}- // 保存步骤的事件序列+ // Save step event sequenceif (stepResult.events && stepResult.events.length > 0) {let eventHistory = this.events.get(operationId);if (!eventHistory) {@@ -83,7 +83,7 @@ export class InMemoryAgentStateManager implements IAgentStateManager {}}- // 更新操作元数据+ // Update operation metadataconst existingMeta = this.metadata.get(operationId);if (existingMeta) {existingMeta.lastActiveAt = new Date().toISOString();@@ -106,7 +106,7 @@ export class InMemoryAgentStateManager implements IAgentStateManager {return [];}- // 返回反转后的数组(最早的在前面)+ // Return reversed array (earliest first)return history.slice(0, limit).reverse();}@@ -161,7 +161,7 @@ export class InMemoryAgentStateManager implements IAgentStateManager {const now = Date.now();const hoursSinceActive = (now - lastActiveTime) / (1000 * 60 * 60);- // 清理超过 1 小时未活跃的操作+ // Clean up operations inactive for more than 1 hourif (hoursSinceActive > 1) {await this.deleteAgentOperation(operationId);cleanedCount++;@@ -214,12 +214,12 @@ export class InMemoryAgentStateManager implements IAgentStateManager {}async disconnect(): Promise<void> {- // 内存实现无需断开连接+ // In-memory implementation doesn't need to disconnectlog('InMemoryAgentStateManager disconnected');}/**- * 清空所有数据(用于测试)+ * Clear all data (for testing)*/clear(): void {this.states.clear();@@ -230,7 +230,7 @@ export class InMemoryAgentStateManager implements IAgentStateManager {}/**- * 获取事件历史(用于测试验证)+ * Get event history (for test verification)*/getEventHistory(operationId: string): any[][] {return this.events.get(operationId) ?? [];@@ -238,6 +238,6 @@ export class InMemoryAgentStateManager implements IAgentStateManager {}/**- * 单例实例,用于测试和本地开发环境+ * Singleton instance for testing and local development environments*/export const inMemoryAgentStateManager = new InMemoryAgentStateManager();diff --git a/src/server/modules/AgentRuntime/InMemoryStreamEventManager.ts b/src/server/modules/AgentRuntime/InMemoryStreamEventManager.tsindex 9293cb50434..ba34eb177a7 100644--- a/src/server/modules/AgentRuntime/InMemoryStreamEventManager.ts+++ b/src/server/modules/AgentRuntime/InMemoryStreamEventManager.ts@@ -9,7 +9,7 @@ type EventCallback = (events: StreamEvent[]) => void;/*** In-Memory Stream Event Manager- * 内存实现,用于测试和本地开发环境+ * In-memory implementation for testing and local development environments*/export class InMemoryStreamEventManager implements IStreamEventManager {private streams: Map<string, StreamEvent[]> = new Map();@@ -34,7 +34,7 @@ export class InMemoryStreamEventManager implements IStreamEventManager {timestamp: Date.now(),};- // 获取或创建 stream+ // Get or create streamlet stream = this.streams.get(operationId);if (!stream) {stream = [];@@ -43,14 +43,14 @@ export class InMemoryStreamEventManager implements IStreamEventManager {stream.push(eventData);- // 限制流长度,防止内存溢出+ // Limit stream length to prevent memory overflowif (stream.length > 1000) {stream.shift();}log('Published event %s for operation %s:%d', eventData.type, operationId, eventData.stepIndex);- // 通知订阅者+ // Notify subscribersconst callbacks = this.subscribers.get(operationId);if (callbacks) {for (const callback of callbacks) {@@ -111,7 +111,7 @@ export class InMemoryStreamEventManager implements IStreamEventManager {return [];}- // 返回最近的 count 条事件(倒序)+ // Return most recent count events (in reverse order)return stream.slice(-count).reverse();}@@ -126,12 +126,12 @@ export class InMemoryStreamEventManager implements IStreamEventManager {}async disconnect(): Promise<void> {- // 内存实现无需断开连接+ // In-memory implementation doesn't need to disconnectlog('InMemoryStreamEventManager disconnected');}/**- * 订阅流式事件(用于测试)+ * Subscribe to stream events (for testing)*/subscribe(operationId: string, callback: EventCallback): () => void {let callbacks = this.subscribers.get(operationId);@@ -141,7 +141,7 @@ export class InMemoryStreamEventManager implements IStreamEventManager {}callbacks.push(callback);- // 返回取消订阅函数+ // Return unsubscribe functionreturn () => {const cbs = this.subscribers.get(operationId);if (cbs) {@@ -154,7 +154,7 @@ export class InMemoryStreamEventManager implements IStreamEventManager {}/**- * 清空所有数据(用于测试)+ * Clear all data (for testing)*/clear(): void {this.streams.clear();@@ -164,14 +164,14 @@ export class InMemoryStreamEventManager implements IStreamEventManager {}/**- * 获取所有事件(用于测试验证)+ * Get all events (for test verification)*/getAllEvents(operationId: string): StreamEvent[] {return this.streams.get(operationId) ?? [];}/**- * 等待特定类型的事件(用于测试)+ * Wait for a specific event type (for testing)*/waitForEvent(operationId: string,@@ -196,7 +196,7 @@ export class InMemoryStreamEventManager implements IStreamEventManager {}});- // 检查已有事件+ // Check existing eventsconst existingEvents = this.streams.get(operationId) ?? [];for (const event of existingEvents) {if (event.type === eventType) {@@ -211,6 +211,6 @@ export class InMemoryStreamEventManager implements IStreamEventManager {}/**- * 单例实例,用于测试和本地开发环境+ * Singleton instance for testing and local development environments*/export const inMemoryStreamEventManager = new InMemoryStreamEventManager();diff --git a/src/server/modules/AgentRuntime/RuntimeExecutors.ts b/src/server/modules/AgentRuntime/RuntimeExecutors.tsindex f5e59e1da39..532b233162c 100644--- a/src/server/modules/AgentRuntime/RuntimeExecutors.ts+++ b/src/server/modules/AgentRuntime/RuntimeExecutors.ts@@ -43,8 +43,8 @@ export const createRuntimeExecutors = (ctx: RuntimeExecutorContext,): Partial<Record<AgentInstruction['type'], InstructionExecutor>> => ({/**- * 创建流式 LLM 执行器- * 集成 Agent Runtime 和流式事件发布+ * Create streaming LLM executor+ * Integrates Agent Runtime and stream event publishing*/call_llm: async (instruction, state) => {const { payload } = instruction as Extract<AgentInstruction, { type: 'call_llm' }>;diff --git a/src/server/modules/AgentRuntime/StreamEventManager.ts b/src/server/modules/AgentRuntime/StreamEventManager.tsindex 45223bd6488..ea2cca67abc 100644--- a/src/server/modules/AgentRuntime/StreamEventManager.ts+++ b/src/server/modules/AgentRuntime/StreamEventManager.ts@@ -53,7 +53,7 @@ export interface StreamChunkData {export class StreamEventManager {private redis: Redis;private readonly STREAM_PREFIX = 'agent_runtime_stream';- private readonly STREAM_RETENTION = 2 * 3600; // 2小时+ private readonly STREAM_RETENTION = 2 * 3600; // 2 hoursconstructor() {const redisClient = getAgentRuntimeRedisClient();@@ -64,7 +64,7 @@ export class StreamEventManager {}/**- * 发布流式事件到 Redis Stream+ * Publish stream event to Redis Stream*/async publishStreamEvent(operationId: string,@@ -84,8 +84,8 @@ export class StreamEventManager {streamKey,'MAXLEN','~',- '1000', // 限制流长度,防止内存溢出- '*', // 自动生成 ID+ '1000', // Limit stream length to prevent memory overflow+ '*', // Auto-generate ID'type',eventData.type,'stepIndex',@@ -99,7 +99,7 @@ export class StreamEventManager {);const xaddEnd = Date.now();- // 设置过期时间+ // Set expiration timeawait this.redis.expire(streamKey, this.STREAM_RETENTION);log(@@ -126,7 +126,7 @@ export class StreamEventManager {}/**- * 发布流式内容块+ * Publish stream content chunk*/async publishStreamChunk(operationId: string,@@ -141,7 +141,7 @@ export class StreamEventManager {}/**- * 发布 Agent 运行时初始化事件+ * Publish Agent runtime initialization event*/async publishAgentRuntimeInit(operationId: string, initialState: any): Promise<string> {return this.publishStreamEvent(operationId, {@@ -152,7 +152,7 @@ export class StreamEventManager {}/**- * 发布 Agent 运行时结束事件+ * Publish Agent runtime end event*/async publishAgentRuntimeEnd(operationId: string,@@ -175,7 +175,7 @@ export class StreamEventManager {}/**- * 订阅流式事件(用于 WebSocket/SSE)+ * Subscribe to stream events (for WebSocket/SSE)*/async subscribeStreamEvents(operationId: string,@@ -193,7 +193,7 @@ export class StreamEventManager {const xreadStart = Date.now();const results = await this.redis.xread('BLOCK',- 1000, // 1秒超时+ 1000, // 1 second timeout'STREAMS',streamKey,currentLastId,@@ -207,7 +207,7 @@ export class StreamEventManager {for (const [id, fields] of messages) {const eventData: any = {};- // 解析 Redis Stream 字段+ // Parse Redis Stream fieldsfor (let i = 0; i < fields.length; i += 2) {const key = fields[i];const value = fields[i + 1];@@ -223,7 +223,7 @@ export class StreamEventManager {events.push({...eventData,- id, // Redis Stream 事件 ID+ id, // Redis Stream event ID} as StreamEvent);currentLastId = id;@@ -231,7 +231,7 @@ export class StreamEventManager {if (events.length > 0) {const now = Date.now();- // 计算事件从发布到被读取的延迟+ // Calculate latency from event publication to readfor (const event of events) {const latency = now - event.timestamp;timing(@@ -254,7 +254,7 @@ export class StreamEventManager {}console.error('[StreamEventManager] Stream subscription error:', error);- // 短暂延迟后重试+ // Retry after brief delayawait new Promise((resolve) => {setTimeout(resolve, 1000);});@@ -265,7 +265,7 @@ export class StreamEventManager {}/**- * 获取流式事件历史+ * Get stream event history*/async getStreamHistory(operationId: string, count: number = 100): Promise<StreamEvent[]> {const streamKey = `${this.STREAM_PREFIX}:${operationId}`;@@ -298,7 +298,7 @@ export class StreamEventManager {}/**- * 清理操作的流式数据+ * Clean up stream data for operation*/async cleanupOperation(operationId: string): Promise<void> {const streamKey = `${this.STREAM_PREFIX}:${operationId}`;@@ -312,7 +312,7 @@ export class StreamEventManager {}/**- * 获取活跃操作数量+ * Get count of active operations*/async getActiveOperationsCount(): Promise<number> {try {@@ -326,7 +326,7 @@ export class StreamEventManager {}/**- * 关闭 Redis 连接+ * Close Redis connection*/async disconnect(): Promise<void> {await this.redis.quit();diff --git a/src/server/modules/AgentRuntime/types.ts b/src/server/modules/AgentRuntime/types.tsindex 2deee73eae5..566fa6bb03e 100644--- a/src/server/modules/AgentRuntime/types.ts+++ b/src/server/modules/AgentRuntime/types.ts@@ -5,16 +5,16 @@ import type { StreamChunkData, StreamEvent } from './StreamEventManager';/*** Agent State Manager Interface- * 用于状态持久化的抽象接口,支持 Redis 和内存实现+ * Abstract interface for state persistence, supports Redis and in-memory implementations*/export interface IAgentStateManager {/**- * 清理过期的操作数据+ * Clean up expired operation data*/cleanupExpiredOperations(): Promise<number>;/**- * 创建新的操作元数据+ * Create new operation metadata*/createOperationMetadata(operationId: string,@@ -26,32 +26,32 @@ export interface IAgentStateManager {): Promise<void>;/**- * 删除 Agent 操作的所有数据+ * Delete all data for Agent operation*/deleteAgentOperation(operationId: string): Promise<void>;/**- * 关闭连接+ * Close connections*/disconnect(): Promise<void>;/**- * 获取所有活跃操作+ * Get all active operations*/getActiveOperations(): Promise<string[]>;/**- * 获取执行历史+ * Get execution history*/getExecutionHistory(operationId: string, limit?: number): Promise<any[]>;/**- * 获取操作元数据+ * Get operation metadata*/getOperationMetadata(operationId: string): Promise<AgentOperationMetadata | null>;/**- * 获取统计信息+ * Get statistics*/getStats(): Promise<{activeOperations: number;@@ -61,48 +61,48 @@ export interface IAgentStateManager {}>;/**- * 加载 Agent 状态+ * Load Agent state*/loadAgentState(operationId: string): Promise<AgentState | null>;/**- * 保存 Agent 状态+ * Save Agent state*/saveAgentState(operationId: string, state: AgentState): Promise<void>;/**- * 保存步骤执行结果+ * Save step execution result*/saveStepResult(operationId: string, stepResult: StepResult): Promise<void>;}/*** Stream Event Manager Interface- * 用于流式事件发布的抽象接口,支持 Redis 和内存实现+ * Abstract interface for stream event publishing, supports Redis and in-memory implementations*/export interface IStreamEventManager {/**- * 清理操作的流式数据+ * Clean up stream data for operation*/cleanupOperation(operationId: string): Promise<void>;/**- * 关闭连接+ * Close connections*/disconnect(): Promise<void>;/**- * 获取活跃操作数量+ * Get count of active operations*/getActiveOperationsCount(): Promise<number>;/**- * 获取流式事件历史+ * Get stream event history*/getStreamHistory(operationId: string, count?: number): Promise<StreamEvent[]>;/**- * 发布 Agent 运行时结束事件+ * Publish Agent runtime end event*/publishAgentRuntimeEnd(operationId: string,@@ -113,12 +113,12 @@ export interface IStreamEventManager {): Promise<string>;/**- * 发布 Agent 运行时初始化事件+ * Publish Agent runtime initialization event*/publishAgentRuntimeInit(operationId: string, initialState: any): Promise<string>;/**- * 发布流式内容块+ * Publish stream content chunk*/publishStreamChunk(operationId: string,@@ -127,7 +127,7 @@ export interface IStreamEventManager {): Promise<string>;/**- * 发布流式事件+ * Publish stream event*/publishStreamEvent(operationId: string,