{"record":{"id":"2240686fcd237db8","repo":"microsoft/autogen","slug":"the-from-property-of-the-message-message-is-diff","errorCode":null,"errorMessage":"The from property of the message {message} is different from the from property of the aggregate message {this}","messagePattern":"The from property of the message (.+?) is different from the from property of the aggregate message (.+?)","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"dotnet/src/AutoGen.Core/Message/AggregateMessage.cs","lineNumber":36,"sourceCode":"        this.Validate();\n    }\n\n    public TMessage1 Message1 { get; }\n\n    public TMessage2 Message2 { get; }\n\n    public string? From { get; set; }\n\n    private void Validate()\n    {\n        var messages = new List<IMessage> { this.Message1, this.Message2 };\n        // the from property of all messages should be the same with the from property of the aggregate message\n\n        foreach (var message in messages)\n        {\n            if (message.From != this.From)\n            {\n                throw new ArgumentException($\"The from property of the message {message} is different from the from property of the aggregate message {this}\");\n            }\n        }\n    }\n\n    public override string ToString()\n    {\n        var stringBuilder = new System.Text.StringBuilder();\n        var messages = new List<IMessage> { this.Message1, this.Message2 };\n        stringBuilder.Append($\"AggregateMessage({this.From})\");\n        foreach (var message in messages)\n        {\n            stringBuilder.Append($\"\\n\\t{message}\");\n        }\n\n        return stringBuilder.ToString();\n    }\n}\n","sourceCodeStart":18,"sourceCodeEnd":54,"githubUrl":"https://github.com/microsoft/autogen/blob/027ecf0a379bcc1d09956d46d12d44a3ad9cee14/dotnet/src/AutoGen.Core/Message/AggregateMessage.cs#L18-L54","documentation":"AggregateMessage wraps exactly two inner messages (Message1, Message2) and its Validate() (run on construction) requires both inner messages' From to equal the aggregate's own From. Any mismatch throws ArgumentException with a description of the offending message. The invariant keeps attribution consistent: an aggregate is understood as coming from a single sender.","triggerScenarios":"new AggregateMessage<TextMessage, ImageMessage>(msg1, msg2, from: \"agent\") where msg1.From is null or set to a different agent name; aggregating a user message and an assistant message into one; inner messages built without setting the from parameter.","commonSituations":"Building multimodal replies by combining a text and an image message but forgetting to set from on each inner message (it defaults null while the wrapper sets a name); mixing messages captured from different agents into one aggregate during pipeline processing.","solutions":["Set the same from value on the aggregate and every inner message at construction time.","Construct inner messages with the agent's name as the from argument rather than relying on defaults.","Before aggregating, assert msg1.From == msg2.From == aggregateFrom to fail with your own clearer error."],"exampleFix":"// before\nvar text = new TextMessage(Role.Assistant, \"check this\", from: null);\nvar img = new ImageMessage(Role.Assistant, dataUri, from: \"agent\");\nvar agg = new AggregateMessage<TextMessage, ImageMessage>(text, img, from: \"agent\"); // throws\n\n// after\nvar text = new TextMessage(Role.Assistant, \"check this\", from: \"agent\");\nvar img = new ImageMessage(Role.Assistant, dataUri, from: \"agent\");\nvar agg = new AggregateMessage<TextMessage, ImageMessage>(text, img, from: \"agent\");","handlingStrategy":"validation","validationCode":"void AssertSameFrom(IEnumerable<IMessage> parts, string? aggregateFrom)\n{\n    if (parts.Any(m => m.From != aggregateFrom))\n        throw new ArgumentException(\"Inner message From differs from aggregate From\");\n}","typeGuard":"static bool IsValidAggregate(IMessage m1, IMessage m2, string? from) => m1.From == from && m2.From == from;","tryCatchPattern":"try { var agg = new AggregateMessage<T1, T2>(m1, m2, from: name); }\ncatch (ArgumentException ex) when (ex.Message.Contains(\"from property\"))\n{\n    // rebuild inner messages with the correct From, then retry\n}","preventionTips":["Always pass from: agentName when constructing inner messages destined for an aggregate.","Centralize message construction in one factory so From is applied uniformly.","Unit-test message builders to assert From consistency."],"tags":["autogen","dotnet","message","aggregate-message","validation","argumentexception"],"backgroundTag":null,"analyzedSha":"027ecf0a379bcc1d09956d46d12d44a3ad9cee14","analyzedAt":"2026-08-15T03:38:00.719Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}