{"record":{"id":"ec297a700a7fc37f","repo":"microsoft/semantic-kernel","slug":"the-task-must-be-a-chatmessagecontent-object","errorCode":null,"errorMessage":"The task must be a ChatMessageContent object.","messagePattern":"The task must be a ChatMessageContent object\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/semantic_kernel/agents/orchestration/magentic.py","lineNumber":820,"sourceCode":"            description=description,\n            input_transform=input_transform,\n            output_transform=output_transform,\n            agent_response_callback=agent_response_callback,\n            streaming_agent_response_callback=streaming_agent_response_callback,\n        )\n\n    @override\n    async def _start(\n        self,\n        task: DefaultTypeAlias,\n        runtime: CoreRuntime,\n        internal_topic_type: str,\n        cancellation_token: CancellationToken,\n    ) -> None:\n        \"\"\"Start the Magentic pattern.\"\"\"\n        if not isinstance(task, ChatMessageContent):\n            # Magentic One only supports ChatMessageContent as input.\n            raise ValueError(\"The task must be a ChatMessageContent object.\")\n\n        target_actor_id = await runtime.get(self._get_manager_actor_type(internal_topic_type))\n        await runtime.send_message(\n            MagenticStartMessage(body=task),\n            target_actor_id,\n            cancellation_token=cancellation_token,\n        )\n\n    @override\n    async def _prepare(\n        self,\n        runtime: CoreRuntime,\n        internal_topic_type: str,\n        exception_callback: Callable[[BaseException], None],\n        result_callback: Callable[[DefaultTypeAlias], Awaitable[None]],\n    ) -> None:\n        \"\"\"Register the actors and orchestrations with the runtime and add the required subscriptions.\"\"\"\n        await self._register_members(runtime, internal_topic_type, exception_callback)","sourceCodeStart":802,"sourceCodeEnd":838,"githubUrl":"https://github.com/microsoft/semantic-kernel/blob/c028a0c7dc4f0814cdcbaba9d998f187a41197bf/python/semantic_kernel/agents/orchestration/magentic.py#L802-L838","documentation":"MagenticOne only supports a single ChatMessageContent as the task because the start message carries that body into the MagenticContext.task field. Passing a plain str or a list of messages would break the context contract, so _start refuses non-ChatMessageContent input.","triggerScenarios":"Calling `await orchestration.invoke(task, runtime)` where task is a str, a list[ChatMessageContent], or any non-ChatMessageContent value. (Other orchestrations accept str/list, but Magentic requires exactly one ChatMessageContent.)","commonSituations":"Porting code from GroupChatOrchestration or SequentialOrchestration which accept str or list inputs. Passing a raw string prompt expecting it to be wrapped automatically.","solutions":["Wrap your task in a ChatMessageContent before invoking: ChatMessageContent(role=AuthorRole.USER, content=...).","If you have a str, convert it: task = ChatMessageContent(role=AuthorRole.USER, content=my_str).","Use the input_transform only for transforming already-valid input, not to bypass the type requirement."],"exampleFix":"// before\nresult = await orch.invoke(\"Summarize the quarterly report\", runtime)  # raises\n\n// after\nfrom semantic_kernel.contents.chat_message_content import ChatMessageContent\nfrom semantic_kernel.contents.utils.author_role import AuthorRole\n\ntask = ChatMessageContent(role=AuthorRole.USER, content=\"Summarize the quarterly report\")\nresult = await orch.invoke(task, runtime)","handlingStrategy":"type-guard","validationCode":"# Coerce input to ChatMessageContent before invoking Magentic\ntask_msg = task if isinstance(task, ChatMessageContent) else ChatMessageContent(\n    role=AuthorRole.USER, content=str(task)\n)\nresult = await orch.invoke(task_msg, runtime)","typeGuard":"from semantic_kernel.contents.chat_message_content import ChatMessageContent\n\ndef is_magentic_task(task) -> bool:\n    return isinstance(task, ChatMessageContent)","tryCatchPattern":"try:\n    result = await orch.invoke(task, runtime)\nexcept ValueError as e:\n    if \"must be a ChatMessageContent\" in str(e):\n        result = await orch.invoke(\n            ChatMessageContent(role=AuthorRole.USER, content=str(task)), runtime\n        )\n    else:\n        raise","preventionTips":["For Magentic, always build a ChatMessageContent(role=AuthorRole.USER, content=...).","Don't assume Magentic accepts str or list like other orchestrations.","Wrap the invoke call in a helper that coerces the input type."],"tags":["semantic-kernel","magentic","input-type","invocation","validation"],"backgroundTag":null,"analyzedSha":"c028a0c7dc4f0814cdcbaba9d998f187a41197bf","analyzedAt":"2026-08-13T13:48:05.040Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}