# qiqihezh/agentic-grpo-longhorizon architecture

> Architecture diagram of the GitHub repository qiqihezh/agentic-grpo-longhorizon, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-07-12). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/qiqihezh/agentic-grpo-longhorizon
- Repository: https://github.com/qiqihezh/agentic-grpo-longhorizon

## Overview

1. **What this repo is**
   This is a research/experiment repository for **training and evaluating long-horizon, multi-tool agents** on **τ-bench**, with the main focus on the airline domain. The project’s contribution is not a new runtime from scratch; it is a **config-driven experiment layer** on top of two vendored codebases: **`verl/`** for RL training/inference infrastructure and **`tau-bench/`** for the benchmark environment and tools.

2. **Main architectural split**
   The repository has three major layers:
   - **Experiment orchestration** in `agentic-grpo-longhorizon/`  
   - **Benchmark/environment** in `tau-bench/`  
   - **RL framework and model/runtime infrastructure** in `verl/`  
   The top layer wires the other two together with configs, scripts, and analysis artifacts.

3. **Experiment configuration layer**
   Most experiment behavior is driven by Hydra YAMLs under `agentic-grpo-longhorizon/configs/`. These separate:
   - **training configs** for GRPO/SFT/mock runs,
   - **evaluation configs** for each ablation and checkpoint,
   - **interaction configs** that define how τ-bench conversations and tool use are exposed,
   - **tool configs** that bind the agent to benchmark tools.
   This is the main boundary for reproducible experiments: the code is relatively stable, while each ablation is a different config stack.

4. **Training pipeline**
   Training is launched from `scripts/train/` and mainly follows two tracks:
   - **SFT** data collection and warm-start training,
   - **GRPO** training for the four ablations and baseline.
   The scripts emit run-specific artifacts into `outputs/`, while curated experiment results and checkpoints live in `experiments/`. The `src/training/sft_dataset.py` module supports dataset construction for the SFT phase.

5. **Evaluation pipeline**
   Evaluation is separate from training and is launched through `scripts/eval/`. It reads model checkpoints and experiment configs, runs benchmark episodes, and writes structured results such as:
   - `eval_report.json`,
   - `split_eval_report.json`,
   - failure-case JSON files.
   `src/evaluation/pass_k_eval.py` provides the independent pass@k-style evaluator used to compare checkpoints across vanilla GRPO, Turn-Discount, PRM-Lite, LATA, and the joint method.

6. **Environment and tool boundary**
   The project-specific environment glue is in `src/envs/`, which wraps τ-bench airline interactions and tool definitions:
   - `tau_bench_wrapper.py`
   - `tau_bench_interaction.py`
   - `tau_bench_tools.py`
   This layer is the boundary between the policy and the benchmark. It translates agent actions into benchmark tool calls and interaction state, and it is where the PRM-Lite-style interaction shaping lives.

7. **Benchmark internals**
   `tau-bench/` contains the actual benchmark domains, data, and tools. The airline and retail domains each include:
   - environment logic,
   - task definitions,
   - tool implementations,
   - domain data files,
   - human-agent transfer and think/calculate helpers.
   The airline domain is the primary training target in this repo; retail is used for cross-domain evaluation and sanity checks.

8. **Policy and inference runtime**
   `src/models/vllm_policy.py` is the local wrapper around the inference stack, and `scripts/vllm_server/` contains launch scripts for the serving side. In the experiment setup, vLLM is used to run both:
   - the **policy model**,
   - the **user simulator**.
   This is important architecturally because rollout generation is not just offline dataset replay; it is a live multi-turn interaction loop backed by model serving.

9. **Core RL framework**
   The vendored `verl/` tree is the main execution engine. It provides:
   - trainer entrypoints,
   - actor/critic/reward manager abstractions,
   - rollout implementations,
   - FSDP and Megatron worker stacks,
   - vLLM/SGLang rollout backends,
   - model registry and checkpoint utilities.
   The project-specific configs and scripts select among these backend choices. In architecture terms, `verl` is the heavy distributed runtime, while this repo’s top-level code decides how to apply it to τ-bench.

10. **Ablation-specific algorithmic boundary**
   The key experimental logic is split across the ablation configs and the benchmark interaction/reward path:
   - **Vanilla GRPO** baseline,
   - **Turn-Discount** shaping,
   - **PRM-Lite** process reward rules,
   - **LATA** length-aware token advantage,
   - **Joint PRM-Lite + LATA**.
   These are not separate services; they are alternate reward/advantage formulations that plug into the same training pipeline.

11. **Data artifacts and provenance**
   The repository keeps both generated and intermediate artifacts under versioned directories:
   - `experiments/` for collected datasets, evaluation reports, and failure cases,
   - `outputs/` for Hydra run outputs and config snapshots,
   - `docs/` for diagnosis reports and ablation analysis,
   - `agentic-grpo-longhorizon-blog.md` as a narrative summary of the findings.
   This makes the repo self-documenting and allows offline reproduction of a specific run.

12. **Operational constraints**
   The project is designed for **offline HPC-style execution** with explicit launcher scripts and environment setup. The stack is Python 3.10+, PyTorch 2.7, CUDA 12.6, and relies on distributed inference/training infrastructure from `verl`. The presence of many shell scripts and generated configs indicates that the main architectural control plane is **script + config**, not a long-running application server.

13. **How to draw the architecture diagram**
   A correct diagram should show:
   - a **config/script orchestration layer** at the top,
   - a **training/evaluation pipeline** in the middle,
   - a **benchmark environment/tool layer** on one side,
   - a **model serving/rollout layer** on the other,
   - and the **verl distributed trainer/runtime** as the core engine.
   The principal data flow is: configs/scripts → trainer/runtime → rollout against τ-bench environment/tools → reward/evaluation → checkpoints/reports back into `experiments/` and `outputs/`.

Main entry points: [`agentic-grpo-longhorizon/src/envs`](https://github.com/qiqihezh/agentic-grpo-longhorizon/tree/main/agentic-grpo-longhorizon/src/envs) (τ-bench glue), [`verl/verl/trainer`](https://github.com/qiqihezh/agentic-grpo-longhorizon/tree/main/verl/verl/trainer) (Trainer core), [`agentic-grpo-longhorizon/outputs`](https://github.com/qiqihezh/agentic-grpo-longhorizon/tree/main/agentic-grpo-longhorizon/outputs) (Outputs), [`agentic-grpo-longhorizon/scripts/train`](https://github.com/qiqihezh/agentic-grpo-longhorizon/tree/main/agentic-grpo-longhorizon/scripts/train) (Train scripts)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_g_orchestration["Experiment layer"]
  node_n_configs["Configs"]
  node_n_scripts_train["Train scripts<br/>launcher scripts"]
  node_n_scripts_eval["Eval scripts<br/>launcher scripts"]
  node_n_scripts_vllm["vLLM launch<br/>serving scripts"]
end

subgraph group_g_project_src["Project code"]
  node_n_envs["τ-bench glue<br/>env adapters"]
  node_n_sft_dataset["SFT data<br/>dataset builder<br/>[sft_dataset.py]"]
  node_n_passk_eval["Pass@k eval<br/>evaluation<br/>[pass_k_eval.py]"]
  node_n_policy["Policy wrapper<br/>vLLM policy<br/>[vllm_policy.py]"]
end

subgraph group_g_bench["τ-bench"]
  node_n_tau_airline["Airline domain<br/>benchmark env"]
  node_n_tau_retail["Retail domain<br/>benchmark env"]
  node_n_tau_models["Model utils<br/>benchmark runtime"]
end

subgraph group_g_verl["verl runtime"]
  node_n_verl_trainer["Trainer core<br/>distributed trainer"]
  node_n_verl_workers["Workers<br/>worker stack"]
  node_n_verl_rollout["Rollouts<br/>inference backends"]
  node_n_verl_reward["Reward loop<br/>reward system"]
  node_n_verl_models["Model registry<br/>model runtime"]
end

subgraph group_g_artifacts["Artifacts"]
  node_n_outputs[("Outputs<br/>run artifacts")]
  node_n_experiments[("Experiments<br/>curated artifacts")]
end

node_n_configs -->|"drives"| node_n_scripts_train
node_n_configs -->|"drives"| node_n_scripts_eval
node_n_scripts_train -->|"launches"| node_n_verl_trainer
node_n_scripts_eval -->|"runs"| node_n_passk_eval
node_n_scripts_vllm -->|"serves"| node_n_policy
node_n_verl_trainer -->|"coordinates"| node_n_verl_workers
node_n_verl_workers -->|"uses"| node_n_verl_rollout
node_n_verl_workers -->|"scores"| node_n_verl_reward
node_n_verl_trainer -->|"loads"| node_n_verl_models
node_n_envs -->|"wraps"| node_n_tau_airline
node_n_envs -->|"wraps"| node_n_tau_retail
node_n_envs -->|"defines shaping"| node_n_verl_reward
node_n_policy -->|"calls"| node_n_tau_models
node_n_policy -->|"acts in"| node_n_envs
node_n_tau_airline -->|"uses"| node_n_tau_models
node_n_tau_retail -->|"uses"| node_n_tau_models
node_n_verl_rollout -->|"rolls out against"| node_n_envs
node_n_verl_reward -->|"compared by"| node_n_passk_eval
node_n_scripts_train -->|"writes"| node_n_outputs
node_n_scripts_eval -->|"writes"| node_n_outputs
node_n_outputs -->|"curates"| node_n_experiments
node_n_verl_trainer -->|"persists"| node_n_outputs
node_n_passk_eval -->|"reads"| node_n_experiments

click node_n_configs "https://github.com/qiqihezh/agentic-grpo-longhorizon/tree/main/agentic-grpo-longhorizon/configs"
click node_n_scripts_train "https://github.com/qiqihezh/agentic-grpo-longhorizon/tree/main/agentic-grpo-longhorizon/scripts/train"
click node_n_scripts_eval "https://github.com/qiqihezh/agentic-grpo-longhorizon/tree/main/agentic-grpo-longhorizon/scripts/eval"
click node_n_scripts_vllm "https://github.com/qiqihezh/agentic-grpo-longhorizon/tree/main/agentic-grpo-longhorizon/scripts/vllm_server"
click node_n_envs "https://github.com/qiqihezh/agentic-grpo-longhorizon/tree/main/agentic-grpo-longhorizon/src/envs"
click node_n_sft_dataset "https://github.com/qiqihezh/agentic-grpo-longhorizon/blob/main/agentic-grpo-longhorizon/src/training/sft_dataset.py"
click node_n_passk_eval "https://github.com/qiqihezh/agentic-grpo-longhorizon/blob/main/agentic-grpo-longhorizon/src/evaluation/pass_k_eval.py"
click node_n_policy "https://github.com/qiqihezh/agentic-grpo-longhorizon/blob/main/agentic-grpo-longhorizon/src/models/vllm_policy.py"
click node_n_tau_airline "https://github.com/qiqihezh/agentic-grpo-longhorizon/tree/main/tau-bench/tau_bench/envs/airline"
click node_n_tau_retail "https://github.com/qiqihezh/agentic-grpo-longhorizon/tree/main/tau-bench/tau_bench/envs/retail"
click node_n_tau_models "https://github.com/qiqihezh/agentic-grpo-longhorizon/tree/main/tau-bench/tau_bench/model_utils"
click node_n_verl_trainer "https://github.com/qiqihezh/agentic-grpo-longhorizon/tree/main/verl/verl/trainer"
click node_n_verl_workers "https://github.com/qiqihezh/agentic-grpo-longhorizon/tree/main/verl/verl/workers"
click node_n_verl_rollout "https://github.com/qiqihezh/agentic-grpo-longhorizon/tree/main/verl/verl/workers/rollout"
click node_n_verl_reward "https://github.com/qiqihezh/agentic-grpo-longhorizon/tree/main/verl/verl/experimental/reward"
click node_n_verl_models "https://github.com/qiqihezh/agentic-grpo-longhorizon/tree/main/verl/verl/models"
click node_n_outputs "https://github.com/qiqihezh/agentic-grpo-longhorizon/tree/main/agentic-grpo-longhorizon/outputs"
click node_n_experiments "https://github.com/qiqihezh/agentic-grpo-longhorizon/tree/main/agentic-grpo-longhorizon/experiments"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_n_configs,node_n_scripts_train,node_n_scripts_eval,node_n_scripts_vllm toneBlue
class node_n_envs,node_n_sft_dataset,node_n_passk_eval,node_n_policy toneAmber
class node_n_tau_airline,node_n_tau_retail,node_n_tau_models toneMint
class node_n_verl_trainer,node_n_verl_workers,node_n_verl_rollout,node_n_verl_reward,node_n_verl_models toneRose
class node_n_outputs,node_n_experiments toneIndigo
```

## Components

### Experiment layer

Config-driven experiment control plane in the repository root.

- [Configs](https://github.com/qiqihezh/agentic-grpo-longhorizon/tree/main/agentic-grpo-longhorizon/configs): hydra configs · Hydra YAML stacks for training, evaluation, interactions, tools, and mock runs. · `agentic-grpo-longhorizon/configs`
- [Train scripts](https://github.com/qiqihezh/agentic-grpo-longhorizon/tree/main/agentic-grpo-longhorizon/scripts/train): launcher scripts · Shell entrypoints for SFT, GRPO, and mock experiment runs. · `agentic-grpo-longhorizon/scripts/train`
- [Eval scripts](https://github.com/qiqihezh/agentic-grpo-longhorizon/tree/main/agentic-grpo-longhorizon/scripts/eval): launcher scripts · Shell and Python entrypoints for benchmark evaluation and ablation comparison. · `agentic-grpo-longhorizon/scripts/eval`
- [vLLM launch](https://github.com/qiqihezh/agentic-grpo-longhorizon/tree/main/agentic-grpo-longhorizon/scripts/vllm_server): serving scripts · Launch scripts for policy and user-simulator inference serving. · `agentic-grpo-longhorizon/scripts/vllm_server`

### Project code

Repository-specific glue code for training, evaluation, models, and τ-bench integration.

- [τ-bench glue](https://github.com/qiqihezh/agentic-grpo-longhorizon/tree/main/agentic-grpo-longhorizon/src/envs): env adapters · Wrappers that adapt τ-bench airline interactions, context, and tools to the agent loop. · `agentic-grpo-longhorizon/src/envs`
- [SFT data](https://github.com/qiqihezh/agentic-grpo-longhorizon/blob/main/agentic-grpo-longhorizon/src/training/sft_dataset.py): dataset builder · Builds supervised fine-tuning datasets for the airline warm-start phase. · `agentic-grpo-longhorizon/src/training/sft_dataset.py`
- [Pass@k eval](https://github.com/qiqihezh/agentic-grpo-longhorizon/blob/main/agentic-grpo-longhorizon/src/evaluation/pass_k_eval.py): evaluation · Independent evaluator used to compare checkpoints across ablations. · `agentic-grpo-longhorizon/src/evaluation/pass_k_eval.py`
- [Policy wrapper](https://github.com/qiqihezh/agentic-grpo-longhorizon/blob/main/agentic-grpo-longhorizon/src/models/vllm_policy.py): vLLM policy · Local wrapper around the inference stack for rollout-time policy execution. · `agentic-grpo-longhorizon/src/models/vllm_policy.py`

### τ-bench

Vendored benchmark environment, domains, tools, and model utilities.

- [Airline domain](https://github.com/qiqihezh/agentic-grpo-longhorizon/tree/main/tau-bench/tau_bench/envs/airline): benchmark env · Primary τ-bench domain with tasks, rules, data, and tools for airline interactions. · `tau-bench/tau_bench/envs/airline`
- [Retail domain](https://github.com/qiqihezh/agentic-grpo-longhorizon/tree/main/tau-bench/tau_bench/envs/retail): benchmark env · Secondary τ-bench domain used for cross-domain evaluation and sanity checks. · `tau-bench/tau_bench/envs/retail`
- [Model utils](https://github.com/qiqihezh/agentic-grpo-longhorizon/tree/main/tau-bench/tau_bench/model_utils): benchmark runtime · τ-bench model serving and API utilities for agent/user simulation. · `tau-bench/tau_bench/model_utils`

### verl runtime

Vendored distributed RL framework, workers, trainers, and rollout backends.

- [Trainer core](https://github.com/qiqihezh/agentic-grpo-longhorizon/tree/main/verl/verl/trainer): distributed trainer · Main RL training entrypoints, configs, PPO/SFT orchestration, and runtime wiring. · `verl/verl/trainer`
- [Workers](https://github.com/qiqihezh/agentic-grpo-longhorizon/tree/main/verl/verl/workers): worker stack · Actor, critic, rollout, reward, and engine workers used by the trainer. · `verl/verl/workers`
- [Rollouts](https://github.com/qiqihezh/agentic-grpo-longhorizon/tree/main/verl/verl/workers/rollout): inference backends · vLLM and SGLang rollout implementations, async servers, and sharding managers. · `verl/verl/workers/rollout`
- [Reward loop](https://github.com/qiqihezh/agentic-grpo-longhorizon/tree/main/verl/verl/experimental/reward): reward system · Reward managers and algorithm-specific reward loops for GRPO and related methods. · `verl/verl/experimental/reward`
- [Model registry](https://github.com/qiqihezh/agentic-grpo-longhorizon/tree/main/verl/verl/models): model runtime · Model adapters, checkpoint utilities, and backend-specific model implementations. · `verl/verl/models`

### Artifacts

Generated experiment outputs, checkpoints, and reports.

- [Outputs](https://github.com/qiqihezh/agentic-grpo-longhorizon/tree/main/agentic-grpo-longhorizon/outputs): run artifacts · Hydra run outputs, config snapshots, checkpoints, reports, and failure cases. · `agentic-grpo-longhorizon/outputs`
- [Experiments](https://github.com/qiqihezh/agentic-grpo-longhorizon/tree/main/agentic-grpo-longhorizon/experiments): curated artifacts · Versioned experiment datasets, evaluation reports, and collected trajectories. · `agentic-grpo-longhorizon/experiments`

## Connections

- Configs → Train scripts: drives · Training runs are selected by config stacks and launched by shell scripts.
- Configs → Eval scripts: drives · Evaluation variants are selected via dedicated Hydra configs and scripts.
- Train scripts → Trainer core: launches · Scripts invoke the distributed trainer runtime for SFT and GRPO.
- Eval scripts → Pass@k eval: runs · Evaluation scripts call the checkpoint comparison and pass@k evaluator.
- vLLM launch → Policy wrapper: serves · Serving scripts boot the local vLLM policy/user-simulator wrapper.
- Trainer core → Workers: coordinates · Trainer orchestrates actor, critic, rollout, and reward workers.
- Workers → Rollouts: uses · Workers delegate generation to vLLM or SGLang rollout backends.
- Workers → Reward loop: scores · Reward managers and reward loops compute training signals.
- Trainer core → Model registry: loads · Trainer and workers rely on the model registry and checkpoint utilities.
- τ-bench glue → Airline domain: wraps · Project glue translates agent actions into airline benchmark interactions.
- τ-bench glue → Retail domain: wraps · The same glue supports retail cross-domain evaluation paths.
- τ-bench glue → Reward loop: defines shaping · Interaction shaping and ablation-specific rules feed the reward path.
- Policy wrapper → Model utils: calls · Rollout-time policy execution uses τ-bench model utilities and simulators.
- Policy wrapper → τ-bench glue: acts in · The policy interacts with benchmark state through the local env wrapper.
- Airline domain → Model utils: uses · Airline domain episodes rely on benchmark model utilities and simulator support.
- Retail domain → Model utils: uses · Retail episodes also use the shared benchmark model utilities.
- Rollouts → τ-bench glue: rolls out against · Distributed generation is executed inside the τ-bench environment boundary.
- Reward loop → Pass@k eval: compared by · Reward formulations are compared offline through the evaluator and reports.
- Train scripts → Outputs: writes · Hydra outputs and snapshots are produced during training runs.
- Eval scripts → Outputs: writes · Evaluation jobs write structured reports and failure cases.
- Outputs → Experiments: curates · Selected run artifacts are promoted into versioned experiment directories.
- Trainer core → Outputs: persists · Trainer checkpoints and logs are saved for later evaluation.
- Pass@k eval → Experiments: reads · Comparative evaluation consumes stored experiment checkpoints and reports.
