

The way The Sims does it is actually pretty interesting. The individual sims have very little behavioral coding involved. They’re basically just monitoring their individual needs. The vast majority of the objects contain “advertisements” that they broadcast, and the sims can simply look for nearby advertisements to decide on what to do.
Basically, you have a sim. They are simply listening to advertisements that are being broadcasted by the objects around them. Maybe the kitchen sink says “Clean +3” while the shower says “Clean +7”. If the sim’s cleanliness meter is low, they’ll check for local “clean” advertisements and choose one. As their needs get lower and lower, they’ll be more likely to pick stronger advertisements. So a slightly dirty sim will be likely to choose the sink, but a very dirty sim will choose the shower.
Then once they get to the chosen object, the object basically goes “okay, here’s how to interact with me”. The sim simply pulls from that pool of interactions for the specific object. There may be flags for specific interactions based on certain conditions, or certain traits that make a sim more likely to choose one object over another. For instance, if your sim is a witch, they may have specific magical interactions available. Or if a sim has the Active trait, they may be more likely to choose fitness-based advertisements.
This makes adding expansions very easy. You don’t need to do a ton of coding for individual sims, to “teach” them how to use new objects. You simply add new advertisements to the objects you’re adding to the game, and make sure your interactions are properly flagged for the various conditions that can exist. And now those objects can be dropped directly into existing save files without any fuss.
Worth noting that this advertisement system is what caused the infamous “my sim is using the bathroom sink to wash dishes” complaint that plagued the series for so long; the bathroom sink was nicer than the kitchen sink, so it had a better advertisement. The sim wasn’t looking at advertisements based on why they needed a sink. They just knew they needed a sink to wash dishes, and picked the one with the strongest advertisement.
That’s actually exactly what they did to fix it. They now allow you to flag sinks as bathroom or kitchen sinks, which simply controls whether or not the dish washing function can be accessed.