If an agent gets things wrong you should stop it and correct it instead.
Sometimes the correction will cost more than starting from scratch. In those cases, you start from scratch.
You do things manually only when novel work is required (the model is unlikely to be trained with the knowledge). The more novel the thing you're doing, the more manual things you have to do.
Identifying "cost of refactoring", and "is this novel?" are also developer skills, so, no formula here. You have to know.
Sometimes the correction will cost more than starting from scratch. In those cases, you start from scratch.
You do things manually only when novel work is required (the model is unlikely to be trained with the knowledge). The more novel the thing you're doing, the more manual things you have to do.
Identifying "cost of refactoring", and "is this novel?" are also developer skills, so, no formula here. You have to know.