The companions I have the fondest memories of are pretty much all of the companions from Mask of the Betrayer. I liked some more than others, but they all felt like real, complex people with their fair share of flaws. They also had their own motivations, usually driven by specific parts of their pasts, and they followed the PC because their motivations and the PC's lined up, at least to some degree (exactly how much depended on how you played). Even their quests were tied into the main plot, reinforcing the idea that they were with the PC because they wanted to be instead of the PC just being a magnet that draws companions to them for gameplay purposes (come to think of it, KOTOR II actually had that as a plot point, which was a great in story explanation of a game mechanic). Comparatively, some of the most annoying companions I ever encountered were in the NWN2 main campaign, where they seemed like cardboard cutouts more often then not. They were set up just enough to have some real potential to be interesting characters, but there wasn't enough follow through on that end. They were entertaining cardboard cutouts, and many of them were likeable, but they could have been so much more.
Oddly enough, one of the best companions in NWN2 was Shandra, even though the game forced you to have her in your party for the second act, which is usually enough to turn me off from a companion. She had a very human element to her and the PC had reasons to care what happened to her, not just because she was needed for the plot, but because the PC was largely responsible for much of the misfortune she suffered before joining the party. She also never hesitated to tell the PC (and by extent the player) off when she disagreed with them, but she made her views felt and then let the player decided instead of constantly nagging them about something.
The other truly interesting companion from that game was Ammon. Much like the MotB companions, he was interesting because he had deep ties to the PC, the plot, and clearly stated motivations (although motivations do not need to be clearly stated, so long as we can tell that they exist and there's some sort of logic to them) that drove his character, as well as a list of flaws as long as my arm. On top of all that, he was a well executed, (mostly) unrepentant, believable evil character, which is rare enough to begin with. The fact that he was a companion and that the player was actually given a chance to understand how he became what he was and possibly even sympathise with him was just icing on the cake.
Basically, good companions are ones that have reason to exist beyond "We need to check the elf druid box", perferably reasons that tie into the main plot of the game itself, are relateable, and act human so that they're doing things for a reason and not just blatanly fulfilling a role that the plot demands be filled with no further depth or purpose.