Skip to content

Add Mem0 long-term memory tools to agent-openai-advanced#234

Draft
kevinyan122 wants to merge 1 commit into
databricks:mainfrom
kevinyan122:feat/mem0-memory-tools
Draft

Add Mem0 long-term memory tools to agent-openai-advanced#234
kevinyan122 wants to merge 1 commit into
databricks:mainfrom
kevinyan122:feat/mem0-memory-tools

Conversation

@kevinyan122
Copy link
Copy Markdown
Contributor

@kevinyan122 kevinyan122 commented Jun 4, 2026

What

Adds long-term memory to the agent-openai-advanced template via Mem0's hosted REST API, exposed as four OpenAI Agents SDK function tools — no mem0 SDK dependency (plain httpx). Complements the template's existing short-term Lakebase session memory.

Changes

  • agent_server/memory_utils.py (new): save_memory, search_memory, list_memories, delete_memory tools, plus Mem0Context and get_mem0_user_id().
  • agent_server/agent.py: register the tools, type the agent on Mem0Context, resolve the user id, pass context= into Runner.run/run_streamed, and add memory-aware instructions.
  • pyproject.toml: add httpx.

How it works

  • Calls api.mem0.ai directly: POST /v3/memories/add (async), POST /v3/memories/search, POST /v3/memories/ (list), DELETE /v1/memories/{id}, auth via Authorization: Token.
  • Per-user scoping: 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 only text/query/limit/memory_id).
  • Mem0 add is asynchronous, so saves are eventually consistent (searchable within ~a minute).

Config

  • Set MEM0_API_KEY in the environment (.env locally; an app env var / Databricks secret on deploy).
  • No databricks.yml grant needed — Mem0 is an external API, not a Databricks resource.

Testing

Verified live end-to-end against api.mem0.ai: the agent autonomously calls save_memory, Mem0 stores the facts, and search_memory recalls them in a fresh conversation. Module imports/compiles and the context stays hidden from the model.

🤖 Generated with Claude Code

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>
@kevinyan122 kevinyan122 force-pushed the feat/mem0-memory-tools branch from 4fa795a to eef067b Compare June 4, 2026 21:49
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.

1 participant