microsoft/autogen · error · ArgumentException

Content is null

Error message

Content is null

What it means

Thrown when converting a foreign (different-sender) message whose conversion path reaches new ChatRequestUserMessage(msg.Content) but Content is null. The code defends with Content ?? throw ArgumentException because ChatRequestUserMessage requires non-null user text.

Source

Thrown at dotnet/src/AutoGen.OpenAI.V1/Extension/MessageExtension.cs:146

                else if (msg.FunctionName is null && msg.FunctionArguments is null)
                {
                    var userMessage = msg.ToChatRequestUserMessage();
                    return [userMessage];
                }
                else if (msg.FunctionName is not null && msg.FunctionArguments is not null && msg.Content is not null)
                {
                    if (msg.Role == Role.Function)
                    {
                        return [new ChatRequestFunctionMessage(msg.FunctionName, msg.Content)];
                    }
                    else
                    {
                        return [new ChatRequestUserMessage(msg.Content)];
                    }
                }
                else
                {
                    var userMessage = new ChatRequestUserMessage(msg.Content ?? throw new ArgumentException("Content is null"));
                    return [userMessage];
                }
            }
            else
            {
                throw new ArgumentException($"Unknown message type: {message.GetType()}");
            }
        }
        else
        {
            if (message is TextMessage textMessage)
            {
                if (textMessage.Role == Role.System)
                {
                    throw new ArgumentException("System message is not supported when message.From is the same with agent");
                }

                return [new ChatRequestAssistantMessage(textMessage.Content)];

View on GitHub (pinned to 027ecf0a37)

Solutions

  1. Guarantee Content is non-empty before adding the message to any conversation sent to OpenAI agents
  2. Prune null-content messages when loading persisted history
  3. Initialize message content to string.Empty and skip empty strings before sending

Example fix

// before
history.Add(new TextMessage(Role.User, null));
await agent.SendAsync(history);

// after
history = history.Where(m => !string.IsNullOrEmpty(m.GetContent())).ToList();
await agent.SendAsync(history);
Defensive patterns

Strategy: validation

Validate before calling

if (string.IsNullOrEmpty(msg.GetContent()))
    throw new ArgumentException($"Message from {msg.From} has null content");

Try / catch

catch (ArgumentException ex) when (ex.Message == "Content is null")
{
    logger.LogWarning("Skipping message with null content from {From}", msg.From);
}

Prevention

When it happens

Trigger: A message from another agent with null Content (e.g. an empty TextMessage or partially-built message) hits the generic user-message branch of the foreign-sender path.

Common situations: Empty assistant turns or placeholder messages accumulated in group-chat history; message objects created with default constructors; content dropped during serialization/deserialization of history.

Related errors


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