microsoft/autogen · error · NotSupportedException

Role {textMessage.Role} is not supported

Error message

Role {textMessage.Role} is not supported

What it means

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.

Source

Thrown at dotnet/src/AutoGen.Mistral/Middleware/MistralChatMessageConnector.cs:234

        else if (textMessage.From == agent.Name)
        {
            // if this message is from agent iteself, then its role should be assistant
            messages = [new ChatMessage(ChatMessage.RoleEnum.Assistant, textMessage.Content)];
        }
        else if (textMessage.From is null)
        {
            // if from is null, then process the message based on the role
            if (textMessage.Role == Role.User)
            {
                messages = [new ChatMessage(ChatMessage.RoleEnum.User, textMessage.Content)];
            }
            else if (textMessage.Role == Role.Assistant)
            {
                messages = [new ChatMessage(ChatMessage.RoleEnum.Assistant, textMessage.Content)];
            }
            else
            {
                throw new NotSupportedException($"Role {textMessage.Role} is not supported");
            }
        }
        else
        {
            // if from is not null, then the message is from user
            messages = [new ChatMessage(ChatMessage.RoleEnum.User, textMessage.Content)];
        }

        return messages.Select(m => new MessageEnvelope<ChatMessage>(m, from: textMessage.From));
    }

    private IEnumerable<IMessage<ChatMessage>> ProcessToolCallResultMessage(ToolCallResultMessage toolCallResultMessage, IAgent _)
    {
        var from = toolCallResultMessage.From;
        var messages = new List<ChatMessage>();
        foreach (var toolCall in toolCallResultMessage.ToolCalls)
        {
            if (toolCall.Result is null)

View on GitHub (pinned to 027ecf0a37)

Solutions

  1. Set From on the message (non-null From is always treated as a user message), or change Role to Role.User/Role.Assistant.
  2. If you need a system prompt, use the MistralClient/agent's system-message mechanism instead of injecting a Role.System TextMessage.
  3. Better: extend the connector to map Role.System to ChatMessage.RoleEnum.System and rebuild the package locally.

Example fix

// before
var sysMsg = new TextMessage(Role.System, "You are a helpful assistant"); // From == null -> throws
await agent.SendAsync(sysMsg);

// after
var sysMsg = new TextMessage(Role.System, "You are a helpful assistant", from: "system");
// or configure the system prompt at agent construction instead of sending it as a message
Defensive patterns

Strategy: validation

Validate before calling

// before sending, normalize TextMessages destined for a Mistral agent
foreach (var m in messages.OfType<TextMessage>())
{
    if (m.From is null && m.Role is not (Role.User or Role.Assistant))
    {
        m.From = "user"; // or convert role, per your intent
    }
}

Type guard

static bool IsMappableTextMessage(TextMessage m) =>
    m.From is not null || m.Role is Role.User or Role.Assistant;

Try / catch

catch (NotSupportedException ex) when (ex.Message.Contains("Role") && ex.Message.Contains("not supported"))
{
    // rewrite the offending message role/from and retry the send
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of microsoft/autogen@027ecf0a37 (2026-08-15). Data as JSON: /api/errors/db537a93b956cc7b. Report an issue: GitHub.