-
Notifications
You must be signed in to change notification settings - Fork 370
Description
Problem / Motivation
Feature Request: Add Memory ID to memory_store Return Value
📋 Summary
Add Memory ID to the return text of memory_store tool to prevent AI hallucination and provide verifiable confirmation of successful memory storage.
🐛 Problem Description
Current Behavior
When calling the memory_store tool, the return value only shows:
Stored: "..." in scope 'agent:main'
The Memory ID exists in the details.id field but is NOT visible in the response text shown to the AI model.
Impact
This creates several critical issues:
-
AI Hallucination Risk: The AI cannot verify whether a memory was actually stored successfully. It may claim "已更新記憶 📂" without having proof of the actual Memory ID.
-
No Verifiable Confirmation: Users cannot confirm that their important data (preferences, facts, decisions) was actually persisted to the memory system.
-
Debugging Difficulty: When troubleshooting memory-related issues, there's no way to reference a specific memory entry by ID.
-
Trust Issues: Users may lose confidence in the system if the AI claims to have stored memories but cannot provide concrete evidence (ID) of the operation.
Proposed Solution
✅ Proposed Solution
Change
Modify the return text format in memory_store tool to include the Memory ID:
Before:
text: `Stored: "${text.slice(0, 100)}${text.length > 100 ? "..." : ""}" in scope '${targetScope}'`,After:
text: `Stored: "${text.slice(0, 100)}${text.length > 100 ? "..." : ""}" (ID: ${entry.id}) in scope '${targetScope}'`,Example Output
Stored: "Test Store..." (ID: 8f82f232-abc1-4def-9012-345680501234) in scope 'agent:main'
🎯 Benefits
-
Prevents AI Hallucination: AI can only claim memory was stored if it has the actual ID as proof.
-
User Confidence: Users can see concrete evidence that their data was persisted.
-
Audit Trail: Each memory operation has a unique identifier for tracking and debugging.
-
Compliance with Best Practices: Follows the principle of "explicit confirmation for state-changing operations."
-
Enables Advanced Features: Future features like memory editing, deletion, or referencing can use these IDs.
🔧 Implementation Details
File to Modify
- Path:
/root/node_modules/memory-lancedb-pro/src/tools.ts - Function:
registerMemoryStoreTool - Line: ~578 (return statement in
executefunction)
Code Change
return {
content: [
{
type: "text",
- text: `Stored: "${text.slice(0, 100)}${text.length > 100 ? "..." : ""}" in scope '${targetScope}'`,
+ text: `Stored: "${text.slice(0, 100)}${text.length > 100 ? "..." : ""}" (ID: ${entry.id}) in scope '${targetScope}'`,
},
],
details: {
action: "created",
id: entry.id,
scope: entry.scope,
category: entry.category,
importance: entry.importance,
},
};📝 Use Case Example
Scenario: User Shares Important Preference
User: "我未來 5 年計劃挑戰 traffic around the world"
AI Action: Calls memory_store with this information
Before (Problem):
- AI receives:
Stored: "我未來 5 年計劃挑戰..." in scope 'agent:main' - AI claims: "已更新記憶 📂" (but has no ID to prove it)
- Risk: AI might claim memory was stored even if the operation failed silently
After (Solution):
- AI receives:
Stored: "我未來 5 年計劃挑戰..." (ID: 8f82f232-abc1-4def-9012-345678901234) in scope 'agent:main' - AI claims: "已更新記憶 📂: 8f82f232" (with verifiable ID)
- Benefit: User can confirm the memory was actually stored with a specific ID
⚠️ Considerations
Privacy
- Memory IDs are UUIDs and do not contain sensitive information
- IDs are already stored in the
detailsfield, so this change only makes them visible in the response text
Performance
- No performance impact: the ID is already generated, this just includes it in the response text
- Text length increase is minimal (~50 characters for a typical UUID)
Backward Compatibility
- This is a non-breaking change
- Existing code that parses the return value can still access
details.id - Only the
content.textformat changes
🧪 Testing Recommendations
- Unit Test: Verify that
entry.idis correctly interpolated into the return text - Integration Test: Call
memory_storeand confirm the response includes a valid UUID - AI Behavior Test: Ensure AI models correctly use the ID in their responses
- Edge Case Test: Test with very long text (truncation should still work correctly)
📚 Related Documentation
- AGENTS.md (Fiona's operational guidelines) specifies:
「(已更新記憶 📂: <Memory_ID>)」標誌只可以在以下兩個條件同時成立時才加入回應:
- 本次回應中確實呼叫了
memory_storetool;且 memory_store返回結果包含實際 Memory ID
- 本次回應中確實呼叫了
This feature enables compliance with such guidelines.
Alternatives Considered
No response
Area
None
Additional Context
No response