agentscope-ai/agentscope · error · ValueError

"AgentScopeEmbedding requires `model` in the config to be an

Error message

"AgentScopeEmbedding requires `model` in the config to be an AgentScope EmbeddingModelBase instance."

What it means

AgentScopeEmbedding is mem0's embedding adapter and requires config.model to be an AgentScope EmbeddingModelBase instance. A None model raises this ValueError at construction time since embedding calls would have nothing to dispatch to.

Source

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

# ----------------------------------------------------------------------


class AgentScopeEmbedding(EmbeddingBase):
    """mem0 ``EmbeddingBase`` backed by an AgentScope
    ``EmbeddingModelBase``."""

    def __init__(
        self,
        config: BaseEmbedderConfig | dict | None = None,
    ) -> None:
        # mem0's EmbeddingBase (unlike LLMBase) does NOT auto-convert
        # dict configs — it stores whatever is passed. Normalize here
        # so callers can use the same dict-config style as the LLM.
        if isinstance(config, dict):
            config = BaseEmbedderConfig(**config)
        super().__init__(config)
        if self.config.model is None:
            raise ValueError(
                "AgentScopeEmbedding requires `model` in the config "
                "to be an AgentScope EmbeddingModelBase instance.",
            )
        if not isinstance(self.config.model, EmbeddingModelBase):
            raise TypeError(
                f"AgentScopeEmbedding `model` must be an "
                f"EmbeddingModelBase, got "
                f"{type(self.config.model).__name__}.",
            )
        self._agentscope_model: EmbeddingModelBase = self.config.model
        self._bridge = _AsyncBridge()

    # ----- EmbeddingBase interface -----
    # pylint: disable=unused-argument
    def embed(
        self,
        text: str | list[str],
        memory_action: str | None = None,  # mem0 contract — unused

View on GitHub (pinned to e90f1c7592)

Solutions

  1. Pass an EmbeddingModelBase instance (e.g. OpenAIEmbedding(model='text-embedding-3-small')) in config.model
  2. Use Mem0Middleware(embedding_model=..., chat_model=...) or build_mem0_config to assemble both adapters

Example fix

// before
emb = AgentScopeEmbedding(BaseEmbedderConfig(provider='agentscope'))
// after
from agentscope.model import OpenAIEmbedding
emb = AgentScopeEmbedding(BaseEmbedderConfig(model=OpenAIEmbedding(model='text-embedding-3-small')))
Defensive patterns

Strategy: validation

Validate before calling

from agentscope.model import EmbeddingModelBase
if getattr(config, 'model', None) is None:
    raise ValueError('config.model must be an EmbeddingModelBase instance')

Type guard

from agentscope.model import EmbeddingModelBase
def has_embedding_model(cfg) -> bool:
    return isinstance(getattr(cfg, 'model', None), EmbeddingModelBase)

Try / catch

try:
    emb = AgentScopeEmbedding(cfg)
except ValueError as e:
    if 'model' in str(e):
        cfg['model'] = OpenAIEmbedding(model='text-embedding-3-small')
        emb = AgentScopeEmbedding(cfg)
    else:
        raise

Prevention

When it happens

Trigger: AgentScopeEmbedding(BaseEmbedderConfig()) or a dict config without a 'model' key; copying a mem0 embedder config that uses provider/model-name strings.

Common situations: Building MemoryConfig embedder blocks by hand; forgetting the embedding model when only the LLM was configured.

Related errors


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