Most of the passive sentences have by phrase. But sometimes I see it is omitted.

What are the rules about the inclusion and exclusion of the by phrase in passive voice?

Generally speaking, just include it if you want to, and don't include it if you don't want to. If it adds to your meaning, you might want to include it.

Best wishes, Clive
It can be omitted if

1) it is clear in the context - no need

2) it is of no significance - no use