name: loop description: Execute a task repeatedly on a configurable interval (polling pattern) tags: [automation, monitoring] tools_required: [wait_seconds] parameters:
- name: instruction type: string description: Task to execute each iteration required: true
- name: interval_seconds type: integer description: Seconds between iterations default: 600
- name: max_iterations type: integer description: Maximum number of iterations default: 6 output_format: json
Loop / Polling Pattern
Execute a task on a recurring interval, collecting results from each iteration.
Steps
-
Initialize: Set
iteration = 0andresults = []. Note the current time asstart_time. -
Execute iteration: Perform the task described by
{instruction}. Record the output and whether it succeeded or failed. -
Record result: Append to results:
{"iteration": <n>, "timestamp": "<ISO 8601>", "status": "ok|error", "output": "..."} -
Check exit conditions: Stop early if:
- The instruction output contains an explicit "STOP" or "DONE" signal
- A critical error occurs that makes further iterations pointless
iteration >= {max_iterations}
-
Wait: If more iterations remain, call
wait_secondswith{interval_seconds}. Then increment the iteration counter and go to step 2. -
Summarize: After all iterations complete (or early exit), return:
{ "iterations_completed": <int>, "max_iterations": {max_iterations}, "interval_seconds": {interval_seconds}, "early_exit": true|false, "early_exit_reason": "...", "results": [...] }
Guidelines
- Keep each iteration's output concise -- avoid accumulating unbounded context.
- If the instruction involves checking a status, compare with the previous iteration and only report changes.
- Respect the agent's overall budget -- if running low on iterations or tokens, exit early and note the reason.