microsoft/autogen · error · ArgumentException
Invalid aggregate message {reason}
Error message
Invalid aggregate message {reason} What it means
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.
Source
Thrown at dotnet/src/AutoGen.Core/Message/MultiModalMessage.cs:32
this.Content = content;
this.From = from;
this.Validate();
}
public Role Role { get; set; }
public IEnumerable<IMessage> Content { get; set; }
public string? From { get; set; }
private void Validate()
{
foreach (var message in this.Content)
{
if (message.From != this.From)
{
var reason = $"The from property of the message {message} is different from the from property of the aggregate message {this}";
throw new ArgumentException($"Invalid aggregate message {reason}");
}
}
// all message must be either text or image
foreach (var message in this.Content)
{
if (message is not TextMessage && message is not ImageMessage)
{
var reason = $"The message {message} is not a text or image message";
throw new ArgumentException($"Invalid aggregate message {reason}");
}
}
}
public override string ToString()
{
var stringBuilder = new System.Text.StringBuilder();
stringBuilder.Append($"MultiModalMessage({this.Role}, {this.From})");View on GitHub (pinned to 027ecf0a37)
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.
Example fix
// before
var parts = new IMessage[]
{
new TextMessage(Role.User, "describe"), // From = null
new ImageMessage(Role.User, uri, from: "user"),
};
var msg = new MultiModalMessage(Role.User, parts, from: "user"); // throws
// after
var parts = new IMessage[]
{
new TextMessage(Role.User, "describe", from: "user"),
new ImageMessage(Role.User, uri, from: "user"),
};
var msg = new MultiModalMessage(Role.User, parts, from: "user"); Defensive patterns
Strategy: validation
Validate before calling
if (content.Any(m => m.From != aggregateFrom))
throw new ArgumentException("All multimodal parts must have the same From as the aggregate");
var msg = new MultiModalMessage(role, content, from: aggregateFrom); Type guard
static bool IsFromConsistent(IEnumerable<IMessage> content, string? from) => content.All(m => m.From == from);
Try / catch
try { var msg = new MultiModalMessage(role, content, from); }
catch (ArgumentException ex) when (ex.Message.Contains("from property"))
{
// normalize each part's From and retry construction
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- The from property of the message {message} is different from
- Invalid DataUri format, expected data:[<mediatype>][;base64]
- Data cannot be empty
- Role mismatch
- All agents must have a name.
AI-assisted analysis of microsoft/autogen@027ecf0a37 (2026-08-15).
Data as JSON: /api/errors/f8b8be8ef7f2b375.
Report an issue: GitHub.