This project puts a small idea to work: an RL agent that can ask a supervised model whether an action looks risky before it takes it. The experiment asks whether that filter makes learning faster, safer, or both, and what it costs.
The world is a 10 by 10 grid with a start state, a goal, and hazards. A baseline Q-learning agent learns from reward alone. The shielded version sends candidate actions through a classifier before it commits.
Environment
Each state-action pair is described by position, action, and features derived from the environment. The reward is deliberately plain: positive at the goal, a small penalty for an ordinary step, a large penalty for a hazard.
That shaping makes the failure mode visible. An agent can learn to reach the goal and still have collected a lot of hazard violations on the way.
Supervised Shield
The shield is a classifier trained on labeled state-action examples. The labels come from a multi-source BFS distance map grown outward from the hazards: immediate hazard, near hazard, farther risk, safe.
At each step the policy proposes an action and the classifier assigns it a risk level. If that level crosses the selected threshold, the agent picks among the safer candidates instead.
Results Pattern
The threshold does most of the work. A loose threshold removes hazard violations without giving up much reward. A strict one makes the agent so conservative that success rate drops.
Both effects show up in the same experiment. A safety layer that only reports fewer violations says nothing about whether the task still gets done.
Knowledge Points
- Q-learning keeps value estimation separate from the environment model, which makes it easy to drop into a grid-world experiment.
- A supervised model can carry domain knowledge into the loop as a reusable action filter.
- When the hazards are known, BFS distance gives a consistent way to label training data.
- A safety layer has to be judged on violations and task performance at the same time.
- False negatives matter most: one dangerous action that gets through can break the safety promise.
- The shield is policy guidance, not a replacement for the RL algorithm.
- Evaluation needs baseline reward, success rate, violations, and intervention counts side by side.
Takeaway
Classical RL and supervised learning do different jobs here. The agent still learns the policy; the classifier draws a boundary around the actions it may consider. Most of the engineering sits in choosing that boundary, and the threshold is the first thing I would tune.