agentscope-ai/agentscope · error · ValueError
"AgentScopeLLM requires `model` in the config to be an Agent
Error message
"AgentScopeLLM requires `model` in the config to be an AgentScope ChatModelBase instance."
What it means
AgentScopeLLM is a mem0 LLM adapter that requires an AgentScope ChatModelBase instance to be supplied via config['model']. The constructor checks that model is set before validating its type; None raises this ValueError. Without it there is no underlying chat model for mem0 to route calls through.
Source
Thrown at src/agentscope/middleware/_longterm_memory/_mem0/_agentscope_adapter.py:110
class AgentScopeLLM(LLMBase):
"""mem0 ``LLMBase`` backed by an AgentScope ``ChatModelBase``.
Pass your AgentScope model into ``config["model"]``; mem0's memory
extraction calls then route through it. Both streaming and
non-streaming AgentScope models are accepted (streaming responses are
drained and the final chunk is used).
"""
def __init__(
self,
config: BaseLlmConfig | dict | None = None,
) -> None:
"""Initialize the AgentScope LLM for mem0."""
super().__init__(config)
if self.config.model is None:
raise ValueError(
"AgentScopeLLM requires `model` in the config to be an "
"AgentScope ChatModelBase instance.",
)
if not isinstance(self.config.model, ChatModelBase):
raise TypeError(
f"AgentScopeLLM `model` must be a ChatModelBase, got "
f"{type(self.config.model).__name__}.",
)
self._agentscope_model: ChatModelBase = self.config.model
self._bridge = _AsyncBridge()
# ----- LLMBase interface -----
# pylint: disable=unused-argument
def generate_response(
self,
messages: list[dict[str, str]],
response_format: Any | None = None, # mem0 contract — unused
tools: list[dict] | None = None,View on GitHub (pinned to e90f1c7592)
Solutions
- Pass an AgentScope ChatModelBase instance (e.g. OpenAIChat(model='gpt-4o-mini')) in the config's model field
- If using Mem0Middleware, pass chat_model=... instead of hand-building the LLM config
- Use build_mem0_config(chat_model=..., embedding_model=...) which constructs the config correctly
Example fix
// before llm = AgentScopeLLM(BaseLlmConfig(provider='agentscope')) // after from agentscope.model import OpenAIChat llm = AgentScopeLLM(BaseLlmConfig(model=OpenAIChat(model='gpt-4o-mini')))
Defensive patterns
Strategy: validation
Validate before calling
from agentscope.model import ChatModelBase
cfg = my_config
if getattr(cfg, 'model', None) is None:
raise ValueError('config.model must be a ChatModelBase instance') Type guard
from agentscope.model import ChatModelBase
def has_chat_model(cfg) -> bool:
return isinstance(getattr(cfg, 'model', None), ChatModelBase) Try / catch
try:
llm = AgentScopeLLM(cfg)
except ValueError as e:
if 'model' in str(e):
cfg['model'] = OpenAIChat(model='gpt-4o-mini')
llm = AgentScopeLLM(cfg)
else:
raise Prevention
- Always construct adapters via build_mem0_config rather than by hand
- Assert config.model is an AgentScope model object before constructing AgentScopeLLM
When it happens
Trigger: Constructing AgentScopeLLM(BaseLlmConfig(...)) or AgentScopeLLM({'model': None, ...}) without setting the model field; e.g. copying a mem0 OpenAI config dict and omitting/replacing 'model' with None.
Common situations: Porting an existing mem0 LLM config to agentscope; passing provider/api_key-style dicts where a model string was expected instead of a ChatModelBase object; building Mem0Middleware config manually.
Related errors
- f"AgentScopeLLM `model` must be a ChatModelBase, got {type(s
- "AgentScopeEmbedding requires `model` in the config to be an
- "build_mem0_config requires `chat_model` and `embedding_mode
- The injection template must contain the '{runtime_state}' pl
- "AgentScopeLLM received no usable messages (empty list or al
AI-assisted analysis of agentscope-ai/agentscope@e90f1c7592 (2026-08-28).
Data as JSON: /api/errors/90afa65d3dea8e1c.
Report an issue: GitHub.