Well, it's possible to take voluntary bankruptcy, but I suspect that the AI would be extremely bad at knowing when to do that, so it probably doesn't do it at all.
The problem is really twofold. Firstly, it's possible to be deep in debt and still functional, so the AI does exactly that. Secondly, the AI treats debt as a significant factor in deciding whether to accept a call, even if it could easily afford to fight the war. Meaning that you can end up with a perfectly viable country making a small profit which nevertheless will consistently reject calls, yet will also happily start its own wars and drag you into them.