Back to series
· 13 min read

Reflection: Self-Reflection and Self-Correction Mechanism


I. Core Concepts of Reflection

Reflection refers to an Agent's ability to evaluate its own reasoning process, action results, and task completion, and to correct subsequent behavior based on the evaluation conclusions.

Traditional LLM calls usually adopt a one-shot generation pattern:

  • Receive user input.
  • Generate an answer or execution plan.
  • Return the result.

This pattern lacks the ability to actively verify results. The model may produce incorrect reasoning, call the wrong tools, omit key steps, or even repeat the same operations after a task fails.

Reflection introduces feedback and self-evaluation mechanisms into the Agent's execution process, enabling the Agent not only to execute tasks but also to determine whether execution is effective.

1.1 Core Capabilities

Capability Description
Result evaluation Determine whether the current output meets the task goal
Error identification Detect factual errors, logical errors, and execution errors
Cause analysis Identify the causes of failure, not just the symptoms of failure
Strategy correction Modify the reasoning path, tool selection, or execution plan
Re-execution Re-execute the task according to the corrected strategy
Stop determination Determine whether the goal has been achieved and avoid meaningless loops

1.2 Difference Between Reflection and Ordinary Reasoning

Dimension Ordinary reasoning Reflection
Core objective Generate a solution Evaluate and improve the solution
Input User task and context Original task, execution process, and execution result
Focus How to complete the task Whether the task is completed and where problems exist
Error handling May directly output incorrect results Attempt to identify and correct errors
Execution mode Single-turn or continuous reasoning Evaluate, feedback, correct, and re-execute
Termination criterion Generation completed Quality meets the standard or stop condition is reached

Note: Reflection is not equivalent to the model simply thinking again.

Truly effective Reflection must be based on verifiable feedback information and be able to translate evaluation results into concrete behavioral adjustments.


II. Overall Architecture of Reflection

Reflection usually serves as an independent step in the Agent execution loop and works together with modules such as Planner, Executor, Tool, and Memory.

2.1 Core Architecture

flowchart TD
    A["User task"] --> B["Planner task planning"]
    B --> C["Executor executes task"]
    C --> D["Get execution result"]
    D --> E["Reflection result evaluation"]
    E --> F{"Goal achieved?"}
    F -->|"Yes"| G["Output final result"]
    F -->|"No"| H["Error analysis"]
    H --> I["Generate correction strategy"]
    I --> J["Update execution plan"]
    J --> C

    style A fill:#DCEFE5,stroke:#4F8B70,color:#24563F
    style B fill:#EAF3EC,stroke:#83A995,color:#315D49
    style C fill:#EAF3EC,stroke:#83A995,color:#315D49
    style D fill:#F5F8F4,stroke:#B5CBBB,color:#40594A
    style E fill:#E0F0FE,stroke:#93BCE8,color:#1E4976
    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:#EAE8FA,stroke:#A49BD5,color:#51477D
    style J fill:#EAF3EC,stroke:#83A995,color:#315D49

Core execution chain:

  1. The Planner generates an execution plan based on the user task.
  2. The Executor calls tools or performs operations according to the plan.
  3. The system collects execution results, tool return values, and intermediate states.
  4. Reflection evaluates the results.
  5. If the task does not meet the standard, analyze the errors and generate a correction strategy.
  6. Feed the correction strategy back to the Planner or Executor.
  7. Re-execute until the goal is met or a termination condition is triggered.

2.2 Module Division of Reflection

Module Primary Responsibility Output
Evaluator Evaluate task execution quality Evaluation results
Critic Identify defects and errors Issue list
Analyzer Analyze the causes of errors Root cause analysis
Reflector Generate reflection conclusions Reflection record
Strategy Updater Revise subsequent execution strategy New execution strategy
Controller Control the number of loops and stop conditions Control decisions

In real-world engineering, these modules are not necessarily implemented by separate models. They can be implemented through different prompts for the same LLM, separate evaluation models, rule engines, or external validators.


III. Core Working Mechanism of Reflection

The key to Reflection is not to regenerate the answer, but to turn execution results into actionable feedback.

3.1 Step 1: Establish Evaluation Criteria

Before executing a task, the Agent needs to define what kind of result counts as success.

Without clear evaluation criteria, Reflection can easily become subjective assessment, for example:

  • Does the answer seem reasonable?
  • Does the code look correct?
  • Is the solution relatively complete?

These judgments lack reliability.

Therefore, task goals should be broken down into checkable acceptance conditions.

For example, the user asks to develop a REST API:

Acceptance Dimension Check Condition
Functional correctness Does the API implement the specified business functionality?
Parameter validation Are invalid parameters handled?
Response format Does it conform to the agreed data structure?
Exception handling Are common exceptions covered?
Security Are authentication and authorization issues handled?
Test coverage Do key test cases pass?

Acceptance criteria can be represented as:

{
  "task": "开发用户查询接口",
  "criteria": [
    {
      "name": "功能正确性",
      "check": "返回指定用户信息",
      "weight": 0.35
    },
    {
      "name": "参数校验",
      "check": "非法用户 ID 返回明确错误",
      "weight": 0.20
    },
    {
      "name": "异常处理",
      "check": "用户不存在时返回约定状态码",
      "weight": 0.20
    },
    {
      "name": "测试通过",
      "check": "核心测试用例全部通过",
      "weight": 0.25
    }
  ]
}

Acceptance conditions should be determined before execution as much as possible, to prevent the model from arbitrarily lowering the success criteria after execution fails.

3.2 Step 2: Collect Execution Evidence

Reflection cannot rely only on the final answer; it also needs to collect the complete execution context.

Typical data includes:

  • Original task goal.
  • Current execution plan.
  • Model-generated reasoning summary.
  • Tool call records.
  • Tool return results.
  • Intermediate states.
  • Final output.
  • External validation results.
  • Execution time and resource consumption.

The execution process can be abstracted as:

{
  "task_id": "task_001",
  "goal": "完成用户查询接口",
  "plan": [
    "设计接口",
    "实现业务逻辑",
    "添加参数校验",
    "执行测试"
  ],
  "actions": [
    {
      "tool": "code_executor",
      "operation": "run_tests",
      "status": "success",
      "output": "8 passed, 1 failed"
    }
  ],
  "result": {
    "status": "partial_success",
    "completed_steps": 3,
    "failed_steps": 1
  }
}

Here is an important principle:

Execution records and the model's interpretation of execution records must be stored separately.

For example, a tool returning a test failure is an objective fact; the model determining that the cause is a missing parameter validation is an analytical conclusion.

The two must not be conflated.

3.3 Step 3: Execution Quality Evaluation

The Evaluator assesses the task result based on the acceptance criteria and execution evidence.

Common evaluation methods include:

1. Rule-based evaluation

Determine whether the result meets requirements through deterministic rules.

For example:

  • Whether the HTTP status code is correct.
  • Whether the JSON fields are complete.
  • Whether all tests pass.
  • Whether the file exists.
  • Whether the database record was successfully written.

The advantages are stability, low cost, and reproducible results.

The disadvantage is that it can only cover explicitly encoded rules.

2. Model-based evaluation

Use an LLM to judge whether the result meets the task requirements.

Applicable to:

  • Natural language quality assessment.
  • Solution rationality analysis.
  • Complex logic review.
  • Document completeness check.
  • Multi-dimensional semantic comparison.

The disadvantages are potential evaluation bias, hallucination, and self-preference.

3. External evaluation

Use an independent system to provide verification results.

For example:

  • Unit tests.
  • Integration tests.
  • Static code analysis.
  • Database queries.
  • Actual API calls.
  • Search result verification.
  • Human review.

External evaluation is usually more reliable than model self-judgment alone.

4. Hybrid evaluation

In actual engineering practice, multiple methods are usually combined:

flowchart TD
    A["Execution Result"] --> B["Rule-based Evaluation"]
    A --> C["LLM Semantic Evaluation"]
    A --> D["External Tool Verification"]
    B --> E["Evaluation Result Fusion"]
    C --> E
    D --> E
    E --> F{"Pass Acceptance?"}
    F -->|"Pass"| G["Confirm Task Completion"]
    F -->|"Fail"| H["Proceed to Error Analysis"]

    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:#F5F8F4,stroke:#B5CBBB,color:#40594A
    style F fill:#F7F4E8,stroke:#C7B77A,color:#675A2D
    style G fill:#DCEFE5,stroke:#4F8B70,color:#24563F
    style H fill:#F7EAE7,stroke:#C98D7C,color:#754438

3.4 Step 4: Identify Problems and Analyze Root Causes

After a task failure is detected, it should not be immediately re-executed; instead, determine where the failure occurred.

Common error types:

Error Type Typical Symptom Possible Cause
Goal misunderstanding Completed a task different from what the user requested Inaccurate intent recognition
Planning error Unreasonable execution order Incorrect dependency analysis
Reasoning error Conclusion inconsistent with facts Incorrect premise or logical leap
Tool selection error Called an inappropriate tool Misunderstanding of tool capabilities
Tool execution error API call failed Incorrect parameters or insufficient permissions
Data error Used outdated or incorrect data Insufficient retrieval quality
Context error Missed key constraints Incomplete context management
Validation error Incorrect result judged as successful Insufficient acceptance criteria

Root cause analysis should distinguish three levels:

  • Symptom: What happened.
  • Direct cause: Why this symptom occurred.
  • Root cause: Which system component caused the direct cause.

For example:

Symptom:
    Unit test failed.

Direct cause:
    API response fields are missing.

Root cause:
    The Planner did not include the response field requirements in the execution plan.

Corrective direction:
    Add interface contract constraints and include response structure validation.

If only the direct cause is fixed without correcting the root cause, similar problems may occur again in the next execution.

3.5 Step 5: Generate a Correction Strategy

After root cause analysis is complete, Reflection needs to generate a specific, executable correction plan.

Correction strategies can be divided into:

Correction type Handling method
Goal correction Re-clarify task constraints
Plan correction Adjust task steps and dependencies
Reasoning correction Recheck premises and logic
Tool correction Replace tools or adjust invocation parameters
Data correction Re-retrieve, validate, or update data
Verification correction Add checks or modify the acceptance process
Context correction Supplement missing information

The correction strategy should have clear execution actions, rather than vague self-evaluation.

Not recommended:

Need to check the code more carefully.

Recommended:

1. Check the response structure of the user query API.
2. Add the missing user_id and created_at fields.
3. Add response structure assertions.
4. Re-run the related unit tests.

3.6 Step 6: Execute Again and Verify

The correction strategy must be fed back into the execution system, rather than only generating a piece of reflection text.

flowchart TD
    A["Receive correction strategy"] --> B["Update execution plan"]
    B --> C["Re-execute failed steps"]
    C --> D["Collect new execution results"]
    D --> E["Re-evaluate"]
    E --> F{"Are acceptance criteria met?"}
    F -->|"Yes"| G["End task"]
    F -->|"No"| H{"Is there retry budget remaining?"}
    H -->|"Yes"| I["Further analyze the problem"]
    I --> B
    H -->|"No"| J["Terminate and report failure"]

    style A fill:#EAE8FA,stroke:#A49BD5,color:#51477D
    style B fill:#EAF3EC,stroke:#83A995,color:#315D49
    style C fill:#EAF3EC,stroke:#83A995,color:#315D49
    style D fill:#F5F8F4,stroke:#B5CBBB,color:#40594A
    style E fill:#E0F0FE,stroke:#93BCE8,color:#1E4976
    style F fill:#F7F4E8,stroke:#C7B77A,color:#675A2D
    style G fill:#DCEFE5,stroke:#4F8B70,color:#24563F
    style H fill:#F7F4E8,stroke:#C7B77A,color:#675A2D
    style I fill:#F7EAE7,stroke:#C98D7C,color:#754438
    style J fill:#F7EAE7,stroke:#C98D7C,color:#754438

Not all tasks need to be executed from scratch.

A more reasonable approach is to locate the failed step, re-execute only the affected part, and retain results that have already passed verification.


IV. Key Technical Mechanisms of Reflection

4.1 Self-Evaluation and the Critic Mechanism

Critic is the core role in Reflection responsible for reviewing results.

It needs to evaluate from perspectives such as task goals, factual accuracy, logical consistency, constraint satisfaction, and execution quality.

Typical Critic Prompt:

You are an independent task quality evaluator.

Please review the Agent's execution results based on the original task and acceptance criteria.

Evaluation requirements:
1. Do not assume the Agent's results are correct by default.
2. Check each acceptance criterion item by item.
3. Distinguish factual errors, logical errors, and execution errors.
4. Must cite execution evidence.
5. Mark uncertain issues as unknown.
6. Provide specific, actionable correction suggestions.

Output JSON:
{
  "passed": false,
  "score": 0.72,
  "issues": [
    {
      "type": "missing_requirement",
      "description": "Missing user creation time field",
      "evidence": "The actual response does not contain created_at",
      "severity": "high"
    }
  ],
  "root_cause": "The API response contract was not fully included in the execution plan",
  "suggestions": [
    "Add the created_at field",
    "Add a response structure test"
  ]
}

The key for Critic is not to give a score, but to provide evidence-supported problem localization.

4.2 Self-Correction and Strategy Updates

Self-Correction (self-correction) is the subsequent action phase of Reflection.

Relationship between the two:

  • Reflection: identify problems and form reflective conclusions.
  • Self-Correction: modify execution behavior based on reflective conclusions.

Common correction targets:

  1. Prompt: Add constraints and execution requirements.
  2. Plan: Modify the task breakdown and step dependencies.
  3. Tool: Replace tools or correct invocation parameters.
  4. Context: Add missing facts and historical information.
  5. Code: Fix incorrect code.
  6. Memory: Record verified experience worth reusing.

Pay special attention here: changing the execution plan and changing model parameters are not the same thing.

Most Agent self-correction occurs at the level of reasoning context, execution plans, and external state; it does not directly update the base model weights.

4.3 Reflection Records and Experience Reuse

If only the final result is retained after each task, it is difficult for the Agent to accumulate effective experience.

Reflection conclusions can be saved in a structured form:

{
  "reflection_id": "reflection_001",
  "task_type": "api_development",
  "failure_type": "missing_requirement",
  "observation": "响应中缺少 created_at 字段",
  "root_cause": "接口契约未完整纳入计划",
  "correction": "增加响应字段清单和结构测试",
  "verification": "相关测试全部通过",
  "confidence": 0.95,
  "reusable": true
}

When similar tasks are encountered later, relevant reflection records can be retrieved to avoid problems that have already occurred in advance.

Note the following:

  • Do not write unverified speculation directly into long-term memory.
  • Do not generalize accidental experience from a single task into universal rules.
  • When recording experience, retain the applicable conditions and source.
  • Expired experience should support updating, invalidation, and deletion.

V. Main Implementation Patterns of Reflection

Reflection is not a single fixed algorithm; different patterns can be used depending on task complexity and execution cost.

5.1 Single-round Reflection

Execute a task once, then perform one evaluation and correction.

flowchart TD
    A["Input task"] --> B["Generate result"]
    B --> C["Evaluate"]
    C --> D{"Meets criteria?"}
    D -->|"Yes"| E["Output result"]
    D -->|"No"| F["Generate correction suggestions"]
    F --> G["Correct result"]
    G --> H["Verify again"]
    H --> I["Output final result"]

    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
    style H fill:#E0F0FE,stroke:#93BCE8,color:#1E4976
    style I fill:#DCEFE5,stroke:#4F8B70,color:#24563F

Characteristics:

  • Simple to implement.
  • The number of calls is controllable.
  • Suitable for short texts, simple code, and structured output.
  • Cannot adequately handle complex multi-stage tasks.

5.2 Multi-round Reflection

The Agent continuously evaluates and corrects over multiple rounds of execution until the acceptance criteria are met or the maximum number of iterations is reached.

flowchart TD
    A["Task Input"] --> B["Execute Task"]
    B --> C["Quality Evaluation"]
    C --> D{"Has the Goal Been Met?"}
    D -->|"Yes"| E["Task Completed"]
    D -->|"No"| F["Analyze Failure Cause"]
    F --> G["Adjust Execution Strategy"]
    G --> H{"Has the Iteration Limit Been Exceeded?"}
    H -->|"No"| B
    H -->|"Yes"| I["Terminate and Return Current Result"]

    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
    style H fill:#F7F4E8,stroke:#C7B77A,color:#675A2D
    style I fill:#F7EAE7,stroke:#C98D7C,color:#754438

Features:

  • Can handle complex problems.
  • Supports step-by-step correction.
  • Can dynamically adjust the execution path based on feedback.
  • Requires controlling the number of iterations, Token consumption, and execution time.

Multi-round Reflection does not mean that more iterations are always better. If each round introduces no new evidence or effective strategy, continuing to reflect only increases cost.

5.3 External Feedback-Driven Reflection

This pattern does not rely entirely on the LLM's self-judgment; instead, it obtains objective feedback through external systems.

For example, a code development Agent:

  • The code generation model is responsible for implementation.
  • The compiler is responsible for syntax checking.
  • Unit tests are responsible for functional verification.
  • Static analysis tools are responsible for code quality checks.
  • Reflection is responsible for explaining the cause of failure and correcting the implementation.
flowchart TD
    A["Generate Code"] --> B["Compiler Check"]
    B --> C{"Does Compilation Pass?"}
    C -->|"No"| F["Reflection Analyzes Compilation Errors"]
    C -->|"Yes"| D["Run Unit Tests"]
    D --> E{"Do Tests Pass?"}
    E -->|"Yes"| G["Static Analysis"]
    E -->|"No"| F
    F --> H["Generate Fix Plan"]
    H --> A
    G --> I{"Does Quality Meet the Standard?"}
    I -->|"Yes"| J["Deliver Code"]
    I -->|"No"| F

    style A fill:#EAF3EC,stroke:#83A995,color:#315D49
    style B fill:#F5F8F4,stroke:#B5CBBB,color:#40594A
    style C fill:#F7F4E8,stroke:#C7B77A,color:#675A2D
    style D fill:#F5F8F4,stroke:#B5CBBB,color:#40594A
    style E fill:#F7F4E8,stroke:#C7B77A,color:#675A2D
    style F fill:#F7EAE7,stroke:#C98D7C,color:#754438
    style G fill:#E0F0FE,stroke:#93BCE8,color:#1E4976
    style H fill:#EAE8FA,stroke:#A49BD5,color:#51477D
    style I fill:#F7F4E8,stroke:#C7B77A,color:#675A2D
    style J fill:#DCEFE5,stroke:#4F8B70,color:#24563F

This pattern is usually more reliable because evaluation results can be verified by external tools.

5.4 Cross-Step Reflection

Complex Agent tasks usually consist of multiple subtasks.

If a step fails, the Agent does not necessarily need to re-execute the entire task; instead, it needs to analyze the impact of the failure on subsequent steps.

For example:

Task:
    Generate a business analysis report.

Subtasks:
    1. Obtain business data.
    2. Clean data.
    3. Calculate metrics.
    4. Analyze trends.
    5. Generate report.

If an error occurs in step 3, calculating metrics, steps 4 and 5 may need to be re-executed, but the data may not need to be re-fetched.

This requires Reflection to have:

  • Identification of subtask dependencies.
  • Analysis of the scope of failure impact.
  • Determination of the validity of intermediate results.
  • Capabilities for partial retry and result reuse.

6. Advanced Mechanisms of Reflection

6.1 Combining Reflection and ReAct

ReAct completes tasks by alternating between Reasoning and Acting.

Reflection adds result evaluation and strategy correction capabilities to the ReAct execution loop.

Differences between the two:

Dimension ReAct Reflection
Core mechanism Alternating reasoning and action Result evaluation and self-correction
Focus What action should be taken now Whether executed actions are effective
Feedback source Tool observation results Task goals, execution traces, and validation results
Primary role Drive task execution Improve execution quality
Typical scenarios Tool invocation, information retrieval Error correction, validation, iterative optimization

When combined, the Agent can check results after each important action and adjust the next action when necessary.

flowchart TD
    A["Receive task"] --> B["Reason (Reasoning)"]
    B --> C["Act (Execute action)"]
    C --> D["Observe (Get observations)"]
    D --> E["Reflection (Evaluation)"]
    E --> F{"Is the current execution reasonable?"}
    F -->|"Yes"| G{"Is the task complete?"}
    G -->|"No"| B
    G -->|"Yes"| H["Output result"]
    F -->|"No"| I["Analyze error"]
    I --> J["Revise execution strategy"]
    J --> B

    style A fill:#DCEFE5,stroke:#4F8B70,color:#24563F
    style B fill:#EAF3EC,stroke:#83A995,color:#315D49
    style C fill:#EAF3EC,stroke:#83A995,color:#315D49
    style D fill:#F5F8F4,stroke:#B5CBBB,color:#40594A
    style E fill:#E0F0FE,stroke:#93BCE8,color:#1E4976
    style F fill:#F7F4E8,stroke:#C7B77A,color:#675A2D
    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

6.2 Combining Reflection and Memory

The experience generated by Reflection can be written to Agent Memory for use in subsequent tasks.

However, two types of data need to be distinguished:

Task-level reflection records

Used for corrections to the current task, for example, what problems exist in the current code and which step failed.

Long-term experience memory

Used for subsequent similar tasks, for example, a certain API invocation method is prone to parameter errors, or a certain type of task requires additional validation.

The two cannot be mixed unconditionally.

Recommended experience accumulation process:

flowchart TD
    A["Reflection produces conclusion"] --> B["Extract candidate experience"]
    B --> C["Check evidence sufficiency"]
    C --> D{"Has it been verified?"}
    D -->|"No"| E["Keep as temporary record"]
    D -->|"Yes"| F["Evaluate reuse value"]
    F --> G{"Is it worth long-term storage?"}
    G -->|"No"| H["Archive or discard"]
    G -->|"Yes"| I["Check for duplicates and conflicts"]
    I --> J["Write to long-term memory"]
    J --> K["Retrieve and reuse in subsequent tasks"]

    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:#F5F8F4,stroke:#B5CBBB,color:#40594A
    style F fill:#EAF3EC,stroke:#83A995,color:#315D49
    style G fill:#F7F4E8,stroke:#C7B77A,color:#675A2D
    style H fill:#F5F8F4,stroke:#B5CBBB,color:#40594A
    style I fill:#EAE8FA,stroke:#A49BD5,color:#51477D
    style J fill:#DCEFE5,stroke:#4F8B70,color:#24563F
    style K fill:#E0F0FE,stroke:#93BCE8,color:#1E4976

Writes to long-term memory should undergo quality control; otherwise, the Agent may solidify incorrect judgments into long-term experience, causing subsequent tasks to be continuously affected by erroneous memories.

6.3 Combining Reflection and Planning

The Planner is responsible for generating task plans, and Reflection is responsible for determining whether a plan is effective.

The two form a dynamic planning mechanism:

  • The initial plan is generated by the Planner.
  • The Executor executes the current plan.
  • Reflection evaluates the execution result.
  • If the plan itself is flawed, the Planner is required to replan.
  • If the plan is correct but execution fails, correct the execution steps first.

There is an important distinction here:

An execution error does not necessarily mean a planning error.

For example:

  • API timeout: may be a temporary network issue.
  • API parameter error: may be a tool invocation issue.
  • Task dependency error: is more likely to be a planning issue.

If all failures are fed back to the Planner for replanning, it will cause unnecessary plan changes.

6.4 Multi-Agent Reflection

In a multi-Agent architecture, different Agents can take on execution, evaluation, and review responsibilities respectively.

For example:

Agent Responsibility
Planner Agent Formulate task plans
Executor Agent Execute tasks
Critic Agent Independently evaluate execution results
Reviewer Agent Review important conclusions
Controller Agent Control task status and retries

The advantage of multi-Agent Reflection is that it reduces role bias between the executor and the evaluator.

However, note that:

  • Multiple Agents do not necessarily mean greater accuracy.
  • Multiple Agents may share the same model biases.
  • Evaluation opinions may conflict with one another.
  • Communication and reasoning costs will increase.
  • The ownership of final decision-making authority must be clearly defined.

For high-risk tasks, a combination of independent models, deterministic validators, and human approval can be adopted.


7. Engineering Implementation of Reflection

7.1 Core Data Structures

In production environments, Reflection should not be just a Prompt; it should be a workflow module with state, evaluation results, and execution records.

The following data structures can be designed:

from dataclasses import dataclass, field
from typing import Any


@dataclass
class EvaluationIssue:
    issue_type: str
    description: str
    evidence: str
    severity: str


@dataclass
class EvaluationResult:
    passed: bool
    score: float
    issues: list[EvaluationIssue] = field(
        default_factory=list
    )
    root_cause: str = ""
    suggestions: list[str] = field(
        default_factory=list
    )


@dataclass
class ReflectionRecord:
    task_id: str
    iteration: int
    execution_result: Any
    evaluation: EvaluationResult
    correction_plan: list[str] = field(
        default_factory=list
    )

Main fields:

  • task_id: Unique task identifier.
  • iteration: Current reflection round.
  • execution_result: Execution result.
  • evaluation: Evaluation conclusion.
  • correction_plan: Correction strategy.