Skip to content

Commit a79804e

Browse files
authored
[feat] Add recipes and documentation for 4 agentic scene (#97)
1 parent 6bb4991 commit a79804e

148 files changed

Lines changed: 10496 additions & 221 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2025 russwest404
3+
Copyright (c) 2025 Agent-R1 Teams
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

README.md

Lines changed: 33 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ Unlike single-turn RL pipelines that treat interaction as one growing prompt-res
1616

1717
## News
1818

19+
- [2026.05.29] **Agent-R1 integrates [StepPO](https://arxiv.org/abs/2604.18401), expands recipe coverage, and releases processed data.** The framework now includes StepPO-style training support together with recipe integrations for HotpotQA, ALFWorld, WebShop, and academic paper search. Processed datasets are available on [ModelScope](https://www.modelscope.cn/datasets/Melmaphother/Agent-R1-data).
1920
- [2026.03.23] **Agent-R1 v0.1.0 is the first official release of the refactored architecture.** It introduces the **Step-level MDP** foundation and new **Layered Abstractions**. The previous implementation is archived on the `legacy` branch.
2021
- [2026.03.04] **[Claw-R1](https://agentr1.github.io/Claw-R1/) is released.** It extends Agentic RL to general agents such as OpenClaw through a middleware-style design. See [AgentR1/Claw-R1](https://github.com/AgentR1/Claw-R1).
2122

@@ -25,7 +26,7 @@ Unlike single-turn RL pipelines that treat interaction as one growing prompt-res
2526
- [2026.01.10] **PaperScout** is released: an autonomous academic paper search agent trained with Agent-R1 and Proximal Sequence Policy Optimization. Read the paper [here](https://arxiv.org/abs/2601.10029).
2627
- [2025.11.18] The Agent-R1 technical report is released on [arXiv](https://arxiv.org/abs/2511.14460).
2728
- [2025.05.06] Tool environments are redesigned to support more flexible agent-tool interaction patterns.
28-
- [2025.05.06] GRPO and REINFORCE++ training crashes caused by NaN values are fixed. See [issue #30](https://github.com/0russwest0/Agent-R1/issues/30).
29+
- [2025.05.06] GRPO and REINFORCE training crashes caused by NaN values are fixed. See [issue #30](https://github.com/0russwest0/Agent-R1/issues/30).
2930
- [2025.04.01] Basic inference scripts and an interactive chat interface are added.
3031
- [2025.03.18] Multi-modal support is added for vision-language model agents.
3132
- [2025.03.18] `verl` is moved to a git submodule and Agent-R1 extensions are separated from upstream code.
@@ -57,10 +58,10 @@ Agent-R1 uses layered abstractions so new tasks can reuse the same trainer witho
5758

5859
| Layer | Responsibility | When to Use |
5960
|---|---|---|
60-
| `AgentFlowBase` | Full control over prompt construction, model calls, and step assembly. | Custom workflows or experimental agent logic. |
61-
| `AgentEnvLoop` | The main multi-step loop connecting model generation with environment `reset()` / `step()`. | Most agentic RL tasks. |
62-
| `AgentEnv` | Task environment interface returning observations, rewards, termination, and metadata. | When your task has state transitions. |
63-
| `ToolEnv` | Built-in environment for parsing tool calls, executing tools, and feeding observations back. | Tool-augmented tasks such as GSM8K-tool. |
61+
| `AgentFlowBase` | Full control over prompt construction, model calls, branching, context management, and step assembly. | Complex custom agents that do not fit a standard environment loop. |
62+
| `AgentEnvLoop` | Generic loop connecting model generation with an environment's `reset()` / `step()` interface. | Agent tasks that can be modeled as environment interaction, including traditional RL-style environments. |
63+
| `AgentEnv` | Task environment interface returning observations, rewards, termination, and metadata. | Implementing the full environment logic for `AgentEnvLoop`. |
64+
| `ToolEnv` | Built-in environment for standard multi-turn tool calling. | Tool-augmented tasks where you only need to define tools. |
6465
| `BaseTool` | Standard interface for registering executable tools. | Adding calculators, search tools, APIs, or task-specific checkers. |
6566

6667
The main loop is:
@@ -79,30 +80,44 @@ Agent-R1 uses the same environment setup as [verl](https://verl.readthedocs.io/e
7980
The recommended path is:
8081

8182
1. Read the [Getting Started](https://agentr1.github.io/Agent-R1/getting-started/) page for the minimal setup flow.
82-
2. Use [`examples/data_preprocess/gsm8k.py`](examples/data_preprocess/gsm8k.py) and [`examples/run_qwen2.5-3b.sh`](examples/run_qwen2.5-3b.sh) as a sanity check that the environment is wired correctly.
83-
3. Move to the [Agent Task Tutorial](https://agentr1.github.io/Agent-R1/tutorials/agent-task/) for the main Agent-R1 workflow based on multi-step interaction and tool use.
83+
2. Download the processed data release from [ModelScope](https://www.modelscope.cn/datasets/Melmaphother/Agent-R1-data), then place or symlink each task's files to the paths expected by the corresponding recipe.
84+
3. Use [`examples/gsm8k/run_steppo.sh`](examples/gsm8k/run_steppo.sh) as a sanity check that the environment is wired correctly.
85+
4. Move to the [Agent Task Tutorial](https://agentr1.github.io/Agent-R1/tutorials/agent-task/) for the minimal GSM8K + Tool example based on `ToolEnv + BaseTool`.
86+
5. Read [Recipes and Algorithms](https://agentr1.github.io/Agent-R1/tutorials/recipes-and-algorithms/) for the current task integrations and launch-script layout.
87+
88+
Download the processed data with either the ModelScope CLI or git:
89+
90+
```bash
91+
pip install modelscope
92+
modelscope download --dataset Melmaphother/Agent-R1-data --local_dir data/agent-r1-data
93+
```
94+
95+
```bash
96+
git lfs install
97+
git clone https://www.modelscope.cn/datasets/Melmaphother/Agent-R1-data.git data/agent-r1-data
98+
```
8499

85100
### Stage 1: Sanity Check the Base Training Stack
86101

87-
Prepare a minimal GSM8K dataset and run the single-step script:
102+
Use the processed GSM8K files from the data release, or regenerate a minimal GSM8K dataset locally, then run the single-step script:
88103

89104
```bash
90-
python3 examples/data_preprocess/gsm8k.py --local_save_dir ~/data/gsm8k
91-
bash examples/run_qwen2.5-3b.sh
105+
python3 -m recipes.gsm8k.data_preprocess.process_gsm8k --local_save_dir ~/data/gsm8k
106+
bash examples/gsm8k/run_steppo.sh
92107
```
93108

94109
This stage is only a **setup check**. It helps confirm that your environment, model path, dataset path, and training stack are wired correctly.
95110

96-
### Stage 2: Run the Main Agent-R1 Workflow
111+
### Stage 2: Try the Minimal Tool-Calling Example
97112

98-
Prepare the tool-augmented dataset and launch the multi-step agent training script:
113+
GSM8K + Tool is the simplest `ToolEnv + BaseTool` example. Use the processed GSM8K tool files from the data release, or regenerate the tool-augmented dataset locally, then launch the multi-step tool-calling script:
99114

100115
```bash
101-
python3 examples/data_preprocess/gsm8k_tool.py --local_save_dir ~/data/gsm8k_tool
102-
bash examples/run_qwen3-4b_gsm8k_tool.sh
116+
python3 -m recipes.gsm8k.data_preprocess.process_gsm8k_tool --local_save_dir ~/data/gsm8k_tool
117+
bash examples/gsm8k/run_steppo_tool.sh
103118
```
104119

105-
This is the main Agent-R1 path, where `AgentEnvLoop` drives multi-step rollout and `ToolEnv` handles tool calls and environment feedback.
120+
This path uses the generic `AgentEnvLoop` with the built-in `ToolEnv` and recipe-local `calc_gsm8k_reward` tool. The plain GSM8K script remains a single-turn environment sanity check.
106121

107122
Core concepts:
108123

@@ -118,17 +133,17 @@ The Agent-R1 report evaluates Qwen3-4B across representative agent scenarios. Th
118133
| ReAct | 53.1 | 25.8 | 7.14 | 2.98 | 51.58 | 23.8 |
119134
| GRPO | **83.3** | **59.4** | **81.29** | **74.58** | 65.83 | 44.2 |
120135
| PPO | 78.1 | 56.7 | 76.42 | 72.38 | **70.18** | **46.0** |
121-
| REINFORCE++ | 78.9 | 52.8 | 73.84 | 69.57 | 63.41 | 41.8 |
136+
| REINFORCE | 78.9 | 52.8 | 73.84 | 69.57 | 63.41 | 41.8 |
122137
| RLOO | 81.6 | 55.2 | 79.08 | 73.46 | 68.02 | 45.1 |
123138

124139
## Building a New Agent Task
125140

126141
For a new task, keep the trainer intact and implement the task-specific layers:
127142

128143
```text
129-
recipe/<task>/
144+
recipes/<task>/
130145
base.yaml
131-
prepare_<task>_agent_r1.py
146+
data_preprocess/process_<task>.py
132147
<task>_agent_flow.py
133148
reward_fn.py
134149
prompts.py

agent_r1/agent_flow/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright 2024 Bytedance Ltd. and/or its affiliates
1+
# Copyright 2025 Agent-R1 Teams
22
#
33
# Licensed under the Apache License, Version 2.0 (the "License");
44
# you may not use this file except in compliance with the License.

agent_r1/agent_flow/agent_flow.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright 2024 Bytedance Ltd. and/or its affiliates
1+
# Copyright 2025 Agent-R1 Teams
22
#
33
# Licensed under the Apache License, Version 2.0 (the "License");
44
# you may not use this file except in compliance with the License.
@@ -736,7 +736,7 @@ def _postprocess(self, inputs: list[AgentFlowOutput]) -> DataProto:
736736

737737
metrics = [input.metrics.model_dump() for input in inputs]
738738

739-
# TODO: 验证 metrics 格式
739+
# TODO: Validate the metrics format.
740740
# Add num_steps to each metric dict for proper aggregation during concat
741741
for i, metric in enumerate(metrics):
742742
metric["num_steps"] = num_steps[i]

agent_r1/agent_flow/single_step_agent_flow.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright 2024 Bytedance Ltd. and/or its affiliates
1+
# Copyright 2025 Agent-R1 Teams
22
#
33
# Licensed under the Apache License, Version 2.0 (the "License");
44
# you may not use this file except in compliance with the License.

agent_r1/config/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright 2024 Bytedance Ltd. and/or its affiliates
1+
# Copyright 2025 Agent-R1 Teams
22
#
33
# Licensed under the Apache License, Version 2.0 (the "License");
44
# you may not use this file except in compliance with the License.
Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,25 @@
1-
# Agent PPO Trainer 配置
2-
# 继承 verlppo_trainer.yaml,只覆盖需要修改的部分
1+
# Agent PPO trainer config
2+
# Inherit verl's ppo_trainer.yaml and override only the required fields.
33

44
defaults:
5-
# 继承 verl 的完整 ppo_trainer 配置
5+
# Inherit the full verl ppo_trainer config.
66
- ppo_trainer
77

8-
# 覆盖 rollout 配置(使用 agent_r1AgentFlowConfig
8+
# Override rollout config with agent_r1's AgentFlowConfig.
99
- /overrides/rollout@actor_rollout_ref.rollout
1010

11-
# _self_ 确保当前文件的配置优先
11+
# _self_ ensures this file takes precedence.
1212
- _self_
1313

14-
# 以 package 的方式使用 verl 时,把 verl 的 Hydra 配置目录加入搜索路径
15-
# 前提:verl 包已将 trainer/config 下的 yaml 打包为 package data
14+
# Add verl's Hydra config directory to the search path when using verl as a package.
15+
# This assumes verl packages trainer/config yaml files as package data.
1616
hydra:
1717
searchpath:
1818
- pkg://verl.trainer.config
1919

20-
# 如果还需要覆盖其他配置,可以直接在这里添加
21-
# 例如:
20+
# Add any additional config overrides here if needed.
21+
# Example:
2222
# actor_rollout_ref:
2323
# rollout:
2424
# agent:
2525
# num_workers: 16
26-

agent_r1/config/config.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright 2024 Bytedance Ltd. and/or its affiliates
1+
# Copyright 2025 Agent-R1 Teams
22
#
33
# Licensed under the Apache License, Version 2.0 (the "License");
44
# you may not use this file except in compliance with the License.
@@ -80,20 +80,21 @@ class BaseModelConfig(BaseConfig):
8080

8181
@dataclass
8282
class AgentFlowConfig(BaseConfig):
83-
"""AgentFlow 配置,兼容 verl 的 AgentLoopConfig 字段。
83+
"""AgentFlow config compatible with verl's AgentLoopConfig fields.
8484
85-
agent_r1 使用 agent_flow 命名,但同时接受 verl 的 agent_loop 字段以便配置合并。
85+
agent_r1 uses agent_flow naming while accepting verl's agent_loop fields
86+
for config merging.
8687
"""
8788

8889
num_workers: int = 8
8990

90-
# agent_r1 字段
91+
# agent_r1 fields
9192
default_agent_flow: str = "single_step_agent"
9293
agent_flow_config_path: Optional[str] = None
9394
max_steps: int = 10
9495
skip_special_tokens: bool = True
9596

96-
# 兼容 verl 的旧字段(接受但忽略)
97+
# Legacy verl fields accepted for compatibility but ignored.
9798
default_agent_loop: Optional[str] = None
9899
agent_loop_config_path: Optional[str] = None
99100

agent_r1/config/overrides/rollout.yaml

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
# 只覆盖需要修改的配置项 - agent 部分
2-
# 其他配置从 verl 的默认配置继承
1+
# Override only the required agent config fields.
2+
# Other fields are inherited from verl defaults.
33

4-
# 使用 async 模式
4+
# Use async mode.
55
mode: async
66

7-
# [Experimental] agent flow based rollout configs (覆盖 verlAgentLoopConfig)
7+
# [Experimental] AgentFlow-based rollout configs that override verl's AgentLoopConfig.
88
agent:
99

10-
# 使用 agent_r1AgentFlowConfig 替代 verlAgentLoopConfig
10+
# Use agent_r1's AgentFlowConfig instead of verl's AgentLoopConfig.
1111
_target_: agent_r1.config.AgentFlowConfig
1212

1313
# Number of agent flow workers
@@ -36,4 +36,3 @@ agent:
3636

3737
# Class name of the custom async server class (e.g. AsyncvLLMServer)
3838
name: null
39-

agent_r1/reward_loop/reward_loop.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright 2024 Bytedance Ltd. and/or its affiliates
1+
# Copyright 2025 Agent-R1 Teams
22
#
33
# Licensed under the Apache License, Version 2.0 (the "License");
44
# you may not use this file except in compliance with the License.

0 commit comments

Comments
 (0)