{"record":{"id":"90997d24642effda","repo":"microsoft/autogen","slug":"invalid-streaming-message-type-reply-gettype-na-90997d","errorCode":null,"errorMessage":"Invalid streaming message type {reply.GetType().Name}","messagePattern":"Invalid streaming message type (.+?)","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"dotnet/src/AutoGen.OpenAI/Middleware/OpenAIChatRequestMessageConnector.cs","lineNumber":75,"sourceCode":"        var chunks = new List<StreamingChatCompletionUpdate>();\n\n        // only streaming the text content\n        await foreach (var reply in streamingReply)\n        {\n            if (reply is IMessage<StreamingChatCompletionUpdate> update)\n            {\n                if (update.Content.ContentUpdate.Count == 1 && update.Content.ContentUpdate[0].Kind == ChatMessageContentPartKind.Text)\n                {\n                    yield return new TextMessageUpdate(Role.Assistant, update.Content.ContentUpdate[0].Text, from: update.From);\n                }\n\n                chunks.Add(update.Content);\n            }\n            else\n            {\n                if (this.strictMode)\n                {\n                    throw new InvalidOperationException($\"Invalid streaming message type {reply.GetType().Name}\");\n                }\n                else\n                {\n                    yield return reply;\n                }\n            }\n        }\n\n        // process the tool call\n        var streamingChatToolCallUpdates = chunks.Where(c => c.ToolCallUpdates.Count > 0)\n                                                .SelectMany(c => c.ToolCallUpdates)\n                                                .ToList();\n\n        // collect all text parts\n        var textParts = chunks.SelectMany(c => c.ContentUpdate)\n            .Where(c => c.Kind == ChatMessageContentPartKind.Text)\n            .Select(c => c.Text)\n            .ToList();","sourceCodeStart":57,"sourceCodeEnd":93,"githubUrl":"https://github.com/microsoft/autogen/blob/027ecf0a379bcc1d09956d46d12d44a3ad9cee14/dotnet/src/AutoGen.OpenAI/Middleware/OpenAIChatRequestMessageConnector.cs#L57-L93","documentation":"InvalidOperationException thrown in OpenAIChatRequestMessageConnector.ProcessStreamingMessage when strictMode is true and a streamed reply item is not an IMessage<StreamingChatCompletionUpdate> envelope. The connector accumulates StreamingChatCompletionUpdate chunks to reassemble tool calls; strict mode rejects anything else rather than passing it through.","triggerScenarios":"Streaming with OpenAIChatRequestMessageConnector(strictMode: true) where the pipeline yields TextMessageUpdate or other message types instead of raw StreamingChatCompletionUpdate envelopes — e.g. another middleware already transformed the stream.","commonSituations":"Stacking this connector after middleware that converts streaming chunks; piping one OpenAI agent's output into another strict agent's streaming pipeline; strict mode left on while composing middlewares.","solutions":["Use strictMode: false so non-envelope streaming items pass through untouched","Order middlewares so this connector is the innermost (first to see raw SDK updates)","Ensure only MessageEnvelope<StreamingChatCompletionUpdate> items reach it in strict pipelines"],"exampleFix":"// before\nvar connector = new OpenAIChatRequestMessageConnector(strictMode: true);\n// stream contains TextMessageUpdate -> throws\n\n// after\nvar connector = new OpenAIChatRequestMessageConnector(); // lenient passthrough","handlingStrategy":"type-guard","validationCode":"// in a streaming pipeline, confirm items are raw SDK update envelopes before the strict connector sees them\nbool ok = item is IMessage<StreamingChatCompletionUpdate>;","typeGuard":"static bool IsStreamingUpdateEnvelope(IMessage m) => m is IMessage<StreamingChatCompletionUpdate>;","tryCatchPattern":"catch (InvalidOperationException ex) when (ex.Message.StartsWith(\"Invalid streaming message type\")) { /* reorder middlewares or disable strict mode */ }","preventionTips":["Keep the message connector innermost in the middleware chain","Use strictMode: false when composing multiple streaming middlewares","Test the full streaming pipeline, not just the agent"],"tags":["autogen","dotnet","openai","middleware","streaming","strict-mode"],"backgroundTag":null,"analyzedSha":"027ecf0a379bcc1d09956d46d12d44a3ad9cee14","analyzedAt":"2026-08-15T03:38:00.719Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}