agentscope-ai/agentscope · error · ValueError
"Mem0Middleware needs one of: a pre-built `client`, a `mem0_
Error message
"Mem0Middleware needs one of: a pre-built `client`, a `mem0_config`, or both `chat_model` and `embedding_model`."
What it means
_resolve_client builds or accepts a mem0 AsyncMemory client; when no client, no mem0_config, and no models are supplied there is no way to construct one, so construction fails with this error listing the three accepted paths.
Source
Thrown at src/agentscope/middleware/_longterm_memory/_mem0/_middleware.py:455
("chat_model", chat_model),
("embedding_model", embedding_model),
("mem0_config", mem0_config),
)
if value is not None
]
if ignored:
logger.warning(
"Mem0Middleware: `client` was provided, so %s "
"%s ignored. Pass them via the mem0 client itself "
"(or omit `client` to let the middleware build one "
"for you).",
", ".join(ignored),
"is" if len(ignored) == 1 else "are",
)
if client is None:
no_models = chat_model is None and embedding_model is None
if mem0_config is None and no_models:
raise ValueError(
"Mem0Middleware needs one of: a pre-built `client`, "
"a `mem0_config`, or both `chat_model` and "
"`embedding_model`.",
)
# When no mem0_config is given, models must come as a pair.
if mem0_config is None and (
(chat_model is None) ^ (embedding_model is None)
):
raise ValueError(
"Mem0Middleware: `chat_model` and "
"`embedding_model` must be passed together when "
"`mem0_config` is not given.",
)
from mem0 import AsyncMemory
from ._agentscope_adapter import build_mem0_config
View on GitHub (pinned to e90f1c7592)
Solutions
- Pass chat_model= and embedding_model= (an AgentScope ChatModelBase and EmbeddingModelBase)
- Or pass mem0_config=dict with full llm/embedder/vector_store blocks
- Or pass a pre-built mem0.AsyncMemory as client=
Example fix
// before mw = Mem0Middleware(user_id='u1') // after mw = Mem0Middleware(user_id='u1', chat_model=chat, embedding_model=emb)
Defensive patterns
Strategy: validation
Validate before calling
if client is None and mem0_config is None and (chat_model is None or embedding_model is None):
raise ValueError('need client, mem0_config, or both chat_model and embedding_model') Try / catch
try:
mw = Mem0Middleware(user_id='u1')
except ValueError as e:
if 'needs one of' in str(e):
mw = Mem0Middleware(user_id='u1', chat_model=c, embedding_model=e)
else:
raise Prevention
- Centralize middleware construction in one factory that always passes models or client
When it happens
Trigger: Mem0Middleware(user_id='u1') with no client, mem0_config, chat_model, or embedding_model arguments.
Common situations: Assuming mem0 falls back to environment variables (it doesn't through this path); forgetting wiring in quick-start code.
Related errors
- "AgentScopeLLM requires `model` in the config to be an Agent
- f"AgentScopeLLM `model` must be a ChatModelBase, got {type(s
- "AgentScopeEmbedding requires `model` in the config to be an
- "build_mem0_config requires `chat_model` and `embedding_mode
- "Mem0Middleware requires an async mem0 client (`mem0.AsyncMe
AI-assisted analysis of agentscope-ai/agentscope@e90f1c7592 (2026-08-28).
Data as JSON: /api/errors/84dad28965d5e504.
Report an issue: GitHub.