Abstract
The rapid development of interactive and autonomous AI systems signals our entry into the agentic era. Training and evaluating agents on complex agentic tasks such as software engineering and computer use requires not only efficient model computation but also sophisticated infrastructure capable of coordinating vast agent-environment interactions. However, no open-source infrastructure can effectively support large-scale training and evaluation on such complex agentic tasks. To address this challenge, we present MegaFlow, a large-scale distributed orchestration system that enables efficient scheduling, resource allocation, and fine-grained task management for agent-environment workloads. MegaFlow abstracts agent training infrastructure into three independent services (Model Service, Agent Service, and Environment Service) that interact through unified interfaces, enabling independent scaling and flexible resource allocation across diverse agent-environment configurations. In our agent training deployments, MegaFlow successfully orchestrates tens of thousands of concurrent agent tasks while maintaining high system stability and achieving efficient resource utilization. By enabling such large-scale agent training, MegaFlow addresses a critical infrastructure gap in the emerging agentic AI landscape.
Introduction
As AI transitions from simple Large Language Model (LLM) prompting to autonomous agents capable of complex software engineering and computer use, infrastructure requirements have shifted dramatically. Training an agent to resolve a bug in a massive GitHub repository is no longer just a matter of GPU compute; it requires a secure, isolated sandbox—typically a container—where the agent can execute code, modify files, and verify its work.
Existing infrastructure faces three critical bottlenecks in this new paradigm:
- Security and Isolation: Traditional training clusters are not designed to securely manage thousands of arbitrary, potentially unstable agent-generated containers.
- Storage Scalability: Benchmarks like SWE-bench require over 25TB of storage for environment images, creating significant management overhead.
- Coordination Throughput: Centralized systems often fail to manage the simultaneous traffic of thousands of agents and environments, leading to network congestion and resource waste.
System Architecture
MegaFlow addresses these challenges through a Three-Service Architecture, which decouples the monolithic agent-training loop into modular, independently scalable components.
- Model Service: Handles the heavy lifting of inference for action generation and training for parameter updates.
- Agent Service: Acts as the central logic hub, managing task state, collecting trajectories, and coordinating interactions between the model and the environment.
- Environment Service: Manages the physical execution of tasks within isolated, secure containers.
MegaFlow utilizes a "many-small-instances" approach, scheduling thousands of lightweight, standardized instances rather than a few high-specification machines. It employs a Hybrid Execution Model, supporting both ephemeral tasks (fresh containers for perfect isolation) and persistent tasks (reused environments to minimize startup time). The entire system is event-driven, leveraging cloud-native signals to track task progress without the overhead of constant polling.
Evaluation and Benchmarks
The system was validated using a comprehensive suite of software engineering benchmarks:
- SWE-bench & SWE-Gym: Real-world GitHub issue-solving tasks.
- SWE-rebench & SWE-smith: Variants focused on decontaminated evaluation and data synthesis.
- Multi-SWE-Bench: Multilingual and multi-repository software tasks.
- Internal Synthesized Data: A collection of over 30,000 internally generated repair tasks used for Reinforcement Learning (RL) training.
Key Results and Insights
MegaFlow demonstrates significant improvements in scalability, cost, and stability:
- Massive Concurrency: The system successfully managed over 10,000 concurrent agent tasks with high stability.
- Cost Efficiency: At a scale of 2,000 concurrent tasks, MegaFlow achieved a 32% cost reduction compared to traditional high-spec centralized approaches.
- Performance Stability: While centralized systems saw execution times degrade as task numbers increased due to resource contention, MegaFlow maintained a consistent execution time of approximately 100 minutes across all scales.
- Startup Speed: In persistent mode, environment startup time remained under 1 minute, whereas centralized systems spiked to 13 minutes due to the "thundering herd" effect of simultaneous container image pulls.
Conclusion and Future Work
MegaFlow addresses a critical infrastructure gap in the agentic AI landscape by prioritizing coordination and modularity over raw compute. Future work will focus on:
- Complex Dependencies: Orchestrating tasks that require multiple interacting environments or complex service dependencies.
- Multi-Cloud Deployment: Expanding the current Alibaba Cloud implementation to a provider-agnostic multi-cloud orchestration system.
- Dynamic Mode Switching: Developing logic to automatically switch between ephemeral and persistent execution modes based on real-time task characteristics to further optimize the balance between isolation and speed.
Summary updated