{"record":{"id":"f8b8be8ef7f2b375","repo":"microsoft/autogen","slug":"invalid-aggregate-message-reason","errorCode":null,"errorMessage":"Invalid aggregate message {reason}","messagePattern":"Invalid aggregate message (.+?)","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"dotnet/src/AutoGen.Core/Message/MultiModalMessage.cs","lineNumber":32,"sourceCode":"        this.Content = content;\n        this.From = from;\n        this.Validate();\n    }\n\n    public Role Role { get; set; }\n\n    public IEnumerable<IMessage> Content { get; set; }\n\n    public string? From { get; set; }\n\n    private void Validate()\n    {\n        foreach (var message in this.Content)\n        {\n            if (message.From != this.From)\n            {\n                var reason = $\"The from property of the message {message} is different from the from property of the aggregate message {this}\";\n                throw new ArgumentException($\"Invalid aggregate message {reason}\");\n            }\n        }\n\n        // all message must be either text or image\n        foreach (var message in this.Content)\n        {\n            if (message is not TextMessage && message is not ImageMessage)\n            {\n                var reason = $\"The message {message} is not a text or image message\";\n                throw new ArgumentException($\"Invalid aggregate message {reason}\");\n            }\n        }\n    }\n\n    public override string ToString()\n    {\n        var stringBuilder = new System.Text.StringBuilder();\n        stringBuilder.Append($\"MultiModalMessage({this.Role}, {this.From})\");","sourceCodeStart":14,"sourceCodeEnd":50,"githubUrl":"https://github.com/microsoft/autogen/blob/027ecf0a379bcc1d09956d46d12d44a3ad9cee14/dotnet/src/AutoGen.Core/Message/MultiModalMessage.cs#L14-L50","documentation":"MultiModalMessage.Validate() (run on construction) checks every inner message's From equals the aggregate's From; a mismatch produces ArgumentException('Invalid aggregate message The from property of the message {message} is different...'). MultiModalMessage aggregates TextMessage/ImageMessage parts that must all be attributed to the same sender so downstream consumers can treat the whole message as one speaker's turn.","triggerScenarios":"new MultiModalMessage(role, new IMessage[] { textWithFromNull, imageFromAgent }, from: \"agent\"); mixing messages produced by different agents into one multimodal message; inner messages created without the from parameter (defaults null) while the wrapper sets from.","commonSituations":"Assembling vision payloads (prompt text + image) where the text was built with a helper that omits from; merging messages collected from a group chat history into a single multimodal request; test fixtures constructing messages inconsistently.","solutions":["Set from on the MultiModalMessage and on every TextMessage/ImageMessage inside it to the same value.","Create inner messages with explicit from arguments rather than defaults.","Pre-validate: content.All(m => m.From == aggregateFrom) before construction and fail with a domain-specific error."],"exampleFix":"// before\nvar parts = new IMessage[]\n{\n    new TextMessage(Role.User, \"describe\"), // From = null\n    new ImageMessage(Role.User, uri, from: \"user\"),\n};\nvar msg = new MultiModalMessage(Role.User, parts, from: \"user\"); // throws\n\n// after\nvar parts = new IMessage[]\n{\n    new TextMessage(Role.User, \"describe\", from: \"user\"),\n    new ImageMessage(Role.User, uri, from: \"user\"),\n};\nvar msg = new MultiModalMessage(Role.User, parts, from: \"user\");","handlingStrategy":"validation","validationCode":"if (content.Any(m => m.From != aggregateFrom))\n    throw new ArgumentException(\"All multimodal parts must have the same From as the aggregate\");\nvar msg = new MultiModalMessage(role, content, from: aggregateFrom);","typeGuard":"static bool IsFromConsistent(IEnumerable<IMessage> content, string? from) => content.All(m => m.From == from);","tryCatchPattern":"try { var msg = new MultiModalMessage(role, content, from); }\ncatch (ArgumentException ex) when (ex.Message.Contains(\"from property\"))\n{\n    // normalize each part's From and retry construction\n}","preventionTips":["Set from on every inner TextMessage/ImageMessage, not just the wrapper.","Use a single builder method for multimodal payloads to enforce consistent attribution.","Assert From consistency in tests of message-construction helpers."],"tags":["autogen","dotnet","message","multimodal","validation","argumentexception"],"backgroundTag":null,"analyzedSha":"027ecf0a379bcc1d09956d46d12d44a3ad9cee14","analyzedAt":"2026-08-15T03:38:00.719Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}