microsoft/autogen · error · Exception

No user message found.

Error message

No user message found.

What it means

Thrown by the save-progress middleware in the FSM group-chat getting-started sample. The middleware does msgs.Last() ?? throw new Exception("No user message found.") and requires a non-empty conversation. Despite the variable name, it does not filter by role — any last message satisfies it — so the throw specifically means the middleware was invoked with an empty msgs collection.

Source

Thrown at dotnet/samples/AgentChat/AutoGen.Basic.Sample/GettingStart/FSM_Group_Chat.cs:97

    {
        #region Create_Save_Progress_Agent
        var tool = new FillFormTool();
        var functionCallMiddleware = new FunctionCallMiddleware(
            functions: [tool.SaveProgressFunctionContract],
            functionMap: new Dictionary<string, Func<string, Task<string>>>
            {
                { tool.SaveProgressFunctionContract.Name!, tool.SaveProgressWrapper },
            });

        var chatAgent = new OpenAIChatAgent(
            chatClient: client,
            name: "application",
            systemMessage: """You are a helpful application form assistant who saves progress while user fills application.""")
            .RegisterMessageConnector()
            .RegisterMiddleware(functionCallMiddleware)
            .RegisterMiddleware(async (msgs, option, agent, ct) =>
            {
                var lastUserMessage = msgs.Last() ?? throw new Exception("No user message found.");
                var prompt = $"""
                Save progress according to the most recent information provided by user.

                ```user
                {lastUserMessage.GetContent()}
                ```
                """;

                return await agent.GenerateReplyAsync([lastUserMessage], option, ct);

            });
        #endregion Create_Save_Progress_Agent

        return chatAgent;
    }

    public static async Task<IAgent> CreateAssistantAgent(ChatClient chatClient)
    {

View on GitHub (pinned to 027ecf0a37)

Solutions

  1. Make the user agent the entry point of the graph so at least one message exists before the application agent is activated.
  2. Replace the throw with a graceful reply or skip when msgs is empty.
  3. If 'last user message' is the real intent, use msgs.LastOrDefault(m => m.From == "user") and handle null explicitly.
  4. When unit-testing this agent, seed the history with at least one user TextMessage.

Example fix

// before
var lastUserMessage = msgs.Last() ?? throw new Exception("No user message found.");

// after
var lastUserMessage = msgs.LastOrDefault(m => m.From == "user");
if (lastUserMessage is null)
{
    return new TextMessage(Role.Assistant, "Please provide your application details first.", from: "application");
}
Defensive patterns

Strategy: validation

Validate before calling

var lastUserMessage = msgs.LastOrDefault(m => m.From == "user");
if (lastUserMessage is null)
{
    return new TextMessage(Role.Assistant, "Please provide your application details first.", from: "application");
}

Type guard

static bool HasUserMessage(IEnumerable<IMessage> msgs) =>
    msgs.Any(m => m.From == "user");

Try / catch

try
{
    return await agent.GenerateReplyAsync(msgs, option, ct);
}
catch (Exception ex) when (ex.Message == "No user message found.")
{
    return new TextMessage(Role.Assistant, "No user information yet.", from: "application");
}

Prevention

When it happens

Trigger: The 'application' agent's reply pipeline runs with zero messages in the chat history: the FSM/graph routes to the application agent before the user agent has produced a first message, or the agent is invoked directly in a test with no history.

Common situations: Customizing the FSM transitions and accidentally making 'application' the entry-point agent; tests that call the wrapped agent with an empty list; earlier middleware swallowing all messages.

Related errors


AI-assisted analysis of microsoft/autogen@027ecf0a37 (2026-08-15). Data as JSON: /api/errors/44b19441d0bfe8d8. Report an issue: GitHub.