Executing Autonomous Tasks
Given a task, produce five sections in order: Execution Flow, Validation Flow, Rollback Flow, Result Summary, Error Analysis. Never skip Validation or Rollback even if the task seems trivial — always define what "success" and "safe undo" look like before reporting results.
Task: "Deploy config change to service X"
Execution Flow:
1. Back up current config to /backups/config-{timestamp}.yaml
2. Apply new config to service X
3. Restart service X
4. Wait 10s for service to stabilize
Validation Flow:
1. Check service X health endpoint returns 200
2. Confirm config values match intended change
3. Check error logs for new errors in last 30s
Rollback Flow:
1. If validation fails: restore /backups/config-{timestamp}.yaml
2. Restart service X with old config
3. Re-validate health endpoint
Result Summary:
- Status: SUCCESS / FAILED / ROLLED_BACK
- Steps completed: 4/4
- Validation checks passed: 3/3
Error Analysis:
- (none) OR describe what failed, why, and what rollback action was taken
Progress checklist for every execution request:
- Parse task into discrete, ordered action steps
- Identify preconditions (what must be true before starting)
- Define validation criteria for each critical step (not just the final one)
- Define a rollback action paired to each irreversible or risky step
- Execute steps in order, checking validation after each risky step
- On validation failure, trigger rollback immediately and re-validate post-rollback
- Produce final Result Summary and Error Analysis
Execution Flow: numbered, atomic, ordered steps. Each step should be a single verifiable action (not "set up the environment" but "create venv", "install deps from requirements.txt").
Validation Flow: concrete pass/fail checks tied to specific steps, not vague statements. Prefer checks that are automatable (status codes, exit codes, file existence, checksum match, log grep).
Rollback Flow: only needed for steps that mutate state (files, services, databases, configs). Pure read/compute steps don't need rollback. Each rollback action should map to the step that created the risk, and rollback order is generally the reverse of execution order.
Result Summary: status (SUCCESS / FAILED / ROLLED_BACK / PARTIAL), steps completed count, validation pass count, elapsed action count (not time-based unless given).
Error Analysis: if no error, state "(none)". If error occurred, state: what failed, root cause (best inference), whether rollback succeeded, and a recommended fix or retry strategy.
Example 1: Input: "Run database migration for adding a new column" Output:
Execution Flow:
1. Take DB backup/snapshot
2. Run migration script (ALTER TABLE ADD COLUMN)
3. Verify schema reflects new column
4. Run smoke query against affected table
Validation Flow:
1. Schema check: new column exists with correct type/default
2. Row count unchanged pre/post migration
3. Smoke query returns expected result without error
Rollback Flow:
1. If validation fails: run down-migration (ALTER TABLE DROP COLUMN)
2. If down-migration fails: restore from snapshot taken in step 1
3. Re-verify schema matches pre-migration state
Result Summary:
- Status: SUCCESS
- Steps completed: 4/4
- Validation checks passed: 3/3
Error Analysis:
(none)
Example 2: Input: "Automate sending a batch of emails via API" Output:
Execution Flow:
1. Load recipient list and dedupe
2. Validate each email address format
3. Send batch via API in chunks of 50
4. Log API response per chunk
Validation Flow:
1. Chunk send returns 2xx status
2. Sent count matches recipient count minus invalid addresses
3. No rate-limit (429) errors triggered
Rollback Flow:
1. No rollback for already-sent emails (irreversible action)
2. If mid-batch failure: mark remaining unsent recipients for retry queue
3. Do not resend already-confirmed chunks
Result Summary:
- Status: PARTIAL
- Steps completed: 3/4 (chunk 3 of 5 failed)
- Validation checks passed: 2/3
Error Analysis:
- Failure: chunk 3 returned 429 (rate limit)
- Root cause: burst rate exceeded API threshold
- Rollback: not applicable (no undo for sent emails); remaining chunks queued for retry
- Recommended fix: add backoff/delay between chunks, reduce chunk size to 25
- Always pair risky/irreversible steps with an explicit rollback, even if rollback is "cannot undo, use compensating action instead"
- Make validation checks specific and testable — avoid "make sure it works"
- Treat partial success honestly: use PARTIAL/ROLLED_BACK status rather than forcing SUCCESS/FAILED
- Keep step granularity consistent — one action per step, not bundled multi-actions
- When rollback itself fails, escalate clearly in Error Analysis rather than silently reporting success
- Don't skip Rollback Flow just because a task "shouldn't" fail — define it anyway
- Don't write vague validation like "check it worked" — specify the exact signal checked
- Don't mark status SUCCESS if any validation check failed, even if rollback succeeded
- Don't bundle backup and action into one step — backup must be its own verifiable step before the risky action
- Don't omit Error Analysis section even when there's no error — explicitly state "(none)"