Abstract
Optimizing LLM-based agentic workflows is challenging for scaling AI capabilities. Current methods rely on coarse, end-to-end evaluation signals and lack fine-grained signals on where to refine, often resulting in inefficient or low-impact modifications. To address these limitations, we propose JudgeFlow, an Evaluation-Judge-Optimization-Update pipeline. We incorporate reusable, configurable logic blocks into agentic workflows to capture fundamental forms of logic. On top of this abstraction, we design a dedicated Judge module that inspects execution traces—particularly failed runs—and assigns rank-based responsibility scores to problematic blocks. These fine-grained diagnostic signals are then leveraged by an LLM-based optimizer, which focuses modifications on the most problematic block in the workflow. Our approach improves sample efficiency, enhances interpretability through block-level diagnostics, and provides a scalable foundation for automating increasingly complex agentic workflows. We evaluate JudgeFlow on mathematical reasoning and code generation benchmarks, where JudgeFlow achieves superior performance and efficiency compared to existing methods.
Introduction
The development of effective Large Language Model (LLM) agents has evolved from simple prompting to the design of complex, multi-step workflows. These workflows often involve intricate combinations of reasoning steps, self-correction loops, and conditional branching. However, as these systems grow in complexity, optimizing them becomes a significant bottleneck.
Traditional optimization methods typically treat agentic workflows as "black boxes," relying on coarse, end-to-end evaluation signals—such as a simple pass/fail score on a final answer. This approach suffers from a severe "credit assignment" problem: if an agent fails a complex task, it is difficult to determine which specific step in the workflow was responsible. Was the initial plan flawed? Did the self-correction mechanism fail to catch an error? Without fine-grained feedback, automated optimizers often struggle to make meaningful improvements, leading to inefficient search processes and sub-optimal results.
The JudgeFlow Framework
To overcome these challenges, we introduce JudgeFlow, a framework designed to provide precise, block-level diagnostic signals for workflow optimization. JudgeFlow operates through a four-stage pipeline: Evaluation, Judge, Optimization, and Update.
Logic Block Abstraction
A key innovation of JudgeFlow is the abstraction of workflows into modular, reusable "logic blocks." Rather than representing workflows as raw code or arbitrary graphs, we define three fundamental logic structures:
- SequenceLogic: Executes a linear series of operators.
- LoopLogic: Iterates through a set of steps until a specific termination condition is met, commonly used for iterative refinement.
- ConditionalLogic: Branches the workflow execution based on the output of an intermediate "test" or evaluation step.
This abstraction provides a "Goldilocks" level of complexity—structured enough for an LLM to reason about, yet flexible enough to represent a wide variety of agentic behaviors.
The Judge Module and Credit Assignment
The heart of the framework is the Judge Module. When a workflow fails on a training instance, the Judge (powered by an LLM) inspects the full execution trace. Unlike previous methods that only look at the final output, the Judge evaluates the performance of each individual logic block.
The Judge assigns a rank-based "responsibility score" to each block, identifying the primary culprit for the failure. To mitigate the inherent noise in individual LLM judgments, JudgeFlow aggregates these scores across the entire training dataset. By applying statistical filtering, the system identifies the block that is consistently the "weakest link" (Bsel).
Targeted Optimization
Once the most problematic block is identified, an LLM-based optimizer is invoked with a specific, localized task: improve Bsel. The optimizer can modify the block's internal instructions, add new operators, or even change the block's logic type. Because the search space is constrained to a single, high-impact area, the optimization process is significantly more efficient and effective than global search methods.
Experimental Evaluation
We evaluated JudgeFlow across a range of demanding benchmarks in mathematical reasoning and code generation.
Benchmarks and Datasets
- Mathematical Reasoning: We utilized GSM8K, MATH, and the highly challenging AIME 2025 dataset.
- Code Generation: Performance was measured on MBPP and HumanEval.
- Transferability: We also conducted cross-benchmark tests, optimizing a workflow on one dataset (e.g., MATH) and evaluating its zero-shot performance on another (e.g., GSM8K) to test robustness.
Key Results
JudgeFlow consistently outperformed state-of-the-art autonomous multi-agent systems, including AFlow and MermaidFlow:
- Accuracy Gains: JudgeFlow achieved an average score of 82.2% across all benchmarks. On the difficult MATH dataset, it delivered a +3.1% absolute improvement (a 5.6% relative gain) over the strongest prior baseline.
- AIME 2025: On the prestigious AIME 2025 benchmark, JudgeFlow reached 44.67% accuracy, surpassing AFlow's 42.00%.
- Efficiency and Interpretability: Training curves demonstrate that JudgeFlow reaches peak performance in fewer iterations. Furthermore, the block-level diagnostics provide clear interpretability, showing exactly which parts of the workflow were improved over time.
Conclusion and Future Work
JudgeFlow demonstrates that the bottleneck in agentic AI optimization is not the generative capability of LLMs, but rather the lack of fine-grained diagnostic feedback. By combining modular logic blocks with a dedicated Judge module, JudgeFlow provides a scalable and efficient path toward automating the design of complex AI agents.
The "Judge" step is remarkably cost-effective, accounting for only about 2% of the total evaluation cost while significantly accelerating the optimization process. Future work will focus on expanding the library of logic blocks and exploring the optimization of even more complex, multi-agent hierarchies.
Summary updated