{"record":{"id":"d0b880dcbbdde593","repo":"agentscope-ai/agentscope","slug":"mem0middleware-chat-model-and-embedding-model","errorCode":null,"errorMessage":"\"Mem0Middleware: `chat_model` and `embedding_model` must be passed together when `mem0_config` is not given.\"","messagePattern":"\"Mem0Middleware: `chat_model` and `embedding_model` must be passed together when `mem0_config` is not given\\.\"","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"src/agentscope/middleware/_longterm_memory/_mem0/_middleware.py","lineNumber":464,"sourceCode":"                    \"%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\n            client = AsyncMemory(\n                config=build_mem0_config(\n                    chat_model=chat_model,\n                    embedding_model=embedding_model,\n                    mem0_config=mem0_config,\n                ),\n            )\n\n        if not _looks_async(","sourceCodeStart":446,"sourceCodeEnd":482,"githubUrl":"https://github.com/agentscope-ai/agentscope/blob/e90f1c7592896cc95f6e5ee506194f533378247d/src/agentscope/middleware/_longterm_memory/_mem0/_middleware.py#L446-L482","documentation":"When mem0_config is absent, the models must arrive as a pair because a MemoryConfig cannot be fabricated from only one; passing just chat_model or just embedding_model raises this error.","triggerScenarios":"Mem0Middleware(chat_model=m) without embedding_model, or the reverse, with mem0_config=None.","commonSituations":"Assuming mem0 uses a default embedder for the LLM-only case; incremental refactors that drop one argument.","solutions":["Pass both chat_model and embedding_model together","Or supply a mem0_config that already contains both llm and embedder sections","Or pass client=AsyncMemory(...) built elsewhere"],"exampleFix":"// before\nMem0Middleware(user_id='u1', chat_model=chat)\n// after\nMemoryMiddleware(user_id='u1', chat_model=chat, embedding_model=emb)","handlingStrategy":"validation","validationCode":"if mem0_config is None and ((chat_model is None) != (embedding_model is None)):\n    raise ValueError('chat_model and embedding_model must be passed together')","typeGuard":null,"tryCatchPattern":"try:\n    mw = Mem0Middleware(user_id='u1', chat_model=c)\nexcept ValueError as e:\n    if 'together' in str(e):\n        mw = Mem0Middleware(user_id='u1', chat_model=c, embedding_model=e)\n    else:\n        raise","preventionTips":["Pass models as an inseparable pair; review diffs that remove one of the two kwargs"],"tags":["mem0","paired-arguments","validation"],"backgroundTag":"missing-required-argument","analyzedSha":"e90f1c7592896cc95f6e5ee506194f533378247d","analyzedAt":"2026-08-28T18:24:12.087Z","schemaVersion":2},"datasetVersion":"2026-08-28T21:17:43.275Z"}