Order Procedure
Input: $ARGUMENTS
Interpretations
Before executing, identify which interpretation matches the user’s input:
Interpretation 1 — Sequence a plan: The user has a set of steps or tasks and needs to determine the correct execution order based on dependencies. Interpretation 2 — Find parallelism: The user has an ordered plan and wants to identify which steps can run simultaneously to reduce total time. Interpretation 3 — Optimize an existing sequence: The user already has a step order but suspects it is inefficient, and wants to reorder for speed, risk reduction, or resource efficiency.
If ambiguous, ask: “I can help with sequencing a plan, finding parallelism opportunities, or optimizing an existing sequence — which fits?” If clear from context, proceed with the matching interpretation.
Overview
Determine the correct execution order for a set of steps based on dependencies and constraints
Steps
Step 1: Collect steps and identify dependencies
Gather all steps and identify their dependency relationships:
- List all steps from input steps_list
- For each step, identify:
- Inputs required (implies dependency on source)
- Outputs produced (others may depend on)
- Resources used (potential conflicts)
- Constraints (deadlines, ordering requirements)
- Classify each dependency by type (hard, soft, mutual exclusion, resource)
Step 2: Build dependency graph
Construct a directed graph representing dependencies:
- Create a node for each step
- Add directed edge A->B for each hard dependency
- Add directed edge A~>B for each soft dependency (marked differently)
- Mark mutual exclusion relationships
- Annotate resource dependencies on edges
Step 3: Detect and resolve circular dependencies
Check for cycles and resolve them:
- Run cycle detection algorithm on the graph
- If cycle found:
- Identify all steps in the cycle
- Examine each edge: is it really a hard dependency?
- Often one edge is actually a soft dependency
- Break the weakest edge in the cycle
- Repeat until no cycles remain
- If cycle cannot be broken, flag as planning error
Step 4: Compute valid execution order
Perform topological sort to get valid ordering:
- Use Kahn’s algorithm or DFS-based topological sort
- If multiple valid orders exist, collect all nodes with no incoming edges
- Apply prioritization rules to choose among equal-priority nodes:
- Blocking steps before blocked (unblocks more work)
- Critical path steps first (determines total duration)
- High-risk steps early (fail fast)
- Quick wins if equal priority (builds momentum)
- Steps with many dependents first (maximizes unblocked work)
- Respect soft dependencies where possible without violating hard dependencies
Step 5: Identify parallel execution opportunities
Group steps that can run simultaneously:
- For each pair of steps, check:
- No dependency relationship (neither depends on other)
- No resource conflict
- No mutual exclusion constraint
- Group parallel-eligible steps that share the same “depth” in the graph
- Format as parallel groups with sync points
Step 6: Identify critical path
Find the longest dependency chain:
- Calculate the “depth” of each step (longest path to reach it)
- Identify the path with maximum total depth
- Mark steps on critical path (these determine minimum duration)
- Calculate slack for non-critical steps
Step 7: Apply optimization rules
Optimize the sequence for efficiency:
- Minimize context switches: group related steps together
- Front-load risk: move uncertain steps earlier
- Batch similar operations: group steps using same tools/resources
- Respect energy constraints: if human executor, hard steps when fresh
- Verify constraints are still satisfied after optimization
Step 8: Format and output final order
Produce the final ordered output in requested format:
- Simple numbered list
- With parallelism markers
- With dependency annotations
- Gantt-compatible format (if requested)
When to Use
- After generating steps from a COMPLETE_PLAN
- When steps have dependencies that must be satisfied
- When parallel execution opportunities should be identified
- When optimizing execution sequence for efficiency
- When constraints (deadlines, resources) must be respected
- When building a Gantt chart or execution timeline
Verification
- Every step’s dependencies appear earlier in the sequence
- No step requires something that hasn’t been produced yet
- All explicit constraints are satisfied
- Parallel groups contain no dependent steps
- Critical path is correctly identified
- Optimization rationale is documented