📝 refactor: Memory Instructions for Improved Performance (#8463)

This commit is contained in:
Danny Avila 2025-07-14 18:37:46 -04:00 committed by GitHub
parent aeeb860fe0
commit a9f01bb86f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -40,33 +40,33 @@ export const memoryInstructions =
const getDefaultInstructions = ( const getDefaultInstructions = (
validKeys?: string[], validKeys?: string[],
tokenLimit?: number, tokenLimit?: number,
) => `Use the \`set_memory\` tool to save important information about the user, but ONLY when the user has explicitly provided this information. If there is nothing to note about the user specifically, END THE TURN IMMEDIATELY. ) => `Use the \`set_memory\` tool to save important information about the user, but ONLY when the user has requested you to remember something.
The \`delete_memory\` tool should only be used in two scenarios: The \`delete_memory\` tool should only be used in two scenarios:
1. When the user explicitly asks to forget or remove specific information 1. When the user explicitly asks to forget or remove specific information
2. When updating existing memories, use the \`set_memory\` tool instead of deleting and re-adding the memory. 2. When updating existing memories, use the \`set_memory\` tool instead of deleting and re-adding the memory.
${ 1. ONLY use memory tools when the user requests memory actions with phrases like:
validKeys && validKeys.length > 0 - "Remember [that] [I]..."
? `CRITICAL INSTRUCTION: Only the following keys are valid for storing memories: - "Don't forget [that] [I]..."
${validKeys.map((key) => `- ${key}`).join('\n ')}` - "Please remember..."
: 'You can use any appropriate key to store memories about the user.' - "Store this..."
} - "Forget [that] [I]..."
- "Delete the memory about..."
${ 2. NEVER store information just because the user mentioned it in conversation.
tokenLimit
? `⚠️ TOKEN LIMIT: Each memory value must not exceed ${tokenLimit} tokens. Be concise and store only essential information.`
: ''
}
WARNING 3. NEVER use memory tools when the user asks you to use other tools or invoke tools in general.
DO NOT STORE ANY INFORMATION UNLESS THE USER HAS EXPLICITLY PROVIDED IT.
ONLY store information the user has EXPLICITLY shared. 4. Memory tools are ONLY for memory requests, not for general tool usage.
NEVER guess or assume user information.
ALL memory values must be factual statements about THIS specific user. 5. If the user doesn't ask you to remember or forget something, DO NOT use any memory tools.
If nothing needs to be stored, DO NOT CALL any memory tools.
If you're unsure whether to store something, DO NOT store it. ${validKeys && validKeys.length > 0 ? `\nVALID KEYS: ${validKeys.join(', ')}` : ''}
If nothing needs to be stored, END THE TURN IMMEDIATELY.`;
${tokenLimit ? `\nTOKEN LIMIT: Maximum ${tokenLimit} tokens per memory value.` : ''}
When in doubt, and the user hasn't asked to remember or forget anything, END THE TURN IMMEDIATELY.`;
/** /**
* Creates a memory tool instance with user context * Creates a memory tool instance with user context
@ -368,6 +368,7 @@ ${memory ?? 'No existing memories'}`;
thread_id: `memory-run-${conversationId}`, thread_id: `memory-run-${conversationId}`,
}, },
streamMode: 'values', streamMode: 'values',
recursionLimit: 3,
version: 'v2', version: 'v2',
} as const; } as const;