microsoft/semantic-kernel · error · ValueError
The task must be a ChatMessageContent object.
Error message
The task must be a ChatMessageContent object.
What it means
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.
Source
Thrown at python/semantic_kernel/agents/orchestration/magentic.py:820
description=description,
input_transform=input_transform,
output_transform=output_transform,
agent_response_callback=agent_response_callback,
streaming_agent_response_callback=streaming_agent_response_callback,
)
@override
async def _start(
self,
task: DefaultTypeAlias,
runtime: CoreRuntime,
internal_topic_type: str,
cancellation_token: CancellationToken,
) -> None:
"""Start the Magentic pattern."""
if not isinstance(task, ChatMessageContent):
# Magentic One only supports ChatMessageContent as input.
raise ValueError("The task must be a ChatMessageContent object.")
target_actor_id = await runtime.get(self._get_manager_actor_type(internal_topic_type))
await runtime.send_message(
MagenticStartMessage(body=task),
target_actor_id,
cancellation_token=cancellation_token,
)
@override
async def _prepare(
self,
runtime: CoreRuntime,
internal_topic_type: str,
exception_callback: Callable[[BaseException], None],
result_callback: Callable[[DefaultTypeAlias], Awaitable[None]],
) -> None:
"""Register the actors and orchestrations with the runtime and add the required subscriptions."""
await self._register_members(runtime, internal_topic_type, exception_callback)View on GitHub (pinned to c028a0c7dc)
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.
Example fix
// before
result = await orch.invoke("Summarize the quarterly report", runtime) # raises
// after
from semantic_kernel.contents.chat_message_content import ChatMessageContent
from semantic_kernel.contents.utils.author_role import AuthorRole
task = ChatMessageContent(role=AuthorRole.USER, content="Summarize the quarterly report")
result = await orch.invoke(task, runtime) Defensive patterns
Strategy: type-guard
Validate before calling
# Coerce input to ChatMessageContent before invoking Magentic
task_msg = task if isinstance(task, ChatMessageContent) else ChatMessageContent(
role=AuthorRole.USER, content=str(task)
)
result = await orch.invoke(task_msg, runtime) Type guard
from semantic_kernel.contents.chat_message_content import ChatMessageContent
def is_magentic_task(task) -> bool:
return isinstance(task, ChatMessageContent) Try / catch
try:
result = await orch.invoke(task, runtime)
except ValueError as e:
if "must be a ChatMessageContent" in str(e):
result = await orch.invoke(
ChatMessageContent(role=AuthorRole.USER, content=str(task)), runtime
)
else:
raise Prevention
- 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.
When it happens
Trigger: 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.)
Common situations: Porting code from GroupChatOrchestration or SequentialOrchestration which accept str or list inputs. Passing a raw string prompt expecting it to be wrapped automatically.
Related errors
- All members must have a description.
- Last message in chat history was null or whitespace.
- At least one action must be provided.
- All declarative agents must have an Id or a Name assigned.
- AgentDefinition Id must be set
AI-assisted analysis of microsoft/semantic-kernel@c028a0c7dc (2026-08-13).
Data as JSON: /api/errors/ec297a700a7fc37f.
Report an issue: GitHub.