Add comprehensive execution protocol to formula description: - EXECUTION LOOP: find ready step, close it, repeat - ON RESUME: same as fresh start, molecule IS the state - DO/DO NOT guidelines for autonomous execution - MONITORING guidance for mega-molecules This enables agents to execute Hanoi autonomously through restarts, proving nondeterministic idempotence at scale. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
133 lines
4.4 KiB
YAML
133 lines
4.4 KiB
YAML
# Towers of Hanoi Formula
|
|
#
|
|
# Demonstrates that molecule algebra solves the "million step workflow" problem.
|
|
# LLMs fail on long sequences because errors accumulate (99.9%^1000 ≈ 37% success).
|
|
# MAKER used voting to reduce error. We use mechanical structure instead.
|
|
#
|
|
# Key insight: The move sequence is deterministic. Only execution needs AI.
|
|
# And each step is trivial: "move disk X from peg Y to peg Z".
|
|
#
|
|
# For n disks: 2^n - 1 moves
|
|
# 20 disks = 1,048,575 moves (the "million step" problem)
|
|
#
|
|
# The iterative algorithm (no recursion needed):
|
|
# For move k (1-indexed):
|
|
# - disk = largest power of 2 dividing k (disk 1 is smallest)
|
|
# - direction = computed from disk parity and move number
|
|
#
|
|
# This formula uses for-each to generate all moves at cook time.
|
|
|
|
formula: towers-of-hanoi
|
|
description: |
|
|
AGENT EXECUTION PROTOCOL - Towers of Hanoi ({disks} disks, {total_moves} steps)
|
|
|
|
PURPOSE: This is a durability proof, not computation. Steps are pre-computed.
|
|
Your job is to execute them mechanically, proving crash-recovery at scale.
|
|
|
|
EXECUTION LOOP:
|
|
1. Find current state: bd mol current <mol-id>
|
|
2. Find the next ready (unblocked) step
|
|
3. Close it: bd close <step-id>
|
|
4. Repeat until no ready steps remain
|
|
|
|
ON RESUME (after crash/restart/handoff):
|
|
- Same as fresh start. The molecule IS the state.
|
|
- Query `bd mol current <mol-id>`, continue from there.
|
|
- No memory of previous session needed.
|
|
|
|
DO:
|
|
- Close steps as fast as possible (they're trivial mechanical moves)
|
|
- Use `gt handoff` when context fills (proactive cycling)
|
|
- Trust the pre-computed solution - every move is already correct
|
|
|
|
DO NOT:
|
|
- Try to solve Hanoi yourself - moves are already computed
|
|
- Mark steps in_progress - just close them directly
|
|
- Ask for permission - this is GUPP territory, just execute
|
|
- Stop for human input - run autonomously until complete
|
|
|
|
MONITORING:
|
|
- Progress: Count closed children of the molecule
|
|
- For mega-molecules: Use convoy dashboard when available
|
|
- Completion: All steps closed = molecule complete
|
|
|
|
This proves Gas Town can execute arbitrarily long workflows with
|
|
nondeterministic idempotence - different sessions, same outcome.
|
|
version: 1
|
|
|
|
vars:
|
|
disks: "{{disks}}"
|
|
source_peg: "A"
|
|
target_peg: "C"
|
|
auxiliary_peg: "B"
|
|
|
|
# The magic: for-each over computed move sequence
|
|
# Each move is deterministic, computed from move number
|
|
generate:
|
|
# This is pseudo-syntax for the runtime expansion we'd need
|
|
for-each:
|
|
var: move_num
|
|
range: "1..2^{disks}" # 1 to 2^n - 1
|
|
step:
|
|
id: "move-{move_num}"
|
|
description: >
|
|
Move {computed_disk} from {computed_source} to {computed_target}.
|
|
|
|
This is move {move_num} of {total_moves}.
|
|
Simply execute the move - no decision needed.
|
|
needs:
|
|
- "move-{move_num - 1}" # Sequential dependency
|
|
compute:
|
|
# Disk to move: position of lowest set bit in move_num
|
|
disk: "lowest_set_bit({move_num})"
|
|
# Peg calculations based on disk parity and move number
|
|
source: "peg_for_disk({disk}, {move_num}, 'source')"
|
|
target: "peg_for_disk({disk}, {move_num}, 'target')"
|
|
|
|
# Alternatively, simpler recursive template for smaller N:
|
|
# (This would need the recursive expansion operator)
|
|
|
|
steps:
|
|
- id: setup
|
|
description: >
|
|
Verify initial state: {disks} disks stacked on peg {source_peg}.
|
|
All disks in order (largest on bottom).
|
|
|
|
- id: solve
|
|
description: >
|
|
Execute all {total_moves} moves to transfer tower from
|
|
{source_peg} to {target_peg}.
|
|
needs: [setup]
|
|
# This step would be expanded by the generate block above
|
|
|
|
- id: verify
|
|
description: >
|
|
Verify final state: all {disks} disks now on peg {target_peg}.
|
|
Tower intact, all moves were legal.
|
|
needs: [solve]
|
|
|
|
# For the prototype, let's show a 3-disk example (7 moves):
|
|
example_3_disk:
|
|
# Move sequence for 3 disks: A→C, A→B, C→B, A→C, B→A, B→C, A→C
|
|
steps:
|
|
- id: move-1
|
|
description: "Move disk 1 from A to C"
|
|
- id: move-2
|
|
description: "Move disk 2 from A to B"
|
|
needs: [move-1]
|
|
- id: move-3
|
|
description: "Move disk 1 from C to B"
|
|
needs: [move-2]
|
|
- id: move-4
|
|
description: "Move disk 3 from A to C"
|
|
needs: [move-3]
|
|
- id: move-5
|
|
description: "Move disk 1 from B to A"
|
|
needs: [move-4]
|
|
- id: move-6
|
|
description: "Move disk 2 from B to C"
|
|
needs: [move-5]
|
|
- id: move-7
|
|
description: "Move disk 1 from A to C"
|
|
needs: [move-6]
|