{"record":{"id":"90afa65d3dea8e1c","repo":"agentscope-ai/agentscope","slug":"agentscopellm-requires-model-in-the-config-to-b","errorCode":null,"errorMessage":"\"AgentScopeLLM requires `model` in the config to be an AgentScope ChatModelBase instance.\"","messagePattern":"\"AgentScopeLLM requires `model` in the config to be an AgentScope ChatModelBase instance\\.\"","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"src/agentscope/middleware/_longterm_memory/_mem0/_agentscope_adapter.py","lineNumber":110,"sourceCode":"\n\nclass AgentScopeLLM(LLMBase):\n    \"\"\"mem0 ``LLMBase`` backed by an AgentScope ``ChatModelBase``.\n\n    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,","sourceCodeStart":92,"sourceCodeEnd":128,"githubUrl":"https://github.com/agentscope-ai/agentscope/blob/e90f1c7592896cc95f6e5ee506194f533378247d/src/agentscope/middleware/_longterm_memory/_mem0/_agentscope_adapter.py#L92-L128","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"// before\nllm = AgentScopeLLM(BaseLlmConfig(provider='agentscope'))\n// after\nfrom agentscope.model import OpenAIChat\nllm = AgentScopeLLM(BaseLlmConfig(model=OpenAIChat(model='gpt-4o-mini')))","handlingStrategy":"validation","validationCode":"from agentscope.model import ChatModelBase\ncfg = my_config\nif getattr(cfg, 'model', None) is None:\n    raise ValueError('config.model must be a ChatModelBase instance')","typeGuard":"from agentscope.model import ChatModelBase\ndef has_chat_model(cfg) -> bool:\n    return isinstance(getattr(cfg, 'model', None), ChatModelBase)","tryCatchPattern":"try:\n    llm = AgentScopeLLM(cfg)\nexcept ValueError as e:\n    if 'model' in str(e):\n        cfg['model'] = OpenAIChat(model='gpt-4o-mini')\n        llm = AgentScopeLLM(cfg)\n    else:\n        raise","preventionTips":["Always construct adapters via build_mem0_config rather than by hand","Assert config.model is an AgentScope model object before constructing AgentScopeLLM"],"tags":["agentscope","mem0","config","constructor"],"backgroundTag":"missing-required-config-field","analyzedSha":"e90f1c7592896cc95f6e5ee506194f533378247d","analyzedAt":"2026-08-28T18:24:12.087Z","schemaVersion":2},"datasetVersion":"2026-08-28T21:17:43.275Z"}