Whenever I think about what happened on top of the tower and what Snape said to Harry afterward, I tend to think that Dumbledore did sacrifice himself for some reason that I can't quite grasp, in order to help Harry. That is until I remember what JKR said that we shouldn't think that Snape is too nice a guy - which throws all of my opinions on the ending right off the tower, so to speak!
It seemed that what happened could have been prearranged between the two of them, but how would Dumbledore know that the potion in the stand would do to him what it did, and how would he have gotten that information to Snape if he didn't know before he went to the cave? I think about Snape and potions and wonder if Snape didn't make that potion for Voldemort when he was still loyal to him and Snape was the one who told Dumbledore of its properties and what would happen when he drank it. Dumbledore knew he had to drink it, he couldn't pour it on the ground in order to empty the basin and he knew the potion would kill him simply by what he said to Harry, that he, Dumbledore, wasn't as important as Harry. He had to know that the only way you could get to the bottom of the basin was to drink the potion and that who ever did drink it would eventually die.
When Dumbledore told Harry what happened to his hand, Dumbledore said it was a small price to pay for one-seventh of Voldemort's soul, but if all that I said above is true and Dumbledore knew he would die by drinking the potion, then he died for nothing, and it makes me wonder if Snape didn't possibly know that what was at the bottom of the basin wasn't what Dumbledore was looking for, and it goes back to JKR's words about Snape's character.
All that said, if thoughts passed between Snape and Dumbledore before the curse, I'd say Dumbledore, who couldn't even stand up, was begging Snape to take him out. He was obviously suffering and I would think that if Snape was on Dumbledore's side and still spying on Voldemort, it might have been prearranged that Snape should kill Dumbledore if the need should arise, and if Snape was on Dumbledore's side, I'm sure he knew where Dumbledore and Harry had gone and what condition Dumbledore would be in when he returned.
As for Snape attacking Flitwick; I think he wanted him out of the way so he wouldn't be harmed. Maybe, if he'd had the chance he would have stunned everyone he could in order to keep them safe, but that makes me wonder if he stunned Flitwick to protect him, why did he let Hermione and Luna walk away. It would seem that he would have wanted to protect them too, so that thought doesn't really fly either.
As for SPF's comment that Dumbledore wouldn't ask Snape to kill, I don't think Snape being at Hogwarts was like him being in rehab or anything. He was there to make amends for something we still don't know about - and if he did kill Dumbledore as he requested, I think he felt guilty about it afterwards just by what he said to Harry on the lawn when Harry called him a coward. JKR tried to show Snape's pain at what he'd done, possibly, his firing of the fatal curse was the hardest thing he had ever done, (we don't know that Snape ever personally killed anyone while in Voldemort's service, maybe Dumbledore was his first?) - this taken along with his words to Harry: "DON'T CALL ME A COWARD!" Maybe it was the bravest thing he ever had to do and his perpetual anger toward Harry because of James, could not override his obligation to Dumbledore. Maybe there was enough good in Snape that he could get just far enough past his old feelings of hate toward James that he
was actually helping Harry with his words -
Keep your mouth shut and mind closed!
As you can tell, I'm still on the fence on this - I have no set in stone view on this and find there is not enough evidence either way for me to make up my mind. JKR left too many dead ends and unanswered questions, as she always does. I could lean more toward Snape killing Dumbledore out of necessity and not because he's an evil traitor, but I can't declare him that good yet. I'm going to read HBP again and see if I can make up my mind!