1. What Is Agent Task Planning?
Agent task planning (Task Planning) refers to the process in which an Agent automatically generates a set of sub-tasks that can be executed in order or in parallel, based on the user's goal, the current environment, available tools, and execution constraints, and continuously adjusts the plan according to execution feedback.
Standard large models mainly address the problem of understanding and generating content, whereas Agent task planning must address:
- What is the ultimate goal?
- Which sub-tasks does it need to be decomposed into?
- What dependencies exist between the sub-tasks?
- What tool should each task use?
- Which tasks can be executed in parallel?
- What should be done if problems arise during execution?
- How can we determine whether the task is truly complete?
For example, a user proposes:
Analyze the sales data from the last three months, identify the main reasons for the sales decline, and generate an analysis report.
This is not a simple text-generation task but a complex task involving multiple execution stages.
The Agent needs to break it down into:
- Determine the analysis time range.
- Query sales data.
- Check data completeness.
- Calculate sales trends.
- Analyze product, region, and customer dimensions.
- Identify the key factors behind the sales decline.
- Cross-validate the analysis conclusions.
- Generate an analysis report.
At its core, task planning transforms an abstract goal into an execution plan with clear inputs, outputs, dependencies, and completion conditions.
2. Where Task Planning Fits in the Agent Architecture
Task planning is usually handled by the Planner component, but it does not work independently; it runs in coordination with the Goal Manager, LLM, Tool Registry, State Manager, and Agent Runtime.
1. Where the Planner Sits in the Agent
flowchart TB
A["User submits goal"] --> B["Goal Manager"]
B --> C["Planner"]
C --> D["LLM Engine"]
D --> E["Generate task plan"]
E --> F["Plan Validator"]
F --> G{"Is the plan valid?"}
G -->|"Yes"| H["Agent Runtime"]
G -->|"No"| I["Revise plan"]
I --> C
H --> J["Tool Executor"]
J --> K["External environment"]
K --> L["Execution result"]
L --> M["State Manager"]
M --> C
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:#DCEFE5,stroke:#4F8B70,color:#24563F
style E fill:#EAF3EC,stroke:#83A995,color:#315D49
style F fill:#E0F0FE,stroke:#93BCE8,color:#1E4976
style G fill:#F7F4E8,stroke:#C7B77A,color:#675A2D
style H fill:#EAF3EC,stroke:#83A995,color:#315D49
style I fill:#F7EAE7,stroke:#C98D7C,color:#754438
style J fill:#EAF3EC,stroke:#83A995,color:#315D49
style K fill:#F5F8F4,stroke:#B5CBBB,color:#40594A
style L fill:#E0F0FE,stroke:#93BCE8,color:#1E4976
style M fill:#EAE8FA,stroke:#A49BD5,color:#51477D
2. Responsibility Boundaries Between the Planner and Other Components
| Component | Core responsibility | Relationship to planning |
|---|---|---|
| Goal Manager | Understand goals and constraints | Provide the basis for planning |
| Planner | Decompose tasks and formulate plans | Generate the execution plan |
| LLM Engine | Reasoning and generation | Provide planning intelligence |
| Tool Registry | Manage available tools | Provide descriptions of action capabilities |
| Plan Validator | Check plan validity | Validate the plan structure |
| Agent Runtime | Drive task execution | Schedule tasks in the plan |
| State Manager | Maintain task status | Record execution progress |
| Tool Executor | Execute specific operations | Complete task actions |
| Result Validator | Validate execution results | Determine whether the goal has been achieved |
Note: the Planner is responsible for deciding what to execute, while the Runtime is responsible for controlling how execution happens. The two should not be conflated.
3. The Complete Task Planning Process
A complete task planning process typically includes eight stages:
- Goal understanding.
- Constraint extraction.
- Environment and capability analysis.
- Task decomposition.
- Dependency analysis.
- Tool and resource allocation.
- Plan validation.
- Plan execution and dynamic adjustment.
1. Complete Planning Process
flowchart TD
A["Receive user goal"] --> B["Understand goal semantics"]
B --> C["Extract task constraints"]
C --> D["Analyze environment and available tools"]
D --> E["Decompose into subtasks"]
E --> F["Establish task dependencies"]
F --> G["Allocate tools and resources"]
G --> H["Generate structured plan"]
H --> I["Validate plan"]
I --> J{"Is the plan executable?"}
J -->|"No"| K["Revise or replan"]
K --> E
J -->|"Yes"| L["Submit to Runtime for execution"]
L --> M["Collect execution feedback"]
M --> N{"Is adjustment needed?"}
N -->|"Yes"| K
N -->|"No"| O["Complete task"]
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:#E0F0FE,stroke:#93BCE8,color:#1E4976
style E fill:#EAE8FA,stroke:#A49BD5,color:#51477D
style F fill:#EAF3EC,stroke:#83A995,color:#315D49
style G fill:#EAF3EC,stroke:#83A995,color:#315D49
style H fill:#DCEFE5,stroke:#4F8B70,color:#24563F
style I fill:#E0F0FE,stroke:#93BCE8,color:#1E4976
style J fill:#F7F4E8,stroke:#C7B77A,color:#675A2D
style K fill:#F7EAE7,stroke:#C98D7C,color:#754438
style L fill:#EAF3EC,stroke:#83A995,color:#315D49
style M fill:#E0F0FE,stroke:#93BCE8,color:#1E4976
style N fill:#F7F4E8,stroke:#C7B77A,color:#675A2D
style O fill:#DCEFE5,stroke:#4F8B70,color:#24563F
These eight stages do not mean the large model must be called eight times. Simple tasks can merge multiple stages, while complex tasks may require multiple rounds of reasoning and multiple plan validations.
IV. Step 1: Goal Understanding and Constraint Extraction
The quality of task planning first depends on whether the goal is understood accurately.
Users usually describe goals in natural language, and natural language may contain ambiguity, missing information, and implicit constraints.
1. Goal Structuring
For example:
Help me analyze the sales data from the last three months, identify the reasons for the decline, and generate a report. The original data must not be modified.
The Planner needs to parse it into:
| Dimension | Parsing Result |
|---|---|
| Primary goal | Analyze the reasons for the sales decline |
| Time range | Last three months |
| Data source | Sales data system |
| Analysis content | Sales trends and influencing factors |
| Output format | Analysis report |
| Operational constraints | Read-only; modifying the original data is not allowed |
| Completion condition | Data-backed analysis conclusions and report |
2. Goals and Constraints Must Be Separated
A goal describes what result is to be achieved, while a constraint describes what must not be done during execution.
For example:
{
"goal": {
"description": "分析销售下降原因并生成报告",
"expected_output": "sales_analysis_report"
},
"constraints": {
"time_range": "last_3_months",
"data_access": "read_only",
"allow_data_modification": false,
"require_evidence": true
}
}
This separation has two important benefits:
- The Planner can flexibly adjust task steps but cannot change the user's goal.
- Runtime and Policy Engine can independently check whether each action violates a constraint.
3. When Is User Clarification Needed?
If missing information would significantly affect the plan, the user should be asked to provide it.
For example:
- No data source is specified.
- The time range for the analysis is unclear.
- The user asks for an action to be performed, but has not explicitly authorized it.
- Multiple conflicting objectives exist.
- The success criteria cannot be determined.
For details that do not affect the correctness of the task, reasonable defaults can be used to avoid repeatedly interrupting the user.
V. Step Two: Task Decomposition
Task decomposition is the most central capability in Agent planning.
Complex goals usually cannot be executed directly; they need to be broken down into smaller, more clearly defined subtasks.
1. Why is task decomposition needed?
Suppose the Agent is asked directly to complete:
Analyze the sales data and generate a report.
This task is too abstract, and the Agent cannot determine: - Which data needs to be read. - Which statistical analyses need to be performed. - How to identify a sales decline. - How to determine the contributing factors. - How to validate the conclusions. - What the report should contain.
After the task is broken down, each subtask can have clear inputs, outputs, and completion conditions.
2. Basic principles of task decomposition
Principle One: Clear objective
Every subtask should have a clear purpose for execution.
Principle Two: Clear inputs
A task needs to know which data or prior results it depends on.
Principle Three: Clear outputs
Every task should produce an identifiable result.
Principle Four: Clear boundaries
Avoid having multiple tasks repeatedly handle the same content.
Principle Five: Appropriate granularity
If tasks are too coarse, they are hard to execute and verify; if tasks are too fine, scheduling costs and the number of model calls increase.
3. Task Tree
Complex tasks can be broken down using a tree structure.
flowchart TD
A["Sales Data Analysis"] --> B["Data Preparation"]
A --> C["Sales Trend Analysis"]
A --> D["Contributing Factor Analysis"]
A --> E["Report Generation"]
B --> B1["Query Sales Data"]
B --> B2["Check Data Completeness"]
B --> B3["Clean Abnormal Data"]
C --> C1["Calculate Monthly Sales"]
C --> C2["Calculate Year-over-Year and Month-over-Month"]
C --> C3["Identify Decline Intervals"]
D --> D1["Product Dimension Analysis"]
D --> D2["Region Dimension Analysis"]
D --> D3["Customer Dimension Analysis"]
E --> E1["Summarize Analysis Conclusions"]
E --> E2["Generate Charts"]
E --> E3["Generate Report"]
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:#EAE8FA,stroke:#A49BD5,color:#51477D
style B1 fill:#F5F8F4,stroke:#B5CBBB,color:#40594A
style B2 fill:#F5F8F4,stroke:#B5CBBB,color:#40594A
style B3 fill:#F5F8F4,stroke:#B5CBBB,color:#40594A
style C1 fill:#F5F8F4,stroke:#B5CBBB,color:#40594A
style C2 fill:#F5F8F4,stroke:#B5CBBB,color:#40594A
style C3 fill:#F5F8F4,stroke:#B5CBBB,color:#40594A
style D1 fill:#F5F8F4,stroke:#B5CBBB,color:#40594A
style D2 fill:#F5F8F4,stroke:#B5CBBB,color:#40594A
style D3 fill:#F5F8F4,stroke:#B5CBBB,color:#40594A
style E1 fill:#F5F8F4,stroke:#B5CBBB,color:#40594A
style E2 fill:#F5F8F4,stroke:#B5CBBB,color:#40594A
style E3 fill:#F5F8F4,stroke:#B5CBBB,color:#40594A
Note that a task tree expresses a hierarchical decomposition relationship, and does not necessarily fully express the execution dependencies among tasks.
For example, sales trend analysis and product dimension analysis can run in parallel, but report generation must wait for the relevant analysis results.
Therefore, complex tasks also require a dependency graph.
VI. Step Three: Dependency Analysis
After task decomposition, the Planner needs to analyze the dependencies among the subtasks.
Task dependencies determine: - Which tasks must be executed first. - Which tasks can be executed simultaneously. - Which tasks need to wait for the results of other tasks. - Which task failures will affect the entire plan.
1. Task Dependency Graph
Suppose the sales analysis task contains:
- A: Query sales data.
- B: Data quality check.
- C: Sales trend analysis.
- D: Product dimension analysis.
- E: Region dimension analysis.
- F: Summary report.
Dependency relationships:
- B depends on A.
- C, D, and E depend on B.
- F depends on C, D, and E.
flowchart TD
A["A: Query sales data"] --> B["B: Data quality check"]
B --> C["C: Sales trend analysis"]
B --> D["D: Product dimension analysis"]
B --> E["E: Regional dimension analysis"]
C --> F["F: Summary report"]
D --> F
E --> F
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:#E0F0FE,stroke:#93BCE8,color:#1E4976
style F fill:#DCEFE5,stroke:#4F8B70,color:#24563F
This type of structure can usually be represented as a directed acyclic graph (DAG).
2. DAG: Directed Acyclic Graph
A DAG (Directed Acyclic Graph) consists of nodes and directed edges:
- Nodes represent tasks.
- Directed edges represent dependencies.
- Acyclic means there are no cycles in task dependencies.
For example:
This means C must wait for B to complete, and B must wait for A to complete.
If there is:
then a circular dependency is formed, and the tasks cannot be executed normally through ordinary topological scheduling.
3. Topological Sorting
For a DAG, topological sorting can be used to calculate a valid execution order.
Common algorithms:
- Kahn's algorithm: based on in-degree and a queue.
- DFS algorithm: based on depth-first search and completion order.
The basic process of Kahn's algorithm:
- Calculate the in-degree of all nodes.
- Put nodes with in-degree 0 into the queue.
- Take out a node and add it to the execution order.
- Remove the outgoing edges of that node.
- Add nodes whose in-degree becomes 0 to the queue.
- Repeat until the queue is empty.
- If the number of output nodes is less than the total number of nodes, a circular dependency exists.
Python implementation:
from collections import deque
def topological_sort(tasks, dependencies):
"""
tasks: List of task IDs
dependencies: (predecessor task, successor task)
"""
graph = {task: [] for task in tasks}
indegree = {task: 0 for task in tasks}
for source, target in dependencies:
graph[source].append(target)
indegree[target] += 1
queue = deque(
task for task in tasks
if indegree[task] == 0
)
result = []
while queue:
current = queue.popleft()
result.append(current)
for neighbor in graph[current]:
indegree[neighbor] -= 1
if indegree[neighbor] == 0:
queue.append(neighbor)
if len(result) != len(tasks):
raise ValueError("检测到循环依赖")
return result
tasks = ["A", "B", "C", "D", "E", "F"]
dependencies = [
("A", "B"),
("B", "C"),
("B", "D"),
("B", "E"),
("C", "F"),
("D", "F"),
("E", "F")
]
print(topological_sort(tasks, dependencies))
Time complexity:
Where: - V represents the number of task nodes. - E represents the number of task dependency edges.
4. Dependency Relationships Are Not the Same as Execution Order
This is a commonly confused concept.
Dependency relationships define the precedence constraints between tasks, while the scheduler determines the actual execution order based on dependencies, resources, and priorities.
For example, C, D, and E all depend on B, but there are no dependencies among them.
Therefore:
- C, D, and E can be executed in parallel.
- If resources are insufficient, they can also be executed sequentially.
- If D fails, whether to block C and E depends on the failure strategy.
A DAG describes feasible execution constraints, not a unique execution order.
7. Step 4: Common Algorithms and Patterns for Task Planning
Agent task planning does not have only one implementation.
Depending on task complexity, execution environment, and degree of dynamic change, different planning patterns can be used.
1. Sequential Planning
Sequential planning is the simplest form of task planning, in which tasks are executed in a clear order.
Applicable to: - Data processing pipelines. - File parsing. - Fixed business processes. - Tasks with strict sequential dependencies.
flowchart TD
A["Task A"] --> B["Task B"]
B --> C["Task C"]
C --> D["Task D"]
D --> E["Task completed"]
style A fill:#DCEFE5,stroke:#4F8B70,color:#24563F
style B fill:#EAF3EC,stroke:#83A995,color:#315D49
style C fill:#E0F0FE,stroke:#93BCE8,color:#1E4976
style D fill:#EAE8FA,stroke:#A49BD5,color:#51477D
style E fill:#DCEFE5,stroke:#4F8B70,color:#24563F
Advantages: - Simple execution logic. - Easy state management. - Predictable results. - Easy exception localization.
Disadvantages: - Cannot fully utilize parallel resources. - Delays in preceding tasks affect all subsequent tasks.
2. Parallel Planning
Parallel planning executes mutually independent tasks at the same time.
Applicable to: - Queries from multiple data sources. - Analysis of multiple files. - Multi-dimensional data statistics. - Multiple independent subtasks.
flowchart TD
A["Main task"] --> B["Task A"]
A --> C["Task B"]
A --> D["Task C"]
B --> E["Result aggregation"]
C --> E
D --> E
E --> F["Task completed"]
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 planning needs to consider:
Data races
Whether multiple tasks will modify the same resource at the same time.
Resource contention
Whether model calls, database connections, API quotas, and the execution environment are limited.
Result merging
Whether the results of multiple subtasks have a consistent data structure.
Partial failure
Whether other tasks continue executing after one task fails.
3. Conditional Planning
Conditional planning determines subsequent paths based on execution results.
Applicable to: - Data quality checks. - Approval processes. - Exception handling. - Dynamic business decisions.
flowchart TD
A["Execute data check"] --> B{"Is the data complete?"}
B -->|"Yes"| C["Execute data analysis"]
B -->|"No"| D["Supplement or repair data"]
D --> E{"Was the repair successful?"}
E -->|"Yes"| C
E -->|"No"| F["Terminate analysis and report the issue"]
C --> G["Generate analysis report"]
style A fill:#DCEFE5,stroke:#4F8B70,color:#24563F
style B fill:#F7F4E8,stroke:#C7B77A,color:#675A2D
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:#F7EAE7,stroke:#C98D7C,color:#754438
style G fill:#DCEFE5,stroke:#4F8B70,color:#24563F
4. Iterative Planning
Iterative planning gradually approaches the goal through continuous execution, observation, and adjustment.
Applicable to: - Code repair. - Content optimization. - Parameter tuning. - Solving complex problems.
flowchart TD
A["Generate initial plan"] --> B["Execute task"]
B --> C["Evaluate execution result"]
C --> D{"Is goal met?"}
D -->|"Yes"| E["Complete task"]
D -->|"No"| F["Analyze gap"]
F --> G["Adjust plan"]
G --> B
style A fill:#DCEFE5,stroke:#4F8B70,color:#24563F
style B fill:#EAF3EC,stroke:#83A995,color:#315D49
style C fill:#E0F0FE,stroke:#93BCE8,color:#1E4976
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:#EAE8FA,stroke:#A49BD5,color:#51477D
Iterative planning needs to set: - Maximum number of iterations. - Total task budget. - Success criteria. - Failure exit conditions. - Plan adjustment strategy.
Otherwise, the Agent may fall into repeated attempts and continuously consume tokens and tool resources.
5. Hierarchical Planning
Hierarchical planning divides complex tasks into multiple levels of abstraction.
The upper layer defines goals and subgoals, while the lower layer handles specific operations.
For example:
flowchart TD
A["Enterprise business analysis"]
A --> B["Sales analysis"]
A --> C["Cost analysis"]
A --> D["Profit analysis"]
B --> B1["Query sales data"]
B --> B2["Summarize sales trends"]
B --> B3["Analyze product performance"]
C --> C1["Query cost data"]
C --> C2["Summarize cost changes"]
D --> D1["Calculate profit margin"]
D --> D2["Analyze profit changes"]
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 B1 fill:#F5F8F4,stroke:#B5CBBB,color:#40594A
style B2 fill:#F5F8F4,stroke:#B5CBBB,color:#40594A
style B3 fill:#F5F8F4,stroke:#B5CBBB,color:#40594A
style C1 fill:#F5F8F4,stroke:#B5CBBB,color:#40594A
style C2 fill:#F5F8F4,stroke:#B5CBBB,color:#40594A
style D1 fill:#F5F8F4,stroke:#B5CBBB,color:#40594A
style D2 fill:#F5F8F4,stroke:#B5CBBB,color:#40594A
The advantage of hierarchical planning is that it controls complexity.
The upper layer does not need to focus on the details of each tool call, and the lower layer does not need to re-understand the entire business goal.
6. Comparison of Planning Modes
| Planning mode | Core characteristics | Applicable scenarios | Main risks |
|---|---|---|---|
| Sequential | Fixed sequence | Pipeline tasks | Low execution efficiency |
| Parallel | Multiple tasks in parallel | Independent subtasks | Resource contention |
| Conditional | Conditional branching | Dynamic decision-making | Complex branching |
| Iterative | Feedback iteration | Continuous optimization | Infinite loops |
| Hierarchical | Multi-level task decomposition | Complex goals | Hierarchical coordination cost |
In practice, an Agent usually does not use just one mode; rather, it combines multiple modes into a task DAG.
8. Step 5: Tool Selection and Task Allocation
After task decomposition is complete, the Planner needs to determine which agent executes each subtask and what tools are used.
1. Mapping Tasks to Tools
For example:
| Subtask | Tool | Input | Output |
|---|---|---|---|
| Query sales data | SQL Tool | Time range | Sales records |
| Check data quality | Python Tool | Sales records | Quality report |
| Calculate sales trends | Data Analysis Tool | Sales records | Trend data |
| Analyze causes of decline | LLM / Analysis Tool | Analysis results | List of reasons |
| Generate report | Report Tool | Analysis conclusions | Report file |
Tool selection cannot rely only on tool names; it also needs to consider: - Whether the tool description matches the task. - Whether the parameters can meet the requirements. - Whether the tool has the necessary permissions. - Whether the tool is available. - Execution cost and latency. - Whether the tool has side effects.
2. Tool Selection Mechanism
Tool selection can be performed by an LLM through semantic judgment, or it can combine rules and tool metadata.
A common process:
flowchart TD
A["Get pending task"] --> B["Extract task capability requirements"]
B --> C["Retrieve available tools"]
C --> D["Match tool descriptions and parameters"]
D --> E["Check tool permissions"]
E --> F{"Is there a suitable tool?"}
F -->|"Yes"| G["Select tool"]
F -->|"No"| H["Request additional capabilities or manual handling"]
G --> I["Generate invocation parameters"]
I --> J["Submit to Tool Executor"]
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:#F7F4E8,stroke:#C7B77A,color:#675A2D
style G fill:#DCEFE5,stroke:#4F8B70,color:#24563F
style H fill:#F7EAE7,stroke:#C98D7C,color:#754438
style I fill:#EAF3EC,stroke:#83A995,color:#315D49
style J fill:#DCEFE5,stroke:#4F8B70,color:#24563F
3. Task Assignment Is Not Equivalent to Tool Invocation
For complex systems, a task may be completed jointly by multiple tools.
For example, a data analysis task may include:
- The SQL tool is responsible for reading data.
- The Python tool is responsible for statistical calculations.
- The chart tool is responsible for generating charts.
- The document tool is responsible for generating reports.
What the Planner needs to decide is the task execution plan, rather than simply handing all the work to one tool.
IX. Step 6: Structured Plan Representation
The Planner should ultimately generate a structured plan, rather than only returning a natural language description.
A structured plan can be directly scheduled by the Runtime and supports status updates, failure recovery, and execution tracking.
1. Task Object Design
A standard task object can include:
| Field | Description |
|---|---|
| task_id | Task unique identifier |
| name | Task name |
| description | Task description |
| input | Input data or reference |
| output | Expected output |
| dependencies | Prerequisite tasks |
| assigned_tool | Execution tool |
| status | Current status |
| priority | Priority |
| timeout | Timeout |
| retry_policy | Retry policy |
| success_criteria | Completion criteria |
2. Structured Plan Example
{
"plan_id": "sales_analysis_001",
"goal": "Analyze the reasons for the sales decline over the past three months",
"tasks": [
{
"task_id": "T1",
"name": "query_sales",
"description": "Query the sales data for the past three months",
"dependencies": [],
"assigned_tool": "sql_query",
"status": "pending",
"priority": 1,
"success_criteria": [
"Query succeeds",
"Sales records returned"
]
},
{
"task_id": "T2",
"name": "validate_data",
"description": "Check data integrity",
"dependencies": ["T1"],
"assigned_tool": "python_analysis",
"status": "pending",
"priority": 1,
"success_criteria": [
"Missing-value check completed",
"Data quality report output"
]
},
{
"task_id": "T3",
"name": "analyze_trend",
"description": "Analyze the sales trend",
"dependencies": ["T2"],
"assigned_tool": "python_analysis",
"status": "pending",
"priority": 2,
"success_criteria": [
"Monthly trend data generated"
]
},
{
"task_id": "T4",
"name": "generate_report",
"description": "Generate the sales analysis report",
"dependencies": ["T3"],
"assigned_tool": "report_generator",
"status": "pending",
"priority": 3,
"success_criteria": [
"Report generated successfully",
"Includes data and conclusions"
]
}
]
}
3. Why do plans need to be structured?
If a plan is just natural language:
First query the data, then analyze it, and finally generate the report.
It is very hard for the Runtime to accurately determine: - Which tasks have already been completed. - Which tasks can run in parallel. - How to recover after a task fails. - Which results should be passed on to subsequent tasks. - How to verify the task completion conditions.
Structured plans turn the planning result from model text into data that the system can execute and manage.
10. Step Seven: Plan Validation
A plan generated by the model is not necessarily correct.
It may contain: - Non-existent tools. - Invalid parameters. - Incorrect dependencies. - Circular dependencies. - Missing necessary steps. - Non-executable operations. - Tasks that violate user constraints.
Therefore, the plan must be validated.
1. Dimensions of plan validation
| Validation dimension | What is checked |
|---|---|
| Structural validation | Whether the plan format is legal |
| Goal coverage | Whether it covers the user's requirements |
| Dependency validation | Whether circular dependencies exist |
| Tool validation | Whether the tools are registered |
| Parameter validation | Whether the parameters conform to the Schema |
| Permission validation | Whether it exceeds the authorized scope |
| Resource validation | Whether it exceeds the budget |
| Executability | Whether the inputs and preconditions are satisfied |
| Completion conditions | Whether task success can be determined |
2. Plan validation process
flowchart TD
A["Receive Planner output"] --> B["Check structural format"]
B --> C["Check goal coverage"]
C --> D["Check task dependencies"]
D --> E["Check tools and parameters"]
E --> F["Check permissions and budget"]
F --> G{"Validation passed?"}
G -->|"Yes"| H["Submit execution schedule"]
G -->|"No"| I["Generate validation errors"]
I --> J["Revise plan"]
J --> B
style A fill:#DCEFE5,stroke:#4F8B70,color:#24563F
style B fill:#EAF3EC,stroke:#83A995,color:#315D49
style C fill:#E0F0FE,stroke:#93BCE8,color:#1E4976
style D fill:#EAF3EC,stroke:#83A995,color:#315D49
style E fill:#E0F0FE,stroke:#93BCE8,color:#1E4976
style F fill:#EAE8FA,stroke:#A49BD5,color:#51477D
style G fill:#F7F4E8,stroke:#C7B77A,color:#675A2D
style H fill:#DCEFE5,stroke:#4F8B70,color:#24563F
style I fill:#F7EAE7,stroke:#C98D7C,color:#754438
style J fill:#EAE8FA,stroke:#A49BD5,color:#51477D
3. Plan validation cannot rely entirely on LLMs
For example, the model may generate a dependency relationship:
- A depends on B.
- B depends on C.
- C depends on A.
The model may not realize that this is a circular dependency.
Therefore, the following checks should be performed by deterministic programs: - JSON Schema validation. - DAG cycle detection. - Tool registration check. - Parameter Schema validation. - Permission validation. - Resource budget check.
LLMs are better suited to semantic-level judgment of goal coverage and task reasonableness.
11. Dynamic Planning and Replanning
Traditional workflows usually determine the complete process before execution, whereas the environment an Agent faces may keep changing.
During execution, the following may occur: - Missing data. - Tool call failure. - New information appears. - The user changes the goal. - Task dependencies change. - The original plan can no longer be executed.
Therefore, an Agent needs dynamic planning capability.
1. What is dynamic planning?
Here, dynamic planning means that the Agent re-evaluates and adjusts the execution plan based on the current task state and environmental feedback.
It is different from Dynamic Programming in the field of algorithms.
The focus of Agent dynamic planning is:
- Preserve valid work that has already been completed.
- Identify the parts that the current plan cannot complete.
- Analyze the causes of failure.
- Regenerate subsequent tasks.
- Verify whether the new plan is consistent with the original goal.
2. Replanning Trigger Conditions
| Trigger condition | Typical situation | Adjustment method |
|---|---|---|
| Tool failure | API unavailable | Switch tools or retry after a delay |
| Data changes | Data source is updated | Re-fetch the relevant data |
| Task failure | Tests not passed | Revise the approach and retest |
| New information appears | A new key factor is discovered | Add analysis tasks |
| User changes the goal | Change the report scope | Update the goal and plan |
| Insufficient resources | Insufficient token or time budget | Narrow the scope or degrade |
3. Dynamic Replanning Process
flowchart TD
A["Execute current plan"] --> B["Obtain execution feedback"]
B --> C["Analyze current task status"]
C --> D{"Is the original plan still feasible?"}
D -->|"Yes"| E["Continue executing the original plan"]
D -->|"No"| F["Identify affected tasks"]
F --> G["Preserve completed tasks"]
G --> H["Re-analyze goals and constraints"]
H --> I["Generate new plan"]
I --> J["Validate new plan"]
J --> K{"Does it pass validation?"}
K -->|"Yes"| L["Update task DAG"]
K -->|"No"| M["Request manual intervention"]
L --> E
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:#F7F4E8,stroke:#C7B77A,color:#675A2D
style E fill:#DCEFE5,stroke:#4F8B70,color:#24563F
style F fill:#F7EAE7,stroke:#C98D7C,color:#754438
style G fill:#EAF3EC,stroke:#83A995,color:#315D49
style H fill:#E0F0FE,stroke:#93BCE8,color:#1E4976
style I fill:#EAE8FA,stroke:#A49BD5,color:#51477D
style J fill:#EAF3EC,stroke:#83A995,color:#315D49
style K fill:#F7F4E8,stroke:#C7B77A,color:#675A2D
style L fill:#DCEFE5,stroke:#4F8B70,color:#24563F
style M fill:#F7EAE7,stroke:#C98D7C,color:#754438
4. Local Replanning and Global Replanning
Local Replanning
Only adjust the affected tasks and their downstream dependent tasks.
For example: - The original plan requires calling Tool A. - Tool A is temporarily unavailable. - Use Tool B to complete the same subtask. - Subsequent tasks remain unchanged.
Advantages: - Lower cost. - Preserves existing execution results. - Has less impact on task status.
Global Replanning
Re-analyze the entire goal and task structure to generate a new execution plan.
Applicable when: - The user's goal changes significantly. - The original plan is infeasible as a whole. - Key assumptions are overturned. - The task dependency structure changes significantly.
In production environments, local replanning is usually preferred, and global replanning is performed only when necessary.
12. Task Scheduling and Concurrency Control
The Planner is responsible for generating plans, but actual execution also requires the Scheduler to perform task scheduling.
The difference between Planner and Scheduler:
- The Planner determines how tasks should be organized.
- The Scheduler determines which tasks can currently be executed and when.
1. Responsibilities of the Scheduler
- Check whether task dependencies are satisfied.
- Identify currently executable tasks.
- Select tasks based on priority.
- Control concurrency.
- Allocate execution resources.
- Handle task timeouts and failures.
- Update task status.
2. Executable Task Set
Suppose in the task DAG:
- A is completed.
- B, C, and D depend on A.
- E depends on B and C.
- F depends on D.
After A is completed, B, C, and D all enter the Ready state.
Only after B and C are completed can E enter the Ready state.
After D is completed, F can be executed independently.
3. Task Scheduling Process
flowchart TD
A["Scheduler retrieves task DAG"] --> B["Check task status"]
B --> C["Check whether dependencies are satisfied"]
C --> D["Filter Ready tasks"]
D --> E["Sort by priority"]
E --> F["Check concurrency and resource limits"]
F --> G{"Are there schedulable tasks?"}
G -->|"Yes"| H["Allocate execution resources"]
H --> I["Start task"]
I --> J["Collect execution results"]
J --> K["Update task status"]
K --> B
G -->|"No"| L["Wait for task completion or external events"]
style A fill:#DCEFE5,stroke:#4F8B70,color:#24563F
style B fill:#EAF3EC,stroke:#83A995,color:#315D49
style C fill:#E0F0FE,stroke:#93BCE8,color:#1E4976
style D fill:#EAF3EC,stroke:#83A995,color:#315D49
style E fill:#EAE8FA,stroke:#A49BD5,color:#51477D
style F fill:#E0F0FE,stroke:#93BCE8,color:#1E4976
style G fill:#F7F4E8,stroke:#C7B77A,color:#675A2D
style H fill:#EAF3EC,stroke:#83A995,color:#315D49
style I fill:#DCEFE5,stroke:#4F8B70,color:#24563F
style J fill:#E0F0FE,stroke:#93BCE8,color:#1E4976
style K fill:#EAF3EC,stroke:#83A995,color:#315D49
style L fill:#F5F8F4,stroke:#B5CBBB,color:#40594A