dual_iterate
Generates code with automated review loop: writes, scores against quality threshold, and iterates until accepted. Reduces token cost for complex single-file tasks.
Instructions
Code generation with an internal review loop: a generator backend writes code, a reviewer backend scores it against quality_threshold, the generator fixes flagged issues, and the cycle repeats until the threshold is met or max_iterations runs out. The whole loop runs inside SAB; Claude sees only the final accepted code (~1 turn of output instead of 3-5). Use for complex single-file generation where you would otherwise pay the token cost of reviewing iterations in-chat. For multi-agent TDD with parallelism + tests, use parallel_agents. For one-shot generation without iteration, use generate_file. Read-only: returns the generated code to the caller; does NOT write to disk (pass the result to write_files_atomic to persist). Returns: {success, code (final accepted code as a string), mode (the iteration mode used), iterations (number actually run), execution_time_ms, metadata:{task_preview, code_length, timestamp}, history (full per-iteration log, only when include_history:true), final_review:{status, notes}, self_review_applied}.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| task | Yes | Code generation task description (e.g., "Write a function that validates email addresses") | |
| max_iterations | No | Maximum review iterations before accepting result (default: 3) | |
| include_history | No | Include iteration history in response (useful for debugging) | |
| quality_threshold | No | Minimum reviewer score (0.5–1.0) needed to accept and stop iterating. 0.7 (default) = balanced. 0.85+ = strict (more iterations, better code, may exhaust `max_iterations`). 0.5 = lenient (returns first plausible attempt). The loop also stops at `max_iterations` regardless of threshold. |