{"record":{"id":"8092307863c79378","repo":"microsoft/autogen","slug":"userinputrequestedevent-should-not-be-sent-to-the","errorCode":null,"errorMessage":"UserInputRequestedEvent should not be sent to the completion client","messagePattern":"UserInputRequestedEvent should not be sent to the completion client","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"dotnet/src/Microsoft.AutoGen/AgentChat/Abstractions/Messages.cs","lineNumber":581,"sourceCode":"        return new Microsoft.Extensions.AI.ChatMessage(ChatRole.Assistant, this.Content) { AuthorName = this.Source };\n    }\n}\n\n/// <summary>\n/// An event signaling that the user proxy has requested user input. Published prior to invoking the\n/// input callback.\n/// </summary>\npublic class UserInputRequestedEvent : AgentEvent\n{\n    /// <summary>\n    /// Identifier for the user input request.\n    /// </summary>\n    public required string RequestId { get; set; }\n\n    /// <inheritdoc cref=\"AgentEvent.ToCompletionClientMessage(ChatRole)\" />/>\n    public override Extensions.AI.ChatMessage ToCompletionClientMessage(ChatRole role)\n    {\n        throw new Exception(\"UserInputRequestedEvent should not be sent to the completion client\");\n    }\n}\n\npublic static class CompletionChatMessageExtensions\n{\n    /// <summary>\n    /// Flattens a <see cref=\"Microsoft.Extensions.AI.ChatMessage\"/> into a single <see cref=\"Microsoft.Extensions.AI.ChatMessage\"/>\n    /// containing all of the content in the original message as a single string.\n    /// </summary>\n    /// <remarks>\n    /// </remarks>\n    /// <param name=\"msg\">\n    /// The <see cref=\"Microsoft.Extensions.AI.ChatMessage\"/> to flatten.\n    /// </param>\n    /// <returns>\n    /// A new <see cref=\"Microsoft.Extensions.AI.ChatMessage\"/> that is a flattened version of the input.\n    /// </returns>\n    public static Microsoft.Extensions.AI.ChatMessage Flatten(this Microsoft.Extensions.AI.ChatMessage msg)","sourceCodeStart":563,"sourceCodeEnd":599,"githubUrl":"https://github.com/microsoft/autogen/blob/027ecf0a379bcc1d09956d46d12d44a3ad9cee14/dotnet/src/Microsoft.AutoGen/AgentChat/Abstractions/Messages.cs#L563-L599","documentation":"UserInputRequestedEvent is a control-plane AgentEvent emitted to signal that a human-input callback is pending; it carries no model-facing content. Calling ToCompletionClientMessage on it always throws Exception, because converting the chat history for a completion client must never include this event type.","triggerScenarios":"Serializing a chat history/session transcript that contains a UserInputRequestedEvent (e.g. after a human-in-the-loop turn) by indiscriminately mapping every AgentMessage via ToCompletionClientMessage, then sending it to an IChatClient.","commonSituations":"Replaying or resuming saved sessions that include input-request events; building prompt builders that iterate all messages; upgrading from a version where events were absent from histories.","solutions":["Filter out events before conversion: skip items where item is AgentEvent / UserInputRequestedEvent (events are not model-facing by design)","Use the library's provided helpers for building completion-client messages rather than a blanket Select over the history","When persisting sessions, keep the event separately from the model-facing message list you will replay"],"exampleFix":"// before\nvar prompt = session.Messages.Select(m => m.ToCompletionClientMessage(role)).ToList();\n// after\nvar prompt = session.Messages\n    .Where(m => m is not AgentEvent)\n    .Select(m => m.ToCompletionClientMessage(role))\n    .ToList();","handlingStrategy":"type-guard","validationCode":"var modelMessages = history.Where(m => m is not AgentEvent).Select(m => m.ToCompletionClientMessage(role)).ToList();","typeGuard":"static bool IsModelFacing(AgentMessage msg) => msg is not AgentEvent; // events (incl. UserInputRequestedEvent) are never sent to the model","tryCatchPattern":"catch (Exception ex) when (ex.Message.Contains(\"UserInputRequestedEvent\")) { // rebuild the prompt from non-event messages and retry }","preventionTips":["Always filter AgentEvent instances out before converting history to completion-client messages","Keep control-plane events in a separate list from the model-facing transcript when persisting sessions","Use library-provided prompt-building helpers instead of blanket Select over all messages"],"tags":["autogen","human-in-the-loop","chat-history","serialization","csharp"],"backgroundTag":null,"analyzedSha":"027ecf0a379bcc1d09956d46d12d44a3ad9cee14","analyzedAt":"2026-08-15T03:38:00.719Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}