microsoft/autogen · error · ValueError
All messages in task list must be valid BaseChatMessage type
Error message
All messages in task list must be valid BaseChatMessage types
What it means
Every element of a list task must be a BaseChatMessage instance (TextMessage, MultiModalMessage, etc.). The constructor loop isinstance-checks each element; anything else — including BaseAgentEvent subclasses or plain dicts — is rejected.
Source
Thrown at python/packages/autogen-agentchat/src/autogen_agentchat/teams/_group_chat/_base_group_chat.py:469
asyncio.run(main())
"""
# Create the messages list if the task is a string or a chat message.
messages: List[BaseChatMessage] | None = None
if task is None:
pass
elif isinstance(task, str):
messages = [TextMessage(content=task, source="user")]
elif isinstance(task, BaseChatMessage):
messages = [task]
elif isinstance(task, list):
if not task:
raise ValueError("Task list cannot be empty.")
messages = []
for msg in task:
if not isinstance(msg, BaseChatMessage):
raise ValueError("All messages in task list must be valid BaseChatMessage types")
messages.append(msg)
else:
raise ValueError("Task must be a string, a BaseChatMessage, or a list of BaseChatMessage.")
# Check if the messages types are registered with the message factory.
if messages is not None:
for msg in messages:
if not self._message_factory.is_registered(msg.__class__):
raise ValueError(
f"Message type {msg.__class__} is not registered with the message factory. "
"Please register it with the message factory by adding it to the "
"custom_message_types list when creating the team."
)
if self._is_running:
raise ValueError("The team is already running, it cannot run again until it is stopped.")
self._is_running = True
if self._embedded_runtime:View on GitHub (pinned to 027ecf0a37)
Solutions
- Wrap plain strings: task=[TextMessage(content="Start", source="user")].
- Convert dicts with the message factory: factory.create(d) before passing.
- Remove non-message items or convert them to a proper BaseChatMessage subclass.
Example fix
# before
await team.run(task=["plan the trip", {"content": "book flight"}])
# after
from autogen_agentchat.messages import TextMessage
await team.run(task=[TextMessage(content="plan the trip", source="user"), TextMessage(content="book flight", source="user")]) Defensive patterns
Strategy: type-guard
Validate before calling
from autogen_agentchat.messages import BaseChatMessage
if not all(isinstance(m, BaseChatMessage) for m in task):
raise TypeError("task list must contain only BaseChatMessage instances") Type guard
from autogen_agentchat.messages import BaseChatMessage
from typing import Any
def is_message_list(task: Any) -> bool:
return isinstance(task, list) and all(isinstance(m, BaseChatMessage) for m in task) Prevention
- Convert raw strings/dicts to TextMessage / factory.create() before building the task list.
- Do not mix agent events (BaseAgentEvent) into task lists.
- Type-annotate task variables as list[BaseChatMessage] to catch mistakes statically.
When it happens
Trigger: Calling team.run_stream(task=["just a string"]) or mixing messages with events/dicts in the list: task=[TextMessage(...), {'content': 'x'}].
Common situations: Feeding raw LLM output or JSON-deserialized dicts back as a task; accidentally including agent events (e.g. ToolCallRequestEvent) which are events, not chat messages.
Related errors
- Task must be a string, a BaseChatMessage, or a list of BaseC
- Expected Memory, List[Memory], or None, got {type(memory)}
- Unsupported tool type: {type(tool)}
- Unsupported handoff type: {type(handoff)}
- Message type must be a string, got {type(message_type)}
AI-assisted analysis of microsoft/autogen@027ecf0a37 (2026-08-15).
Data as JSON: /api/errors/50a120b74a25efb5.
Report an issue: GitHub.