{"record":{"id":"58698494d206f92e","repo":"microsoft/autogen","slug":"invalid-streaming-message-type-reply-gettype-na-586984","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.V1/Middleware/OpenAIChatRequestMessageConnector.cs","lineNumber":80,"sourceCode":"                if (update.Content.FunctionName is string functionName)\n                {\n                    currentToolName = functionName;\n                }\n                else if (update.Content.ToolCallUpdate is StreamingFunctionToolCallUpdate toolCallUpdate && toolCallUpdate.Name is string toolCallName)\n                {\n                    currentToolName = toolCallName;\n                }\n                var postProcessMessage = PostProcessStreamingMessage(update, currentToolName);\n                if (postProcessMessage != null)\n                {\n                    yield return postProcessMessage;\n                }\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\n    public IMessage PostProcessMessage(IMessage message)\n    {\n        return message switch\n        {\n            IMessage<ChatResponseMessage> m => PostProcessChatResponseMessage(m.Content, m.From),\n            IMessage<ChatCompletions> m => PostProcessChatCompletions(m),\n            _ when strictMode is false => message,\n            _ => throw new InvalidOperationException($\"Invalid return message type {message.GetType().Name}\"),\n        };","sourceCodeStart":62,"sourceCodeEnd":98,"githubUrl":"https://github.com/microsoft/autogen/blob/027ecf0a379bcc1d09956d46d12d44a3ad9cee14/dotnet/src/AutoGen.OpenAI.V1/Middleware/OpenAIChatRequestMessageConnector.cs#L62-L98","documentation":"OpenAIChatRequestMessageConnector's streaming path only processes MessageEnvelope<StreamingChatCompletionsUpdate> chunks (text deltas and tool-call deltas). Any other streaming message type hits this branch; in strictMode it throws InvalidOperationException, otherwise it passes the message through untouched.","triggerScenarios":"Stacking middlewares that inject custom IMessage types into the streaming pipeline ahead of this connector while it was constructed with strictMode: true, then invoking GenerateStreamingReplyAsync.","commonSituations":"Composing custom streaming middleware (logging, routing, caching) that yields non-update messages; mixing connectors from different provider packages on one agent with strict mode enabled.","solutions":["Construct the connector with strictMode: false (default) so foreign streaming messages pass through","Ensure only MessageEnvelope<StreamingChatCompletionsUpdate> items flow through the OpenAI connector's streaming path, or place custom middleware after it","Have custom middleware wrap its output as updates or defer emission to post-processing"],"exampleFix":"// before\nvar connector = new OpenAIChatRequestMessageConnector(strictMode: true);\nagent = agent.RegisterStreamingMiddleware(connector)\n              .RegisterStreamingMiddleware(myCustomYieldingMiddleware); // throws in strict mode\n\n// after\nvar connector = new OpenAIChatRequestMessageConnector(strictMode: false);\nagent = agent.RegisterStreamingMiddleware(connector)\n              .RegisterStreamingMiddleware(myCustomYieldingMiddleware);","handlingStrategy":"fallback","validationCode":"bool isUpdate = reply is MessageEnvelope<StreamingChatCompletionsUpdate>;\nif (!isUpdate && connectorStrictMode) { /* route around connector */ }","typeGuard":"static bool IsStreamingUpdate(IMessage m) =>\n    m is MessageEnvelope<StreamingChatCompletionsUpdate>;","tryCatchPattern":"catch (InvalidOperationException ex) when (ex.Message.Contains(\"Invalid streaming message type\"))\n{\n    logger.LogError(\"Custom streaming middleware clashed with strict connector; disabling strict mode\");\n    connector = new OpenAIChatRequestMessageConnector(strictMode: false);\n}","preventionTips":["Use strictMode: false when stacking custom streaming middleware","Order custom middleware after the OpenAI connector","Emit only StreamingChatCompletionsUpdate envelopes upstream of the connector in strict mode"],"tags":["openai","streaming","middleware","strict-mode"],"backgroundTag":null,"analyzedSha":"027ecf0a379bcc1d09956d46d12d44a3ad9cee14","analyzedAt":"2026-08-15T03:38:00.719Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}