If the agent's change has such a catastrophic effect, the first thing you do is tell it to explain why its change had that effect.
Once you understand what the problem is, you can give it better instructions. If the architecture is shit, the agent is going to have a rough time of it.