You should make sure that your queries to the agent contain a "loop condition"[1]. This can be something like "keep trying until yarn test passes".
Always remember that these agents are just LLMs running tools in a loop and treat them as such.
[1] https://www.skeptrune.com/posts/prompting-the-agent-loop/