Skip to content

feat: include exchanged agent messages into ExternalMemory metadata #3290

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

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

lucasgomide
Copy link
Contributor

@lucasgomide lucasgomide commented Aug 7, 2025

Including the messages exchanged by the Agent at the ExternalMemory level is useful for helping external memory providers gain more context about the full conversation

@lucasgomide lucasgomide force-pushed the lg-external-memory-messages branch from d88bf0c to 793efc8 Compare August 7, 2025 19:58
@Vidit-Ostwal
Copy link
Contributor

Vidit-Ostwal commented Aug 8, 2025

Hi @lucasgomide, I was thinking instead of sending all the previous message in the metadata, we should instead send it to Memory Object inside External Memory directly, while saving.

The metadata I feel is not used while making or searching memory.

Something like this, we should make a function which removed the system prompt and also the other prommt we add in the user and assisstant prompt. wdyt?

client = MemoryClient(api_key="your_api_key", org_id="your_org_id", project_id="your_project_id")

messages = [
    {"role": "user", "content": "<user-message>"},
    {"role": "assistant", "content": "<assistant-response>"}
]

client.add(messages, user_id="<user-id>", version="v2")

@lucasgomide
Copy link
Contributor Author

lucasgomide commented Aug 8, 2025

The metadata I feel is not used while making or searching memory.

I didn't get it, we're propagating the metadata thought save storage method

I'm exposing the whole exchanged messages by Agent only for External memory, so each storage implementation can decide which messages will be picked.

@Vidit-Ostwal
Copy link
Contributor

I'm exposing the whole exchanged messages by Agent only for External memory, so each storage implementation can decide which messages will be picked.

Aligned on this.

I am suggesting additional to this, we should make a little change in the Mem0 Storage, here

def save(self, value: Any, metadata: Dict[str, Any]) -> None:
user_id = self.config.get("user_id", "")
assistant_message = [{"role" : "assistant","content" : value}]

We should change this to something like

    def save(self, value: Any, metadata: Dict[str, Any]) -> None:
        user_id = self.config.get("user_id", "")
        assistant_message = metadata.get('messages') or [{"role" : "assistant","content" : value}]

Here messages should be more like

{'role': 'system', 'content': 'You are Friendly chatbot assistant. You are a kind and knowledgeable chatbot assistant. You excel at understanding user needs, providing helpful responses, and maintaining engaging conversations. You remember previous interactions to provide a personalized experience.\nYour personal goal is: Engage in useful and interesting conversations with users while remembering context.\nTo give my best complete final answer to the task respond using the exact following format:\n\nThought: I now can give a great answer\nFinal Answer: Your final answer must be the great and the most complete as possible, it must be outcome described.\n\nI MUST use these formats, my job depends on it!'}
{'role': 'user', 'content': '\nCurrent Task: Respond to user conversation. User message: Can you remember my name ?\n\nThis is the expected criteria for your final answer: Contextually appropriate, helpful, and friendly response.\nyou MUST return the actual complete content as the final answer, not a summary.\n\nBegin! This is VERY important to you, use the tools available and give your best Final Answer, your job depends on it!\n\nThought:'}
{'role': 'assistant', 'content': "I now can give a great answer  \nFinal Answer: While I don’t have the ability to remember your name right now, I’d love to learn it! Feel free to share your name, and I’ll remember it for our future chats. I'm here to help and make our conversations as personal and enjoyable as possible!"}```

@Vidit-Ostwal
Copy link
Contributor

Additional to this, in the list of messages,
we should remove the system prompt as well, just keep the user and assistant message.

@lucasgomide
Copy link
Contributor Author

Yup, I’d prefer not to include that in this PR to keep the scope smaller
We can definitely add it later

@Vidit-Ostwal
Copy link
Contributor

Yup, I’d prefer not to include that in this PR to keep the scope smaller We can definitely add it later

Aye, Aye Captain. :)

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.

3 participants