{"record":{"id":"c9744322e7719578","repo":"microsoft/autogen","slug":"invalid-message-type-c97443","errorCode":null,"errorMessage":"Invalid message type","messagePattern":"Invalid message type","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"dotnet/src/AutoGen.Mistral/Agent/MistralClientAgent.cs","lineNumber":119,"sourceCode":"            MaxTokens = options?.MaxToken,\n            ResponseFormat = _jsonOutput ? new ResponseFormat() { ResponseFormatType = \"json_object\" } : null,\n        };\n\n        if (options?.Functions != null)\n        {\n            chatRequest.Tools = options.Functions.Select(f => new FunctionTool(f.ToMistralFunctionDefinition())).ToList();\n            chatRequest.ToolChoice = _toolChoice ?? ToolChoiceEnum.Auto;\n        }\n\n        return chatRequest;\n    }\n\n    private IEnumerable<ChatMessage> BuildChatHistory(IEnumerable<IMessage> messages)\n    {\n        var history = messages.Select(m => m switch\n        {\n            IMessage<ChatMessage> chatMessage => chatMessage.Content,\n            _ => throw new ArgumentException(\"Invalid message type\")\n        });\n\n        // if there's no system message in the history, add one to the beginning\n        if (!history.Any(m => m.Role == ChatMessage.RoleEnum.System))\n        {\n            history = new[] { new ChatMessage(ChatMessage.RoleEnum.System, _systemMessage) }.Concat(history);\n        }\n\n        return history;\n    }\n}\n","sourceCodeStart":101,"sourceCodeEnd":131,"githubUrl":"https://github.com/microsoft/autogen/blob/027ecf0a379bcc1d09956d46d12d44a3ad9cee14/dotnet/src/AutoGen.Mistral/Agent/MistralClientAgent.cs#L101-L131","documentation":"MistralClientAgent.BuildChatHistory only accepts messages already wrapped as IMessage<ChatMessage> (the Mistral-native chat shape); anything else throws ArgumentException. The wrapping is normally done by MistralChatMessageConnector middleware, so this error means raw AutoGen messages reached the agent unconverted.","triggerScenarios":"Calling a MistralClientAgent's reply pipeline without registering MistralChatMessageConnector (or calling the underlying client directly) and passing TextMessage/ToolCallMessage instances instead of MessageEnvelope<ChatMessage>.","commonSituations":"Using MistralClientAgent instead of the higher-level MistralAgent that auto-registers the connector; custom middleware ordering that strips envelopes; sending messages produced by other providers into the Mistral client agent.","solutions":["Use MistralAgent (which wires MistralChatMessageConnector) or explicitly register the connector middleware on MistralClientAgent.","If calling the client agent directly, wrap content yourself: MessageEnvelope.Create(new ChatMessage(role, content), from).","Check middleware order: the connector must run before the request is serialized."],"exampleFix":"// before\nvar agent = new MistralClientAgent(name: \"a\", client: client, model: \"mistral-large-latest\");\nvar reply = await agent.SendAsync(new TextMessage(Role.User, \"hi\"));\n\n// after\nvar agent = new MistralAgent(name: \"a\", client: client, model: \"mistral-large-latest\"); // connector registered\nvar reply = await agent.SendAsync(\"hi\");","handlingStrategy":"type-guard","validationCode":"var unwrapped = messages.Where(m => m is not Core.IMessage<ChatMessage>).ToList();\nif (unwrapped.Count > 0) { messages = ConvertViaConnector(messages); } // or use MistralAgent","typeGuard":"static bool IsMistralChatReady(IEnumerable<IMessage> msgs) => msgs.All(m => m is Core.IMessage<ChatMessage>);","tryCatchPattern":null,"preventionTips":["Prefer MistralAgent over MistralClientAgent for normal use","Register MistralChatMessageConnector before custom middleware","Wrap foreign messages in MessageEnvelope<ChatMessage> when calling the client agent directly"],"tags":["mistral","message-mapping","middleware","argument"],"backgroundTag":null,"analyzedSha":"027ecf0a379bcc1d09956d46d12d44a3ad9cee14","analyzedAt":"2026-08-15T03:38:00.719Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}