diff --git a/.gitattributes b/.gitattributes index bed0738c7eeb449bca98b5d2f33c89a1ee56349a..2414993a943f030fb1951e089c61a68145d52667 100644 --- a/.gitattributes +++ b/.gitattributes @@ -58,3 +58,20 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text # Video files - compressed *.mp4 filter=lfs diff=lfs merge=lfs -text *.webm filter=lfs diff=lfs merge=lfs -text +RAGEN-2.pdf filter=lfs diff=lfs merge=lfs -text +RAGEN.pdf filter=lfs diff=lfs merge=lfs -text +external/kimina-lean-server/Technical_Report.pdf filter=lfs diff=lfs merge=lfs -text +external/webshop-minimal/webshop_minimal/search_engine/indexes/_1.fdt filter=lfs diff=lfs merge=lfs -text +external/webshop-minimal/webshop_minimal/search_engine/indexes/_1.tvd filter=lfs diff=lfs merge=lfs -text +external/webshop-minimal/webshop_minimal/search_engine/indexes/_1_Lucene90_0.pos filter=lfs diff=lfs merge=lfs -text +external/webshop-minimal/webshop_minimal/search_engine/indexes/_1_Lucene90_0.tim filter=lfs diff=lfs merge=lfs -text +external/webshop-minimal/webshop_minimal/search_engine/indexes_100/_1.fdt filter=lfs diff=lfs merge=lfs -text +external/webshop-minimal/webshop_minimal/search_engine/indexes_100k/_1.fdt filter=lfs diff=lfs merge=lfs -text +external/webshop-minimal/webshop_minimal/search_engine/indexes_100k/_1.tvd filter=lfs diff=lfs merge=lfs -text +external/webshop-minimal/webshop_minimal/search_engine/indexes_100k/_1_Lucene90_0.pos filter=lfs diff=lfs merge=lfs -text +external/webshop-minimal/webshop_minimal/search_engine/indexes_100k/_1_Lucene90_0.tim filter=lfs diff=lfs merge=lfs -text +external/webshop-minimal/webshop_minimal/search_engine/indexes_1k/_1.fdt filter=lfs diff=lfs merge=lfs -text +external/webshop-minimal/webshop_minimal/search_engine/indexes_1k/_1.tvd filter=lfs diff=lfs merge=lfs -text +external/webshop-minimal/webshop_minimal/search_engine/indexes_1k/_1_Lucene90_0.pos filter=lfs diff=lfs merge=lfs -text +external/webshop-minimal/webshop_minimal/search_engine/indexes_1k/_1_Lucene90_0.tim filter=lfs diff=lfs merge=lfs -text +verl/flash_attn-2.8.1+cu12torch2.8cxx11abiFALSE-cp312-cp312-linux_x86_64.whl filter=lfs diff=lfs merge=lfs -text diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..26380667e73c59156a97b98a592572ed2ce29213 --- /dev/null +++ b/.gitignore @@ -0,0 +1,124 @@ +**/*.pt +**/checkpoints +**/wget-log +**/_build/ +**/*.ckpt +**/outputs +**/*.tar.gz +**/playground +**/wandb + +# Byte-compiled / optimized / DLL files +__pycache__/ +*.py[cod] +*$py.class +dataset/* +tensorflow/my_graph/* +.idea/ +# C extensions +*.so +data +results/ + +# Distribution / packaging +.Python +build/ +develop-eggs/ +dist/ +downloads/ +eggs/ +.eggs/ +lib/ +lib64/ +parts/ +sdist/ +var/ +*.egg-info/ +.installed.cfg +*.egg + +# PyInstaller +# Usually these files are written by a python script from a template +# before PyInstaller builds the exe, so as to inject date/other infos into it. +*.manifest +*.spec + +# Installer logs +pip-log.txt +pip-delete-this-directory.txt + +# Unit test / coverage reports +htmlcov/ +.tox/ +.coverage +.coverage.* +.cache +nosetests.xml +coverage.xml +*,cover +.hypothesis/ + +# Translations +*.mo +*.pot + +# Django stuff: +*.log +local_settings.py + +image_outputs + +checkpoints +model_saving/ + +# Flask stuff: +instance/ +.webassets-cache + +# Scrapy stuff: +.scrapy + +# Sphinx documentation +docs/_build/ + +# PyBuilder +target/ + +# IPython Notebook +.ipynb_checkpoints + +# pyenv +.python-version + +# celery beat schedule file +celerybeat-schedule + + +# virtualenv +venv/ + + +# Spyder project settings +.spyderproject + +# Rope project settings +.ropeproject + +# vscode +.vscode + +# Mac +.DS_Store + +# output logs +tests/e2e/toy_examples/deepspeed/synchronous/output.txt + +# vim +*.swp + + +log/ +*.result + +# Search data (large files) +search_data/ \ No newline at end of file diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000000000000000000000000000000000000..831ce47b90d7912a3f5d43e91b923c478ef5ed05 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,13 @@ +[submodule "verl"] + path = verl + url = https://github.com/volcengine/verl.git +[submodule "external/webshop-minimal"] + path = external/webshop-minimal + url = https://github.com/ZihanWang314/webshop-minimal.git + branch = xjin-alignment +[submodule "external/kimina-lean-server"] + path = external/kimina-lean-server + url = https://github.com/project-numina/kimina-lean-server.git +[submodule "ragen/env/spatial/Base"] + path = ragen/env/spatial/Base + url = https://github.com/williamzhangNU/ToS_Base diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000000000000000000000000000000000000..3231ddc3348e3a2f1f158aa3881e727aea9e2c2b --- /dev/null +++ b/LICENSE @@ -0,0 +1,7 @@ +Copyright 2025 RAGEN Team + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the โSoftwareโ), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED โAS ISโ, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. \ No newline at end of file diff --git a/RAGEN-2.pdf b/RAGEN-2.pdf new file mode 100644 index 0000000000000000000000000000000000000000..d2a0d7533b960483243274674ccbeb6632d68bb0 --- /dev/null +++ b/RAGEN-2.pdf @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:281e5ec72985dd16ca2988739f65846977cb5940b579f97947c309999a5c04d7 +size 7203416 diff --git a/RAGEN.pdf b/RAGEN.pdf new file mode 100644 index 0000000000000000000000000000000000000000..42dddc5894bca2cbf83243e77cc8d1793ce604c4 --- /dev/null +++ b/RAGEN.pdf @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:674a33a9634ea6ab1e347c22fa94e4535af7bdba34146a8001ddd2b355662c2b +size 1478341 diff --git a/README.md b/README.md new file mode 100644 index 0000000000000000000000000000000000000000..d5bdfb717ec2f6c6533773c183889c9b3f41afd0 --- /dev/null +++ b/README.md @@ -0,0 +1,224 @@ +

+ RAGEN (Reasoning AGENT) is a flexible RL framework for training reasoning agents. +
++ We develop diagnostics to understand how agent RL training works , and how to fix hidden issues. +
+ + + +> **Looking for the V1 README?** Please take a look [here](docs/readme_v1.md). + +## News + +- **2026.3.12.** We are excited to release RAGEN-2! We introduce a systematic study of reasoning collapse in agent RL and lightweight interventions for stable training. See the [v2 paper](https://ragen-ai.github.io/v2). +- **2025.4.20.** RAGEN V1 [paper](https://arxiv.org/abs/2504.20073) published on arXiv. +- **2025.1.27.** Initial RAGEN release. [Post](https://x.com/wzihanw/status/1884092805598826609). + + +## About + +RAGEN is built around **StarPO** (**S**tate-**T**hinking-**A**ctions-**R**eward **P**olicy **O**ptimization), a unified RL framework for training multi-turn, trajectory-level agents with flexible control over reasoning processes, reward assignment mechanisms, and prompt-rollout structures. + +**RAGEN is flexible with:** + +- **StarPO framework.** Unified optimization for multi-turn agents, supporting both trajectory-level and turn-wise training. +- **10 built-in environments.** Sokoban, FrozenLake, WebShop, DeepCoder, SearchQA, Lean, Bandit, Countdown, MetaMathQA, Sudoku. +- **Gym-compatible interface.** Easy to add custom environments. + +**RAGEN-2 additionally introduces:** + +- **SNR-Adaptive Filtering (V2).** Lightweight rollout filtering based on reward variance to mitigate noisy gradient updates. +- **Reasoning collapse diagnostics (V2).** Mutual information proxy metrics to detect and monitor template collapse during training. + + +## Algorithm + +### StarPO: Reinforcing Reasoning via Trajectory-Level Optimization + +
+The StarPO (State-Thinking-Action-Reward Policy Optimization) framework with two interleaved stages: rollout stage and update stage. The LLM generates reasoning-guided actions to interact with the environment, collecting trajectory-level rewards to jointly optimize reasoning and action strategies. +
+ +**MDP Formulation.** Agent-environment interactions are formulated as Markov Decision Processes (MDPs) where states and actions are token sequences, allowing LLMs to reason over environment dynamics. The objective is to maximize expected cumulative rewards across multiple interaction turns. + +**Rollout Stage.** Given an initial state, the LLM generates multiple trajectories. At each step, the model produces a reasoning-guided action: `
+Left: Input-driven reasoning adapts to the current state; templated reasoning produces nearly identical responses across different inputs. Right: Four reasoning regimes along two axes โ conditional entropy H(Z|X) (within-input diversity) and mutual information I(X;Z) (input dependence). Template collapse (high entropy, low MI) is invisible to existing entropy-based metrics. +
+ +**Train (no filter, default):** +```bash +python train.py --config-name _2_sokoban +``` + +**Train with SNR-Adaptive Filtering (V2, Top-p):** +```bash +python train.py --config-name _2_sokoban \ + actor_rollout_ref.rollout_filter_strategy=top_p \ + actor_rollout_ref.rollout.rollout_filter_value=0.9 +``` + +**Evaluate:** +```bash +python -m ragen.llm_agent.agent_proxy --config-name _2_sokoban +``` + +SNR-Adaptive Filtering consistently improves training across algorithms, model scales, and modalities (green = gain from filtering): + +