{"record":{"id":"50367922c2d9b5ed","repo":"agentscope-ai/agentscope","slug":"agentscopellm-received-no-usable-messages-empty","errorCode":null,"errorMessage":"\"AgentScopeLLM received no usable messages (empty list or all roles unrecognized).\"","messagePattern":"\"AgentScopeLLM received no usable messages \\(empty list or all roles unrecognized\\)\\.\"","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"src/agentscope/middleware/_longterm_memory/_mem0/_agentscope_adapter.py","lineNumber":136,"sourceCode":"            )\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).\"\"\"\n        as_messages = _convert_messages_to_agentscope(messages)\n        if not as_messages:\n            raise ValueError(\n                \"AgentScopeLLM received no usable messages \"\n                \"(empty list or all roles unrecognized).\",\n            )\n\n        response = self._bridge.run(\n            _await_chat(self._agentscope_model, as_messages, tools),\n        )\n        return _parse_chat_response(response, has_tool=bool(tools))\n\n\nasync def _await_chat(\n    model: ChatModelBase,\n    messages: list[Msg],\n    tools: list[dict] | None,\n) -> \"ChatResponse\":\n    \"\"\"Call the AgentScope chat model, handling both streaming and\n    non-streaming returns.\"\"\"\n    result = await model(messages, tools=tools)","sourceCodeStart":118,"sourceCodeEnd":154,"githubUrl":"https://github.com/agentscope-ai/agentscope/blob/e90f1c7592896cc95f6e5ee506194f533378247d/src/agentscope/middleware/_longterm_memory/_mem0/_agentscope_adapter.py#L118-L154","documentation":"generate_response converts mem0 messages to AgentScope Msg objects by role; if the input list is empty or every message has an unrecognized role, nothing survives conversion and the adapter raises rather than calling the model with no input.","triggerScenarios":"Calling AgentScopeLLM.generate_response([]) or with messages whose roles fall outside the mapped set (e.g. 'tool'/'function' roles that the converter doesn't recognize).","commonSituations":"mem0 internals stripping messages; custom pipelines building message lists dynamically that end up empty; role-name mismatches after a mem0 version change.","solutions":["Ensure at least one message with a standard role ('system', 'user', 'assistant') is passed","Log the raw messages list before calling generate_response to spot empty/odd-role inputs","If calling from custom code, guard with a length check before invoking the LLM"],"exampleFix":"// before\nresp = llm.generate_response(messages)\n// after\nif not messages:\n    raise ValueError('messages must not be empty')\nresp = llm.generate_response(messages)","handlingStrategy":"validation","validationCode":"us = _convert_messages_to_agentscope(messages) if hasattr(m, '_convert') else messages\nif not messages or all(m.get('role') not in ('system','user','assistant','tool') for m in messages):\n    raise ValueError('no usable messages')","typeGuard":"def has_usable_messages(msgs: list[dict]) -> bool:\n    return any(isinstance(m, dict) and m.get('role') in {'system','user','assistant'} for m in msgs)","tryCatchPattern":"try:\n    resp = llm.generate_response(messages)\nexcept ValueError as e:\n    if 'no usable messages' in str(e):\n        messages = [{'role': 'user', 'content': fallback_prompt}]\n        resp = llm.generate_response(messages)\n    else:\n        raise","preventionTips":["Check message list length and roles before calling generate_response","Log messages right before the call in dynamic pipelines"],"tags":["agentscope","mem0","messages","validation"],"backgroundTag":"empty-request-payload","analyzedSha":"e90f1c7592896cc95f6e5ee506194f533378247d","analyzedAt":"2026-08-28T18:24:12.087Z","schemaVersion":2},"datasetVersion":"2026-08-28T21:17:43.275Z"}