The Kreps—Wilson—Milgrom—Roberts framework is one of the most renowned ways of modelling reputation—building. Once the number of repetitions of the game is considered as a choice variable, such a framework can fruitfully be employed to study the optimal length of a relationship. We analyze a model where a principal delegates to an agent the task of playing with a third party a finitely repeated trust game, characterize the optimal length of the relationship between principal and agent when the principal’s preferences on the agent’s type stochastically change over time and show that stable relationships may optimally obtain (even) in very unstable environments.