# AgentFly

> Scalable and extensible reinforcement learning for LM agents.

- **Type:** MCP server
- **Install:** `agentstack add mcp-agent-one-lab-agentfly`
- **Verified:** Yes — security-reviewed for prompt injection and unsafe behavior
- **Seller:** [Agent-One-Lab](https://agentstack.voostack.com/s/agent-one-lab)
- **Installs:** 0
- **Category:** [AI & ML](https://agentstack.voostack.com/c/ai-and-ml)
- **Latest version:** 0.1.0
- **License:** Apache-2.0
- **Upstream author:** [Agent-One-Lab](https://github.com/Agent-One-Lab)
- **Source:** https://github.com/Agent-One-Lab/AgentFly

## Install

```sh
agentstack add mcp-agent-one-lab-agentfly
```

Requires the [AgentStack CLI](https://agentstack.voostack.com/docs/cli). Works with Claude Code, Cursor, and any MCP-compatible agent.

## About

# 🪽AgentFly: Training scalable LLM agents with RL (multi-turn, async tools/rewards, multimodal)

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.

## News

**4/2026 SWE and SimuScene**: Added SWE-Bench style (R2E-Gym) tasks and [SimuScene](https://arxiv.org/abs/2602.10840) training.

**3/2026 Resource System**: Added a resource system for better environment and container management, and integrated SWE like tasks training.

**12/2025 Method-Based Tool**: Support using `@tool` for a class method

**12/2025 Verl Update**: Updated verl to 0.6.x version.

**08/2025 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](docs/examples/predefined_training_examples.md) for ready-to-use scripts.

---

**08/2025 Chat Template System**: A flexible framework for creating conversation templates with multi-model support, vision capabilities, and tool integration. [Learn more →](docs/chat_template/)

## Installation
**Option 1**: One-line Installation:
```
bash install.sh # Assume conda with python3.12.x
```
**Option 2**: Customized Installation

Please refer to [installation.md](docs/start/installation.md) for custmoized installation.

## Tasks

| Task | Model | Report | Status |
|------|-------|--------|--------|
| SearchR1 | Qwen2.5 | [report](https://wandb.ai/AgentRL/Open/reports/SearchR1--VmlldzoxNjYzNzQ0Ng) | ✅ |
| WebShop | Qwen2.5 | [report](https://api.wandb.ai/links/AgentRL/kpmsvggh) | ✅ |
| ScienceWorld | Qwen3-4B-Instruct | [report](https://api.wandb.ai/links/AgentRL/f99omj98) | ✅ |
| SWE | Qwen3-32B | [report](https://wandb.ai/AgentRL/Resource/reports/SWE-OS---VmlldzoxNjUzNjk0Mw?accessToken=x4co1e22ddhkm1qjo791a9blmvt4uqz9jmgytybkq4xtgfwt0u8jjx28wpqcsqex) | ✅ (on going) |
| SimuScene | SFT DeepSeek-R1-Distill-Qwen |[report](https://wandb.ai/AgentRL/SimuScene/reports/SimuScene--VmlldzoxNjYzNzYzMg?accessToken=qe00f9dy59hiu2uyndyn22xl141s37sybnxlp5e5ybryqqahao5mvyra0sbmlf9v) | ✅ |
 
## Quick Start
```python
# Really small example to build an agent and run
import asyncio

from agentfly.agents import HFAgent
from agentfly.tools import calculator

async def main():
    messages = [{"role": "user", "content": "What is the result of 1 + 1?"}]
    agent = HFAgent(
        model_name_or_path="Qwen/Qwen2.5-3B-Instruct",
        tools=[calculator],
        template="qwen2.5",
        backend_config={"backend": "async_vllm"},
    )
    result = await agent.run(
        messages=messages,
        max_turns=3,
        num_chains=1,
    )

    print(result.trajectories)
    print(result.rewards)

asyncio.run(main())
```

## Features
### 1. Multi-Chain Agent Rollout and Multi-Turn Training
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](https://github.com/volcengine/verl).

### 2. Simple Tool and Reward Integration
Define tools and rewards, which can be used directly by agents.
```python
@tool(name=...)
def customized_tool(...):
    ...

@reward(name=...)
def customized_reward(...):
    ...

agent = HFAgent(
    model_name_or_path=model_name,
    tools=[customized_tool],
    reward=customized_reward,
    backend_config={"backend": "async_vllm"},
)
```

### 3. Easy Development
Decoupled agent and training module. Simply customize your own agent, which can directly be applied to training.

## Training
### Run Example Training
Suppose you are in a compute node (with 8 GPUs). We have prepared training scripts for different tasks and tools in `examples/train_scripts/`. The scripts can download prepared datasets and run training.

Run RL training of code_interpreter:
```python
bash examples/train_scripts/train_example.sh
```
### Customized Training
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.

#### 1. Data Format:
Data should be a json file, which contain a list of dicts with the following keys:
```json
[
    {
        "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:
```json
{
    "messages": [
        {"role": "user", "content": [{"type": "text", "text": question}]}
    ]
    "optional_field1": ...
    "optional_field2": ...
    ...
}
```
#### 2. Tools & Rewards
You can use any existing tool, which is in [documentation](https://agentfly.readthedocs.io/), or define a tool by decorating it with `@tool`. The output should eighther be a string, or a dictionary containing `observation` as a key.
```python
@tool(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.

```python
@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](https://agentfly.readthedocs.io/).

#### 3. Agents
You can use existing agents, 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](https://agentfly.readthedocs.io/) for more details.

```python
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
        ...
```

## Demo
1. The following shows an example of WebShop agent.

2. What does the training look like. During training, the resource system will dynamically allocate environments.

3. Monitoring training on [WANDB](https://wandb.ai/). Items include number of turns for each step, numer of tool calls, allocated environments.

https://github.com/user-attachments/assets/b8f42534-8d40-48a0-a264-f378e479bb3a

## Contribute & Discussion
[WeChat|微信](https://agent-one-lab.github.io/assets/agentfly/wechat.jpg)

[Discord](https://discord.gg/Ze5Z9QhhJ3)

## Cite
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},
}
```

## Source & license

This open-source MCP server is cataloged on AgentStack and links to its original source — we do not rehost the code.

- **Author:** [Agent-One-Lab](https://github.com/Agent-One-Lab)
- **Source:** [Agent-One-Lab/AgentFly](https://github.com/Agent-One-Lab/AgentFly)
- **License:** Apache-2.0

Install and usage instructions live in the source repository linked above.

## Pricing

- **Free** — Free

## Security capabilities

Automated source analysis of v0.1.0 — what this tool can access:

- **Network access:** no
- **Filesystem access:** no
- **Shell / process execution:** no
- **Environment & secrets:** no
- **Dynamic code execution:** no

*"Yes" means the capability is present in the source — more access means more to trust, not that it is unsafe.*


## Versions

- **0.1.0** — security scan: passed — Imported from the upstream source.

## Links

- Listing page: https://agentstack.voostack.com/l/mcp-agent-one-lab-agentfly
- Seller: https://agentstack.voostack.com/s/agent-one-lab
- Browse the marketplace: https://agentstack.voostack.com/browse

---
Listed on AgentStack — the marketplace for AI agent skills and MCP servers. Every listing is security-reviewed. Creators keep 70%.
