microsoft/autogen · error · Exception

No coder message found

Error message

No coder message found

What it means

Thrown inside the runner agent's middleware in the dynamic group-chat coding sample. The middleware does msgs.LastOrDefault(x => x.From == "coder") ?? throw new Exception("No coder message found") — it requires at least one prior message in the conversation sent by an agent named "coder", because the runner's whole job is to extract and execute the ```python code block from the coder's latest reply. If the runner is invoked before the coder has ever spoken (or the coder agent has a different name), the lookup returns null and this exception fires.

Source

Thrown at dotnet/samples/AgentChat/AutoGen.Basic.Sample/Example04_Dynamic_GroupChat_Coding_Task.cs:147

            ```review
            comment: The code is inside main function. Please rewrite the code in top level statement.
            result: REJECTED
            ```

            """)
            .RegisterMessageConnector()
            .RegisterPrintMessage();

        // create runner agent
        // The runner agent will run the code block from coder's reply.
        // It runs dotnet code using dotnet interactive service hook.
        // It also truncate the output if the output is too long.
        var runner = new DefaultReplyAgent(
            name: "runner",
            defaultReply: "No code available, coder, write code please")
            .RegisterMiddleware(async (msgs, option, agent, ct) =>
            {
                var mostRecentCoderMessage = msgs.LastOrDefault(x => x.From == "coder") ?? throw new Exception("No coder message found");

                if (mostRecentCoderMessage.ExtractCodeBlock("```python", "```") is string code)
                {
                    var result = await kernel.RunSubmitCodeCommandAsync(code, "python");
                    // only keep the first 500 characters
                    if (result.Length > 500)
                    {
                        result = result.Substring(0, 500);
                    }
                    result = $"""
                    # [CODE_BLOCK_EXECUTION_RESULT]
                    {result}
                    """;

                    return new TextMessage(Role.Assistant, result, from: agent.Name);
                }
                else
                {

View on GitHub (pinned to 027ecf0a37)

Solutions

  1. Ensure the conversation order puts at least one coder reply in msgs before the runner is invoked (in this sample the workflow/graph must transition coder -> runner).
  2. If you renamed the coder agent, keep From == "coder" consistent: the middleware matches on the literal agent name string.
  3. For a more resilient runner, replace the throw with the agent's own default reply ('No code available, coder, write code please') so the chat can recover instead of crashing.
  4. When testing the runner in isolation, seed msgs with a synthetic MessageEnvelope/TextMessage { From = "coder" } containing a ```python block.

Example fix

// before
var mostRecentCoderMessage = msgs.LastOrDefault(x => x.From == "coder") ?? throw new Exception("No coder message found");

// after (fall back to the agent's default reply instead of crashing the group chat)
var mostRecentCoderMessage = msgs.LastOrDefault(x => x.From == "coder");
if (mostRecentCoderMessage?.ExtractCodeBlock("```python", "```") is not string code)
{
    return new TextMessage(Role.Assistant, "No code available, coder, write code please", from: "runner");
}
Defensive patterns

Strategy: validation

Validate before calling

var mostRecentCoderMessage = msgs.LastOrDefault(x => x.From == "coder");
var code = mostRecentCoderMessage?.ExtractCodeBlock("```python", "```");
if (code is null)
{
    // no coder turn yet: ask the coder instead of executing
    return new TextMessage(Role.Assistant, "No code available, coder, write code please", from: "runner");
}

Type guard

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

Try / catch

try
{
    return await next(msgs, option, ct);
}
catch (Exception ex) when (ex.Message == "No coder message found")
{
    return new TextMessage(Role.Assistant, "No code available, coder, write code please", from: "runner");
}

Prevention

When it happens

Trigger: The runner agent receives a GenerateReplyAsync/SendAsync call while the message history contains zero messages with From == "coder" — e.g. the group-chat workflow routes to the runner first, a previous coder turn was never produced (coder error/termination), or the coder agent was instantiated with a name other than exactly "coder".

Common situations: Modifying the sample's group-chat order or graph transitions so runner executes before coder; renaming agents during customization; coder's reply being dropped by other middleware; running the runner agent standalone for testing with an empty message list.

Related errors


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