{"record":{"id":"c2d0ef1c8f9104cd","repo":"agentscope-ai/agentscope","slug":"f-agentscopellm-model-must-be-a-chatmodelbase-g","errorCode":null,"errorMessage":"f\"AgentScopeLLM `model` must be a ChatModelBase, got {type(self.config.model).__name__}.\"","messagePattern":"f\"AgentScopeLLM `model` must be a ChatModelBase, got (.+?)\\.\"","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"src/agentscope/middleware/_longterm_memory/_mem0/_agentscope_adapter.py","lineNumber":115,"sourceCode":"    Pass your AgentScope model into ``config[\"model\"]``; mem0's memory\n    extraction calls then route through it. Both streaming and\n    non-streaming AgentScope models are accepted (streaming responses are\n    drained and the final chunk is used).\n    \"\"\"\n\n    def __init__(\n        self,\n        config: BaseLlmConfig | dict | None = None,\n    ) -> None:\n        \"\"\"Initialize the AgentScope LLM for mem0.\"\"\"\n        super().__init__(config)\n        if self.config.model is None:\n            raise ValueError(\n                \"AgentScopeLLM requires `model` in the config to be an \"\n                \"AgentScope ChatModelBase instance.\",\n            )\n        if not isinstance(self.config.model, ChatModelBase):\n            raise TypeError(\n                f\"AgentScopeLLM `model` must be a ChatModelBase, got \"\n                f\"{type(self.config.model).__name__}.\",\n            )\n        self._agentscope_model: ChatModelBase = self.config.model\n        self._bridge = _AsyncBridge()\n\n    # ----- LLMBase interface -----\n    # pylint: disable=unused-argument\n    def generate_response(\n        self,\n        messages: list[dict[str, str]],\n        response_format: Any | None = None,  # mem0 contract — unused\n        tools: list[dict] | None = None,\n        tool_choice: str = \"auto\",  # mem0 contract — unused\n    ) -> str | dict:\n        \"\"\"mem0 ``LLMBase`` entry — runs the AgentScope chat model\n        synchronously and returns str (or dict with tool_calls when\n        ``tools`` is given).\"\"\"","sourceCodeStart":97,"sourceCodeEnd":133,"githubUrl":"https://github.com/agentscope-ai/agentscope/blob/e90f1c7592896cc95f6e5ee506194f533378247d/src/agentscope/middleware/_longterm_memory/_mem0/_agentscope_adapter.py#L97-L133","documentation":"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.","triggerScenarios":"AgentScopeLLM({'model': 'gpt-4o'}) (string), or config.model set to an OpenAI SDK client, a mem0 OpenAILLM, or any non-AgentScope chat wrapper.","commonSituations":"Assuming mem0's string model naming convention applies; passing an SDK client object instead of an AgentScope model wrapper; mixing adapters between frameworks.","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="],"exampleFix":"// before\nAgentScopeLLM({'model': 'gpt-4o', 'provider': 'agentscope'})\n// after\nfrom agentscope.model import OpenAIChat\nAgentScopeLLM({'model': OpenAIChat(model='gpt-4o')})","handlingStrategy":"type-guard","validationCode":"from agentscope.model import ChatModelBase\nif not isinstance(config.get('model'), ChatModelBase):\n    raise TypeError('model must be ChatModelBase, e.g. OpenAIChat(...)')","typeGuard":"from agentscope.model import ChatModelBase\ndef is_chat_model_base(m) -> bool:\n    return isinstance(m, ChatModelBase)","tryCatchPattern":"try:\n    llm = AgentScopeLLM(cfg)\nexcept TypeError as e:\n    raise SystemExit(f'Bad model config: {e}') from e","preventionTips":["Never pass model names as strings to agentscope adapters","Import model classes from agentscope.model, not the provider SDK"],"tags":["agentscope","mem0","type-error","config"],"backgroundTag":"wrong-type-config-value","analyzedSha":"e90f1c7592896cc95f6e5ee506194f533378247d","analyzedAt":"2026-08-28T18:24:12.087Z","schemaVersion":2},"datasetVersion":"2026-08-28T21:17:43.275Z"}