microsoft/autogen · error · Exception
Failed to review code block
Error message
Failed to review code block
What it means
Thrown by the reviewer agent's middleware in the Fibonacci group-chat sample. The middleware expects the inner agent's reply to contain a ReviewCodeBlock tool/function call; it first checks the reply for the function call, and if absent it re-prompts the inner agent to convert the content into ReviewCodeBlock arguments. If that second attempt still does not yield a usable function call, the middleware falls through to throw new Exception("Failed to review code block"). It is a sample-authored parse/validation failure, not an AutoGen core error.
Source
Thrown at dotnet/samples/AgentChat/AutoGen.Basic.Sample/Example07_Dynamic_GroupChat_Calculate_Fibonacci.cs:221
From = "code_reviewer",
};
return msg;
}
}
else
{
var originalContent = reply.GetContent();
var prompt = $@"Please convert the content to ReviewCodeBlock function arguments.
## Original Content
{originalContent}";
reply = await innerAgent.SendAsync(prompt, msgs, ct);
}
}
throw new Exception("Failed to review code block");
})
.RegisterPrintMessage();
return reviewer;
}
#endregion create_reviewer
public static async Task RunWorkflowAsync()
{
long the39thFibonacciNumber = 63245986;
var kernel = DotnetInteractiveKernelBuilder
.CreateDefaultInProcessKernelBuilder()
.Build();
var gpt4o = LLMConfiguration.GetOpenAIGPT4o_mini();
#region create_workflow
var reviewer = await CreateReviewerAgentAsync(gpt4o);View on GitHub (pinned to 027ecf0a37)
Solutions
- Use the model/configuration the sample was written for (a strong tool-calling model such as gpt-4o class) so the inner agent reliably emits the ReviewCodeBlock call.
- Verify the reviewer's inner agent actually has the ReviewCodeBlock function contract registered (FunctionCallMiddleware with the function definition) before the conversion prompt is sent.
- Increase maxTokens / retry on the inner SendAsync so truncated replies don't strip the tool call.
- Make the middleware tolerant: on final failure return a TextMessage verdict (e.g. 'need more info') instead of throwing, so the workflow loop can continue.
Example fix
// before
reply = await innerAgent.SendAsync(prompt, msgs, ct);
}
throw new Exception("Failed to review code block");
// after (bounded retry, then degrade gracefully)
reply = await innerAgent.SendAsync(prompt, msgs, ct);
}
var reviewCall = reply.GetToolCalls().FirstOrDefault(c => c.FunctionName == "ReviewCodeBlock");
if (reviewCall is null)
{
return new TextMessage(Role.Assistant, "ReviewCodeBlock not produced; ask coder to resend the code block.", from: "reviewer");
} Defensive patterns
Strategy: try-catch
Validate before calling
var reviewCall = reply.GetToolCalls()?.FirstOrDefault(c => c.FunctionName == "ReviewCodeBlock");
if (reviewCall is null)
{
// don't reach the throw: re-prompt once more or degrade gracefully
reply = await innerAgent.SendAsync(prompt, msgs, ct);
} Type guard
static bool HasReviewCodeBlockCall(IMessage reply) =>
reply.GetToolCalls()?.Any(c => c.FunctionName == "ReviewCodeBlock") == true; Try / catch
try
{
return await next(msgs, option, ct);
}
catch (Exception ex) when (ex.Message == "Failed to review code block")
{
return new TextMessage(Role.Assistant, "Could not produce a structured review; ask coder to resend.", from: "reviewer");
} Prevention
- Use tool-call-capable models for reviewer agents — weak models frequently skip function calls.
- Verify the function contract is registered on the inner agent before relying on tool-call extraction.
- Bound retries and degrade to a text verdict instead of throwing from middleware.
When it happens
Trigger: Two consecutive failures: (1) the coder's reply does not trigger the model to emit the ReviewCodeBlock function call, and (2) the explicit 'Please convert the content to ReviewCodeBlock function arguments' re-prompt also returns a reply without a ReviewCodeBlock call (or with arguments the connector cannot extract). Typical with weaker models, truncated replies, or an overloaded/incorrect chat client behind the reviewer.
Common situations: Swapping the sample's model for a smaller/cheaper one that rarely emits tool calls; function-call schemas not registered on the inner agent; reply truncated by max tokens so the tool call is missing; rate-limit or auth issues making the inner reply an error message instead of a tool call.
Related errors
- No name is returned.
- ToolCallMessage is not supported when message.From is not th
- No coder message found
- No user message found.
- Please set OPENAI_API_KEY environment variable.
AI-assisted analysis of microsoft/autogen@027ecf0a37 (2026-08-15).
Data as JSON: /api/errors/d6491870b56e2122.
Report an issue: GitHub.