I. What Is Planning?
Planning is the process by which an agent, before or during task execution, constructs and continuously adjusts an execution plan based on the goal, constraints, current state, and available tools.
The core problem it solves is not simply answering the user, but determining:
- What to do: clarify the final goal and the sub-goals that must be completed.
- How to do it: determine the execution steps, tools, and processing strategy.
- What to do first: analyze the dependencies among tasks.
- How to judge completion: define the completion conditions for each sub-task and for the overall task.
- What to do on failure: design retry, fallback, compensation, and re-planning mechanisms.
- When to stop: judge whether the goal has been achieved and avoid endless execution.
For example, a user asks:
Analyze the sales data from the last three months, identify the main reasons for the performance decline, and generate an analysis report.
This is not a simple single-step task; it is a composite task that spans data acquisition, data cleaning, statistical analysis, cause identification, report generation, and several other stages.
The agent must first understand the goal, then decompose the task, determine dependencies, select tools, and finally execute and verify step by step.
1. How Planning Differs from Related Concepts
| Concept | Core Responsibility | Focus |
|---|---|---|
| Reasoning | Inference and judgment | Why it is done this way |
| Planning | Formulating the execution plan | What to do next |
| Task Decomposition | Breaking down tasks | Which sub-tasks the goal is split into |
| Execution | Executing tasks | How to complete specific operations |
| Workflow | Workflow orchestration | How steps run according to rules |
| Evaluation | Evaluating results | Whether the execution results meet the requirements |
These capabilities work together, but they must not be conflated.
Reasoning helps the agent decide how a given task should be handled; Planning organizes those judgments into an execution plan; Task Decomposition refines complex goals into executable units; Execution carries out the actual work; Evaluation determines whether the execution results meet the requirements.
II. Why Is Task Decomposition Needed?
Although large models possess complex reasoning capabilities, directly executing complex goals still presents obvious problems:
- Complex context: a single goal may involve a large amount of information, constraints, and business rules.
- Many execution steps: complex tasks usually contain multiple interdependent operations.
- Uncertain tool calls: external tools may time out, fail, or return anomalous data.
- Results are hard to verify: the overall goal may lack a clear, single criterion for judgment.
- Error propagation: an error in an earlier step can invalidate every subsequent step.
- High execution cost: unreasonable step sequencing leads to repeated calls and wasted resources.
The value of task decomposition lies in reducing the complexity of each individual execution unit, enabling the agent to execute, check, and recover each sub-task independently.
1. The Overall Goal and Sub-tasks
Take sales data analysis as an example:
Overall goal:
Generate a sales analysis report for the last three months and identify the reasons for the performance decline.
Sub-tasks after decomposition:
| No. | Sub-task | Output |
|---|---|---|
| T1 | Confirm the analysis time range and metric definitions | Analysis scope |
| T2 | Retrieve sales data | Raw dataset |
| T3 | Check data completeness and quality | Data quality report |
| T4 | Clean and transform the data | Standardized dataset |
| T5 | Calculate sales trends and key metrics | Statistical results |
| T6 | Analyze regional, product, and channel performance | Dimensional analysis results |
| T7 | Identify the main factors behind the performance decline | Cause analysis |
| T8 | Generate the analysis report | Final report |
Among these, T3 depends on T2, T4 depends on T3, T5 and T6 depend on T4, T7 depends on T5 and T6, and T8 depends on T7.
Task decomposition is not merely splitting one sentence into several; it is about forming a task structure that can be executed, verified, and tracked.
III. Core Principles of Task Decomposition
1. Clear Goals
Every sub-task should have a clear goal, avoiding vague descriptions.
Unreasonable tasks:
- Analyze the data.
- Process the results.
- Optimize the report.
These tasks do not specify the concrete operations or the expected results, so there is no way to judge whether they are complete.
More reasonable tasks:
- Calculate monthly sales revenue, order count, and average order value.
- Calculate the year-over-year and month-over-month change in sales revenue for each region.
- Identify the three product categories with the largest decline in sales revenue.
- Generate an analysis report containing conclusions and supporting data based on the statistical results.
2. Clear Inputs and Outputs
Every task should define its inputs and outputs.
For example:
{
"task_id": "T5",
"name": "Calculate Sales Trends",
"description": "Calculate sales amount, order count, and average order value by month",
"inputs": {
"dataset": "cleaned_sales_data",
"time_range": "last_3_months"
},
"outputs": {
"monthly_metrics": "MonthlyMetrics"
},
"status": "pending"
}
Inputs define what data a task needs, and outputs define what result should be produced after the task is completed.
A clear input/output contract can reduce ambiguity between subtasks and also facilitates task retries, parallel execution, and result validation.
3. Clear Dependencies
There are usually dependencies between tasks.
For example:
- Data analysis depends on data acquisition.
- Report generation depends on analysis results.
- Report publishing depends on report review.
If dependencies are not correctly identified, the Agent may execute subsequent tasks before the necessary data has been produced.
4. Appropriate Granularity
If tasks are broken down too coarsely, the execution process is difficult to control; if broken down too finely, it creates significant overhead for task scheduling and context management.
For example:
Too Coarsely Decomposed:
T1: Complete sales analysis and generate a report
It is impossible to independently control data acquisition, statistical analysis, and report generation.
Too Finely Decomposed:
T1: Read file
T2: Read first column
T3: Read second column
T4: Read third column
T5: Calculate first row
T6: Calculate second row
Too many tasks increase scheduling costs.
Reasonable Decomposition:
T1: Acquire sales data
T2: Clean data
T3: Calculate key metrics
T4: Analyze business dimensions
T5: Summarize reasons for decline
T6: Generate report
Appropriate granularity should be judged mainly by independent execution, clear acceptance criteria, and recoverability.
5. Clear Completion Criteria
A task must define not only the execution actions but also the completion criteria.
For example:
{
"task_id": "T3",
"name": "Data Quality Check",
"completion_criteria": [
"No null values in key fields",
"Date format meets requirements",
"Sales amounts are all valid numeric values",
"Duplicate orders have been identified"
]
}
Without completion criteria, the Agent may mistake a successful tool call for a successful task.
IV. Common Methods for Task Decomposition
Different tasks have different structures, so the Agent can adopt different decomposition strategies.
1. Sequential Decomposition
Break a complex task into subtasks with a strict sequential order.
Applicable to:
- Data processing pipelines.
- Document processing.
- Code compilation and testing.
- Business processes that require step-by-step validation.
flowchart TD
A["Receive Overall Goal"] --> B["Task T1: Acquire Data"]
B --> C["Task T2: Clean Data"]
C --> D["Task T3: Analyze Data"]
D --> E["Task T4: Generate Report"]
E --> F["Validate Final Result"]
style A fill:#DCEFE5,stroke:#4F8B70,color:#24563F
style B fill:#E0F0FE,stroke:#93BCE8,color:#1E4976
style C fill:#E0F0FE,stroke:#93BCE8,color:#1E4976
style D fill:#EAE8FA,stroke:#A49BD5,color:#51477D
style E fill:#E0F0FE,stroke:#93BCE8,color:#1E4976
style F fill:#DCEFE5,stroke:#4F8B70,color:#24563F
The advantage of sequential decomposition is that the structure is simple and the execution process is easy to trace; the disadvantage is that it cannot fully exploit opportunities for parallelism between tasks.
2. Parallel Decomposition
When multiple subtasks have no direct dependencies between them, they can be executed simultaneously.
For example, when analyzing sales data, you can simultaneously analyze the performance of different regions, product categories, and sales channels.
flowchart TD
A["Obtain and clean sales data"] --> B["Regional sales analysis"]
A --> C["Product sales analysis"]
A --> D["Channel sales analysis"]
B --> E["Aggregate analysis results"]
C --> E
D --> E
E --> F["Generate comprehensive conclusions"]
style A fill:#DCEFE5,stroke:#4F8B70,color:#24563F
style B fill:#E0F0FE,stroke:#93BCE8,color:#1E4976
style C fill:#EAE8FA,stroke:#A49BD5,color:#51477D
style D fill:#EAF3EC,stroke:#83A995,color:#315D49
style E fill:#F7F4E8,stroke:#C7B77A,color:#675A2D
style F fill:#DCEFE5,stroke:#4F8B70,color:#24563F
Parallel execution requires attention to:
- Whether the tasks are truly independent.
- Whether there is contention for shared resources.
- Whether the results need to be aggregated.
- Whether the degree of concurrency exceeds system limits.
- Whether the failure of one task affects the other tasks.
Parallelism does not mean that all tasks can be executed at the same time. Parallel scheduling is only appropriate when the input data is already available and no unresolved dependencies exist between the tasks.
3. Hierarchical Decomposition
Break a complex goal into multiple sub-goals, then further break each sub-goal into concrete tasks.
For example:
Sales analysis
├── Data preparation
│ ├── Obtain sales data
│ ├── Check data quality
│ └── Clean data
├── Business analysis
│ ├── Time trend analysis
│ ├── Regional analysis
│ └── Product analysis
└── Report generation
├── Aggregate analysis results
├── Extract core conclusions
└── Generate report
Hierarchical decomposition is suited to complex tasks that cover a large scope and contain multiple business modules.
It keeps planning complexity under control and also makes it easier for different Agents or sub-planners to take responsibility for different domains.
Note that a hierarchical structure does not necessarily imply an execution order. Multiple tasks under a single level may still have dependencies between them, and may also be executed in parallel.
4. Conditional Decomposition
Subsequent tasks are decided based on execution results.
For example, if the data quality check passes, analysis continues; if it fails, data repair is carried out first.
flowchart TD
A["Obtain sales data"] --> B["Check data quality"]
B --> C{"Is the data quality acceptable?"}
C -->|"Yes"| D["Run sales analysis"]
C -->|"No"| E["Run data repair"]
E --> F{"Did the repair succeed?"}
F -->|"Yes"| D
F -->|"No"| G["Log the failure and request manual handling"]
D --> H["Generate analysis report"]
style A fill:#DCEFE5,stroke:#4F8B70,color:#24563F
style B fill:#E0F0FE,stroke:#93BCE8,color:#1E4976
style C fill:#F7F4E8,stroke:#C7B77A,color:#675A2D
style D fill:#EAF3EC,stroke:#83A995,color:#315D49
style E fill:#EAE8FA,stroke:#A49BD5,color:#51477D
style F fill:#F7F4E8,stroke:#C7B77A,color:#675A2D
style G fill:#F7EAE7,stroke:#C98D7C,color:#754438
style H fill:#DCEFE5,stroke:#4F8B70,color:#24563F
The key to conditional decomposition is making the decision logic explicit, so that the Agent does not arbitrarily change the task path during execution.
5. Iterative Decomposition
Some tasks cannot be fully planned in one go; the plan must be continuously refined based on intermediate results.
For example, a user asks for an analysis of a system's performance bottlenecks. The Agent may first conduct an overall performance analysis, then drill into the database, network, or CPU based on the hotspots it discovers.
flowchart TD
A["Receive complex goal"] --> B["Generate initial task plan"]
B --> C["Execute current task"]
C --> D["Evaluate intermediate results"]
D --> E{"Are there issues requiring deeper processing?"}
E -->|"Yes"| F["Generate a new subtask"]
F --> G["Update task plan"]
G --> C
E -->|"No"| H{"Is the overall goal complete?"}
H -->|"No"| B
H -->|"Yes"| I["Output final result"]
style A fill:#DCEFE5,stroke:#4F8B70,color:#24563F
style B fill:#E0F0FE,stroke:#93BCE8,color:#1E4976
style C fill:#EAF3EC,stroke:#83A995,color:#315D49
style D fill:#EAE8FA,stroke:#A49BD5,color:#51477D
style E fill:#F7F4E8,stroke:#C7B77A,color:#675A2D
style F fill:#E0F0FE,stroke:#93BCE8,color:#1E4976
style G fill:#EAF3EC,stroke:#83A995,color:#315D49
style H fill:#F7F4E8,stroke:#C7B77A,color:#675A2D
style I fill:#DCEFE5,stroke:#4F8B70,color:#24563F
Iterative decomposition can adapt to unknown problems, but a maximum iteration count, budget, and termination conditions must be set to prevent tasks from expanding indefinitely.
5. Task Dependencies and DAG
Complex tasks usually cannot be represented by a list alone.
For example:
T1: Get sales data
T2: Get product information
T3: Clean sales data
T4: Join product information
T5: Calculate sales metrics
T6: Analyze sales causes
T7: Generate report
Where:
- T3 depends on T1.
- T4 depends on T2 and T3.
- T5 depends on T4.
- T6 depends on T5.
- T7 depends on T6.
This relationship can be represented using a directed acyclic graph (DAG).
1. Basic Structure of a DAG
A DAG consists of nodes and directed edges:
- Node: represents a task.
- Directed edge: represents a dependency relationship between tasks.
- Acyclic: there is no dependency path that starts from a task and returns to itself.
flowchart TD
A["T1: Get sales data"] --> C["T3: Clean sales data"]
B["T2: Get product information"] --> D["T4: Join product information"]
C --> D
D --> E["T5: Calculate sales metrics"]
E --> F["T6: Analyze sales causes"]
F --> G["T7: Generate report"]
style A fill:#E0F0FE,stroke:#93BCE8,color:#1E4976
style B fill:#EAE8FA,stroke:#A49BD5,color:#51477D
style C fill:#EAF3EC,stroke:#83A995,color:#315D49
style D fill:#F7F4E8,stroke:#C7B77A,color:#675A2D
style E fill:#E0F0FE,stroke:#93BCE8,color:#1E4976
style F fill:#EAE8FA,stroke:#A49BD5,color:#51477D
style G fill:#DCEFE5,stroke:#4F8B70,color:#24563F
Here, T1 and T2 have no direct dependency, so they can be executed simultaneously.
T4 is eligible for execution only after both T1 and T2 are complete and T3 is complete.
2. DAG Execution Mechanism
A DAG usually uses topological sorting to determine a valid execution order for tasks.
Topological sorting can produce a task order that satisfies dependencies, but it does not mean there is only one execution order.
For example:
T1, T2 can run in parallel
T3 must wait for T1
T4 must wait for T2 and T3
The scheduler needs to dynamically determine whether a task has met its execution conditions.
A task usually needs to have the following states:
| State | Meaning |
|---|---|
| PENDING | Waiting for execution |
| READY | Dependencies satisfied, ready to execute |
| RUNNING | Executing |
| SUCCESS | Execution succeeded |
| FAILED | Execution failed |
| BLOCKED | Blocked by a failed dependency |
| SKIPPED | Skipped based on conditions |
| CANCELLED | Cancelled |
3. DAG and Cyclic Dependencies
A DAG does not allow cyclic dependencies.
For example:
T1 depends on T2
T2 depends on T3
T3 depends on T1
The three tasks wait on one another, and none can start.
Therefore, after a task plan is generated, dependency validation must be performed:
- Whether any self-dependency exists.
- Whether any circular dependency exists.
- Whether any referenced dependency node is missing.
- Whether any unreachable task exists.
- Whether any prerequisite can never be satisfied.
Note that a business process may require repeated iteration, but circular edges should not be constructed directly in a static DAG. Iteration should be implemented through explicit loop control, a state machine, or dynamically generated new tasks.
6. Data Structure of the Task Plan
To turn Planning from a language description into an executable structure, a unified task model needs to be defined.
A task should contain at least the following fields:
| Field | Description |
|---|---|
| task_id | Unique task identifier |
| name | Task name |
| description | Task description |
| inputs | Input parameters |
| outputs | Output definitions |
| dependencies | Prerequisites |
| tool | Tool used |
| status | Execution status |
| priority | Priority |
| timeout | Timeout |
| retry_policy | Retry policy |
| completion_criteria | Completion criteria |
| risk_level | Risk level |
Example:
{
"task_id": "T5",
"name": "计算销售指标",
"description": "计算月度销售额、订单数和客单价",
"inputs": {
"dataset": "cleaned_sales_data"
},
"outputs": {
"metrics": "MonthlySalesMetrics"
},
"dependencies": [
"T4"
],
"tool": "python_data_analyzer",
"status": "pending",
"priority": 2,
"timeout": 60,
"retry_policy": {
"max_attempts": 3,
"backoff": "exponential"
},
"completion_criteria": [
"所有月份均生成统计结果",
"指标计算通过校验"
],
"risk_level": "low"
}
The task structure must satisfy two requirements at the same time: it must be understandable by the model and parseable by the execution engine.
It cannot rely only on natural language descriptions; otherwise, the scheduler will find it difficult to reliably identify task dependencies, execution status, and retry conditions.
7. Core Execution Architecture of Planning
In an Agent system, Planning is usually not a standalone prompt but a set of modules that work together.
A typical architecture includes:
| Module | Responsibility |
|---|---|
| Goal Parser | Parse user goals |
| Constraint Extractor | Extract constraints |
| Planner | Generate task plans |
| Task Decomposer | Decompose complex tasks |
| Dependency Analyzer | Analyze task dependencies |
| Scheduler | Decide when tasks are executed |
| Executor | Call tools to execute tasks |
| State Manager | Manage task state |
| Verifier | Verify execution results |
| Replanner | Replan based on feedback |
1. Overall Architecture
flowchart TD
A["User Goal"] --> B["Goal Parser"]
B --> C["Constraint Extractor"]
C --> D["Planner"]
D --> E["Task Decomposer"]
E --> F["Dependency Analyzer"]
F --> G["Task Plan / DAG"]
G --> H["Scheduler"]
H --> I["Executor"]
I --> J["Tools and External Systems"]
J --> K["Execution Results"]
K --> L["Verifier"]
L --> M{"Is the Task Complete?"}
M -->|"Yes"| N["Update Task Status"]
M -->|"No"| O["Replanner"]
O --> G
N --> P{"Is the Overall Goal Complete?"}
P -->|"No"| H
P -->|"Yes"| Q["Output Final Result"]
style A fill:#DCEFE5,stroke:#4F8B70,color:#24563F
style B fill:#E0F0FE,stroke:#93BCE8,color:#1E4976
style C fill:#E0F0FE,stroke:#93BCE8,color:#1E4976
style D fill:#EAE8FA,stroke:#A49BD5,color:#51477D
style E fill:#EAE8FA,stroke:#A49BD5,color:#51477D
style F fill:#EAF3EC,stroke:#83A995,color:#315D49
style G fill:#F7F4E8,stroke:#C7B77A,color:#675A2D
style H fill:#EAF3EC,stroke:#83A995,color:#315D49
style I fill:#E0F0FE,stroke:#93BCE8,color:#1E4976
style J fill:#EAF3EC,stroke:#83A995,color:#315D49
style K fill:#E0F0FE,stroke:#93BCE8,color:#1E4976
style L fill:#EAE8FA,stroke:#A49BD5,color:#51477D
style M fill:#F7F4E8,stroke:#C7B77A,color:#675A2D
style N fill:#EAF3EC,stroke:#83A995,color:#315D49
style O fill:#F7EAE7,stroke:#C98D7C,color:#754438
style P fill:#F7F4E8,stroke:#C7B77A,color:#675A2D
style Q fill:#DCEFE5,stroke:#4F8B70,color:#24563F
2. Planner: Plan Generator
The Planner is responsible for generating plans based on goals and constraints.
Inputs typically include:
- User goals.
- Current conversation context.
- List of available tools.
- Data provided by the user.
- Execution environment state.
- Budget and permission constraints.
The output is a structured task plan.
The Planner can be implemented by a large model, or by a rule engine or traditional planning algorithm.
3. Task Decomposer: Task Decomposer
The Task Decomposer breaks high-level goals into smaller execution units.
It needs to determine:
- Whether further decomposition is needed.
- Whether each task has clear boundaries.
- Whether there are task dependencies.
- Which tasks can run in parallel.
- Whether sub-agents are needed to handle them.
- Whether there are tasks that cannot be executed.
Finer task decomposition is not always better. When a task already has clear inputs, outputs, and completion conditions, there is usually no need to decompose it further.
4. Scheduler: Task Scheduler
The Scheduler is responsible for determining which tasks can be executed.
It is not responsible for understanding complex business goals; rather, it schedules based on task dependencies, priorities, resources, and status.
For example:
- Tasks whose dependencies are all satisfied enter READY.
- READY tasks are allocated execution slots according to priority and resource limits.
- After successful execution, the status is updated.
- After a failure, related downstream tasks are blocked, or a recovery strategy is triggered.
5. Verifier: Task Verifier
The Verifier is responsible for determining whether the execution results meet the task requirements.
Verification cannot just check whether the tool returned success; it also needs to check:
- Whether the returned data is complete.
- Whether the data format is correct.
- Whether key metrics satisfy the constraints.
- Whether the results are consistent with the task goal.
- Whether there are anomalies or untrustworthy content.
The Verifier's result can trigger task approval, retry, repair, or replanning.
VIII. How Does an LLM Generate a Task Plan?
Large models are a common way to implement planners in current Agent Planning.
It is good at understanding natural-language goals, identifying implicit constraints, generating task steps, and adjusting plans based on execution feedback.
However, a plan output by an LLM is still essentially a candidate solution and cannot be directly regarded as a verified executable program.
1. Planning Prompts
Clear output requirements can be defined for the Planner:
You are a task planner.
Generate a structured task plan based on the user's goal.
Requirements:
1. Break down complex goals into independently executable subtasks.
2. Each task must have clear inputs and outputs.
3. Specify the dependencies between tasks.
4. Mark tasks that can be executed in parallel.
5. Define completion conditions for each task.
6. Select appropriate tools.
7. Identify task risks and execution constraints.
8. Do not generate operations beyond the scope of user authorization.
9. If information is insufficient, clearly identify the missing information.
10. Output results that conform to the specified JSON Schema.
User goal:
Analyze sales data from the last three months and generate a report.
2. Structured Plan Output
The Planner can return a result similar to the following:
{
"goal": "Generate a sales analysis report for the last three months",
"tasks": [
{
"id": "T1",
"name": "Retrieve sales data",
"dependencies": [],
"tool": "sales_data_api",
"outputs": ["raw_data"]
},
{
"id": "T2",
"name": "Retrieve product information",
"dependencies": [],
"tool": "product_api",
"outputs": ["product_data"]
},
{
"id": "T3",
"name": "Clean sales data",
"dependencies": ["T1"],
"tool": "python",
"outputs": ["cleaned_data"]
},
{
"id": "T4",
"name": "Join product information",
"dependencies": ["T2", "T3"],
"tool": "python",
"outputs": ["merged_data"]
},
{
"id": "T5",
"name": "Calculate sales metrics",
"dependencies": ["T4"],
"tool": "python",
"outputs": ["metrics"]
},
{
"id": "T6",
"name": "Generate sales report",
"dependencies": ["T5"],
"tool": "report_generator",
"outputs": ["report"]
}
]
}
Structured output facilitates subsequent scheduling and validation, but it still requires Schema validation, dependency validation, tool permission validation, and business rule validation.
3. Why Can't LLM-Generated Plans Be Fully Trusted?
When an LLM generates a plan, it may:
- Reference tools that do not exist.
- Generate incorrect parameters.
- Ignore necessary prerequisite dependencies.
- Mark tasks that cannot run in parallel as parallel.
- Omit key acceptance steps.
- Generate circular dependencies.
- Include high-risk operations directly in the execution plan.
- Produce a plan that itself cannot satisfy user constraints.
Therefore, production environments usually adopt a hybrid planning architecture:
The LLM is responsible for understanding and generating candidate plans, while deterministic programs are responsible for validation and scheduling.
IX. Coordination Between Planning and Task Execution
Planning is not a static process completed in one pass.
While executing tasks, an Agent may discover new information, encounter exceptions, or find that its original assumptions no longer hold, so it needs to continuously adjust the plan.
1. Static Planning and Dynamic Planning
| Type | Characteristics | Applicable Scenarios |
|---|---|---|
| Static planning | Generates a complete plan before execution | Clear rules, stable environment |
| Dynamic planning | Continuously adjusts based on execution feedback | Changing environment, uncertain results |
| Hybrid planning | Generates an initial plan first, then adjusts locally | Most complex Agent tasks |
Static planning helps control the execution path, but it is easily affected by unexpected situations.
Dynamic planning is more adaptable, but it increases model invocation costs and execution uncertainty.
Practical systems usually adopt hybrid planning: first form an executable initial plan, then perform local replanning when necessary.
2. Dynamic Replanning
Suppose the Agent discovers that a data source is unavailable while retrieving sales data.
Original plan:
T1: Retrieve sales data from data source A
T2: Clean sales data
T3: Analyze sales trends
T4: Generate report
If T1 fails, the Agent can choose:
- Retry data source A.
- Switch to data source B.
- Use cached data that has already been authorized.
- Ask the user to provide a data file.
- Terminate the task and explain the reason.
The key to dynamic replanning is to preserve the results of tasks that have already been completed successfully, rather than re-executing the entire plan every time a failure occurs.
3. The Complete Replanning Process
flowchart TD
A["Execute current task"] --> B["Collect execution results"]
B --> C["Validate task output"]
C --> D{"Did execution succeed?"}
D -->|"Yes"| E["Update task status"]
D -->|"No"| F["Analyze failure cause"]
F --> G{"Can it be retried?"}
G -->|"Yes"| H["Re-execute according to retry policy"]
H --> A
G -->|"No"| I{"Is there an alternative?"}
I -->|"Yes"| J["Generate alternative task plan"]
J --> K["Validate new plan"]
K --> L{"Is the new plan valid?"}
L -->|"Yes"| M["Update task graph"]
M --> A
L -->|"No"| N["Request human intervention"]
I -->|"No"| N
E --> O["Check overall goal"]
O --> P{"Is everything complete?"}
P -->|"Yes"| Q["Output final result"]
P -->|"No"| A
style A fill:#E0F0FE,stroke:#93BCE8,color:#1E4976
style B fill:#EAF3EC,stroke:#83A995,color:#315D49
style C fill:#EAE8FA,stroke:#A49BD5,color:#51477D
style D fill:#F7F4E8,stroke:#C7B77A,color:#675A2D
style E fill:#DCEFE5,stroke:#4F8B70,color:#24563F
style F fill:#F7EAE7,stroke:#C98D7C,color:#754438
style G fill:#F7F4E8,stroke:#C7B77A,color:#675A2D
style H fill:#E0F0FE,stroke:#93BCE8,color:#1E4976
style I fill:#F7F4E8,stroke:#C7B77A,color:#675A2D
style J fill:#EAE8FA,stroke:#A49BD5,color:#51477D
style K fill:#EAF3EC,stroke:#83A995,color:#315D49
style L fill:#F7F4E8,stroke:#C7B77A,color:#675A2D
style M fill:#DCEFE5,stroke:#4F8B70,color:#24563F
style N fill:#F7EAE7,stroke:#C98D7C,color:#754438
style O fill:#EAF3EC,stroke:#83A995,color:#315D49
style P fill:#F7F4E8,stroke:#C7B77A,color:#675A2D
style Q fill:#DCEFE5,stroke:#4F8B70,color:#24563F