TL;DR
Optimizing LLM agent workflows is often hindered by coarse, end-to-end evaluation metrics that leave optimizers guessing which part of a system failed. JudgeFlow introduces structured, reusable "logic blocks" (sequential, loops, conditional) combined with a dedicated Judge LLM that performs execution trace diagnostics and rank-orders failure responsibility. By pinpointing the weakest structural block across failed runs, an LLM optimizer can make targeted modifications—achieving superior accuracy and faster search convergence at minimal diagnostic cost.
What Problem Does This Paper Address?
Automating the design of LLM-based agentic workflows typically follows two extremes:
- Directed Acyclic Graphs (DAGs), which are easy to optimize but cannot natively capture dynamic control flow like loops and conditional branching.
- Code-represented workflows, which are maximally expressive but notoriously difficult for error attribution.
When a multi-step workflow fails on a task, existing automated optimizers (like MCTS-based methods) typically receive only binary or coarse end-to-end feedback (e.g., test pass/fail). Without knowing where the failure originated, LLM optimizers resort to blind trial-and-error, exploring ineffective or redundant architectural changes.
Methods
JudgeFlow structures workflow optimization into an Evaluation–Judge–Optimization–Update loop:
- Logic Block Abstractions: Workflows are composed of higher-level modular blocks rather than raw code or flat operators. Three fundamental control patterns are supported:
- SequenceLogic (
seq): Linear operator execution pipeline. - LoopLogic (
for): Iterative execution until a condition or iteration limit is reached. - ConditionalLogic (
cond): Branching logic based on intermediate evaluation results. - Trace-Based Block Judge: For every failed execution, a dedicated Judge module inspects the full execution trace and input/output states of each block. It assigns a rank-based responsibility score ($r_i \in \{1, \dots, M\}$, where 1 indicates the primary culprit).
- Statistical Filtering (
OverallWorst): To overcome the inherent noise and bias of LLM judges, responsibility ranks are summed across all failed instances in the dataset. The block with the lowest cumulative rank sum is selected as the globally weakest component ($B_{sel}$). - Targeted Optimization: An LLM optimizer focuses modifications exclusively on $B_{sel}$ using few-shot failure examples and three discrete operations: Add Block, Remove Block, or Modify Block. Candidate workflows are maintained in a top-$K$ candidate pool and sampled using temperature-scaled softmax scores.
[ Input Query ]
│
▼
[ Execute Workflow ] ───(Passed)──► [ Success ]
│
(Failed)
▼
[ Block-Level Judge ] ──► Trace inspection & rank scoring
▼
[ OverallWorst Aggregation ] ──► Identify bottleneck block (B_sel)
▼
[ LLM Optimizer ] ──► Add / Remove / Modify B_sel
▼
[ Candidate Pool ] ──► Top-K pool update & softmax selection
Datasets
The authors evaluate JudgeFlow on four standard benchmarks across mathematical reasoning and code generation:
- GSM8K: Grade-school math word problems.
- MATH: Challenging high-school competition math.
- MBPP: Mostly Basic Python Problems benchmark.
- HumanEval: Python functional coding benchmark.
- AIME 2024 / 2025: American Invitational Mathematics Examination datasets, used to test complex multi-step reasoning capabilities.
Key Insights and Ideas
- Modular Abstractions Enable Localized Attribution: Encapsulating control flow into standardized blocks provides a stable semantic boundary. It prevents the ambiguity of trying to attribute blame to an unexecuted branch or an ambiguous step in raw code.
- Aggregation Mitigates LLM-as-a-Judge Noise: While individual LLM evaluations of intermediate failure causes can be noisy, aggregated rank distributions over many failures reliably expose systematic architectural bottlenecks.
- Diagnostic Cost is Negligible: Diagnosing failed traces with an LLM judge adds very little overhead. In a GSM8K run, evaluation cost \$0.45 while judging cost \$0.01 (~2% overhead), yielding major sample-efficiency gains.
Key Results
- Benchmark Superiority: Using
gpt-4o-mini-0718, JudgeFlow achieves an average score of 82.2% across the four primary benchmarks, outperforming the previous state-of-the-art framework MermaidFlow (80.8%) and AFlow (78.7%). - MATH: 58.5% (+3.1% over MermaidFlow).
- MBPP: 83.8% (+1.5% over MermaidFlow).
- GSM8K: 93.0%; HumanEval: 93.4%.
- High-Difficulty Reasoning (AIME 2025): Evaluated with
gpt-4.1-mini, JudgeFlow achieves 44.67% accuracy, outperforming AFlow (42.00%) by +2.67%. - Sample Efficiency: JudgeFlow discovers high-performing workflows within the first 5 optimization iterations, whereas baseline methods often plateau or require extensive exploration.
- Ablations: On MBPP, removing the Judge module drops accuracy from 83.8% to 80.6%, and removing Logic Block abstractions drops accuracy to 81.8%.
- Cross-Task Transferability: Workflows optimized on MATH score 92.89% when transferred zero-shot to GSM8K; workflows optimized on MBPP achieve 93.89% pass@1 on HumanEval.
Limitations and Future Work
- Judge Bias and Hallucination: The Judge is powered by an LLM and may occasionally misattribute root causes or exhibit positional bias in complex execution traces.
- Constrained Workflow Complexity: Experiments capped workflows at a maximum of $M \le 3$ blocks to maintain search stability. Scalability to deeper, highly nested architectures remains to be explored.
- Future Directions: Exploring more robust, non-LLM statistical signals, automated unit testing, or formal verification signals alongside the LLM Judge to enhance attribution precision.
Summary updated