fix: gracefully fall back to FileMemory when a string memory backend fails to initialise

CI test-core (subdirs) failed on test_every_advertised_preset_resolves with
"Mem0 API Key not provided" because the mem0 package is installed in that job
but no MEM0_API_KEY is set. Agent(memory="mem0") already promised a graceful
"Falling back to FileMemory" for missing optional dependencies (ImportError),
but an installed-yet-uninitialisable SaaS backend raised ValueError, which was
uncaught and crashed construction. Broaden the string-preset branch to honour
the same fallback contract for runtime init failures.

Pre-existing, unrelated to PR #4340 (gateway durability); no Agent params added.

Co-authored-by: Mervin Praison <[email protected]>
This commit is contained in:
praisonai-triage-agent[bot]andMervin Praison committed 2026-08-25 09:34:46 +00:00
1 parent a84c6ace9f
commit 2eacdcf794
1 file changed
+8
@@ -5781,6 +5781,14 @@ Summary:"""
logging.warning(f"Memory provider '{memory}' requires additional dependencies. Falling back to FileMemory.")
from ..memory.file_memory import FileMemory
self._memory_instance = FileMemory(user_id=mem_user_id)
except Exception as e:
# The backend package is installed but could not initialise
# (e.g. a SaaS backend like mem0 needs credentials/network).
# Honour the same "Falling back to FileMemory" contract used for
# missing dependencies so construction never hard-crashes.
logging.warning(f"Memory provider '{memory}' could not initialise ({e}). Falling back to FileMemory.")
from ..memory.file_memory import FileMemory
self._memory_instance = FileMemory(user_id=mem_user_id)
elif isinstance(memory, dict):
# Configuration dict
provider = memory.get("provider", memory.get("backend", "file"))