{"record":{"id":"745d2c20ae2b46da","repo":"agentscope-ai/agentscope","slug":"f-unknown-mode-mode-r-expected-one-of-static-c","errorCode":null,"errorMessage":"f\"Unknown mode {mode!r}; expected one of 'static_control', 'agent_control', 'both'.\"","messagePattern":"f\"Unknown mode (.+?); expected one of 'static_control', 'agent_control', 'both'\\.\"","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"src/agentscope/middleware/_longterm_memory/_mem0/_middleware.py","lineNumber":258,"sourceCode":"                When ``True`` (default) the post-turn ``add`` call is\n                awaited inline. When ``False`` it's fire-and-forget —\n                faster response but exceptions only surface in logs.\n            memory_section_header, memory_section_intro:\n                Strings used when injecting retrieved memories into\n                the model's messages list (``static_control`` /\n                ``both`` modes).\n            tool_instructions:\n                Markdown block appended to the agent's system prompt\n                in ``agent_control`` / ``both`` modes, advertising the\n                ``search_memory`` / ``add_memory`` tools to the LLM.\n        \"\"\"\n        is_empty_user_id = isinstance(user_id, str) and not user_id.strip()\n        if user_id is None or is_empty_user_id:\n            raise ValueError(\n                \"Mem0Middleware requires a non-empty `user_id`.\",\n            )\n        if mode not in (\"static_control\", \"agent_control\", \"both\"):\n            raise ValueError(\n                f\"Unknown mode {mode!r}; expected one of \"\n                f\"'static_control', 'agent_control', 'both'.\",\n            )\n\n        client = self._resolve_client(\n            client=client,\n            chat_model=chat_model,\n            embedding_model=embedding_model,\n            mem0_config=mem0_config,\n        )\n        self._client = client\n\n        self._user_id = user_id\n        self._agent_id = agent_id\n        self._mode = mode\n        self._top_k = top_k\n        self._threshold = threshold\n        self._scope_search_by_agent = scope_search_by_agent","sourceCodeStart":240,"sourceCodeEnd":276,"githubUrl":"https://github.com/agentscope-ai/agentscope/blob/e90f1c7592896cc95f6e5ee506194f533378247d/src/agentscope/middleware/_longterm_memory/_mem0/_middleware.py#L240-L276","documentation":"Mem0Middleware supports exactly three memory-injection modes ('static_control', 'agent_control', 'both'); any other string is rejected at construction with the offending value echoed.","triggerScenarios":"Mem0Middleware(mode='auto'), mode='static', or a typo like 'agent-controll'.","commonSituations":"Assuming mode names from other middleware; renaming during version upgrades; IDE autocomplete typos.","solutions":["Use one of 'static_control', 'agent_control', 'both'","Check the installed version's signature if the mode list changed","Consider 'both' when unsure — it enables both injection styles"],"exampleFix":"// before\nMem0Middleware(user_id='u1', mode='auto')\n// after\nMem0Middleware(user_id='u1', mode='both')","handlingStrategy":"validation","validationCode":"VALID_MODES = ('static_control', 'agent_control', 'both')\nif mode not in VALID_MODES:\n    raise ValueError(f'mode must be one of {VALID_MODES}')","typeGuard":"from typing import Literal\nMode = Literal['static_control', 'agent_control', 'both']\ndef is_valid_mode(m: str) -> bool:\n    return m in ('static_control', 'agent_control', 'both')","tryCatchPattern":"try:\n    mw = Mem0Middleware(user_id='u1', mode=mode)\nexcept ValueError as e:\n    if 'Unknown mode' in str(e):\n        mw = Mem0Middleware(user_id='u1', mode='both')\n    else:\n        raise","preventionTips":["Type-annotate mode with a Literal to get static checking","Check the middleware's docstring for the mode list on upgrade"],"tags":["mem0","mode","enum-validation"],"backgroundTag":"invalid-enum-value","analyzedSha":"e90f1c7592896cc95f6e5ee506194f533378247d","analyzedAt":"2026-08-28T18:24:12.087Z","schemaVersion":2},"datasetVersion":"2026-08-28T21:17:43.275Z"}