# Skill: Set up a safe autonomous agent loop with a kill switch and bridge file > Configure an AI agent to run a repeating pipeline (do -> tidy -> check -> save) unattended overnight without burning budget or losing progress. Applies whenever a task is too large to supervise step-by-step and needs to run across multiple agent sessions. Source: sodigi·learn — vibecoding/avtonomnye-cikly · https://sodigi.io/learn/vibecoding/avtonomnye-cikly ## When to use - A task covers many files or modules (e.g., "add tests to every function in the project"). - You want the agent to work unsupervised overnight and deliver a result by morning. - A pipeline has repeating phases: generate, clean, verify, commit. - Budget control is critical and you cannot monitor each step manually. ## Core rules - Every autonomous loop MUST have a kill switch: a cap on rounds, a spending limit, a time limit, or a "done" signal phrase from the agent. - Use a bridge file (e.g., SHARED_TASK_NOTES.md) so the agent writes what is done and what is left at the end of each round. The next round reads this file first. - Each round should handle one small unit of work (one module, one file) -- not the whole project at once. - Use a separate cleanup round instead of "don't do X" rules: let the agent work freely on step 1, then clean up in a fresh context on step 2. - When the same step fails two rounds in a row, pass the error text forward and move to the next unit -- do not blindly retry. - Spread the pipeline steps across separate agent runs (separate context windows) so the desk stays clean. - Trust the "done" signal only after the agent repeats it multiple rounds in a row (e.g., 3 consecutive times). ## Procedure 1. Define the goal and the "done" condition before writing the prompt. 2. Slice the total work into small per-round units (one module, one file, one test suite). 3. Write the loop prompt: name the bridge file, describe each phase (do / tidy / check / save), set the kill switch (max N rounds or spending cap), and add the failure-forward rule. 4. Start the agent with the loop prompt. It reads the bridge file on round 1 (or creates it), works one unit, writes progress, stops. 5. Re-run the agent for each subsequent round. It reads the bridge file to know where to continue. 6. After the loop ends (kill switch or done signal), review the bridge file and the committed output. ## Ready-to-use prompt ``` Work in autonomous-loop mode: keep adding tests to the project until every function has test coverage. Loop rules: 1. At the start of each round, read SHARED_TASK_NOTES.md. If it does not exist, create it. Pull from it the list of what is done and what is left. 2. Take ONE module per round. Write the tests thoroughly. 3. As a separate action in the same round, remove clutter: junk checks, debug prints. Run the tests and fix anything broken. 4. At the end of the round, write to SHARED_TASK_NOTES.md: what you did and what remains. 5. Kill switch: maximum 8 rounds. If all modules are covered before that -- write WORK COMPLETE and stop. 6. If the same test fails two rounds in a row -- do not retry blindly. Write the cause in the notes and move to the next module. ``` ## Pitfalls - A loop with no kill switch -- the most dangerous mistake; always set a round, money, or time limit. - No bridge file -- the agent forgets all progress between sessions and walks in circles, redoing done work. - A giant task in one round -- the context fills up and quality collapses; keep rounds small. - Blindly repeating a failed step -- pass the error text forward, not just "try again." - Cramming "don't do X" rules into the prompt instead of a dedicated cleanup round -- the agent becomes timid and skips necessary work. - Trusting a single "I'm done" signal -- wait for it to repeat across multiple rounds.