How openmanus/openmanus-rl works
Project Type & Purpose
• OpenManus-RL is a research-oriented Python library and toolkit for fine-tuning large language model (LLM) agents via reinforcement learning (RL) (SFT, GRPO, PPO, DPO, etc.).
• It integrates the Verl RL framework as a submodule, wraps multiple environments (ALFWorld, WebShop, custom grid/text tasks), orchestrates multi-turn rollouts, memory, reward modeling, and tool invocation to benchmark and optimize LLM reasoning.
Top-Level Components
• Submodule “verl/” – third-party RL algorithms (PPO, DPO, reward modeling).
• Core library “openmanus_rl/”
• algorithms/ – custom RL algorithm glue (GigPO)
• environments/ – environment abstractions & wrappers (base, env_manager, AlfWorld, WebShop)
• llm_agent/ – LLM agent interface, tensor helpers
• memory/ – memory abstractions (file-based, RAG)
• multi_turn_rollout/ – rollout loop, modular stages, tool integration
• reward_manager/ – episode and reward model management
• tools/ – plugin tools for external APIs (object detector, searchers, captioner…)
• utils/ – visualization, common helpers
• scripts/ – shell-based training entrypoints (train_alfworld.sh, train_webshop.sh)
• configs/ (YAML) – environment and training hyperparameters
• data/ – sample datasets in parquet for quick prototyping
• examples/ – small usage snippets (data preprocessing)
• docs/ – developer guides, evaluation guides, SFT guides
• tests/ – unit & integration tests (pytest, mypy)
• CI & lint workflows (.github/workflows)
Component Relationships & Data Flows
• CLI scripts (scripts/ or user code) → load YAML configs → instantiate openmanus_rl environments via env_manager → instantiate LLM agent (via llm_agent + vllm/flash-attn) → multi_turn_rollout orchestrates:
• at each step: agent “think” → optionally call tool (tools/) → receive tool output → update memory (memory/) → compute reward (reward_manager/) → send feedback to Verl RL alg.
• openmanus_rl delegates RL updates to Verl submodule APIs.
• Environments import external RL environments (Gym, AlfWorld, WebShop) and expose standard step/reset.
• Tools are loaded dynamically via a base class, return results for model prompts.
• Data (data/*.parquet) and Hugging Face dataset are used for offline SFT / GRPO training loops.
• Tests validate each module; CI ensures style and type correctness.
Architectural Patterns & Principles
• Layered Architecture:
• Presentation/entry: scripts, CLI
• Orchestration: multi_turn_rollout, rollout_loop
• Core services: agent interface, memory, reward manager
• Environment abstraction: env_manager, base env, packages
• Tool plugin pattern: each tool extends a base class, loaded at runtime
• External frameworks: Verl (RL), vllm (inference), Gymnasium, stable-baselines3, Hugging Face
• Modular Design: clear separation of concerns, pluggable environments and tools
• Configuration-driven: YAML and command-line flags drive experiments
• Testing & CI: pre-commit, mypy, pytest, ruff enforce quality