Skip to content

[MRG] add mem0 memory#310

Merged
YuanmingLeee merged 2 commits into
MLSysOps:mainfrom
leeeizhang:lei/add_mem0
Jul 13, 2025
Merged

[MRG] add mem0 memory#310
YuanmingLeee merged 2 commits into
MLSysOps:mainfrom
leeeizhang:lei/add_mem0

Conversation

@leeeizhang
Copy link
Copy Markdown
Collaborator

@leeeizhang leeeizhang commented Jul 13, 2025

Closes #298

Use the Mem0 to store and retrieve long-term chat history in memory.

  • infer=True enables automatic memory summarization.
  • chat history is structured using role and content, compatible with OpenAI chat format.
  • each memory entry is deduplicated via content hash and time-stamped for tracking.
from mle.utils.memory import Mem0

# initialize memory instance
mem = Mem0()

# A chat session example
chat_sessions: list[dict[str, str]] = [
    {"role": "system", "content": "You are a helpful assistant."},
    {"role": "assistant", "content": "What is your favorite city?"},
    {"role": "user", "content": "The capital of France, Paris."},
    {"role": "assistant", "content": "Sure, I will remember for these"},
]

# store the session with automatic summarization
mem.add(chat_sessions, infer=True, prompt="Remember the information for the user")

# retrieve all stored memories
mem.get_all()

output example:

{
  "results": [
    {
      "id": "066436ec-e495-4f27-988d-223e5db68c9e",
      "memory": "Favorite city is Paris, the capital of France",
      "hash": "11828c80c2d0105db6c02af3adc7aec4",
      "metadata": null,
      "created_at": "2025-07-13T05:01:23.911676-07:00",
      "updated_at": null,
      "agent_id": "default"
    }
  ]
}

Before submitting this PR, please make sure you have:

  • confirmed all checks still pass OR confirm CI build passes.
  • verified that any code or assets from external sources are properly credited in comments and/or in
    the credit file.

@dosubot dosubot Bot added the size:M This PR changes 30-99 lines, ignoring generated files. label Jul 13, 2025
@dosubot dosubot Bot added the enhancement New feature or request label Jul 13, 2025
@leeeizhang leeeizhang changed the title [WIP] add mem0 memory [MRG] add mem0 memory Jul 13, 2025
Copy link
Copy Markdown
Contributor

@YuanmingLeee YuanmingLeee left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm, straightforward support

@YuanmingLeee YuanmingLeee merged commit cbe4c48 into MLSysOps:main Jul 13, 2025
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request size:M This PR changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[feature] add mem0 memory

2 participants