{"record":{"id":"d6491870b56e2122","repo":"microsoft/autogen","slug":"failed-to-review-code-block","errorCode":null,"errorMessage":"Failed to review code block","messagePattern":"Failed to review code block","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"dotnet/samples/AgentChat/AutoGen.Basic.Sample/Example07_Dynamic_GroupChat_Calculate_Fibonacci.cs","lineNumber":221,"sourceCode":"                                From = \"code_reviewer\",\n                            };\n\n                            return msg;\n                        }\n                    }\n                    else\n                    {\n                        var originalContent = reply.GetContent();\n                        var prompt = $@\"Please convert the content to ReviewCodeBlock function arguments.\n\n        ## Original Content\n        {originalContent}\";\n\n                        reply = await innerAgent.SendAsync(prompt, msgs, ct);\n                    }\n                }\n\n                throw new Exception(\"Failed to review code block\");\n            })\n            .RegisterPrintMessage();\n\n        return reviewer;\n    }\n    #endregion create_reviewer\n\n    public static async Task RunWorkflowAsync()\n    {\n        long the39thFibonacciNumber = 63245986;\n        var kernel = DotnetInteractiveKernelBuilder\n            .CreateDefaultInProcessKernelBuilder()\n            .Build();\n\n        var gpt4o = LLMConfiguration.GetOpenAIGPT4o_mini();\n\n        #region create_workflow\n        var reviewer = await CreateReviewerAgentAsync(gpt4o);","sourceCodeStart":203,"sourceCodeEnd":239,"githubUrl":"https://github.com/microsoft/autogen/blob/027ecf0a379bcc1d09956d46d12d44a3ad9cee14/dotnet/samples/AgentChat/AutoGen.Basic.Sample/Example07_Dynamic_GroupChat_Calculate_Fibonacci.cs#L203-L239","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\nreply = await innerAgent.SendAsync(prompt, msgs, ct);\n}\n\nthrow new Exception(\"Failed to review code block\");\n\n// after (bounded retry, then degrade gracefully)\nreply = await innerAgent.SendAsync(prompt, msgs, ct);\n}\n\nvar reviewCall = reply.GetToolCalls().FirstOrDefault(c => c.FunctionName == \"ReviewCodeBlock\");\nif (reviewCall is null)\n{\n    return new TextMessage(Role.Assistant, \"ReviewCodeBlock not produced; ask coder to resend the code block.\", from: \"reviewer\");\n}","handlingStrategy":"try-catch","validationCode":"var reviewCall = reply.GetToolCalls()?.FirstOrDefault(c => c.FunctionName == \"ReviewCodeBlock\");\nif (reviewCall is null)\n{\n    // don't reach the throw: re-prompt once more or degrade gracefully\n    reply = await innerAgent.SendAsync(prompt, msgs, ct);\n}","typeGuard":"static bool HasReviewCodeBlockCall(IMessage reply) =>\n    reply.GetToolCalls()?.Any(c => c.FunctionName == \"ReviewCodeBlock\") == true;","tryCatchPattern":"try\n{\n    return await next(msgs, option, ct);\n}\ncatch (Exception ex) when (ex.Message == \"Failed to review code block\")\n{\n    return new TextMessage(Role.Assistant, \"Could not produce a structured review; ask coder to resend.\", from: \"reviewer\");\n}","preventionTips":["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."],"tags":["autogen","function-calling","group-chat","dotnet","llm-output-parsing"],"backgroundTag":null,"analyzedSha":"027ecf0a379bcc1d09956d46d12d44a3ad9cee14","analyzedAt":"2026-08-15T03:38:00.719Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}