AgentFly: Extensible and Scalable Reinforcement Learning for LM Agents

Renxi Wang, Rifo Ahmad Genadi, Bilal El Bouardi, Yongxin Wang, Fajri Koto, Zhengzhong Liu, Timothy Baldwin, Haonan LiarXiv 2025 · DOI

Abstract

Reinforcement Learning (RL) presents a promising avenue for enhancing the reasoning and tool-use capabilities of Large Language Model (LLM) agents. However, existing frameworks often struggle with the complexities of multi-turn interactions, rollout bottlenecks, and rigid architectures. We introduce AgentFly, an open-source framework designed for scalable and developer-friendly RL training of agents. By employing token-level masking, asynchronous chain-based rollouts, and centralized resource management, AgentFly enables efficient training across diverse environments. Our results demonstrate significant performance gains, particularly as model size scales, and highlight the framework's ability to reduce hallucinations and foster meta-strategy learning.

Introduction

While LLMs excel at instruction following, their transition into autonomous agents capable of complex tool-use typically relies on prompt engineering or Supervised Finetuning (SFT). RL offers a path toward higher reasoning, yet its application to agentic workflows faces three primary hurdles: the complexity of multi-turn "thought-action-observation" chains, the computational bottleneck of thousands of external tool calls during rollouts, and the lack of flexible frameworks for defining custom tools and rewards. AgentFly addresses these challenges by providing a decoupled, high-performance infrastructure built on top of the verl library.

Framework Architecture

AgentFly introduces a specialized "Agent Module" to handle the unique requirements of agentic workflows. The architecture is designed to be both scalable and extensible, separating the agent logic from the RL training core.

The AgentFly framework architecture, featuring the Agent Module, RL controller, and Resource Manager.

Key technical innovations include:

  • Token-level Masking: To manage multi-turn trajectories, AgentFly uses a masking strategy that ensures the model only calculates losses based on generated tokens, ignoring environment observations. This prevents the model from being penalized for external inputs.
  • Asynchronous Chain-based Rollout: Utilizing the vLLM engine, the framework implements non-blocking tool calls and asynchronous execution to maximize generation speed and throughput.
  • Centralized Resource Management: For stateful environments (e.g., web browsers), AgentFly manages a pool of instances, allowing for massive parallelism without resource conflicts.
  • Developer-Friendly Interface: Simple @tool and @reward decorators allow researchers to define behaviors in standard Python, abstracting away the underlying distributed training logic.

Experimental Evaluation

We validated AgentFly across six diverse environments: Code Interpreter (math via Python), Search & Retrieve (Google/Wikipedia), WebShop (e-commerce navigation), ALFWorld (household tasks), and ScienceWorld (text-based experiments). We trained Qwen2.5-Instruct (3B and 7B) models using PPO, REINFORCE++, GRPO, and RLOO algorithms.

Key Results

Our experiments reveal that RL training significantly enhances agent performance across all tested environments.

Performance comparison of 3B and 7B models across various agentic environments during RL training.
  • Scaling Matters: The 7B models exhibited substantially higher performance gains from RL compared to 3B models, especially in complex tasks like ScienceWorld and ALFWorld.
  • Algorithm Stability: While all algorithms showed improvement, REINFORCE++ was slightly less stable in multi-turn settings, likely due to interactions between masking and the advantage function.
  • Operational Efficiency: The asynchronous resource management maintained high throughput even with heavy, containerized code executors.

Discussion and Insights

Beyond raw performance, we observed several qualitative improvements in agent behavior:

  • Meta-Strategy Learning: In environments like ALFWorld, agents learned to use "meta-tools" (e.g., requesting valid command lists) to narrow their search space effectively.
  • Reduction in Hallucinations: RL training led to a marked decrease in hallucinated tool calls or incorrect formatting.
  • Stability vs. Horizon: We noted a trade-off where longer trajectories enabled more complex problem-solving but increased gradient noise, impacting training stability.

Conclusion and Future Work

AgentFly provides a robust foundation for scaling RL for LM agents. While smaller models still face "cold start" challenges in highly complex tasks, the framework successfully demonstrates the power of RL in refining agentic reasoning. Future work will focus on improving the warm-up phase for smaller models, exploring longer trajectory horizons, and extending the framework to multi-agent coordination scenarios.

Summary updated

BibTeX
@misc{wang2025agentfly,
  author = {Renxi Wang and Rifo Ahmad Genadi and Bilal El Bouardi and Yongxin Wang and Fajri Koto and Zhengzhong Liu and Timothy Baldwin and Haonan Li},
  title = {{AgentFly: Extensible and Scalable Reinforcement Learning for LM Agents}},
  year = {2025},
  eprint = {2507.14897},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2507.14897},
}
Figure