They are both good, but have different meanings.
If I agree with someone, then my opinion is the same as theirs.
If two or more people agree on something, then they’ve made a decision together.
The city council agreed on a policy to close the parks at night, but I don’t agree with it. (‘it’ meaning ‘the policy’. I could also replace ‘it’ with ‘them’, with ‘them’ meaning ‘the city council’)