Inferensys

Prompt

Dynamic Re-Decomposition Prompt for Failed Sub-Tasks

A practical prompt playbook for orchestrators that must re-plan when a sub-task fails and cannot be retried as-is. Produces a revised decomposition that preserves completed work, re-routes dependencies, and adjusts contracts for replacement sub-tasks.
Product manager reviewing autonomous task execution dashboard on laptop, completed tasks visible, casual work session.
PROMPT PLAYBOOK

When to Use This Prompt

Define the job, reader, and constraints for dynamic re-decomposition.

This prompt is for an orchestrator agent that must re-plan when a sub-task fails and cannot be retried as-is. The core job is to produce a revised decomposition that preserves completed work, re-routes dependencies, and adjusts contracts for replacement sub-tasks. The ideal user is an agent framework developer or orchestration engineer building a multi-agent system where a single sub-task failure should not force a full restart. Required context includes the original decomposition plan, the failed sub-task's ID and error signature, the current state of all completed and in-progress tasks, and the capability registry of available agents.

Use this prompt when a sub-task has definitively failed due to a capability gap, a tool outage, an invalid contract, or a dependency that produced unexpected output. Do not use it for transient errors that a simple retry with backoff can resolve, or for failures caused by a malformed user request that requires clarification. The prompt assumes the orchestrator has already exhausted local retry and repair strategies. It is designed for structural re-planning, not error-message patching. The output must be a valid revised plan that can be passed directly to the orchestration engine without manual editing.

Before wiring this into production, ensure you have a state-serialization mechanism that captures exactly what completed and what failed. The prompt's dependency repair logic depends on accurate state. Also define a maximum re-decomposition depth to prevent infinite re-planning loops. If the prompt cannot produce a valid revised plan after a configured number of attempts, the orchestrator should escalate to a human operator with the full failure trace and the last attempted re-decomposition. This prompt is a recovery tool, not a guarantee; always pair it with an escalation path.

PRACTICAL GUARDRAILS

Use Case Fit

Where the Dynamic Re-Decomposition Prompt delivers value and where it introduces unacceptable risk.

01

Good Fit: Partial Progress Exists

Use when: A multi-step agent workflow has completed some sub-tasks successfully, but one or more have failed irrecoverably. The orchestrator must preserve valid intermediate state and re-plan only the broken branch. Guardrail: Require the prompt to receive a structured manifest of completed, in-progress, and failed tasks with their output artifacts before re-decomposition begins.

02

Bad Fit: Single-Step or Stateless Tasks

Avoid when: The original request was a single, atomic task with no dependencies or intermediate state. Re-decomposition adds unnecessary planning overhead when a simple retry with backoff or a model fallback is sufficient. Guardrail: Implement a pre-check that counts the number of dependent sub-tasks; bypass re-decomposition if the original plan had fewer than two steps.

03

Required Inputs

What to watch: The prompt cannot function without a complete execution trace, including the original task decomposition graph, per-task statuses, failure reasons, and the payloads of successfully completed tasks. Missing context causes hallucinated dependencies. Guardrail: Validate the input payload against a strict schema that requires original_plan, task_states, failure_details, and completed_artifacts before invoking the prompt.

04

Operational Risk: State Corruption

What to watch: The re-decomposition might inadvertently discard valid completed work or create a new plan that conflicts with already-persisted state, leading to duplicated side effects or data inconsistencies. Guardrail: Run a deterministic state-diff after the new plan is generated to ensure all previously completed task outputs are explicitly referenced as inputs to the new sub-tasks and no completed task is re-executed.

05

Operational Risk: Infinite Re-planning Loops

What to watch: A poorly constrained prompt can produce a new decomposition that fails in the same way, triggering an infinite loop of re-decomposition attempts that exhaust context windows and compute budgets. Guardrail: Enforce a hard limit on re-decomposition depth (maximum 2-3 attempts) and require the prompt to produce a structurally different plan each time. Escalate to a human if the limit is reached.

06

Bad Fit: Real-Time or Latency-Critical Systems

Avoid when: The workflow is synchronous and user-facing with a strict latency SLA. Re-decomposition requires an extra LLM call plus plan validation, which can add unacceptable tail latency. Guardrail: Use a fast-path retry with an alternative model for latency-sensitive tasks. Reserve re-decomposition for asynchronous, background agent workflows where correctness outweighs response time.

PROMPT PLAYBOOK

Copy-Ready Prompt Template

A reusable prompt for orchestrators to generate a revised decomposition plan when a sub-task fails and cannot be retried as-is.

This prompt template is designed for an orchestrator agent that must re-plan after a sub-task failure. It takes the original decomposition, the completed work, the failure details, and the current state, then produces a revised plan that preserves valid partial results, re-routes dependencies, and adjusts contracts for replacement sub-tasks. Use this when a retry of the original sub-task is impossible or would violate idempotency constraints.

text
You are an orchestrator agent responsible for dynamic re-decomposition when a sub-task fails.

Your job is to produce a revised task decomposition plan that:
- Preserves all successfully completed sub-tasks and their outputs.
- Replaces the failed sub-task with one or more replacement sub-tasks.
- Repairs any dependency chains broken by the failure.
- Adjusts input/output contracts for downstream sub-tasks that depended on the failed sub-task's output.
- Flags any completed sub-tasks whose results may now be invalidated by the re-plan.

## ORIGINAL DECOMPOSITION PLAN
[ORIGINAL_PLAN]

## COMPLETED SUB-TASKS (with outputs)
[COMPLETED_TASKS]

## FAILED SUB-TASK
Task ID: [FAILED_TASK_ID]
Failure Reason: [FAILURE_REASON]
Failure Evidence: [FAILURE_EVIDENCE]

## CURRENT STATE
[STATE_SNAPSHOT]

## CONSTRAINTS
- Maximum replacement sub-tasks: [MAX_REPLACEMENT_TASKS]
- Preserve completed work unless explicitly invalidated.
- Replacement sub-tasks must have clear input/output contracts.
- Dependencies must form a valid directed acyclic graph.
- Flag any assumptions made during re-planning.

## OUTPUT SCHEMA
Return a JSON object with this structure:
{
  "revision_id": "string",
  "failure_analysis": {
    "root_cause": "string",
    "recoverable_outputs": ["task_id"],
    "invalidated_outputs": ["task_id"]
  },
  "replacement_tasks": [
    {
      "task_id": "string",
      "description": "string",
      "agent_role": "string",
      "input_contract": { "required_fields": ["string"], "optional_fields": ["string"] },
      "output_contract": { "fields": ["string"], "validation_rules": ["string"] },
      "dependencies": ["task_id"],
      "estimated_effort": "low|medium|high",
      "risk_flags": ["string"]
    }
  ],
  "dependency_repairs": [
    {
      "downstream_task_id": "string",
      "original_dependency": "task_id",
      "new_dependency": "task_id",
      "contract_adjustment": "string"
    }
  ],
  "state_preservation_checks": [
    {
      "completed_task_id": "string",
      "still_valid": true,
      "invalidation_risk": "string"
    }
  ],
  "assumptions": ["string"],
  "escalation_recommended": true
}

## VALIDATION RULES
- No circular dependencies in the revised plan.
- Every replacement task must have at least one dependency or be a root task.
- All dependency references must resolve to existing task IDs.
- Invalidated outputs must be explicitly listed with reasons.
- If the failure cannot be recovered within constraints, set escalation_recommended to true.

Adapt this template by replacing the square-bracket placeholders with your system's actual data structures. The [ORIGINAL_PLAN] should include the full task graph with contracts. The [COMPLETED_TASKS] must carry actual outputs, not just status codes, so the orchestrator can assess whether downstream tasks can still consume them. The [STATE_SNAPSHOT] should capture session context, user intent, and any side effects already committed. Before deploying, validate that the output schema matches your agent framework's task representation and that the dependency repair logic handles partial failures without creating orphaned tasks. For high-risk workflows, route the revised plan through a human approval step before dispatching replacement sub-tasks.

IMPLEMENTATION TABLE

Prompt Variables

Required inputs for the Dynamic Re-Decomposition Prompt. Each variable must be populated from the orchestrator's execution state before the prompt is assembled. Missing or stale values produce invalid re-decomposition plans.

PlaceholderPurposeExampleValidation Notes

[FAILED_TASK_DEFINITION]

The original sub-task contract that failed, including its input schema, expected output schema, assigned agent role, and completion criteria

{"task_id": "extract-invoice-line-items", "agent_role": "document-extractor", "input_schema": {"document_id": "string"}, "output_schema": {"line_items": "array"}, "completion_criteria": "all line items extracted with confidence >= 0.9"}

Must be a valid JSON object with task_id, agent_role, input_schema, output_schema, and completion_criteria fields. Reject if any field is null or missing

[FAILURE_DIAGNOSTIC]

Structured description of why the sub-task failed, including error type, failure stage, and any partial output or error messages produced

{"error_type": "tool_timeout", "failure_stage": "extraction", "error_message": "PDF parsing timed out after 30s on page 4", "partial_output": {"line_items": [{"item": "Widget A", "confidence": 0.95}]}}

Must contain error_type, failure_stage, and error_message. partial_output may be null. Validate error_type against known failure taxonomy: tool_timeout, schema_violation, confidence_below_threshold, agent_unavailable, dependency_failure, context_overflow

[COMPLETED_TASKS_STATE]

Array of all successfully completed sub-tasks with their outputs, preserving work that must not be re-executed or invalidated by the new plan

[{"task_id": "classify-document-type", "output": {"document_type": "invoice", "confidence": 0.97}, "completed_at": "2025-01-15T10:30:00Z"}, {"task_id": "extract-header-fields", "output": {"vendor": "Acme Corp", "invoice_date": "2025-01-10"}, "completed_at": "2025-01-15T10:31:00Z"}]

Must be an array. Each entry requires task_id, output, and completed_at. Validate that no task_id duplicates exist. Check that completed_at timestamps are monotonically increasing. Reject if any output field is missing

[PENDING_DEPENDENCIES]

Map of sub-tasks that are waiting on the failed task's output, including what specific fields they require and their current blocking status

{"validate-invoice-totals": {"required_fields": ["line_items"], "blocking_status": "blocked", "timeout_at": "2025-01-15T10:35:00Z"}, "generate-report": {"required_fields": ["line_items", "vendor"], "blocking_status": "partially_blocked"}}

Must be a JSON object keyed by dependent task_id. Each value requires required_fields array and blocking_status. Validate blocking_status against enum: blocked, partially_blocked, at_risk. Check that required_fields references actual fields from the failed task's output_schema

[AGENT_POOL_SNAPSHOT]

Current state of available agents including their capabilities, current load, health status, and cost tier for re-assignment decisions

{"available_agents": [{"agent_id": "doc-extractor-v2", "capabilities": ["pdf-extraction", "table-parsing"], "status": "healthy", "current_load": 2, "cost_tier": "standard"}, {"agent_id": "doc-extractor-v3", "capabilities": ["pdf-extraction", "table-parsing", "ocr"], "status": "healthy", "current_load": 0, "cost_tier": "premium"}]}

Must include at least one available agent. Each agent requires agent_id, capabilities array, status, current_load, and cost_tier. Validate status against enum: healthy, degraded, overloaded. Reject if no agent has capabilities matching the failed task's requirements

[CONTEXT_BUDGET_REMAINING]

Remaining token budget for the overall orchestration, constraining how much new decomposition overhead is acceptable

{"total_budget": 128000, "consumed": 89000, "remaining": 39000, "per_task_limit": 8000, "overhead_reserved": 5000}

Must include total_budget, consumed, remaining, per_task_limit, and overhead_reserved. Validate that remaining >= overhead_reserved + (per_task_limit * number_of_replacement_tasks). Reject if remaining < overhead_reserved

[ESCALATION_POLICY]

Rules defining when re-decomposition should be abandoned in favor of human escalation, including max retry count, time budget, and risk thresholds

{"max_recomposition_attempts": 2, "current_attempt": 1, "max_total_latency_ms": 60000, "elapsed_ms": 35000, "risk_threshold": "medium", "escalation_target": "human-ops-queue"}

Must include max_recomposition_attempts, current_attempt, max_total_latency_ms, elapsed_ms, risk_threshold, and escalation_target. Validate that current_attempt < max_recomposition_attempts. Reject if elapsed_ms >= max_total_latency_ms. Validate risk_threshold against enum: low, medium, high, critical

[ORIGINAL_USER_REQUEST]

The original user request that initiated the full task decomposition, preserved for intent alignment in the re-decomposition

"Extract all line items from this invoice PDF and validate the totals against the header amounts. Flag any discrepancies over $10."

Must be a non-empty string. Validate that the original intent is still achievable given the failure diagnostic. Reject if the original request has been invalidated by upstream state changes

PROMPT PLAYBOOK

Implementation Harness Notes

How to wire the Dynamic Re-Decomposition Prompt into an orchestrator with state management, validation, and retry logic.

This prompt is not a standalone chat interaction; it is a recovery module inside an agent orchestrator. It fires when a sub-task fails and the orchestrator determines that a simple retry is insufficient—for example, when a tool is permanently unavailable, an upstream output is invalid, or a dependency graph must be restructured. The orchestrator must provide the prompt with a complete snapshot of the current plan state, including which tasks succeeded, which failed, their outputs, and the original user intent. The prompt's output is a revised decomposition that the orchestrator must validate before re-dispatching any work.

The implementation harness should treat this prompt as a transactional recovery step. Before calling the model, serialize the current execution state into the [CURRENT_PLAN_STATE] placeholder: a structured object containing the original task graph, completed sub-tasks with their validated outputs, the failed sub-task with its error signature, and any dependency edges that are now broken. After receiving the model's output, run a dependency repair validator that checks for cycles, missing inputs for any new or re-routed sub-tasks, and orphaned tasks that lost their upstream providers. If validation fails, do not blindly retry the prompt; instead, feed the specific validation errors back into a second invocation with a [VALIDATION_ERRORS] field appended to the context. Limit this repair loop to two attempts before escalating to a human operator with the full plan diff.

State management is the hardest part of this integration. The orchestrator must preserve the outputs of completed sub-tasks and ensure the new decomposition does not re-execute work that has already succeeded. Implement a completed-work immutability guard: any sub-task ID that appears in the completed_tasks array of [CURRENT_PLAN_STATE] must not appear in the model's output as a new or modified task. If it does, reject the output and flag a state corruption risk. For logging and auditability, record every re-decomposition event with a before/after diff of the task graph, the failure trigger, the model's raw output, validation results, and the final dispatched plan. This audit trail is essential for debugging orchestrator behavior and for governance reviews in production systems.

Model choice matters here. This prompt requires strong reasoning about dependencies and constraints, so prefer models with demonstrated planning capability. Set temperature low (0.0–0.2) to reduce variance in structural outputs. The output schema should be strictly validated: expect a JSON object with a revised_tasks array, each containing task_id, agent_role, input_contract, output_contract, depends_on (array of task IDs), and a reason_for_change field explaining why this task was added or modified. Reject any output that references task IDs not present in either the completed list or the new decomposition. Finally, wire this prompt behind a circuit breaker: if re-decomposition fails more than three times for the same root task within a session, halt the workflow and escalate to a human with the full execution trace and the last failed plan.

IMPLEMENTATION TABLE

Expected Output Contract

Fields, format, and validation rules for the revised decomposition plan produced by the Dynamic Re-Decomposition Prompt. Use this contract to validate the orchestrator's output before dispatching replacement sub-tasks.

Field or ElementType or FormatRequiredValidation Rule

revised_plan_id

string (UUID v4)

Must be a new UUID distinct from the original plan_id. Parse check: valid UUID v4 format.

original_plan_id

string (UUID v4)

Must match the plan_id of the failed decomposition. Parse check: exact match against orchestrator state.

failed_subtask_id

string (UUID v4)

Must reference a sub-task that exists in the original plan and is marked as FAILED. Parse check: membership in original task list with status=FAILED.

failure_root_cause

string (enum)

Must be one of: CONTRACT_VIOLATION, TIMEOUT, AGENT_UNAVAILABLE, TOOL_FAILURE, INVALID_OUTPUT, DEPENDENCY_FAILURE, POLICY_REFUSAL. Enum check: exact match.

preserved_completed_tasks

array of UUID strings

Every UUID must reference a sub-task in the original plan with status=COMPLETED. No UUID may appear in the replacement_tasks array. Schema check: array of strings, no duplicates, all valid UUIDs.

replacement_tasks

array of objects

Must contain at least 1 task object. Each object must include task_id (new UUID), agent_role, input_contract, output_contract, and depends_on fields. Schema check: valid JSON Schema against replacement_task_schema.

dependency_repair_map

object

Keys are original downstream task UUIDs that depended on the failed task. Values are arrays of replacement task UUIDs that now satisfy the dependency. Schema check: all keys and values must be valid UUIDs; no orphaned dependencies allowed.

state_preservation_notes

string (max 500 chars)

Must describe what intermediate state from completed tasks is preserved and how replacement tasks consume it. Null not allowed. Length check: 1-500 characters.

confidence_score

number (0.0-1.0)

Orchestrator's confidence that the revised plan will succeed. Must be a float between 0.0 and 1.0 inclusive. Threshold check: if below 0.6, human approval is required before dispatch.

human_approval_required

boolean

Must be true if confidence_score < 0.6 or if any replacement task involves a regulated action. Approval check: if true, plan must not be dispatched until approval is logged.

PRACTICAL GUARDRAILS

Common Failure Modes

Dynamic re-decomposition fails in predictable ways. These are the most common failure modes when an orchestrator attempts to re-plan a failed sub-task, along with concrete guardrails to prevent them.

01

Orphaned Dependency Chains

What to watch: The re-decomposition creates a new sub-task that depends on output from a cancelled or unreachable predecessor, leaving the replacement task permanently blocked. Guardrail: Validate the dependency graph after re-decomposition by checking that every input reference resolves to a completed or in-progress task ID. Reject plans with dangling references before dispatch.

02

Completed Work Discard

What to watch: The re-planner generates a fresh decomposition that ignores already-completed sibling sub-tasks, causing the orchestrator to re-execute work that was already done correctly. Guardrail: Require the re-decomposition prompt to receive a manifest of completed sub-tasks with their outputs. Add an explicit instruction: 'Preserve all completed work. Only replace the failed sub-task and adjust its direct dependents.'

03

Contract Drift in Replacement Tasks

What to watch: The replacement sub-task produces output in a different shape or with different field semantics than the original contract, breaking downstream consumers that expect the original schema. Guardrail: Pin the output contract of the replacement sub-task to the original contract. If the contract must change, flag all downstream consumers and require their contracts to be re-validated before execution resumes.

04

Infinite Re-Decomposition Loops

What to watch: The orchestrator repeatedly re-decomposes the same failing sub-task with minor variations, consuming tokens and time without resolving the underlying cause of failure. Guardrail: Cap re-decomposition attempts at a fixed limit (e.g., 3). After the limit, escalate to a human or a supervisor agent with the failure history, attempted re-plans, and the original task context. Log every re-decomposition attempt with its rationale.

05

State Contamination Across Attempts

What to watch: The re-decomposition prompt inadvertently carries stale state, error messages, or partial outputs from the failed attempt into the new plan, causing the replacement to inherit the same failure mode. Guardrail: Scrub the context passed to the re-decomposition prompt. Include only the original task definition, the failure reason, the completed-work manifest, and the dependency graph. Exclude raw error traces and intermediate agent reasoning unless they are diagnostically essential.

06

Silent Dependency Breakage

What to watch: The re-planner adjusts a sub-task that other parallel tasks depend on but does not update those dependents, causing them to consume stale or missing inputs without explicit errors. Guardrail: After re-decomposition, run a dependency integrity check that compares every consumer's input references against the updated task graph. Flag any consumer whose input source has changed or been removed. Require explicit re-validation of those consumers before they execute.

IMPLEMENTATION TABLE

Evaluation Rubric

Criteria for testing whether the re-decomposition prompt produces a safe, correct, and executable revised plan before it is dispatched to agents.

CriterionPass StandardFailure SignalTest Method

Completed Work Preservation

All previously completed sub-tasks are explicitly marked as DONE and excluded from the new execution plan

Completed sub-task appears in the new task list or its output is overwritten

Diff the input [COMPLETED_TASKS] list against the output task list; assert zero overlap

Dependency Repair

Every replacement sub-task lists only valid upstream dependencies that exist in the revised plan or are already completed

Replacement sub-task references a non-existent, failed, or circular dependency

Parse the dependency graph from the output; assert all referenced task IDs exist and no cycles are detected

Contract Adjustment

Replacement sub-task contracts include all required inputs from preserved outputs and exclude inputs that were only produced by the failed task

Replacement contract requires an output field that no upstream task produces

Schema-diff each replacement contract's required inputs against available outputs from upstream tasks

State Consistency

The revised plan does not introduce conflicting writes to shared state or duplicate side effects already performed by completed tasks

Two tasks in the revised plan write to the same resource without a defined merge rule

Scan output for shared resource identifiers; assert each resource has at most one writer or an explicit merge task

Failure Root Cause Handling

The re-decomposition explicitly addresses the reported failure reason and adjusts the approach, not just retries the same task with the same contract

Replacement sub-task has identical description, inputs, and agent assignment as the failed task

Semantic similarity check between failed task definition and replacement task definition; assert cosine similarity below 0.9

Escalation Trigger Respect

If the failure reason matches an escalation rule in [ESCALATION_POLICY], the output routes to human review instead of re-decomposing

Re-decomposition is produced for a failure that policy marks as non-retryable

Check failure reason against escalation policy regex patterns; assert no re-decomposition when escalation is required

Output Schema Validity

The revised plan conforms exactly to [OUTPUT_SCHEMA] with all required fields present and correctly typed

Missing required field, wrong type, or extra undeclared fields in the output

Validate output against the JSON Schema provided in [OUTPUT_SCHEMA]; assert zero validation errors

Idempotency Marker

The revised plan includes a new plan version or idempotency key distinct from the original plan to prevent duplicate execution

Revised plan reuses the same plan ID as the original or omits a version marker

Assert output.plan_id != input.original_plan_id and output.plan_version > input.original_plan_version

ADAPTATION OPTIONS

Adapt This Prompt

How to adapt

Start with the base prompt and a simple JSON schema for the re-decomposition output. Run it against a small set of synthetic failure scenarios. Focus on getting the dependency graph repair logic correct before adding production guardrails.

  • Use a lightweight orchestrator script that calls the LLM with the failed sub-task context and the original decomposition.
  • Accept the output if it parses as valid JSON with the expected keys (revised_tasks, dependency_map, state_preservation_notes).
  • Log the raw prompt and response for manual review.

Watch for

  • The model dropping completed sub-tasks from the revised plan.
  • Circular dependencies introduced during repair.
  • The model re-decomposing the entire task instead of only the failed branch.
  • Placeholder fields like [FAILED_TASK_ID] and [ORIGINAL_DECOMPOSITION] not being replaced before sending.
Prasad Kumkar

About the author

Prasad Kumkar

CEO & MD, Inference Systems

Prasad Kumkar is the CEO & MD of Inference Systems and writes about AI systems architecture, LLM infrastructure, model serving, evaluation, and production deployment. Over 5+ years, he has worked across computer vision models, L5 autonomous vehicle systems, and LLM research, with a focus on taking complex AI ideas into real-world engineering systems.

His work and writing cover AI systems, large language models, AI agents, multimodal systems, autonomous systems, inference optimization, RAG, evaluation, and production AI engineering.