{"record":{"id":"3569602041cb4b1f","repo":"microsoft/autogen","slug":"task-list-cannot-be-empty","errorCode":null,"errorMessage":"Task list cannot be empty.","messagePattern":"Task list cannot be empty\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/packages/autogen-agentchat/src/autogen_agentchat/agents/_base_chat_agent.py","lineNumber":140,"sourceCode":"        ):\n            if cancellation_token is None:\n                cancellation_token = CancellationToken()\n            input_messages: List[BaseChatMessage] = []\n            output_messages: List[BaseAgentEvent | BaseChatMessage] = []\n            if task is None:\n                pass\n            elif isinstance(task, str):\n                text_msg = TextMessage(content=task, source=\"user\")\n                input_messages.append(text_msg)\n                if output_task_messages:\n                    output_messages.append(text_msg)\n            elif isinstance(task, BaseChatMessage):\n                input_messages.append(task)\n                if output_task_messages:\n                    output_messages.append(task)\n            else:\n                if not task:\n                    raise ValueError(\"Task list cannot be empty.\")\n                # Task is a sequence of messages.\n                for msg in task:\n                    if isinstance(msg, BaseChatMessage):\n                        input_messages.append(msg)\n                        if output_task_messages:\n                            output_messages.append(msg)\n                    else:\n                        raise ValueError(f\"Invalid message type in sequence: {type(msg)}\")\n            response = await self.on_messages(input_messages, cancellation_token)\n            if response.inner_messages is not None:\n                output_messages += response.inner_messages\n            output_messages.append(response.chat_message)\n            return TaskResult(messages=output_messages)\n\n    async def run_stream(\n        self,\n        *,\n        task: str | BaseChatMessage | Sequence[BaseChatMessage] | None = None,","sourceCodeStart":122,"sourceCodeEnd":158,"githubUrl":"https://github.com/microsoft/autogen/blob/027ecf0a379bcc1d09956d46d12d44a3ad9cee14/python/packages/autogen-agentchat/src/autogen_agentchat/agents/_base_chat_agent.py#L122-L158","documentation":"In BaseChatAgent.run(), when the task argument is a sequence it must be non-empty. Passing an empty list/tuple means the agent has no input messages to send to on_messages.","triggerScenarios":"Calling agent.run(task=[]) or agent.run(task=some_list) where some_list was emptied by upstream filtering logic; passing an empty generator-backed list.","commonSituations":"Dynamic pipelines that build message lists from filtered data (e.g. all messages filtered out) and pass the empty remainder as the task.","solutions":["Check the sequence is non-empty before calling run(); pass task=None to continue from the existing model context instead.","Fix the upstream filtering logic that produced an empty list.","Pass a str or a single BaseChatMessage instead of a list when there is only one item."],"exampleFix":"// before\ntask = [m for m in messages if keep(m)]  # may be []\nresult = await agent.run(task=task)\n\n// after\ntask = [m for m in messages if keep(m)]\nresult = await agent.run(task=task if task else None)","handlingStrategy":"validation","validationCode":"task_msgs = [m for m in candidates if keep(m)]\nif not task_msgs:\n    task_msgs = None  # or skip the run\nresult = await agent.run(task=task_msgs)","typeGuard":"from collections.abc import Sequence\nfrom autogen_agentchat.messages import BaseChatMessage\n\ndef is_valid_task(task) -> bool:\n    if task is None or isinstance(task, (str, BaseChatMessage)):\n        return True\n    return isinstance(task, Sequence) and len(task) > 0 and all(isinstance(m, BaseChatMessage) for m in task)","tryCatchPattern":"try:\n    result = await agent.run(task=task)\nexcept ValueError as e:\n    if \"cannot be empty\" in str(e):\n        result = await agent.run(task=None)  # continue from context\n    else:\n        raise","preventionTips":["Guard dynamic/filtered task lists with an emptiness check before run().","Pass task=None to continue an ongoing conversation rather than an empty list."],"tags":["validation","task-input","empty-list"],"backgroundTag":null,"analyzedSha":"027ecf0a379bcc1d09956d46d12d44a3ad9cee14","analyzedAt":"2026-08-15T03:38:00.719Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}