According to a friend of mine, the solution is to:
1) Create a README file for the AI agent telling it to run the compiler and all automated tests, and try another solution if compiler or tests fail. Do not claim to have solved a problem before this happens.
This works well for him.
He uses Claude code