agentscope-ai/agentscope · error · ValueError

"build_mem0_config requires `chat_model` and `embedding_mode

Error message

"build_mem0_config requires `chat_model` and `embedding_model` when `mem0_config` is not given."

What it means

build_mem0_config constructs a mem0 MemoryConfig from AgentScope models; when mem0_config is None it needs both chat_model and embedding_model to fabricate the llm and embedder blocks, so missing either one raises this ValueError.

Source

Thrown at src/agentscope/middleware/_longterm_memory/_mem0/_agentscope_adapter.py:355

        mem0_config:
            Optional pre-built ``MemoryConfig`` to use as the base.
            When given, only the LLM / embedder slots are overridden
            from ``chat_model`` / ``embedding_model`` — every other
            field (``vector_store``, ``history_db_path``, ``reranker``,
            ``custom_instructions``, ``version``) is preserved.

    Returns:
        A ``MemoryConfig`` ready to pass to ``AsyncMemory(config=...)``
        or ``Memory(config=...)``.
    """
    from mem0.configs.base import MemoryConfig

    _register_agentscope_provider()
    llm_cfg_cls, emb_cfg_cls = _agentscope_config_classes()

    if mem0_config is None:
        if chat_model is None or embedding_model is None:
            raise ValueError(
                "build_mem0_config requires `chat_model` and "
                "`embedding_model` when `mem0_config` is not given.",
            )
        return MemoryConfig(
            llm=llm_cfg_cls(
                provider=_AGENTSCOPE_PROVIDER,
                config={"model": chat_model},
            ),
            embedder=emb_cfg_cls(
                provider=_AGENTSCOPE_PROVIDER,
                config={"model": embedding_model},
            ),
        )

    # Use the user's config as base; partial-override .llm / .embedder
    # only for fields they actually passed. Pydantic v2 doesn't
    # re-validate on attribute assignment, so this sticks.
    if chat_model is not None:

View on GitHub (pinned to e90f1c7592)

Solutions

  1. Supply both chat_model and embedding_model when mem0_config is omitted
  2. Or pass a complete mem0_config dict containing llm and embedder sections
  3. Or use Mem0Middleware with a pre-built AsyncMemory client

Example fix

// before
cfg = build_mem0_config(chat_model=chat)
// after
cfg = build_mem0_config(chat_model=chat, embedding_model=emb)
Defensive patterns

Strategy: validation

Validate before calling

if mem0_config is None and (chat_model is None or embedding_model is None):
    raise ValueError('chat_model and embedding_model are both required without mem0_config')

Try / catch

try:
    cfg = build_mem0_config(chat_model=c, embedding_model=e)
except ValueError as e:
    raise ConfigurationError(str(e)) from e

Prevention

When it happens

Trigger: build_mem0_config(chat_model=m) without embedding_model, or vice versa; calling with both None and no mem0_config.

Common situations: Assuming mem0 will default the embedder from environment variables; partial migration from a mem0 dict config.

Related errors


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