RL Training Environments
Train reinforcement learning agents against a live cloud simulation. Each environment wraps a simulation as a Gym-compatible loop — episodes, observations, scalar rewards, and discrete actions — with no real cloud spend.
Training loop
POST /resetStart a fresh episode from a clean initial state.
GET /observationRead the current 6-field observation vector.
POST /stepSubmit an action and receive next obs + reward.
reward signalDecomposed reward: latency, cost, and throughput.
Quick start
Create an environment, run a full episode, then reset and repeat.
# 1. Create an environment linked to a simulationenv = requests.post(f"{BASE}/api/rl/environments",headers=HEADERS, json={"simulationId": sim_id}).json()env_id = env["id"]# 2. Training loopfor episode in range(NUM_EPISODES):obs = env["observation"] # initial observation vectorwhile True:action = policy(obs) # your agent's decisionstep = requests.post(f"{BASE}/api/rl/environments/{env_id}/step",headers=HEADERS,json={"action": action} # scale_up | scale_down | no_op).json()obs = step["observation"] # next state vectorreward = step["reward"] # scalar reward signaldone = step["done"] # episode complete?if done:break# Reset to start a fresh episoderequests.post(f"{BASE}/api/rl/environments/{env_id}/reset",headers=HEADERS)
Action space
The action space is discrete with three choices. Pass the string label as the action field in the POST /step body.
scale_upAdd one instance to the pool
Reduces CPU / latency, increases cost
scale_downRemove one instance from the pool
Lowers cost, risks latency spike under load
no_opHold current instance count unchanged
Baseline — observe without intervening
Observation vector
Each step returns a 6-field observation vector: rps, cpu_util, instances, traffic, currentTime, and tick_seconds. Only cpu_util is a normalised 0–1 fraction; the others are raw values.
# Observation vector fields{"rps": 1240, # requests per second"cpu_util": 0.72, # 0–1 fraction, current CPU load"instances": 4, # active compute instances"traffic": 1.8, # current traffic relative to baseline"currentTime": 720, # elapsed simulation time (seconds)"tick_seconds": 60 # simulation seconds advanced per step}
Reward signal
The scalar reward is decomposed into three components so you can inspect what the agent is optimising for.
# Reward shaping — returned on every /step response{"reward": -0.34,"rewardComponents": {"latencyPenalty": -0.20, # latency above SLO target"costPenalty": -0.18, # cost above budget"throughputBonus": 0.04 # requests served successfully},"done": false,"episodeStep": 12,"maxSteps": 100}
/step or/reset call.done: true, callPOST /reset to continue.GET /observation at any time to read the current state without consuming a step.Eval episodes
After training, run eval episodes with real-world cost dimensions priced in to check whether your policy is robust. A reward collapse means the agent's score dropped significantly once egress and cross-AZ charges were applied — a sign the policy exploited those costs being free during training.
write scope.