microsoft/autogen · error · TypeError

Expected Memory, List[Memory], or None, got {type(memory)}

Error message

Expected Memory, List[Memory], or None, got {type(memory)}

What it means

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.

Source

Thrown at python/packages/autogen-agentchat/src/autogen_agentchat/agents/_assistant_agent.py:764

    ):
        super().__init__(name=name, description=description)
        self._metadata = metadata or {}
        self._model_client = model_client
        self._model_client_stream = model_client_stream
        self._output_content_type: type[BaseModel] | None = output_content_type
        self._output_content_type_format = output_content_type_format
        self._structured_message_factory: StructuredMessageFactory | None = None
        if output_content_type is not None:
            self._structured_message_factory = StructuredMessageFactory(
                input_model=output_content_type, format_string=output_content_type_format
            )

        self._memory = None
        if memory is not None:
            if isinstance(memory, list):
                self._memory = memory
            else:
                raise TypeError(f"Expected Memory, List[Memory], or None, got {type(memory)}")

        self._system_messages: List[SystemMessage] = []
        if system_message is None:
            self._system_messages = []
        else:
            self._system_messages = [SystemMessage(content=system_message)]
        self._tools: List[BaseTool[Any, Any]] = []
        if tools is not None:
            if model_client.model_info["function_calling"] is False:
                raise ValueError("The model does not support function calling.")
            for tool in tools:
                if isinstance(tool, BaseTool):
                    self._tools.append(tool)
                elif callable(tool):
                    if hasattr(tool, "__doc__") and tool.__doc__ is not None:
                        description = tool.__doc__
                    else:
                        description = ""

View on GitHub (pinned to 027ecf0a37)

Solutions

  1. Wrap single memory instances in a list: memory=[my_memory].
  2. Pass memory=None to use no memory.
  3. If passing a list, ensure every element is a Memory instance.

Example fix

# before
agent = AssistantAgent(name="a", model_client=client, memory=ListChatMemoryContext())

# after
agent = AssistantAgent(name="a", model_client=client, memory=[ListChatMemoryContext()])
Defensive patterns

Strategy: type-guard

Validate before calling

from autogen_core.memory import Memory
if memory is not None and not (isinstance(memory, list) and all(isinstance(m, Memory) for m in memory)):
    memory = [memory] if isinstance(memory, Memory) else None

Type guard

from typing import List, Union
from autogen_core.memory import Memory

def normalize_memory(m: Union[Memory, List[Memory], None]) -> Union[List[Memory], None]:
    if m is None or isinstance(m, list):
        return m
    if isinstance(m, Memory):
        return [m]
    raise TypeError(f"Expected Memory, List[Memory], or None, got {type(m)}")

Try / catch

try:
    agent = AssistantAgent(name="a", model_client=client, memory=normalize_memory(memory))
except TypeError as e:
    raise ValueError(f"bad memory config: {e}") from e

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of microsoft/autogen@027ecf0a37 (2026-08-15). Data as JSON: /api/errors/5b7cb24129eed5a1. Report an issue: GitHub.