Hmm, I'm not sure there is a reliable formula.
Everyone falls over themselves to tell me how great my teenage dd is - teachers, friends, strangers, her friend's parents. She is polite, confident, considerate, compassionate.
If I'm honest, I think it's about luck as much as anything...which could mean it's genetic or some other happy coincidence of circumstances. However, I do think there are some things that we have done which have helped.
For example, we have always tried to treat her with genuine respect and consideration - we have always explained the reasons behind why stuff was right or wrong, rather than going down the "I'm an adult and you're a child, so you'll do what you're told" route. I believe that kids probably need to feel respected themselves before they can properly show respect for others. I think it's also important that they see their parents consistently modeling respect and consideration in their interactions with others. A child watches their parents and copies their behaviour, so there is no point in preaching one thing and doing another.
People always talk on here about clear rules and boundaries, but that has never really meant much to me. Our main boundary is don't be an arse! We don't have loads of rules and we have never used rewards or punishments of any kind. We expect dd to be a decent, kind and respectful person. If she ever falls short of that, we talk about it with her, just as she would talk to us if she felt that we were falling short in some way. My parents raised dsis and me in a very similar manner.
We are fortunate in that dd takes pride in being a kind and decent person. Perhaps this has been helped by us noticing kind actions from an early age and helping her to see this as a central part of her identity, or perhaps it's just luck. She has a very strong sense of right and wrong, which makes parenting her quite easy.
Perhaps our approach would have been different with a different child, who's to say? But I do believe that showing them how to behave is much more important than telling them.