TL;DR
AgentFactory is a novel framework that automates the creation of LLM agent systems by jointly optimizing both the underlying foundation models (via targeted fine-tuning) and their workflow structures (via executable code). By balancing multiple objectives like accuracy, cost, and latency, it consistently outperforms manual designs and workflow-only optimizers, delivering massive performance leaps in specialized domains like medicine and finance.
What Problem Does This Paper Address?
Building effective LLM-based agent systems currently requires heavy manual engineering to define roles, prompts, and interaction patterns (e.g., ChatDev, MetaGPT). While recent frameworks have attempted to automate this process, they suffer from two major limitations:
- Fixed Underlying Models: Existing automated methods (like ADAS or AFlow) only optimize prompts or workflow structures, treating the underlying LLM as a fixed black box. This leaves a significant "domain adaptation gap" when agents face highly specialized tasks.
- Single-Metric Focus: They typically optimize purely for accuracy, ignoring real-world deployment constraints such as inference costs and response latency.
AgentFactory addresses these gaps by co-optimizing the models and the workflows simultaneously within a multi-objective framework.
Methods
The authors formulate agentic system design as a multi-objective optimization problem over a joint search space of model parameters and workflow representations. Instead of relying on traditional gradient descent, AgentFactory leverages a powerful LLM as an optimizer guided by a specialized meta-prompt.
The optimization proceeds through an iterative, three-stage pipeline:
- Planning: The LLM optimizer reviews the historical trajectory of previous attempts and synthesizes a structured plan containing strategic insights, model specifications, and workflow designs.
- Tuning: Based on the plan, a fine-tuning backend (OpenRLHF) automatically modifies the foundation models using domain-specific datasets and optimized hyperparameters (e.g., learning rate, batch size).
- Workflow Design: The system generates Turing-complete, executable Python code to define complex control flows, tool utilization, and agent interactions.
Datasets
The framework was evaluated across eight public benchmarks spanning five distinct domains:
- General Reasoning: MMLU, DROP
- Coding: HumanEval, MBPP
- Mathematics: GSM8K, MATH (Difficulty Level 5)
- Medicine: MedQA
- Finance: FinEval
For the automated model-tuning phase, AgentFactory was provided with descriptive triples of curated datasets, including CodeBagel (Python segments), MathInstruct, and IndustryInstruction (Health-Medicine and Finance-Economics subsets).
Key Insights and Ideas
- The Joint Optimization Advantage: Workflow tweaks can only go so far. True domain adaptation requires modifying both the "brain" (the model) and the "procedure" (the workflow).
- Cross-Domain Synergy: In a case study on FinEval, the LLM optimizer realized that financial reasoning errors were frequently caused by underlying calculation mistakes. It strategically injected mathematical instruction data into the financial model's fine-tuning mix, unlocking a major performance breakthrough.
- Cost-Aware Pareto Optimization: Instead of blindly chasing accuracy at all costs, AgentFactory successfully navigates multi-objective trade-offs. It can meet strict budget constraints by streamlining workflows or strategically swapping in cheaper models (like GPT-4o-mini) where high-end models aren't strictly necessary.
Key Results
- State-of-the-Art Performance: AgentFactory achieved an average 9.1% performance improvement over existing automated design methods across all benchmarks.
- Domain-Specific Jumps: The gains were particularly massive in specialized areas, yielding a 19.6% improvement on MedQA and an 18.7% improvement on FinEval compared to workflow-only methods.
- Dramatic Cost Reductions: Through its multi-objective optimization strategy, the framework reduced average inference costs by up to 68% while maintaining competitive operational performance.
- Optimizer Robustness: Testing different LLMs as the core optimizer revealed that models of comparable capability (like GPT-4o and Claude-3.5-Sonnet) produced similarly high-quality optimization outcomes.
Limitations and Future Work
- Computational Complexity: Fine-tuning foundation models iteratively is highly resource-intensive. To maintain efficiency, the authors had to impose strict constraints (maximum 20K samples and a 4-hour time limit per tuning session).
- Dependency on Optimizer Strength: The framework's success is tightly coupled with the capabilities of the LLM used as the optimizer. Utilizing smaller or less capable models (like GPT-4o-mini) as the optimizer led to a noticeable drop in the quality of the generated agent systems.
Summary updated