{"record":{"id":"5b7cb24129eed5a1","repo":"microsoft/autogen","slug":"expected-memory-list-memory-or-none-got-type","errorCode":null,"errorMessage":"Expected Memory, List[Memory], or None, got {type(memory)}","messagePattern":"Expected Memory, List\\[Memory\\], or None, got (.+?)","errorType":"validation","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"python/packages/autogen-agentchat/src/autogen_agentchat/agents/_assistant_agent.py","lineNumber":764,"sourceCode":"    ):\n        super().__init__(name=name, description=description)\n        self._metadata = metadata or {}\n        self._model_client = model_client\n        self._model_client_stream = model_client_stream\n        self._output_content_type: type[BaseModel] | None = output_content_type\n        self._output_content_type_format = output_content_type_format\n        self._structured_message_factory: StructuredMessageFactory | None = None\n        if output_content_type is not None:\n            self._structured_message_factory = StructuredMessageFactory(\n                input_model=output_content_type, format_string=output_content_type_format\n            )\n\n        self._memory = None\n        if memory is not None:\n            if isinstance(memory, list):\n                self._memory = memory\n            else:\n                raise TypeError(f\"Expected Memory, List[Memory], or None, got {type(memory)}\")\n\n        self._system_messages: List[SystemMessage] = []\n        if system_message is None:\n            self._system_messages = []\n        else:\n            self._system_messages = [SystemMessage(content=system_message)]\n        self._tools: List[BaseTool[Any, Any]] = []\n        if tools is not None:\n            if model_client.model_info[\"function_calling\"] is False:\n                raise ValueError(\"The model does not support function calling.\")\n            for tool in tools:\n                if isinstance(tool, BaseTool):\n                    self._tools.append(tool)\n                elif callable(tool):\n                    if hasattr(tool, \"__doc__\") and tool.__doc__ is not None:\n                        description = tool.__doc__\n                    else:\n                        description = \"\"","sourceCodeStart":746,"sourceCodeEnd":782,"githubUrl":"https://github.com/microsoft/autogen/blob/027ecf0a379bcc1d09956d46d12d44a3ad9cee14/python/packages/autogen-agentchat/src/autogen_agentchat/agents/_assistant_agent.py#L746-L782","documentation":"AssistantAgent's constructor validates the memory parameter: None and list are accepted (the code path shown assigns self._memory only for lists), and anything else falls through to a TypeError listing the offending type. Notably the check as written rejects a bare Memory instance even though the message claims it is allowed — only None and list values pass.","triggerScenarios":"Passing memory as a single Memory object (e.g. ListChatMemoryContext()) instead of a list, or passing an unrelated type (string, dict) to the AssistantAgent constructor.","commonSituations":"Following older API examples where memory=ListChatMemoryContext() was valid, upgrading autogen-agentchat versions where the accepted shape changed to a list, or wrapping memory in the wrong container.","solutions":["Wrap single memory instances in a list: memory=[my_memory].","Pass memory=None to use no memory.","If passing a list, ensure every element is a Memory instance."],"exampleFix":"# before\nagent = AssistantAgent(name=\"a\", model_client=client, memory=ListChatMemoryContext())\n\n# after\nagent = AssistantAgent(name=\"a\", model_client=client, memory=[ListChatMemoryContext()])","handlingStrategy":"type-guard","validationCode":"from autogen_core.memory import Memory\nif memory is not None and not (isinstance(memory, list) and all(isinstance(m, Memory) for m in memory)):\n    memory = [memory] if isinstance(memory, Memory) else None","typeGuard":"from typing import List, Union\nfrom autogen_core.memory import Memory\n\ndef normalize_memory(m: Union[Memory, List[Memory], None]) -> Union[List[Memory], None]:\n    if m is None or isinstance(m, list):\n        return m\n    if isinstance(m, Memory):\n        return [m]\n    raise TypeError(f\"Expected Memory, List[Memory], or None, got {type(m)}\")","tryCatchPattern":"try:\n    agent = AssistantAgent(name=\"a\", model_client=client, memory=normalize_memory(memory))\nexcept TypeError as e:\n    raise ValueError(f\"bad memory config: {e}\") from e","preventionTips":["Always pass memory as a list in new code: memory=[...].","Centralize agent construction in a factory that normalizes parameters once."],"tags":["python","constructor","type-validation","memory","autogen"],"backgroundTag":null,"analyzedSha":"027ecf0a379bcc1d09956d46d12d44a3ad9cee14","analyzedAt":"2026-08-15T03:38:00.719Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}