{"record":{"id":"dcca3ba2363f520e","repo":"microsoft/autogen","slug":"the-from-field-must-be-null-or-the-agent-name","errorCode":null,"errorMessage":"The from field must be null or the agent name","messagePattern":"The from field must be null or the agent name","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"dotnet/src/AutoGen.Ollama/Middlewares/OllamaMessageConnector.cs","lineNumber":144,"sourceCode":"            var uri = new Uri(imageMessage.Url);\n            // download the image from the URL\n            using var client = new HttpClient();\n            var response = client.GetAsync(uri).Result;\n            if (!response.IsSuccessStatusCode)\n            {\n                throw new HttpRequestException($\"Failed to download the image from {uri}\");\n            }\n\n            data = response.Content.ReadAsByteArrayAsync().Result;\n        }\n\n        var base64Image = Convert.ToBase64String(data);\n        var message = imageMessage.From switch\n        {\n            null when imageMessage.Role == Role.User => new Message { Role = \"user\", Images = [base64Image] },\n            null => throw new InvalidOperationException(\"Invalid Role, the role must be user\"),\n            _ when imageMessage.From != agent.Name => new Message { Role = \"user\", Images = [base64Image] },\n            _ => throw new InvalidOperationException(\"The from field must be null or the agent name\"),\n        };\n\n        return [MessageEnvelope.Create(message, agent.Name)];\n    }\n\n    private IEnumerable<IMessage> ProcessTextMessage(TextMessage textMessage, IAgent agent)\n    {\n        if (textMessage.Role == Role.System)\n        {\n            var message = new Message\n            {\n                Role = \"system\",\n                Value = textMessage.Content\n            };\n\n            return [MessageEnvelope.Create(message, agent.Name)];\n        }\n        else if (textMessage.From == agent.Name)","sourceCodeStart":126,"sourceCodeEnd":162,"githubUrl":"https://github.com/microsoft/autogen/blob/027ecf0a379bcc1d09956d46d12d44a3ad9cee14/dotnet/src/AutoGen.Ollama/Middlewares/OllamaMessageConnector.cs#L126-L162","documentation":"Thrown by OllamaMessageConnector when converting an ImageMessage for an Ollama agent. The connector maps an image to an Ollama 'user' Message only when imageMessage.From is null (with Role.User) or equals a different agent's name; if From is set and equals the current agent's own name, it throws because an agent cannot send itself a user-role image.","triggerScenarios":"ProcessImageMessage is invoked (directly or via the connector middleware) with an ImageMessage where From == agent.Name (non-null), e.g. replaying an agent's own prior output back into the same agent without clearing From.","commonSituations":"Building group-chat loops in AutoGen.Ollama where the assistant's own image output is fed back into its history; copying messages between agents while keeping the original From value.","solutions":["Set imageMessage.From = null (and Role = Role.User) before sending the image to the same agent","If the image genuinely comes from another participant, set From to that participant's name instead of the receiving agent's name","When persisting conversation history, strip or rewrite From on messages you intend to re-submit as user input"],"exampleFix":"// before\nvar img = new ImageMessage(role: Role.User, from: agent.Name, url: imageUrl);\nvar reply = await agent.SendAsync(img);\n\n// after\nvar img = new ImageMessage(role: Role.User, from: null, url: imageUrl);\nvar reply = await agent.SendAsync(img);","handlingStrategy":"validation","validationCode":"bool CanSendImage(OllamaAgent agent, ImageMessage msg) =>\n    msg.From is null || msg.From != agent.Name;","typeGuard":null,"tryCatchPattern":"try { var reply = await agent.SendAsync(img); }\ncatch (InvalidOperationException ex) when (ex.Message.Contains(\"from field\"))\n{\n    var sanitized = new ImageMessage(Role.User, from: null, url: img.Url);\n    reply = await agent.SendAsync(sanitized);\n}","preventionTips":["Always set From = null on user-supplied images","Strip From when replaying an agent's own output","Keep agent names unique in multi-agent setups"],"tags":["ollama","message-connector","validation","image-message"],"backgroundTag":null,"analyzedSha":"027ecf0a379bcc1d09956d46d12d44a3ad9cee14","analyzedAt":"2026-08-15T03:38:00.719Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}