AgentFly is an extensible framework for building LLM agents with reinforcement learning. It supports multi-turn training by adapting traditional RL methods with token-level masking. It features a decorator-based interface for defining tools and reward functions, enabling seamless extension and ease of use. To support high-throughput training, it implemented asynchronous execution of tool calls and reward computations, and design a centralized resource management system for scalable environment coordination. A suite of prebuilt tools and environments are provided.
Multi-Modal (Vision) Agent Training Support - Thanks to the powerful template system, AgentFly now supports training vision-language agents! ๐
Train agents that can see and understand visual content, including GUI automation and image-based QA. See our predefined training examples for ready-to-use scripts.
New: Chat Template System - A flexible framework for creating conversation templates with multi-model support, vision capabilities, and tool integration. Learn more โ
Clone and initialize the project:
git clone https://github.com/Agent-One-Lab/AgentFly
cd AgentFly
git submodule init
git submodule update
Basic python packages installation:
pip install -e .
pip install -e '.[verl]' --no-build-isolation
Optionally, some tools actually require some additional dependencies:
Some of our tools & environments are managed by enroot backend. To use them, please install enroot (sudo required). Such tools include code_interpreter, retrieval, webshop, alfworld, sciencworld.
Search requires redis to cache results, an optional way to install with conda:
conda install conda-forge::redis-server==7.4.0
To support algorithms like GRPO, Reinforce++, we design multi-chain inference, enabling agents to solve one task with multiple paths at the same time. We build RL computation and update LLMs in multi-turn manner by applying token masks. The training is based on verl.
Define tools and rewards, which can be used directly by agents.
@tool(name=...)
def customized_tool(...):
...
def custmozed_reward(...):
...
agent = ReactAgent(
model_name,
tools=[customized_tool],
reward=customized_reward
)
Decoupled agent and training module. Simply customize your own agent, which can directly be applied to training.
Suppose you are in a compute node (with 8 gpus). We have prepared some training scripts for different tasks and tools in verl/examples/run_agents/
. The script will try to download our prepared datasets and run training.
Run RL training of code_interpreter:
cd verl
bash examples/run_agents/run_code_agent.sh
To customize your own training, you need to prepare: 1. Datasets. 2. Define or use existing tools. 3. Define or use existing rewards. 3. Define your own agents or use an existing type of agent.
Data should be a json file, which contain a list of dicts with the following keys:
[
{
"question": ...
"optional_field1": ...
"optional_field2": ...
...
}
]
During training, question
will be used to format the input messages, while other fields can be used in reward function. An example message that are put into the agent looks like this:
{
"messages": [
{"role": "user", "content": [{"type": "text", "text": question}]}
]
"optional_field1": ...
"optional_field2": ...
...
}
You can use any existing tool, which is in documentation, or define a tool by decorating it with @tool
. The output should eighther be a string, or a dictionary containing observation
as a key.
@reward(name="customized_tool")
def customized_tool(arg1, arg2):
# tool logic here
Define your reward function or use an existing one. The reward function can accept prediction
and trajectory
as the argument, which is the agent's final response and the whole trajectory. Other fields will also be given if you defined them in dataset. To use them, simply put these fields as arguments in reward function.
@reward(name="customized_reward")
def customized_reward(prediction, trajectory, optional_field1, optional_field2):
# calculate reward
...
For stateful tools and rewards that hold environment instances, please refer to documentation.
You can use existing code agent, react agent, or customize an agent. To customize an agent, the agent class must inherit BaseAgent
, which handles tool calling, chain rollout. You can custom the generate
and parse
function. Refer to documentation for more details.
class CustomizedAgent(BaseAgent):
def __init__(self,
**kwargs
)
super().__init__(**kwargs)
async def generate_async(self, messages_list: List[List[Dict]], **args):
return await self.llm_engine.generate_async(messages_list, **args)
def parse(self, responses: List(str), tools):
# parse responses into tool calls
...
-
The following shows an example of WebShop agent.
-
What does the training look like. During training, the resource system will dynamically allocate environments.
-
Monitoring training on WANDB. Items include number of turns for each step, numer of tool calls, allocated environments.
demo.mp4
Reward curves on Qwen2.5-Instruct 3B and 7B models.
If you used our code or find it helpful, please cite:
@misc{wang2025agentfly,
title={AgentFly: Extensible and Scalable Reinforcement Learning for LM Agents},
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},
year={2025},
eprint={2507.14897},
archivePrefix={arXiv},
primaryClass={cs.AI},
url={https://arxiv.org/abs/2507.14897},
}