{"record":{"id":"ea0aa7c63ca926dd","repo":"microsoft/autogen","slug":"unsupported-reply-content-type","errorCode":null,"errorMessage":"Unsupported reply content type","messagePattern":"Unsupported reply content type","errorType":"exception","errorClass":"NotImplementedException","httpStatus":null,"severity":"error","filePath":"dotnet/src/AutoGen.WebAPI/OpenAI/Service/OpenAIChatCompletionService.cs","lineNumber":54,"sourceCode":"        {\n            var message = new OpenAIChatCompletionMessage()\n            {\n                Content = content,\n            };\n\n            var choice = new OpenAIChatCompletionChoice()\n            {\n                Message = message,\n                Index = 0,\n                FinishReason = \"stop\",\n            };\n\n            openAIChatCompletion.Choices = [choice];\n\n            return openAIChatCompletion;\n        }\n\n        throw new NotImplementedException(\"Unsupported reply content type\");\n    }\n\n    public async IAsyncEnumerable<OpenAIChatCompletion> GetStreamingChatCompletionAsync(OpenAIChatCompletionOption request)\n    {\n        if (this.agent is IStreamingAgent streamingAgent)\n        {\n            var messages = this.ProcessMessages(request.Messages ?? Array.Empty<OpenAIMessage>());\n\n            var generateOption = this.ProcessReplyOptions(request);\n\n            await foreach (var reply in streamingAgent.GenerateStreamingReplyAsync(messages, generateOption))\n            {\n                var openAIChatCompletion = new OpenAIChatCompletion()\n                {\n                    Created = DateTimeOffset.UtcNow.Ticks / TimeSpan.TicksPerMillisecond / 1000,\n                    Model = this.agent.Name,\n                };\n","sourceCodeStart":36,"sourceCodeEnd":72,"githubUrl":"https://github.com/microsoft/autogen/blob/027ecf0a379bcc1d09956d46d12d44a3ad9cee14/dotnet/src/AutoGen.WebAPI/OpenAI/Service/OpenAIChatCompletionService.cs#L36-L72","documentation":"OpenAIChatCompletionService.GetChatCompletionAsync maps the agent's reply into an OpenAI completion response only when reply.GetContent() is a string. Any other content (image bytes, multimodal collections, structured objects) hits NotImplementedException 'Unsupported reply content type' — this endpoint is text-only on the response side.","triggerScenarios":"The backing agent returns an ImageMessage, MultiModalMessage, or any reply whose GetContent() is not a string (e.g. null content or byte[]/Uri content).","commonSituations":"Registering an image-generation or multimodal agent behind the OpenAI-compatible WebAPI; an agent returning an empty content message; tool-call replies whose content is an object.","solutions":["Ensure the registered agent replies with string content (TextMessage / MessageEnvelope<string>)","In the agent, stringify non-text results (URL for images, JSON for structured data) before returning","Do not expose image/multimodal-output agents through this completion endpoint; serve them from a dedicated route"],"exampleFix":"// before\nreturn new ImageMessage(Role.Assistant, imageUri, from: Name); // GetContent() != string -> throws\n\n// after\nreturn new TextMessage(Role.Assistant, imageUri.ToString(), from: Name);","handlingStrategy":"type-guard","validationCode":"var content = reply.GetContent();\nif (content is not string)\n    throw new InvalidOperationException($\"Agent '{agent.Name}' must reply with string content for the OpenAI endpoint (got {content?.GetType().Name ?? \"null\"}).\");","typeGuard":"static bool HasStringContent(IMessage reply) => reply.GetContent() is string;","tryCatchPattern":"try { return await service.GetChatCompletionAsync(request); }\ncatch (NotImplementedException ex) when (ex.Message.Contains(\"reply content\"))\n{\n    return StatusCode(501, \"Backing agent does not produce text replies through this endpoint.\");\n}","preventionTips":["Register only text-replying agents behind the OpenAI-compatible endpoint","Stringify image/structured outputs inside the agent before returning","Add a startup sanity check that invokes each registered agent once with a trivial prompt"],"tags":["csharp","webapi","openai-compatible","reply-type","not-implemented"],"backgroundTag":null,"analyzedSha":"027ecf0a379bcc1d09956d46d12d44a3ad9cee14","analyzedAt":"2026-08-15T03:38:00.719Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}