microsoft/autogen · error · ArgumentException

The from property of the message {message} is different from

Error message

The from property of the message {message} is different from the from property of the aggregate message {this}

What it means

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.

Source

Thrown at dotnet/src/AutoGen.Core/Message/AggregateMessage.cs:36

        this.Validate();
    }

    public TMessage1 Message1 { get; }

    public TMessage2 Message2 { get; }

    public string? From { get; set; }

    private void Validate()
    {
        var messages = new List<IMessage> { this.Message1, this.Message2 };
        // the from property of all messages should be the same with the from property of the aggregate message

        foreach (var message in messages)
        {
            if (message.From != this.From)
            {
                throw new ArgumentException($"The from property of the message {message} is different from the from property of the aggregate message {this}");
            }
        }
    }

    public override string ToString()
    {
        var stringBuilder = new System.Text.StringBuilder();
        var messages = new List<IMessage> { this.Message1, this.Message2 };
        stringBuilder.Append($"AggregateMessage({this.From})");
        foreach (var message in messages)
        {
            stringBuilder.Append($"\n\t{message}");
        }

        return stringBuilder.ToString();
    }
}

View on GitHub (pinned to 027ecf0a37)

Solutions

  1. Set the same from value on the aggregate and every inner message at construction time.
  2. Construct inner messages with the agent's name as the from argument rather than relying on defaults.
  3. Before aggregating, assert msg1.From == msg2.From == aggregateFrom to fail with your own clearer error.

Example fix

// before
var text = new TextMessage(Role.Assistant, "check this", from: null);
var img = new ImageMessage(Role.Assistant, dataUri, from: "agent");
var agg = new AggregateMessage<TextMessage, ImageMessage>(text, img, from: "agent"); // throws

// after
var text = new TextMessage(Role.Assistant, "check this", from: "agent");
var img = new ImageMessage(Role.Assistant, dataUri, from: "agent");
var agg = new AggregateMessage<TextMessage, ImageMessage>(text, img, from: "agent");
Defensive patterns

Strategy: validation

Validate before calling

void AssertSameFrom(IEnumerable<IMessage> parts, string? aggregateFrom)
{
    if (parts.Any(m => m.From != aggregateFrom))
        throw new ArgumentException("Inner message From differs from aggregate From");
}

Type guard

static bool IsValidAggregate(IMessage m1, IMessage m2, string? from) => m1.From == from && m2.From == from;

Try / catch

try { var agg = new AggregateMessage<T1, T2>(m1, m2, from: name); }
catch (ArgumentException ex) when (ex.Message.Contains("from property"))
{
    // rebuild inner messages with the correct From, then retry
}

Prevention

When it happens

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

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

Related errors


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