{"record":{"id":"db537a93b956cc7b","repo":"microsoft/autogen","slug":"role-textmessage-role-is-not-supported-db537a","errorCode":null,"errorMessage":"Role {textMessage.Role} is not supported","messagePattern":"Role (.+?) is not supported","errorType":"exception","errorClass":"NotSupportedException","httpStatus":null,"severity":"error","filePath":"dotnet/src/AutoGen.Mistral/Middleware/MistralChatMessageConnector.cs","lineNumber":234,"sourceCode":"        else if (textMessage.From == agent.Name)\n        {\n            // if this message is from agent iteself, then its role should be assistant\n            messages = [new ChatMessage(ChatMessage.RoleEnum.Assistant, textMessage.Content)];\n        }\n        else if (textMessage.From is null)\n        {\n            // if from is null, then process the message based on the role\n            if (textMessage.Role == Role.User)\n            {\n                messages = [new ChatMessage(ChatMessage.RoleEnum.User, textMessage.Content)];\n            }\n            else if (textMessage.Role == Role.Assistant)\n            {\n                messages = [new ChatMessage(ChatMessage.RoleEnum.Assistant, textMessage.Content)];\n            }\n            else\n            {\n                throw new NotSupportedException($\"Role {textMessage.Role} is not supported\");\n            }\n        }\n        else\n        {\n            // if from is not null, then the message is from user\n            messages = [new ChatMessage(ChatMessage.RoleEnum.User, textMessage.Content)];\n        }\n\n        return messages.Select(m => new MessageEnvelope<ChatMessage>(m, from: textMessage.From));\n    }\n\n    private IEnumerable<IMessage<ChatMessage>> ProcessToolCallResultMessage(ToolCallResultMessage toolCallResultMessage, IAgent _)\n    {\n        var from = toolCallResultMessage.From;\n        var messages = new List<ChatMessage>();\n        foreach (var toolCall in toolCallResultMessage.ToolCalls)\n        {\n            if (toolCall.Result is null)","sourceCodeStart":216,"sourceCodeEnd":252,"githubUrl":"https://github.com/microsoft/autogen/blob/027ecf0a379bcc1d09956d46d12d44a3ad9cee14/dotnet/src/AutoGen.Mistral/Middleware/MistralChatMessageConnector.cs#L216-L252","documentation":"NotSupportedException from ProcessTextMessage in the Mistral connector: a TextMessage with From == null must have Role User or Assistant. Any other role (System, Custom, or a custom enum value) cannot be mapped to a Mistral ChatMessage role.","triggerScenarios":"Sending a TextMessage with Role = Role.System (or any non-User/Assistant role) and no From field into a Mistral agent conversation. The else-branch at MistralChatMessageConnector.cs:234 has no System mapping even though Mistral supports the system role.","commonSituations":"Porting code from another AutoGen connector that accepts System-role messages with null From; group-chat orchestration forwarding system/context messages; constructing chat history manually with Role.System.","solutions":["Set From on the message (non-null From is always treated as a user message), or change Role to Role.User/Role.Assistant.","If you need a system prompt, use the MistralClient/agent's system-message mechanism instead of injecting a Role.System TextMessage.","Better: extend the connector to map Role.System to ChatMessage.RoleEnum.System and rebuild the package locally."],"exampleFix":"// before\nvar sysMsg = new TextMessage(Role.System, \"You are a helpful assistant\"); // From == null -> throws\nawait agent.SendAsync(sysMsg);\n\n// after\nvar sysMsg = new TextMessage(Role.System, \"You are a helpful assistant\", from: \"system\");\n// or configure the system prompt at agent construction instead of sending it as a message","handlingStrategy":"validation","validationCode":"// before sending, normalize TextMessages destined for a Mistral agent\nforeach (var m in messages.OfType<TextMessage>())\n{\n    if (m.From is null && m.Role is not (Role.User or Role.Assistant))\n    {\n        m.From = \"user\"; // or convert role, per your intent\n    }\n}","typeGuard":"static bool IsMappableTextMessage(TextMessage m) =>\n    m.From is not null || m.Role is Role.User or Role.Assistant;","tryCatchPattern":"catch (NotSupportedException ex) when (ex.Message.Contains(\"Role\") && ex.Message.Contains(\"not supported\"))\n{\n    // rewrite the offending message role/from and retry the send\n}","preventionTips":["Set system prompts via the agent's system-message API, not injected TextMessages","When porting between connectors, review role mappings of every history message"],"tags":["mistral","message-role","system-message","not-supported"],"backgroundTag":null,"analyzedSha":"027ecf0a379bcc1d09956d46d12d44a3ad9cee14","analyzedAt":"2026-08-15T03:38:00.719Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}