{"record":{"id":"cc247c7996c2097f","repo":"microsoft/autogen","slug":"unsupported-message-type-type-msg","errorCode":null,"errorMessage":"Unsupported message type: {type(msg)}","messagePattern":"Unsupported message type: (.+?)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/packages/autogen-ext/src/autogen_ext/models/llama_cpp/_llama_cpp_completion_client.py","lineNumber":298,"sourceCode":"            | ChatCompletionRequestUserMessage\n            | ChatCompletionRequestAssistantMessage\n            | ChatCompletionRequestUserMessage\n            | ChatCompletionRequestToolMessage\n            | ChatCompletionRequestFunctionMessage\n        ] = []\n        for msg in messages:\n            if isinstance(msg, SystemMessage):\n                converted_messages.append({\"role\": \"system\", \"content\": msg.content})\n            elif isinstance(msg, UserMessage) and isinstance(msg.content, str):\n                converted_messages.append({\"role\": \"user\", \"content\": msg.content})\n            elif isinstance(msg, AssistantMessage) and isinstance(msg.content, str):\n                converted_messages.append({\"role\": \"assistant\", \"content\": msg.content})\n            elif (\n                isinstance(msg, SystemMessage) or isinstance(msg, UserMessage) or isinstance(msg, AssistantMessage)\n            ) and isinstance(msg.content, list):\n                raise ValueError(\"Multi-part messages such as those containing images are currently not supported.\")\n            else:\n                raise ValueError(f\"Unsupported message type: {type(msg)}\")\n\n        if isinstance(json_output, type) and issubclass(json_output, BaseModel):\n            create_args[\"response_format\"] = {\"type\": \"json_object\", \"schema\": json_output.model_json_schema()}\n        elif json_output is True:\n            create_args[\"response_format\"] = {\"type\": \"json_object\"}\n        elif json_output is not False and json_output is not None:\n            raise ValueError(\"json_output must be a boolean, a BaseModel subclass or None.\")\n\n        # Handle tool_choice parameter\n        if tool_choice != \"auto\":\n            warnings.warn(\n                \"tool_choice parameter is specified but LlamaCppChatCompletionClient does not support it. \"\n                \"This parameter will be ignored.\",\n                UserWarning,\n                stacklevel=2,\n            )\n\n        if self.model_info[\"function_calling\"]:","sourceCodeStart":280,"sourceCodeEnd":316,"githubUrl":"https://github.com/microsoft/autogen/blob/027ecf0a379bcc1d09956d46d12d44a3ad9cee14/python/packages/autogen-ext/src/autogen_ext/models/llama_cpp/_llama_cpp_completion_client.py#L280-L316","documentation":"During create(), any message that is not SystemMessage/UserMessage/AssistantMessage falls into the final else and raises 'Unsupported message type: {type(msg)}'. The client deliberately rejects function/tool result messages (FunctionExecutionResultMessage) and any custom LLMMessage subclass, because it has no conversion path for them.","triggerScenarios":"Passing FunctionExecutionResultMessage back into create() (common in tool-calling loops that reuse the full history); passing GetToolContentMessage or other autogen-ext message types; passing a custom class subclassing LLMMessage; passing None or a raw dict instead of an LLMMessage.","commonSituations":"Replaying an entire conversation history — including tool results — from a RoundRobinGroupChat or AssistantAgent transcript into this client; migrating from ReplayChatAgent or an agent-chat serialization format that includes tool-result entries.","solutions":["Filter history to only System/User/Assistant string-content messages before calling create(): [m for m in messages if isinstance(m, (SystemMessage, UserMessage, AssistantMessage))]","Convert FunctionExecutionResultMessage entries into UserMessage(content=str(result.content), source='user') if the model needs the tool output as text","Check the printed type in the message — it names the exact class that slipped through; fix that producer"],"exampleFix":"# before\nhistory.append(FunctionExecutionResultMessage(content=[FunctionExecutionResult(content=\"42\", call_id=\"1\")], source=\"tool\"))\nawait client.create(history)\n\n# after\ntext_history = [m for m in history if isinstance(m, (SystemMessage, UserMessage, AssistantMessage))]\nawait client.create(text_history)","handlingStrategy":"type-guard","validationCode":"SUPPORTED = (SystemMessage, UserMessage, AssistantMessage)\nif not all(isinstance(m, SUPPORTED) for m in messages):\n    messages = [m for m in messages if isinstance(m, SUPPORTED)]","typeGuard":"from autogen_core.models import LLMMessage, SystemMessage, UserMessage, AssistantMessage\n\ndef is_supported_message(msg: object) -> TypeGuard[SystemMessage | UserMessage | AssistantMessage]:\n    return isinstance(msg, (SystemMessage, UserMessage, AssistantMessage))","tryCatchPattern":"try:\n    result = await client.create(messages)\nexcept ValueError as e:\n    if \"Unsupported message type\" in str(e):\n        messages = [m for m in messages if is_supported_message(m)]\n        result = await client.create(messages)\n    else:\n        raise","preventionTips":["Never replay raw group-chat transcripts into this client — filter to the three supported types","Convert FunctionExecutionResultMessage to UserMessage text when a tool-less model needs the result","Type message lists as Sequence[SystemMessage | UserMessage | AssistantMessage] in your own APIs"],"tags":["llama-cpp","messages","tool-calling","history"],"backgroundTag":null,"analyzedSha":"027ecf0a379bcc1d09956d46d12d44a3ad9cee14","analyzedAt":"2026-08-15T03:38:00.719Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}