Your guess is right, names do have to agree with the rest of the sentence. In fact, all nouns (except for some loanwords like 'salami' or 'tabu') and several other parts of speech do. That's because we have declination with 7 cases. In other words, any name, noun, pronoun or adjective in Polish has 14 different forms: 7 singular and 7 plural ones (for many words some of them overlap though).
Let's use examples:
"Kasia dostała prezent od Janka" - "Kasia received a present from John"
"Kasia dała prezent Jankowi" - "Kasia gave John a present"
The two constructions: "(to receive sth) from sb" and "(to give sth) to sb" need two different cases, that's why 'John' is not always 'Janek' in a Polish setence.
For further explanations go there:
http://polish.slavic.pitt.edu/firstyear/nutshell.pdf
(read from page 13)
The declination in Polish is a complicated issue and I'm quite sure it will give you a lot of confusion but I recommend you not to think about it too much - I guess there's no effective method to master it but practice. Anyway, I think most of times Polish people will understand you even if you use wrong cases, so be cool :)
Hope this helps.