Hr1th1k17/razorpay-itch
Razorpay Itch: Autonomous Fleet & Freight Dispatcher
An OpenEnv / Gymnasium reinforcement learning environment for the logistics pain point:
Why can't manufacturers rely on guaranteed, accountable pickup logistics for outbound deliveries?
This project models outbound pickup logistics as a dynamic vehicle routing and capacity-constrained dispatch problem. An RL agent controls a fleet of trucks that must pick up factory cargo, return it to a hub, and prevent factory loading docks from overflowing.
Why this is a strong hackathon problem
- It maps to a real operations problem, not a toy environment.
- It has meaningful partial-progress rewards instead of a binary win/loss signal.
- It combines routing, capacity management, backlog control, and limited operating time.
- It is directly trainable with standard RL tooling.
Screenshots
Initial environment state after reset:
Mid-episode state after several dispatch steps:
Demo walkthrough
Suggested live demo flow:
- Introduce the logistics problem in one sentence.
- Show the environment screenshots and explain factories, trucks, and hub.
- Run
demo.pyto show a random rollout. - Show
train.pyand the saved artifacts inartifacts/. - Close with the evaluation result and why this is a strong RL benchmark.
Environment design
Observation space
The observation is a fixed-length vector built from:
- factory backlog, fullness, cargo wait time, and coordinates
- truck position, remaining capacity, utilization, current status, and target
- traffic grid features
- global congestion and utilization signals
Action space
The action space is discrete but semantically meaningful:
0:NOOP1..N: smart-dispatch a truck to the best available factoryN+1..2N: return a truck to the hub- remaining actions: explicit truck-to-factory assignments
The OpenEnv adapter exposes the same logic through typed actions:
SMART_DISPATCHDISPATCH_TO_FACTORYRETURN_TO_HUBNOOP
Reward shaping
The reward is designed for partial progress:
- positive reward for successful pickups
- higher reward for efficient truck utilization
- positive reward for returning cargo to the hub
- penalty when factories remain full
- penalty for impossible dispatches
- penalty for ending an episode with undelivered cargo on trucks
Task graders
The OpenEnv observation includes three explicit task scores in the 0.0 to 1.0 range:
easy_deliver_one_load:1.0once at least one load has been delivered, else0.0medium_fleet_efficiency: current average fleet utilizationhard_zero_overflow: starts at1.0and drops as overflow events accumulate
Repo layout
razorpay_itch_env/
__init__.py
env.py
models.py
openenv_models.py
openenv_env.py
spaces.py
generator.py
renderer.py
train.py
evaluate.py
demo.py
openenv_app.py
inference.py
openenv.yaml
Dockerfile
tests/
artifacts/
media/Quickstart
1. Create and activate a virtual environment
python -m venv venv
venv\Scripts\Activate.ps12. Install dependencies
pip install -r requirements.txtNote: pygame is intentionally excluded because it fails to build on Python 3.14 on Windows and is not required for the current matplotlib renderer or PPO baseline.
3. Run a random-policy sanity check
venv\Scripts\python.exe demo.py --episodes 2 --max-steps 25 --seed 424. Train a PPO baseline
venv\Scripts\python.exe train.py --timesteps 20000 --n-envs 2 --seed 425. Evaluate the saved model
venv\Scripts\python.exe evaluate.py --model-path artifacts\ppo_razorpay_itch.zip --episodes 10 --seed 426. Run the OpenEnv server
venv\Scripts\python.exe -m uvicorn openenv_app:app --host 0.0.0.0 --port 8000To enable the built-in OpenEnv web UI:
$env:ENABLE_WEB_INTERFACE="true"
venv\Scripts\python.exe -m uvicorn openenv_app:app --host 0.0.0.0 --port 8000Then open:
http://localhost:8000/web7. Run LLM inference
Set the required environment variables and run the root inference script:
$env:API_BASE_URL="https://your-openai-compatible-endpoint/v1"
$env:MODEL_NAME="your-model-name"
$env:HF_TOKEN="your-token"
venv\Scripts\python.exe inference.py --max-steps 25 --seed 42inference.py uses the OpenAI Python client and converts model JSON output into FreightAction objects.
Usage guide
Run the demo
Use the demo script to prove the environment resets, steps, and returns metrics correctly.
venv\Scripts\python.exe demo.pyExpected output format:
{"episode": 0, "steps": 25, "total_reward": 7.51, "cargo_delivered": 1, "cargo_picked_up": 23, "overflow_events": 55, "fuel_consumed": 237.89}Train your own baseline
The included PPO script uses:
Monitorfor episode loggingVecNormalizefor observation and reward normalizationEvalCallbackfor checkpointing and evaluation
Example:
venv\Scripts\python.exe train.py --timesteps 100000 --n-envs 4 --seed 42Outputs are saved to:
artifacts/ppo_razorpay_itch.zipartifacts/vecnormalize.pklartifacts/tensorboard/artifacts/eval_logs/
Evaluate a trained model
venv\Scripts\python.exe evaluate.py --model-path artifacts\ppo_razorpay_itch.zipUse the OpenEnv adapter
This repo now supports two interfaces over the same logistics simulation:
- Gymnasium environment for PPO training in
razorpay_itch_env/env.py - OpenEnv server adapter for typed API access in
razorpay_itch_env/openenv_env.py
Typed OpenEnv request and response models are defined in razorpay_itch_env/openenv_models.py.
Deployment files
The repo includes the root deployment files required for OpenEnv/Hugging Face packaging:
openenv.yamlDockerfileinference.py
Baseline results
Random-policy sanity check:
{"episode": 0, "steps": 25, "total_reward": 7.51, "cargo_delivered": 1, "cargo_picked_up": 23, "overflow_events": 55, "fuel_consumed": 237.89}
{"episode": 1, "steps": 25, "total_reward": 3.17, "cargo_delivered": 7, "cargo_picked_up": 20, "overflow_events": 95, "fuel_consumed": 187.473}PPO baseline trained for 20000 timesteps with 2 environments:
{"episodes": 10, "avg_reward": -695.246, "avg_deliveries": 71.6, "avg_overflows": 4292.3}Interpretation:
- the environment is trainable end to end
- the PPO agent already learns to increase completed deliveries
- overflow pressure remains high, which makes the environment non-trivial and leaves room for better policies
How to present this in the hackathon
Pitch it as a logistics control benchmark, not just a training script.
Use this framing:
- Manufacturers lose throughput when finished goods pile up at loading docks.
- This environment turns that pain point into an RL problem with explicit observations, actions, and shaped rewards.
- The contribution is a reusable, trainable benchmark for outbound pickup logistics with a working PPO baseline.
Submission checklist
- environment code in
razorpay_itch_env/ - OpenEnv server entrypoint in
openenv_app.py - root inference script in
inference.py - root deployment manifest in
openenv.yaml - root container file in
Dockerfile - training script in
train.py - evaluation script in
evaluate.py - screenshots in
media/ - trained checkpoint in
artifacts/ - solution summary in
SOLUTION.md
Next improvements
- add multi-stop routing instead of single-pickup dispatch
- model travel time directly instead of instant movement
- add hard delivery deadlines and SLA penalties
- add curriculum generation for easy-to-hard scenarios
- benchmark PPO against hand-built dispatch heuristics
