Browse Source

fix(chat-engine): instruct LLM not to call document tool for existing memory

Memory context is already injected into system prompt, so add explicit
instruction telling the LLM to use it directly instead of calling the
document tool to re-read memories.

Co-authored-by: CodeFree <codefree@chinatelcom.cn>
feat/agent-independence
npmrun 2 months ago
parent
commit
c2bf347dc3
  1. 6
      server/service/agent/chat-engine.ts

6
server/service/agent/chat-engine.ts

@ -251,9 +251,11 @@ export async function executeChat(params: ChatEngineParams): Promise<ChatEngineR
if (user) { if (user) {
const memoryContext = await getMemoryContext(user.id); const memoryContext = await getMemoryContext(user.id);
if (memoryContext) { if (memoryContext) {
const memoryInstruction =
"\n\n以下 <memory> 标签内是你的持久记忆,已注入上下文。回答问题时优先参考这些记忆,不要重复调用 document 工具读取已有记忆。";
systemPrompt = systemPrompt systemPrompt = systemPrompt
? `${systemPrompt}\n\n${memoryContext}` ? `${systemPrompt}${memoryInstruction}\n${memoryContext}`
: memoryContext; : `${memoryInstruction}\n${memoryContext}`;
} }
} }

Loading…
Cancel
Save