Skip to content

After storing the new memory in the database, the returned message includes the memory storage ID #139

@petersing

Description

@petersing

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:

  1. 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.

  2. No Verifiable Confirmation: Users cannot confirm that their important data (preferences, facts, decisions) was actually persisted to the memory system.

  3. Debugging Difficulty: When troubleshooting memory-related issues, there's no way to reference a specific memory entry by ID.

  4. 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

  1. Prevents AI Hallucination: AI can only claim memory was stored if it has the actual ID as proof.

  2. User Confidence: Users can see concrete evidence that their data was persisted.

  3. Audit Trail: Each memory operation has a unique identifier for tracking and debugging.

  4. Compliance with Best Practices: Follows the principle of "explicit confirmation for state-changing operations."

  5. 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 execute function)

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 details field, 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.text format changes

🧪 Testing Recommendations

  1. Unit Test: Verify that entry.id is correctly interpolated into the return text
  2. Integration Test: Call memory_store and confirm the response includes a valid UUID
  3. AI Behavior Test: Ensure AI models correctly use the ID in their responses
  4. Edge Case Test: Test with very long text (truncation should still work correctly)

📚 Related Documentation

  • AGENTS.md (Fiona's operational guidelines) specifies:

    「(已更新記憶 📂: <Memory_ID>)」標誌只可以在以下兩個條件同時成立時才加入回應:

    1. 本次回應中確實呼叫了 memory_store tool;
    2. memory_store 返回結果包含實際 Memory ID

This feature enables compliance with such guidelines.


Alternatives Considered

No response

Area

None

Additional Context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions