Here is how the AI works:
If you have NO attack ships in a system, Pirates can and will spawn there and kill your ships that are undefended.
Pirate will also steal resources if there are no ships around to kill.
Pirates are attracted to people trading resources via canisters, or transfers.
Placing a few attack ships in your freighter fleets is like in Stellaris with attack fleets in a system, they basically ward of pirates attacking.
IF you have attack fleets in most of your systems, pirate instead spawn right outside a system, and will move away.
Pirate fleets are insanely easy to kill, if you are having trouble killing them, please ask someone for help. As a human player, the weakest of the four races, I have constantly outpaced pirates. I can take on 11/14 fleets without T3 ships, only a fleet of T2 frigates. Since literally every other T2 ship in the game is more powerful than human T2, that means everyone else can take these pirates out too fairly easy.
Pirates are super super super easy, if you are having issues with pirates, then you need to change how you are dealing with them, or how you are defending yourself. If you have issues with pirates, then most likely you will be rolled over by actual PvP, as people are smarter than the AI.
A couple other things to mention, pirates are deadly if you don’t use shields cause they use armor bane weapons, they only use plasmas/armor bane. This means heavy shields + ballistics can take them down.
Pirates drop massive amounts of resources, each fleet drops around 1-2 ships worth of resources at the appropriate levels. 11/14 fleets drop 70k F, and 18k Zi. Its worth it to invest in a pirate killing fleet, then farm back the resources that you invested, it shouldn’t take too long as pirate spawn at least a couple times per week.
Keep attack ships with your hauling ships
Keep attack ships in systems/gravity wells of your planets
Build a shield heavy/ballistic heavy fleet to fight pirates
These basic concepts will help you, once you find your sweet spot, you will beg the Devs to put more pirates in game.