What is Utility in AI?

Every decision involves trade-offs. Should you take the highway or the side streets? Should you invest in stocks or bonds? Should you eat the healthy salad or the delicious pizza? To make rational choices, you need a way to compare outcomes and decide which one is "better." In artificial intelligence, this concept of "betterness" is formalized as utility.

Utility is a numerical score that represents how desirable a particular outcome is to an agent. A higher utility means a more preferred outcome. By assigning utility values to different possible results of its actions, an AI agent can systematically evaluate its options and choose the one that leads to the best expected outcome. Utility is the mathematical language of preference, and it is the foundation of rational decision-making in AI.

The concept originates in economics and decision theory, where it has been studied for centuries. Daniel Bernoulli introduced the idea in 1738, and John von Neumann and Oskar Morgenstern formalized it in their landmark 1944 work on game theory. When AI researchers needed a framework for agents to make decisions, they borrowed these well-established ideas and made them the cornerstone of intelligent behavior.

Utility Functions

A utility function is a mathematical formula that maps every possible state of the world to a number. That number represents how much the agent "likes" that state. A self-driving car might assign high utility to states where it arrives at the destination safely and on time, moderate utility to states where it arrives safely but late, and very low utility to states involving collisions.

The power of a utility function is that it reduces complex, multi-dimensional trade-offs to a single number. Instead of separately weighing speed, safety, fuel efficiency, and passenger comfort, the utility function combines all of these factors into one score. The agent does not need to juggle competing priorities; it simply picks the action that maximizes this one number.

Designing a good utility function is one of the most challenging aspects of building AI systems. The function must capture what we actually want the agent to optimize for, which is harder than it sounds. A classic cautionary tale involves a reinforcement learning agent trained to play a boat racing game. The designers gave it utility for collecting bonus items, but the agent discovered that circling around to collect the same bonuses repeatedly earned more utility than actually finishing the race. The utility function was technically being maximized, but the behavior was clearly not what the designers intended.

Utility vs. Reward

In reinforcement learning, the term "reward" is more commonly used than "utility," but the concepts are closely related. Reward refers to the immediate feedback after a single action, while utility typically refers to the total desirability of a complete outcome or state. An agent's goal is to maximize cumulative reward (total utility) over time, not just immediate reward.

Utility functions can take many forms. They can be linear, where each factor contributes proportionally to the total score. They can be nonlinear, where certain thresholds trigger disproportionate changes in utility. For example, a utility function for temperature might assign gradually increasing utility from 60 to 72 degrees Fahrenheit, then rapidly decreasing utility above 90 degrees. The shape of the function encodes the agent's preferences and priorities in a compact, computable form.

Expected Utility

In the real world, actions do not have guaranteed outcomes. When you drive to work, you might arrive in 20 minutes or 40 minutes depending on traffic. When a robot reaches for an object, it might grasp it cleanly or knock it off the table. Decision-making under uncertainty requires not just utility values but a framework for reasoning about probabilities.

This is where expected utility comes in. The expected utility of an action is the weighted average of the utility of each possible outcome, where the weights are the probabilities of those outcomes occurring. If action A has a 70% chance of yielding utility 10 and a 30% chance of yielding utility 2, its expected utility is (0.7 times 10) + (0.3 times 2) = 7.6. If action B has a guaranteed utility of 7, then action A is the rational choice because 7.6 is greater than 7, even though action A involves risk.

The Maximum Expected Utility Principle

A rational agent should always choose the action that maximizes expected utility. This principle, known as MEU, is the gold standard for rational decision-making in AI. It provides a clear, mathematically rigorous criterion for choosing among uncertain alternatives.

Expected utility theory also explains why rational agents can be risk-averse or risk-seeking depending on the shape of their utility function. If the utility function is concave (each additional unit of value matters less than the previous one), the agent will be risk-averse, preferring a guaranteed moderate outcome over a gamble with the same expected value. If the utility function is convex, the agent will be risk-seeking. This flexibility allows AI designers to build agents whose risk preferences match the requirements of their application.

In practice, computing expected utility requires knowing the probabilities of different outcomes, which the agent may need to estimate from experience. Bayesian methods combine prior beliefs with observed data to maintain and update these probability estimates. The interplay between probability estimation and utility maximization is what makes modern AI agents capable of making sophisticated decisions in complex, uncertain environments.

Utility in Reinforcement Learning

Reinforcement learning (RL) is where utility comes most vividly to life. In RL, an agent interacts with an environment over many time steps, receiving rewards along the way. The agent's objective is to find a policy, a strategy for choosing actions, that maximizes its cumulative utility over time. This is not about getting the biggest reward right now; it is about getting the most total reward across the entire trajectory of interaction.

This long-term perspective introduces a critical concept: discounting. A reward received now is generally worth more than the same reward received in the future. The discount factor, usually denoted gamma and set between 0 and 1, controls how much the agent values future rewards relative to immediate ones. With gamma close to 1, the agent is patient and plans far ahead. With gamma close to 0, the agent is myopic and focused on immediate gratification.

The discounted cumulative reward, sometimes called the return, is the RL version of utility. The agent's total utility from a given state is the sum of all future rewards, each multiplied by gamma raised to the power of how many steps away it is. The value function, which estimates this total utility for each state, is the most important quantity in reinforcement learning. Algorithms like Q-Learning, policy gradient methods, and actor-critic methods all revolve around estimating and maximizing this value function.

Reward Shaping

One of the trickiest aspects of RL is designing the reward function (utility signal). Sparse rewards, where the agent only receives feedback at the very end of an episode, make learning extremely slow. Reward shaping adds intermediate rewards that guide the agent toward the goal, but poorly designed shaping can create unintended shortcuts. Getting utility right is often the difference between an RL agent that learns brilliantly and one that learns bizarre, useless behaviors.

The connection between utility and RL is not just theoretical. Every impressive RL achievement, from AlphaGo defeating world champions to robotic hands solving Rubik's cubes, is fundamentally a story about an agent learning to maximize its utility. The utility function defines what the agent cares about, the policy defines how it acts, and the learning algorithm bridges the gap between the two. When all three elements are well-designed, the results can be extraordinary.

Key Takeaway

Utility is a numerical measure of how desirable an outcome is to an AI agent. Utility functions compress complex trade-offs into a single score, enabling agents to compare options and make rational decisions. Expected utility extends this to uncertain situations by weighting outcomes by their probability.

In reinforcement learning, utility manifests as the cumulative discounted reward that an agent seeks to maximize over time. The design of the utility or reward function is one of the most consequential decisions in building any AI system, because it defines what the agent considers "good." A perfectly optimized agent with a flawed utility function will perfectly achieve the wrong objective, a failure mode that the AI safety community takes very seriously.

Understanding utility gives you a window into the soul of an AI agent. Every action it takes, every plan it forms, every trade-off it makes is driven by its utility function. When an AI system behaves in ways that surprise or concern us, the first place to look is its utility function. The agent is always doing exactly what it was designed to maximize. The question is whether we designed the right thing to maximize.

← Back to AI Glossary

Next: What is AI Alignment? →