# openmanus/openmanus-rl architecture

> Architecture diagram of the GitHub repository openmanus/openmanus-rl, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-09-08). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/openmanus/openmanus-rl
- Repository: https://github.com/openmanus/openmanus-rl

## Overview

##### 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

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Entry Layer
    subgraph "Entry Layer"
        direction TB
        Scripts["Scripts (train_*.sh)"]:::gray
        click Scripts "https://github.com/openmanus/openmanus-rl/blob/main/scripts/ppo_train/train_alfworld.sh"
        click Scripts "https://github.com/openmanus/openmanus-rl/blob/main/scripts/ppo_train/train_webshop.sh"
        Configs1["Config: config_thor.yaml"]:::gray
        click Configs1 "https://github.com/openmanus/openmanus-rl/blob/main/openmanus_rl/environments/env_package/alfworld/configs/config_thor.yaml"
        Configs2["Config: config_tw.yaml"]:::gray
        click Configs2 "https://github.com/openmanus/openmanus-rl/blob/main/openmanus_rl/environments/env_package/alfworld/configs/config_tw.yaml"
    end

    %% Orchestration Layer
    subgraph "Orchestration Layer"
        direction TB
        RolloutLoop["rollout_loop.py"]:::blue
        click RolloutLoop "https://github.com/openmanus/openmanus-rl/blob/main/openmanus_rl/multi_turn_rollout/rollout_loop.py"
        OpenmanusRollout["openmanus_rollout.py"]:::blue
        click OpenmanusRollout "https://github.com/openmanus/openmanus-rl/blob/main/openmanus_rl/multi_turn_rollout/openmanus_rollout.py"
        ModularStages["modular_stages.py"]:::blue
        click ModularStages "https://github.com/openmanus/openmanus-rl/blob/main/openmanus_rl/multi_turn_rollout/modular_stages.py"
        ToolIntegration["tool_integration.py"]:::blue
        click ToolIntegration "https://github.com/openmanus/openmanus-rl/blob/main/openmanus_rl/multi_turn_rollout/tool_integration.py"
        MultiUtils["utils.py"]:::blue
        click MultiUtils "https://github.com/openmanus/openmanus-rl/blob/main/openmanus_rl/multi_turn_rollout/utils.py"
    end

    %% Core Services
    subgraph "Core Services"
        direction TB
        Agent["LLM Agent Interface"]:::blue
        click Agent "https://github.com/openmanus/openmanus-rl/blob/main/openmanus_rl/llm_agent/openmanus.py"
        TensorHelper["Tensor Helper"]:::blue
        click TensorHelper "https://github.com/openmanus/openmanus-rl/blob/main/openmanus_rl/llm_agent/tensor_helper.py"
        MemoryBase["memory/base.py"]:::blue
        click MemoryBase "https://github.com/openmanus/openmanus-rl/blob/main/openmanus_rl/memory/base.py"
        FileMemory["file_memory.py"]:::blue
        click FileMemory "https://github.com/openmanus/openmanus-rl/blob/main/openmanus_rl/memory/file_memory.py"
        RagMemory["rag_memory.py"]:::blue
        click RagMemory "https://github.com/openmanus/openmanus-rl/blob/main/openmanus_rl/memory/rag_memory.py"
        MemoryCore["memory.py"]:::blue
        click MemoryCore "https://github.com/openmanus/openmanus-rl/blob/main/openmanus_rl/memory/memory.py"
        EpisodeMgr["episode.py"]:::blue
        click EpisodeMgr "https://github.com/openmanus/openmanus-rl/blob/main/openmanus_rl/reward_manager/episode.py"
    end

    %% Environment Adapters
    subgraph "Environment Adapters"
        direction TB
        BaseEnv["base.py"]:::orange
        click BaseEnv "https://github.com/openmanus/openmanus-rl/blob/main/openmanus_rl/environments/base.py"
        EnvManager["env_manager.py"]:::orange
        click EnvManager "https://github.com/openmanus/openmanus-rl/blob/main/openmanus_rl/environments/env_manager.py"
        subgraph "ALFWorld Package"
            direction TB
            AlfPkg["alfworld/"]:::orange
            click AlfPkg "https://github.com/openmanus/openmanus-rl/tree/main/openmanus_rl/environments/env_package/alfworld/"
            AlfPrompt["alfworld.py"]:::orange
            click AlfPrompt "https://github.com/openmanus/openmanus-rl/blob/main/openmanus_rl/environments/prompts/alfworld.py"
        end
        subgraph "WebShop Package"
            direction TB
            WebPkg["webshop/"]:::orange
            click WebPkg "https://github.com/openmanus/openmanus-rl/tree/main/openmanus_rl/environments/env_package/webshop/"
            WebPrompt["webshop.py"]:::orange
            click WebPrompt "https://github.com/openmanus/openmanus-rl/blob/main/openmanus_rl/environments/prompts/webshop.py"
        end
    end

    %% Tool Plugins
    subgraph "Tool Plugins"
        direction TB
        ToolBase["base.py"]:::yellow
        click ToolBase "https://github.com/openmanus/openmanus-rl/blob/main/openmanus_rl/tools/base.py"
        ToolsDir["tools/"]:::yellow
        click ToolsDir "https://github.com/openmanus/openmanus-rl/tree/main/openmanus_rl/tools/"
    end

    %% RL Algorithms (Verl)
    subgraph "RL Algorithms (Verl Submodule)"
        direction TB
        VerlSub["verl/"]:::green
        click VerlSub "https://github.com/openmanus/openmanus-rl/tree/main/verl/"
    end

    %% Data, Docs, Tests, CI
    subgraph "Support Files"
        direction TB
        DataStore["Data (parquet)"]:::gray
        Examples["examples/"]:::gray
        click Examples "https://github.com/openmanus/openmanus-rl/blob/main/examples/data_preprocess/prepare.py"
        Docs["docs/"]:::gray
        click Docs "https://github.com/openmanus/openmanus-rl/blob/main/docs/README.md"
        Tests["tests/"]:::gray
        click Tests "https://github.com/openmanus/openmanus-rl/blob/main/test/test_openmanus.py"
        CI["CI & Workflows"]:::gray
        click CI "https://github.com/openmanus/openmanus-rl/blob/main/.github/workflows/mypy.yml"
        click CI "https://github.com/openmanus/openmanus-rl/blob/main/.github/workflows/pytest.yml"
        click CI "https://github.com/openmanus/openmanus-rl/blob/main/.github/workflows/ruff.yml"
        click CI "https://github.com/openmanus/openmanus-rl/blob/main/.github/workflows/isort.yml"
    end

    %% External Frameworks
    subgraph "External Frameworks"
        direction TB
        Gym["Gymnasium"]:::green
        AlfWorldExt["AlfWorld"]:::green
        WebShopExt["WebShop"]:::green
        vllm["vllm / flash-attn"]:::green
    end

    %% Data Flow
    Scripts -->|loads| Configs1
    Scripts -->|loads| Configs2
    Configs1 --> RolloutLoop
    Configs2 --> RolloutLoop
    RolloutLoop --> Agent
    Agent --> EnvManager
    EnvManager --> BaseEnv
    EnvManager --> AlfPkg
    EnvManager --> WebPkg
    BaseEnv --> Gym
    AlfPkg --> AlfWorldExt
    WebPkg --> WebShopExt
    RolloutLoop --> ToolIntegration
    ToolIntegration --> ToolBase
    ToolIntegration --> ToolsDir
    RolloutLoop --> FileMemory
    RolloutLoop --> RagMemory
    RolloutLoop --> EpisodeMgr
    RolloutLoop --> VerlSub
    VerlSub -->|updates| Agent
    DataStore -->|used by| RolloutLoop
    Examples -->|illustrates| Scripts
    Docs -->|guides| Scripts
    Tests -->|validate| RolloutLoop
    CI -->|ensures| Tests

    classDef blue fill:#D0E8FF,stroke:#0377FF,color:#000
    classDef green fill:#D6F5D6,stroke:#20A020,color:#000
    classDef orange fill:#FFE5CC,stroke:#FF8C00,color:#000
    classDef yellow fill:#FFF5CC,stroke:#FFCC00,color:#000
    classDef gray fill:#F0F0F0,stroke:#AAAAAA,color:#000
```
