stable-baselines3
Enables your agent to train and evaluate reinforcement learning models. It's used to teach agents how to make decisions in complex environments, like games or robotics.
What it does
This tool helps train artificial intelligence 'agents' to learn how to make decisions in simulated environments. It uses reinforcement learning algorithms so the agents improve with experience.
When to use it
- ✓When you want to teach a virtual robot to walk.
- ✓When creating a game where a character learns to play by itself.
- ✓To test strategies in complex simulations.
Example of what to ask your AI
“Train an agent to play Pac-Man using the PPO algorithm.”
Want more? Open the sections below.
How to use
The easiest way: copy the message below and paste it into Claude, ChatGPT, Cursor or any AI. It reads the skill and follows the instructions.
Skill link
Ready-to-paste message
How it works
You define the environment where the agent will learn and choose an algorithm. The tool then runs the training, allowing the agent to adjust its actions to get rewards.
Installation
Easiest way: copy the skill link and paste it into Claude, ChatGPT or Cursor asking it to follow the instructions.
In the terminal (Claude Code, Codex, Cursor), in your project folder:
npx skills add K-Dense-AI/scientific-agent-skills --skill stable-baselines3Or download just the file:
curl -L https://raw.githubusercontent.com/K-Dense-AI/scientific-agent-skills/main/skills/stable-baselines3/SKILL.md -o SKILL.mdTechnical content (original SKILL.md)
Original text by the author, straight from GitHub.
Stable Baselines3
Overview
Stable Baselines3 (SB3) is a PyTorch-based library providing reliable implementations of reinforcement learning algorithms. This skill provides comprehensive guidance for training RL agents, creating custom environments, implementing callbacks, and optimizing training workflows using SB3's unified API.
Current upstream: SB3 2.9.0 (June 15, 2026). Docs: stable-baselines3.readthedocs.io.
Installation
Tested against stable-baselines3 2.9.0. Requires Python 3.10+ (3.9 dropped in 2.8.0) and PyTorch >= 2.8.
# Basic installation
uv pip install "stable-baselines3==2.9.0"
# With extra dependencies (TensorBoard, ale-py for Atari, etc.)
uv pip install "stable-baselines3[extra]==2.9.0"
The 2.9.0 release supports Gymnasium >=0.29.1,<2.0; this review exercised Gymnasium 1.3.0, PyTorch 2.14.1 and Python 3.13 on CPU. pandas/matplotlib are now optional extras. Installation requires network unless packages are cached; local RL training needs no credentials or service endpoints.
On zsh, quote brackets: uv pip install 'stable-baselines3[extra]==2.9.0'.
For MuJoCo continuous-control benchmarks:
uv pip install "gymnasium[mujoco]"
Check your version:
import stable_baselines3
print(stable_baselines3.__version__)
Related Projects
- SB3-Contrib: experimental algorithms (MaskablePPO, CrossQ, QR-DQN, RecurrentPPO) — separate
sb3-contribpackage - RL Baselines3 Zoo: pre-trained agents, hyperparameters, training scripts
- SBX: SB3 + JAX implementations for users who prefer JAX over PyTorch
Core Capabilities
1. Training RL Agents
Basic Training Pattern:
import gymnasium as gym
from stable_baselines3 import PPO
# Create environment
env = gym.make("CartPole-v1")
# Initialize agent (device="cpu" is often faster for MlpPolicy on small envs)
model = PPO("MlpPolicy", env, verbose=1, device="cpu", seed=0)
# Train the agent
model.learn(total_timesteps=10000)
# Save the model
model.save("ppo_cartpole")
# Load the model (without prior instantiation)
model = PPO.load("ppo_cartpole", env=env, device="cpu")
env.close()
Important Notes:
total_timestepsis a lower bound; actual training may exceed this due to batch collection- Call the class method
PPO.load(...)and keep the returned new model - The replay buffer is NOT saved with the model to save space
Algorithm Selection:
Use references/algorithms.md for detailed algorithm characteristics and selection guidance. Quick reference:
- PPO/A2C: General-purpose, supports Box, Discrete, flat MultiDiscrete and MultiBinary actions, good for multiprocessing
- SAC/TD3: Continuous control, off-policy, sample-efficient
- DQN: Discrete actions, off-policy
- HER: Replay-buffer strategy for goal-conditioned off-policy tasks
See scripts/train_rl_agent.py for a complete training template with best practices.
2. Custom Environments
Requirements:
Custom environments must inherit from gymnasium.Env and implement:
__init__(): Define action_space and observation_spacereset(seed, options): Return initial observation and info dictstep(action): Return observation, reward, terminated, truncated, inforender(): Visualization (optional)close(): Cleanup resources
Key Constraints:
- Default CNN image preprocessing expects
np.uint8in range [0, 255] - Use channel-first format when possible (channels, height, width)
- SB3 normalizes images automatically by dividing by 255
- For pre-normalized float images, use channel-first layout and
policy_kwargs={"normalize_images": False} - SB3 does NOT support
DiscreteorMultiDiscretespaces withstart!=0
Validation:
from stable_baselines3.common.env_checker import check_env
check_env(env, warn=True)
See the template and environment guide.
The template now observes both agent and random goal coordinates, shape (4,);
old shape (2,) checkpoints require retraining. gym.make("CustomEnv-v0") adds
the 100-step time limit; direct CustomEnv() does not. check_env checks API
consistency, not Markov sufficiency, reward correctness or learnability.
…
FAQ
What is 'reinforcement learning'?
It's a type of machine learning where an agent learns to make decisions by receiving rewards or punishments for its actions.
What are 'custom environments'?
These are simulations you create yourself to train the agent in specific situations that aren't readily available.
Why use 'vectorized environments'?
They allow running multiple simulations at the same time, which greatly speeds up agent training.
Details
Original description by the author
Trains and evaluates single-agent reinforcement learning with Stable Baselines3 (PPO, SAC, DQN, TD3, DDPG, A2C), Gymnasium custom environments, vectorized rollouts, callbacks, and checkpoint normalization. Applies to reproducible RL experiments, continuous control, discrete actions, and SB3-Contrib recurrent or masked policies.
Popularity
- GitHub stars
- 51k
- Ranking position
- #1983
- License
- MIT
- Updated
- 10/15/2026
Comments
- …
More skills from this repository
13c-metabolic-flux
Estimates metabolic fluxes using carbon-13 isotope tracing data. It is useful for analyzing cellular metabolism and biochemical pathways.
K-Dense-AI/scientific-agent-skills
adaptyv
Designs protein characterization experiments using the Adaptyv API. It helps estimate costs, submit sequences, and monitor lab results.
K-Dense-AI/scientific-agent-skills
aeon
Performs machine learning tasks on time series data. It is useful for classifying, forecasting, detecting anomalies, and finding patterns in sequential data.
K-Dense-AI/scientific-agent-skills
alphagenome
Looks up precomputed genomic effects for genetic variants. It provides scores and explanations to understand the impact of variants on the genome.
K-Dense-AI/scientific-agent-skills
Similar skills
agent-architecture-audit
Makes your agent check if everything is working correctly. It finds and fixes problems in AI systems, ensuring they perform as expected.
affaan-m/ECC
agent-eval
Helps your agent compare different AI coding tools. It measures which one is faster, cheaper, and more reliable for specific tasks.
affaan-m/ECC
agent-harness-construction
Makes your agent better understand how to perform tasks. It optimizes the tools and instructions the agent uses to increase its chances of success.
affaan-m/ECC