TAP: Learning to Execute Real-World Tasks Safely through Tail-Aware Post-training
Language model agents now execute code and operate on file systems, where a single harmful tool call takes effect immediately and often cannot be undone. As agents take on long-horizon tasks, much of this harm arises not from malicious requests but while the agent carries out benign ones. In this setting, safety failures are tail events. Acting directly usually succeeds and only occasionally causes severe harm, so the mean reward that post-training methods such as GRPO maximize averages these failures away and favors the shortcut. We model the user's satisfaction as the expected utility of the reward under a risk-averse utility, and show that the mean reward overstates it for any risky policy, which drives the agent toward overly aggressive behavior that a larger penalty does not correct. We introduce Tail-Aware Post-training (TAP), which maximizes the certainty equivalent of the user's satisfaction under an exponential utility instead of the mean reward. TAP standardizes rewards within each group and applies an entropic-risk weighting that concentrates the update on the worst rollouts, which keeps the risk aversion fixed throughout training. It is a drop-in replacement for GRPO. We build SafeTask, a benchmark of benign tool-use tasks with hidden hazards. Across three open models on SafeTask and CAPE-Bench, GRPO leaves every agent less safe than before training, while TAP lowers harm below both the untrained model and GRPO in every case. Addtionally, TAP largely preserves task completion and general capability.