{"record":{"id":"84dad28965d5e504","repo":"agentscope-ai/agentscope","slug":"mem0middleware-needs-one-of-a-pre-built-client","errorCode":null,"errorMessage":"\"Mem0Middleware needs one of: a pre-built `client`, a `mem0_config`, or both `chat_model` and `embedding_model`.\"","messagePattern":"\"Mem0Middleware needs one of: a pre-built `client`, a `mem0_config`, or both `chat_model` and `embedding_model`\\.\"","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"src/agentscope/middleware/_longterm_memory/_mem0/_middleware.py","lineNumber":455,"sourceCode":"                    (\"chat_model\", chat_model),\n                    (\"embedding_model\", embedding_model),\n                    (\"mem0_config\", mem0_config),\n                )\n                if value is not None\n            ]\n            if ignored:\n                logger.warning(\n                    \"Mem0Middleware: `client` was provided, so %s \"\n                    \"%s ignored. Pass them via the mem0 client itself \"\n                    \"(or omit `client` to let the middleware build one \"\n                    \"for you).\",\n                    \", \".join(ignored),\n                    \"is\" if len(ignored) == 1 else \"are\",\n                )\n        if client is None:\n            no_models = chat_model is None and embedding_model is None\n            if mem0_config is None and no_models:\n                raise ValueError(\n                    \"Mem0Middleware needs one of: a pre-built `client`, \"\n                    \"a `mem0_config`, or both `chat_model` and \"\n                    \"`embedding_model`.\",\n                )\n            # When no mem0_config is given, models must come as a pair.\n            if mem0_config is None and (\n                (chat_model is None) ^ (embedding_model is None)\n            ):\n                raise ValueError(\n                    \"Mem0Middleware: `chat_model` and \"\n                    \"`embedding_model` must be passed together when \"\n                    \"`mem0_config` is not given.\",\n                )\n\n            from mem0 import AsyncMemory\n\n            from ._agentscope_adapter import build_mem0_config\n","sourceCodeStart":437,"sourceCodeEnd":473,"githubUrl":"https://github.com/agentscope-ai/agentscope/blob/e90f1c7592896cc95f6e5ee506194f533378247d/src/agentscope/middleware/_longterm_memory/_mem0/_middleware.py#L437-L473","documentation":"_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.","triggerScenarios":"Mem0Middleware(user_id='u1') with no client, mem0_config, chat_model, or embedding_model arguments.","commonSituations":"Assuming mem0 falls back to environment variables (it doesn't through this path); forgetting wiring in quick-start code.","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="],"exampleFix":"// before\nmw = Mem0Middleware(user_id='u1')\n// after\nmw = Mem0Middleware(user_id='u1', chat_model=chat, embedding_model=emb)","handlingStrategy":"validation","validationCode":"if client is None and mem0_config is None and (chat_model is None or embedding_model is None):\n    raise ValueError('need client, mem0_config, or both chat_model and embedding_model')","typeGuard":null,"tryCatchPattern":"try:\n    mw = Mem0Middleware(user_id='u1')\nexcept ValueError as e:\n    if 'needs one of' in str(e):\n        mw = Mem0Middleware(user_id='u1', chat_model=c, embedding_model=e)\n    else:\n        raise","preventionTips":["Centralize middleware construction in one factory that always passes models or client"],"tags":["mem0","client","config"],"backgroundTag":"missing-required-config-field","analyzedSha":"e90f1c7592896cc95f6e5ee506194f533378247d","analyzedAt":"2026-08-28T18:24:12.087Z","schemaVersion":2},"datasetVersion":"2026-08-28T21:17:43.275Z"}