agentscope-ai/agentscope · error · ValueError

"Mem0Middleware: `chat_model` and `embedding_model` must be

Error message

"Mem0Middleware: `chat_model` and `embedding_model` must be passed together when `mem0_config` is not given."

What it means

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.

Source

Thrown at src/agentscope/middleware/_longterm_memory/_mem0/_middleware.py:464

                    "%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

            client = AsyncMemory(
                config=build_mem0_config(
                    chat_model=chat_model,
                    embedding_model=embedding_model,
                    mem0_config=mem0_config,
                ),
            )

        if not _looks_async(

View on GitHub (pinned to e90f1c7592)

Solutions

  1. Pass both chat_model and embedding_model together
  2. Or supply a mem0_config that already contains both llm and embedder sections
  3. Or pass client=AsyncMemory(...) built elsewhere

Example fix

// before
Mem0Middleware(user_id='u1', chat_model=chat)
// after
MemoryMiddleware(user_id='u1', chat_model=chat, embedding_model=emb)
Defensive patterns

Strategy: validation

Validate before calling

if mem0_config is None and ((chat_model is None) != (embedding_model is None)):
    raise ValueError('chat_model and embedding_model must be passed together')

Try / catch

try:
    mw = Mem0Middleware(user_id='u1', chat_model=c)
except ValueError as e:
    if 'together' in str(e):
        mw = Mem0Middleware(user_id='u1', chat_model=c, embedding_model=e)
    else:
        raise

Prevention

When it happens

Trigger: Mem0Middleware(chat_model=m) without embedding_model, or the reverse, with mem0_config=None.

Common situations: Assuming mem0 uses a default embedder for the LLM-only case; incremental refactors that drop one argument.

Understand the failure class

Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.

Related errors


AI-assisted analysis of agentscope-ai/agentscope@e90f1c7592 (2026-08-28). Data as JSON: /api/errors/d0b880dcbbdde593. Report an issue: GitHub.