agentscope-ai/agentscope · error · TypeError
f"AgentScopeLLM `model` must be a ChatModelBase, got {type(s
Error message
f"AgentScopeLLM `model` must be a ChatModelBase, got {type(self.config.model).__name__}." What it means
AgentScopeLLM validates that config.model is an instance of AgentScope's ChatModelBase. Passing a string name, a LangChain/OpenAI client, or any other object raises this TypeError naming the offending type.
Source
Thrown at src/agentscope/middleware/_longterm_memory/_mem0/_agentscope_adapter.py:115
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,
tool_choice: str = "auto", # mem0 contract — unused
) -> str | dict:
"""mem0 ``LLMBase`` entry — runs the AgentScope chat model
synchronously and returns str (or dict with tool_calls when
``tools`` is given)."""View on GitHub (pinned to e90f1c7592)
Solutions
- Wrap the provider in an AgentScope model class (OpenAIChat, DashScopeChat, etc.) and pass that instance
- Check the object came from agentscope.model, not the raw provider SDK
- Let build_mem0_config / Mem0Middleware construct the adapter from chat_model=
Example fix
// before
AgentScopeLLM({'model': 'gpt-4o', 'provider': 'agentscope'})
// after
from agentscope.model import OpenAIChat
AgentScopeLLM({'model': OpenAIChat(model='gpt-4o')}) Defensive patterns
Strategy: type-guard
Validate before calling
from agentscope.model import ChatModelBase
if not isinstance(config.get('model'), ChatModelBase):
raise TypeError('model must be ChatModelBase, e.g. OpenAIChat(...)') Type guard
from agentscope.model import ChatModelBase
def is_chat_model_base(m) -> bool:
return isinstance(m, ChatModelBase) Try / catch
try:
llm = AgentScopeLLM(cfg)
except TypeError as e:
raise SystemExit(f'Bad model config: {e}') from e Prevention
- Never pass model names as strings to agentscope adapters
- Import model classes from agentscope.model, not the provider SDK
When it happens
Trigger: AgentScopeLLM({'model': 'gpt-4o'}) (string), or config.model set to an OpenAI SDK client, a mem0 OpenAILLM, or any non-AgentScope chat wrapper.
Common situations: Assuming mem0's string model naming convention applies; passing an SDK client object instead of an AgentScope model wrapper; mixing adapters between frameworks.
Related errors
- "AgentScopeLLM requires `model` in the config to be an Agent
- "AgentScopeEmbedding requires `model` in the config to be an
- f"AgentScopeEmbedding `model` must be an EmbeddingModelBase,
- "build_mem0_config requires `chat_model` and `embedding_mode
- The injection template must contain the '{runtime_state}' pl
AI-assisted analysis of agentscope-ai/agentscope@e90f1c7592 (2026-08-28).
Data as JSON: /api/errors/c2d0ef1c8f9104cd.
Report an issue: GitHub.