Skip to content

Add mem0 Memory Implementation #6510

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 46 commits into from
Jun 16, 2025

Conversation

alpha-xone
Copy link
Contributor

@alpha-xone alpha-xone commented May 11, 2025

Why are these changes needed?

These changes are needed to expand AutoGen's memory capabilities with a robust, production-ready integration with Mem0.ai.

This PR adds a new memory component for AutoGen that integrates with Mem0.ai, providing a robust memory solution that supports both cloud and local backends. The Mem0Memory class enables agents to store and retrieve information persistently across conversation sessions.

Key Features

  • Seamless integration with Mem0.ai memory system
  • Support for both cloud-based and local storage backends
  • Robust error handling with detailed logging
  • Full implementation of AutoGen's Memory interface
  • Context updating for enhanced agent conversations
  • Configurable search parameters for memory retrieval

Related issue number

Checks

Copy link

gitguardian bot commented May 11, 2025

️✅ There are no secrets present in this pull request anymore.

If these secrets were true positive and are still valid, we highly recommend you to revoke them.
While these secrets were previously flagged, we no longer have a reference to the
specific commits where they were detected. Once a secret has been leaked into a git
repository, you should consider it compromised, even if it was deleted immediately.
Find here more information about risks.


🦉 GitGuardian detects secrets in your source code to help developers and security teams secure the modern development process. You are seeing this because you or someone else with access to this repository has authorized GitGuardian to scan your pull request.

@alpha-xone
Copy link
Contributor Author

@microsoft-github-policy-service agree

@alpha-xone alpha-xone changed the title add mem0 memory implementation Add mem0 Memory Implementation May 12, 2025
ekzhu
ekzhu previously requested changes May 13, 2025
Copy link
Collaborator

@ekzhu ekzhu left a comment

Choose a reason for hiding this comment

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

Thanks for the PR! Could you add unit tests so we can ensure the correctness of the features?

Copy link

codecov bot commented May 13, 2025

Codecov Report

Attention: Patch coverage is 80.00000% with 30 lines in your changes missing coverage. Please review.

Project coverage is 79.77%. Comparing base (8a2582c) to head (7ed5163).
Report is 6 commits behind head on main.

Files with missing lines Patch % Lines
...ackages/autogen-ext/src/autogen_ext/memory/mem0.py 80.00% 30 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff            @@
##             main    #6510    +/-   ##
========================================
  Coverage   79.77%   79.77%            
========================================
  Files         228      229     +1     
  Lines       17054    17204   +150     
========================================
+ Hits        13605    13725   +120     
- Misses       3449     3479    +30     
Flag Coverage Δ
unittests 79.77% <80.00%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@alpha-xone
Copy link
Contributor Author

Thanks for replying 🚀

Unit test added: https://github.com/alpha-xone/autogen/actions/runs/14992498495
This is tested with my mem0 api key. If the test is from the main branch, it requires another key to test.

@ekzhu
Copy link
Collaborator

ekzhu commented May 14, 2025

Thanks for adding the tests. Can we use the open source verison of mem0? I think it can run entirely locally.

@alpha-xone
Copy link
Contributor Author

Yes we can. I'm running it locally with the combination of neo4j for graph storage + chromadb for vector db + SQLite for historical db. All we need to do is setup the local environment and pass a dict of configurations of these in. But for unit testing, I'm not sure how to make these environments ready to test.

@ekzhu
Copy link
Collaborator

ekzhu commented May 14, 2025

For SQLite and Chroma DB, I think you can instantiate directly as test fixture, right? See example on ChromaDBVectorMemory tests: https://github.com/microsoft/autogen/blob/78ef148c88beb29a7e7602aa39a772b0ffbc50d5/python/packages/autogen-ext/tests/memory/test_chroma_memory.py

For Neo4j, there should be github actions that can set this up in CI. For local integration test, we can skip it if no neo4j server is running.

Besides all these above, I thought mem0's can run independently as in-memory python code? That's my impression reading their documentation. https://docs.mem0.ai/open-source/python-quickstart#basic

@alpha-xone
Copy link
Contributor Author

The neo4j container cannot initiated on the server:
https://github.com/alpha-xone/autogen/actions/runs/15066738718

  Error: Failed to initialize container neo4j:5.19
Error: One or more containers failed to start.

I can only test locally with the same config in the test_mem0.py file - it's working on my side.

@ekzhu ekzhu self-assigned this May 19, 2025
@rickyloynd-microsoft
Copy link
Contributor

@alpha-xone, your PR should update python/uv.lock. Please try the following steps:

  1. Pull the current remote mem0-memory branch to your local branch, to get the latest merges from main.
  2. Checkout python/uv.lock
  3. Overwrite uv.lock with the latest copy of uv.lock from main.
  4. In the python dir, do uv sync --all-extras. This will modify uv.lock.
  5. Run the usual local poe checks.
  6. Checkin and push the modified uv.lock to your remote branch.

Hopefully this will fix most of the remaining errors.

@alpha-xone
Copy link
Contributor Author

Hi @rickyloynd-microsoft

Thanks a lot for the detailed instructions. I'm trying the fixes and hopefully can fix in few days.

@alpha-xone
Copy link
Contributor Author

hi @rickyloynd-microsoft

I tried the above steps, and I've uploaded the uv.lock after step 4 but before 5.
The poe check does not work as below.
Copilot says it may be due to docker and OpenAI keys, which I don't have on my side.
These are not related to, nor required for the codes I added.

Is it possible to run the tests online again and I tried to look where to fix? Thanks

peo check failed

@rickyloynd-microsoft
Copy link
Contributor

hi @rickyloynd-microsoft

I tried the above steps, and I've uploaded the uv.lock after step 4 but before 5. The poe check does not work as below. Copilot says it may be due to docker and OpenAI keys, which I don't have on my side. These are not related to, nor required for the codes I added.

Is it possible to run the tests online again and I tried to look where to fix? Thanks

peo check failed

Sure, if you push a change to the branch, I'll approve the checks to be run again.

@alpha-xone
Copy link
Contributor Author

hi @rickyloynd-microsoft

Great, thanks. Could you approve current branch pls - there is no update to main button now - I think there's no change since my last upload. There could be some time to fix CIs. Thanks

@rickyloynd-microsoft
Copy link
Contributor

hi @rickyloynd-microsoft

Great, thanks. Could you approve current branch pls - there is no update to main button now - I think there's no change since my last upload. There could be some time to fix CIs. Thanks

There's no button for me to approve the check workflow right now, because you haven't pushed any changes since the last time it ran.

@alpha-xone alpha-xone requested a review from ekzhu June 7, 2025 17:28
@alpha-xone
Copy link
Contributor Author

does it require Eric to review?

image

@rickyloynd-microsoft
Copy link
Contributor

does it require Eric to review?

image

Merging the PR requires the review, and it requires that all the checks pass.

@alpha-xone
Copy link
Contributor Author

Should be able to approve now:

Fixed the bug in uv.lock - it's missing the agbench version, which is missing running the uv command.

@rickyloynd-microsoft
Copy link
Contributor

Should be able to approve now:

Fixed the bug in uv.lock - it's missing the agbench version, which is missing running the uv command.

Not sure I understand. No PR can be approved or merged until none of the checks fail. For instance, PR #6622 passes the checks and is awaiting approval.

@alpha-xone
Copy link
Contributor Author

alpha-xone commented Jun 8, 2025

finally! all checks passed!

The problem was:
uv sync --all-extras does not add version to a few autogen packages in their [[package]] sections.
Hope noting this can make easier for others in the future. 🙏

@rickyloynd-microsoft
Copy link
Contributor

finally! all checks passed!

The problem was: uv sync --all-extras does not add version to a few autogen packages in their [[package]] sections. Hope noting this can make easier for others in the future. 🙏

That's great! Do you have recommendations for the [[package]] sections or the readme.md to help others deal with this?

@alpha-xone
Copy link
Contributor Author

@alpha-xone, your PR should update python/uv.lock. Please try the following steps:

  1. Pull the current remote mem0-memory branch to your local branch, to get the latest merges from main.
  2. Checkout python/uv.lock
  3. Overwrite uv.lock with the latest copy of uv.lock from main.
  4. In the python dir, do uv sync --all-extras. This will modify uv.lock.
  5. Run the usual local poe checks.
  6. Checkin and push the modified uv.lock to your remote branch.

Hopefully this will fix most of the remaining errors.

Sure.

On top of the 5 steps above, just add two versions below.
The problem with uv.lock will be gone:

[[package]]Add commentMore actions
name = "agbench"Add commentMore actions
version = "0.0.1a1"

...

[[package]]Add commentMore actions
name = "autogenstudio"
version = "0.4.2.2"

Note: need to read the exact versions from main.

@rickyloynd-microsoft
Copy link
Contributor

I'll try to run the code and finish reviewing the PR this week. Thanks @alpha-xone !

@alpha-xone
Copy link
Contributor Author

hi @rickyloynd-microsoft

Thanks for running the CIs. I saw the conflicts in these two files:

  • In memory.ipynb, only line 641-732 from mem0-memory branch is relevant for this PR - others are not related but somehow being changed for unknown reasons.
  • For uv.lock, that is running machine related - all conflicts can be skipped?

@rickyloynd-microsoft rickyloynd-microsoft dismissed ekzhu’s stale review June 16, 2025 22:37

Requested change was made, but reviewer is on vacation.

@rickyloynd-microsoft rickyloynd-microsoft merged commit 89927ca into microsoft:main Jun 16, 2025
65 checks passed
@alpha-xone alpha-xone deleted the mem0-memory branch June 17, 2025 01:05
ZenWayne pushed a commit to ZenWayne/autogen that referenced this pull request Jun 19, 2025
<!-- Thank you for your contribution! Please review
https://microsoft.github.io/autogen/docs/Contribute before opening a
pull request. -->

<!-- Please add a reviewer to the assignee section when you create a PR.
If you don't have the access to it, we will shortly find a reviewer and
assign them to your PR. -->

## Why are these changes needed?

These changes are needed to expand AutoGen's memory capabilities with a
robust, production-ready integration with Mem0.ai.

<!-- Please give a short summary of the change and the problem this
solves. -->

This PR adds a new memory component for AutoGen that integrates with
Mem0.ai, providing a robust memory solution that supports both cloud and
local backends. The Mem0Memory class enables agents to store and
retrieve information persistently across conversation sessions.

## Key Features

- Seamless integration with Mem0.ai memory system
- Support for both cloud-based and local storage backends
- Robust error handling with detailed logging
- Full implementation of AutoGen's Memory interface
- Context updating for enhanced agent conversations
- Configurable search parameters for memory retrieval

## Related issue number

<!-- For example: "Closes microsoft#1234" -->

## Checks

- [x] I've included any doc changes needed for
<https://microsoft.github.io/autogen/>. See
<https://github.com/microsoft/autogen/blob/main/CONTRIBUTING.md> to
build and test documentation locally.
- [x] I've added tests (if relevant) corresponding to the changes
introduced in this PR.
- [ ] I've made sure all auto checks have passed.

---------

Co-authored-by: Victor Dibia <victordibia@microsoft.com>
Co-authored-by: Eric Zhu <ekzhu@users.noreply.github.com>
Co-authored-by: Ricky Loynd <riloynd@microsoft.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants