Add Mem0 long-term memory tools to agent-openai-advanced#234
Draft
kevinyan122 wants to merge 1 commit into
Draft
Add Mem0 long-term memory tools to agent-openai-advanced#234kevinyan122 wants to merge 1 commit into
kevinyan122 wants to merge 1 commit into
Conversation
Register four OpenAI Agents SDK function tools (save/search/list/delete) that call the Mem0 hosted REST API directly via httpx — no mem0 SDK. Memories are scoped per user; user_id is resolved from the end user's Databricks identity (current_user.me().user_name) and injected via the run context so the model cannot set it. Endpoints verified live against api.mem0.ai (v3 add/search/list, v1 delete). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
4fa795a to
eef067b
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Adds long-term memory to the
agent-openai-advancedtemplate via Mem0's hosted REST API, exposed as four OpenAI Agents SDK function tools — no mem0 SDK dependency (plainhttpx). Complements the template's existing short-term Lakebase session memory.Changes
agent_server/memory_utils.py(new):save_memory,search_memory,list_memories,delete_memorytools, plusMem0Contextandget_mem0_user_id().agent_server/agent.py: register the tools, type the agent onMem0Context, resolve the user id, passcontext=intoRunner.run/run_streamed, and add memory-aware instructions.pyproject.toml: addhttpx.How it works
api.mem0.aidirectly:POST /v3/memories/add(async),POST /v3/memories/search,POST /v3/memories/(list),DELETE /v1/memories/{id}, auth viaAuthorization: Token.user_id= the end user's Databricks identity (current_user.me().user_name), injected through the SDK run context so the LLM cannot set it (verified: tool schemas expose onlytext/query/limit/memory_id).addis asynchronous, so saves are eventually consistent (searchable within ~a minute).Config
MEM0_API_KEYin the environment (.envlocally; an app env var / Databricks secret on deploy).databricks.ymlgrant needed — Mem0 is an external API, not a Databricks resource.Testing
Verified live end-to-end against
api.mem0.ai: the agent autonomously callssave_memory, Mem0 stores the facts, andsearch_memoryrecalls them in a fresh conversation. Module imports/compiles and the context stays hidden from the model.🤖 Generated with Claude Code