The question of past participle agreement with auxiliary verb "avere" when direct object is present in the sentence is covered in sections 365 to 369 of the book Italiano by Luca Serianni. In section 365 this author explains:
Si ha [...] obbligo di accordo quando il participio si riferisca a uno dei seguenti pronomi atoni precedenti: lo, la, li, le.
That is, agreement is compulsory when participle refers to one of these pronouns preceding it: "lo", "la", "li", "le".
This book gives these examples:
- "io vedo sempre lui che me l'ha data, questa libertà" (Pirandello, Il giuco delle parti, III 33).
- "Di quei funghi si fece, in famiglia, un gran parlare: e i miei fratelli dissero alla mia nonna paterna [...] che li avremmo cucinati e mangiati" (Ginzburg, Lessico famigliare, 31).
As explained by Treccani Encyclopedia, another case in which agreement of participle with direct object is compulsory is when the pronominal particle "ne" is used as a partitive with the function of direct object, as in these examples:
- di film, ne ho visti parecchi
- ho comprato delle mele e ne ho mangiate tre (Cordin 2001: 650).
There are other instances with auxiliary verb "avere" in which agreement of past participle with direct object is optional, with a tendency in modern Italian to not do such agreement. They are covered in detail in Serianni's book. Some of them are explained in this article by Accademia della Crusca.