diff --git a/agent/escort/agent.js b/agent/escort/agent.js index 927115d..2b1edf7 100644 --- a/agent/escort/agent.js +++ b/agent/escort/agent.js @@ -77,10 +77,13 @@ export default class EscortAgent { } } } else if (mode === "messages") { - const [message] = data; + const [message, metadata] = data; if (message.tool_call_chunks?.length) { continue; } + if (metadata?.lcSource === "summarization" || metadata?.lc_source === "summarization") { + continue; + } if (AIMessageChunk.isInstance(message)) { if (message.text && !message.tool_call_chunks?.length) { callback(source, "ai", message.text, message.id); @@ -103,20 +106,23 @@ export default class EscortAgent { return this.agent; } - this.messages = []; - const rootDir = process.cwd(); - const userMemoryPath = path.join(rootDir, "data", userInfo._id, "memories"); - console.log(userMemoryPath); - const backend = new CompositeBackend( - new FilesystemBackend({ rootDir }), - { - "/memories/": new FilesystemBackend({ - rootDir: userMemoryPath, - virtualMode: true - }) - }, - ) + this.messages = []; + let backend = new FilesystemBackend({ rootDir }); + + if (userInfo) { + const userMemoryPath = path.join(rootDir, "data", userInfo._id, "memories"); + console.log(userMemoryPath); + backend = new CompositeBackend( + new FilesystemBackend({ rootDir }), + { + "/memories/": new FilesystemBackend({ + rootDir: userMemoryPath, + virtualMode: true + }) + }, + ) + } this.flashModel = new ChatDeepSeek({ model: 'deepseek-v4-flash', @@ -139,13 +145,6 @@ export default class EscortAgent { getCalendarInfoTool, getLunarCalendarInfoTool, getYearHolidaysTool, getYearTermsTool, createEscortRecordQueryTool(userInfo)], skills: ["./agent/escort/skills/"], - middleware: [ - summarizationMiddleware({ - model: this.flashModel, - trigger: { tokens: 5000 }, - keep: { messages: 10 }, - }), - ], }); return this.agent; diff --git a/websocket.js b/websocket.js index ee9c6a4..f0437e9 100644 --- a/websocket.js +++ b/websocket.js @@ -81,7 +81,7 @@ export default class WebSocketServerManager { } if (msg.type === 'chat' || msg.type === 'clear') { - if (msg.agent === 'escort-admin') { + if (msg.agent === 'escort-admin') { const userInfo = await this.getUserInfo(msg.token, msg.userId); adminAgent.streamChat(userInfo, [msg], (source, type, content, id) => { ws.send(JSON.stringify({ source, type, content, id })); @@ -134,18 +134,23 @@ export default class WebSocketServerManager { } async getUserInfo(token, userId) { - if (!token && !userId) return null; + try { + if (!token && !userId) return null; - const url = "http://127.0.0.1:9010/user/userInfo"; - const res = await fetch(url, { - method: "POST", - headers: { "Content-Type": "application/json" }, - body: JSON.stringify({ - token, - userId - }) - }); - const data = await res.json(); - return data.data.user; + const url = "http://127.0.0.1:9010/user/userInfo"; + const res = await fetch(url, { + method: "POST", + headers: { "Content-Type": "application/json" }, + body: JSON.stringify({ + token, + userId + }) + }); + const data = await res.json(); + return data.data.user; + } catch (error) { + console.error('Error fetching user info:', error); + return null; + } } }