Skip to content

fix(mem0): merge env vars with mem0.json instead of either/or#4836

Closed
ellenlivia-mem0 wants to merge 1 commit into
NousResearch:mainfrom
ellenlivia-mem0:fix/mem0-config-merge-env-vars
Closed

fix(mem0): merge env vars with mem0.json instead of either/or#4836
ellenlivia-mem0 wants to merge 1 commit into
NousResearch:mainfrom
ellenlivia-mem0:fix/mem0-config-merge-env-vars

Conversation

@ellenlivia-mem0

Copy link
Copy Markdown

Summary

  • Bug: hermes memory status shows mem0 as "not available" even when MEM0_API_KEY is correctly set in ~/.hermes/.env
  • Cause: _load_config() in the mem0 plugin treats mem0.json and env vars as mutually exclusive. If mem0.json exists (created by hermes memory setup with just user_id/agent_id), it returns that file's contents and never checks env vars — so api_key is silently empty.
  • Fix: Use env vars as the base config, then let mem0.json override individual keys on top. Both sources now work together instead of one replacing the other.

Reproduction

  1. hermes memory setup → configure user_id and agent_id
  2. Add MEM0_API_KEY=m0-xxx to ~/.hermes/.env
  3. hermes memory status → shows "not available"

Test plan

  • Verify hermes memory status shows available with key only in .env
  • Verify hermes memory status shows available with key only in mem0.json
  • Verify mem0.json values override env vars when both are set
  • Verify empty/falsy values in mem0.json don't clobber env var defaults

When mem0.json exists but is missing the api_key (e.g. after running
`hermes memory setup`), the plugin reports "not available" even though
MEM0_API_KEY is set in .env.  This happens because _load_config()
returns the JSON file contents verbatim, never falling back to env vars.

Use env vars as the base config and let mem0.json override individual
keys on top, so both config sources work together.

Fixes: mem0 plugin shows "not available" despite valid MEM0_API_KEY in .env
@teknium1

teknium1 commented Apr 4, 2026

Copy link
Copy Markdown
Contributor

Merged via PR #4939. Your commit was cherry-picked onto current main with authorship preserved. We added a small follow-up fix: changed the merge filter from if v to if v is not None and v != "" so that "rerank": false in mem0.json isn't silently dropped. Thanks for the clean fix!

@ellenlivia-mem0

Copy link
Copy Markdown
Author

thankyou @teknium1

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