The Complete Production SOP: How to Deploy and Run Plan-and-Solve Hierarchical Task Decomposition in Autonomous AI Agents
Step-by-step SOP to install and run Plan-and-Solve Hierarchical Task Decomposition in Codex, Claude Code, and Cursor. Includes verified prompts and DAG workflows.
Technical Overview & Architectural Context
Autonomous coding agents frequently suffer from greedy execution bias when handed complex, multi-file engineering challenges. Without an explicit planning constraint, LLMs immediately generate and mutate code files on the first step before discovering circular dependencies, missing database schema fields, or contradictory interface contracts three layers deep. This reactive loop exhausts context tokens through repeated rollbacks and causes hallucinated patches that break existing system architectures. Plan-and-Solve Hierarchical Task Decomposition enforces a hard boundary between the architectural planning phase and concrete code execution. By requiring the agent to synthesize an initial dependency-ordered Directed Acyclic Graph (DAG) before writing a single byte to disk, this skill neutralizes execution drift. Each subtask is linked to strict prerequisite gates (e.g., database migration -> ORM entities -> repository interface -> HTTP controllers). Furthermore, the skill equips agents with a formal replanning mechanism: whenever a subtask triggers a compiler error or unresolvable test regression, the agent pauses instead of thrashing, updates the DAG state dynamically, and recalculates downstream subtasks. This converts erratic trial-and-error agent behavior into deterministic, verifiable engineering progress.
Prerequisites & Environment Requirements
Verified Search Intents & Long-Tail Queries Solved
This operational tutorial is engineered to provide deterministic solutions for these developer search queries:
Step-by-Step Execution Playbook
Local Environment Setup & SKILL.md Mounting
Create the local agent skill manifest directory and inject verified procedural rules into your workspace.
Autonomous runtimes parse skills dynamically from canonical project directories such as `.agents/skills` or `.claude/skills`. We mount the raw `SKILL.md` file containing strict frontmatter directives (`fs_write: workspace`, `shell_exec: false`) and deterministic SOP prompts directly into your project tree.
mkdir -p .agents/skills/plan-and-solve-decomposition && curl -fsSL https://askills.dev/api/skills/plan-and-solve-decomposition/raw -o .agents/skills/plan-and-solve-decomposition/SKILL.md---
name: "plan-and-solve-decomposition"
description: "Decompose large, complex engineering goals into subtasks before executing single steps."
metadata:
author: "Wang et al."
version: "1.0.0"
runtime_compatibility:
- "codex"
- "claude-code"
- "cursor"
- "windsurf"
triggers:
- "create execution plan"
- "decompose large task"
- "plan and solve engineering request"
permissions:
fs_read: true
fs_write: "workspace"
shell_exec: false
net_access: false
---
# Plan-and-Solve Hierarchical Task Decomposition
Separates the planning phase from the execution phase: generating a dependency-ordered directed acyclic graph (DAG) of subtasks, tracking completion state, and dynamically replanning on failures.
## Execution SOP & Rules
1. Always draft the complete numbered plan before modifying any workspace files.
2. Order subtasks based on strict dependency requirements (e.g. schema migration before API handler).
3. Check off completed items incrementally as progress is made.
4. If a subtask fails or hits a blocker, pause to revise the remaining steps rather than blindly forging ahead.
Place the SKILL.md inside the root repository `.agents/skills` path to allow seamless project-level hot-reloading across Windsurf, Cursor, and Claude Code without restarting your IDE.
Ensure `.agents/skills` is tracked in git. If gitignored, cloud agent sandboxes (e.g., GitHub Workspace Agent) will fail to discover the frontmatter triggers.
Workspace Runtime Registration & Verification
Link the skill to your agent's system prompt or configuration file depending on the active IDE runtime.
For Claude Code and Codex, point your configuration to read local skill manifests. For Cursor or Windsurf, register the trigger phrases inside your `.cursorrules` or `.windsurfrules` file so the agent automatically delegates complex prompts to the Plan-and-Solve DAG pipeline.
echo 'Skill: .agents/skills/plan-and-solve-decomposition/SKILL.md' >> .cursorrules{
"skills": [
{
"name": "plan-and-solve-decomposition",
"path": ".agents/skills/plan-and-solve-decomposition/SKILL.md",
"auto_invoke_triggers": [
"create execution plan",
"decompose large task",
"plan and solve engineering request"
]
}
]
}Keep the auto_invoke triggers exact. When triggers match user input tokens identically, agent orchestrators bypass expensive semantic router evaluations.
Do not elevate `shell_exec` to true in the SKILL.md frontmatter; hierarchical decomposition plans must remain purely analytical prior to the execution phase to prevent premature destructive commands.
Intent Matching & Trigger Invocation
Verify deterministic activation using tested natural language prompts and review the generated DAG plan.
Trigger the skill explicitly using frontmatter-aligned phrases. The agent will output a step-by-step DAG checklist with strict completion gates prior to issuing file modifications or executing bash commands.
### Hierarchical Execution Plan (DAG)
- [ ] 1. Define PostgreSQL schema migration for tenant-scoped billing tables
- [ ] 2. Generate Prisma/Drizzle schema definitions and validate TypeScript types
- [ ] 3. Implement Stripe webhook handler verifying signature and idempotent events
- [ ] 4. Wire webhook handler into Express router with middleware validation
- [ ] 5. Write end-to-end integration tests using Vitest
- [ ] 6. Execute full verification suite (lint, typecheck, tests)Instruct the agent to write its intermediate plan into a temporary `PLAN.md` file in the workspace root. This preserves context across context-window compactions.
If the agent attempts to modify application files before writing the plan, reject the output and re-assert the trigger phrase.
Verification, Linting & Output Quality Gate
Enforce automated self-healing checks and plan reconciliation before accepting deliverables.
Once all subtasks are sequentially marked complete, the skill instructs the agent to run project linters, compiler checks, and unit tests. If any step fails, the agent must revise the remaining DAG rather than hallucinating ad-hoc fixes.
npm run typecheck && npm run test -- --bail#!/usr/bin/env bash
set -euo pipefail
echo "Validating plan completion..."
git diff --exit-code PLAN.md || echo "PLAN.md updated."
echo "Running lint and typecheck..."
pnpm lint
pnpm typecheck
echo "Running isolated test suite..."
pnpm test --runReview `git diff PLAN.md` alongside code changes during PR review to verify the agent did not skip prerequisite subtasks.
Watch out for circular dependency loops where the agent continuously replans subtask 2 after subtask 4 fails; set a max retry limit of 3 replanning cycles in your instructions.
Real-World Scenario: Multi-Tenant Stripe Billing Webhook Integration & Ledger Sync
“decompose large task: Implement multi-tenant Stripe subscription webhooks in our Fastify/Prisma backend. Ensure idempotent invoice processing, ledger balance reconciliation, and integration tests with mocked webhook events.”
Runtime Troubleshooting & Failure Modes
Root Cause: The agent runtime did not load the SKILL.md manifest, or the user prompt did not match the registered triggers in the frontmatter.
Ensure prompt begins with an exact trigger phrase: 'create execution plan: <goal>' and confirm `.agents/skills/plan-and-solve-decomposition/SKILL.md` exists in the root.Root Cause: The agent is encountering a persistent environmental or permission failure (e.g., missing Docker daemon for integration test database) and repeatedly rewriting the DAG instead of failing fast.
Run `docker compose up -d postgres redis` to provide required local services, or add '--skip-integration-tests' to the subtask constraints.Frequently Asked Questions (Plan-and-Solve Hierarchical Task Decomposition SOP)
Q:Can I use Plan-and-Solve Hierarchical Task Decomposition across Codex, Claude Code, and Cursor simultaneously?
Yes. The skill conforms to the universal SKILL.md specification. By placing the file in `.agents/skills/plan-and-solve-decomposition/SKILL.md` or linking it in `.cursorrules` and `.claude/skills.json`, all four runtimes parse and honor the identical DAG decomposition rules.
Q:How does Plan-and-Solve Hierarchical Task Decomposition prevent context window overflow during long agent sessions?
Instead of keeping the entire debugging history in the LLM context, the skill offloads state tracking to a structured checklist (such as `PLAN.md`). Subtasks are executed sequentially, allowing earlier subtask intermediate logs to be trimmed or summarized safely.
Q:Does this skill require escalated root or container permissions?
No. The skill is audited with a security score of 98/100. It requires read and workspace-write access to create planning and code files, while shell execution and external network calls remain restricted unless explicitly permitted by your IDE workspace policy.
Ready to equip your autonomous agent with Plan-and-Solve Hierarchical Task Decomposition?
Copy the complete audited SKILL.md specification or download the 1-click zip bundle directly from our verified registry.