Build a super AI assistant: Master the Reflection mode and let your Agent's IQ skyrocket!

Written by
Clara Bennett
Updated on:June-21st-2025
Recommendation

Master the Reflection mode, let your AI assistant's IQ soar, and open a new era of intelligent agents!

Core content:
1. Explore the secret of AI intelligence: the revolutionary impact of the Reflection mode
2. The rise of intelligent agents: how ChatGPT, Claude, etc. reshape AI interaction
3. Analysis of the four major agent design patterns: Why the Reflection mode has become the king

Yang Fangxian
Founder of 53A/Most Valuable Expert of Tencent Cloud (TVP)

 


Are you curious about why some AIs are so smart and some are so dumb? The secret lies in the Reflection pattern! This is the most cutting-edge AI Agent design pattern, recommended by Andrew Ng and adopted by top AI products, giving AI the ability to "self-evolve" . Whether you are an AI enthusiast, developer, or just an ordinary person who wants to know about future trends, this article will take you deep into this game-changing technology and teach you how to use it to build smarter AI applications.

The Agent Revolution: Why You Must Know About It

The explosive development of large language models such as ChatGPT, Claude, and Gemini has completely changed the rules of the game for AI. They are not just chatbots, but also the cornerstone and engine of future intelligent agents. If you haven't started paying attention to agent technology, you are already behind! Why? Because agents are reshaping the way we interact with AI, from passive answers to active services, from simple conversations to complex task solving.

Today’s AI Agents are not just smart, they can make decisions, use various tools, plan tasks, and continue to learn and improve. Look at AutoGPT, Microsoft Copilot, Devin, these products are already changing the way we write code, create content, and analyze data. Among them, Devin (an AI programmer launched by Cognition AI) is a good example. It can write code autonomously, debug problems, and reflect and improve its methods when encountering errors.

Agent design pattern: four major schools, one king

In the course Building and Evaluating LLM Agents, Professor Andrew Ng revealed four main agent design patterns (you can also see the author's summary: 10 AI Agent Strategies Full Analysis ). These patterns determine the way AI thinks and its ability to solve problems. Just like there are different schools of martial arts, each pattern has its unique advantages:

  • •  Plan-and-Execute : Like a chess master, plan the entire game before taking action, suitable for tasks with clear structure
  • •  ReAct (Think-Action-Observe) : Like a flexible fighter, think, act and observe at the same time, suitable for interactive tasks that require instant response
  • •  Chain-of-Thought (CoT) : Just like a mathematician solving a problem, it shows each step of the reasoning process, making complex problems clear and solvable
  • •  Reflection : Like a martial arts master, he constantly reflects on his moves and improves them. He is the "king" among the four modes.

Among them, the Reflection mode is recognized as the most advanced form, which enables AI to have the ability of "self-reflection". Imagine an AI that can not only think about problems, but also think about "whether its thinking is right"! This ability of self-examination and continuous optimization allows AI to learn from mistakes and make continuous progress like humans, which is the core feature of true intelligence. This is why top AI products such as GitHub Copilot, Claude and Devin are all using this mode.

Reflection mode: Create a super AI that evolves on its own

The core idea of ​​the Reflection mode is actually very simple: let AI learn to "think about whether it is right or not". This is just like top athletes constantly reviewing their game videos to find out their shortcomings and improve them. With this ability, AI can learn from experience like humans, find out their mistakes and shortcomings, and then actively improve instead of making the same mistakes over and over again. This is a key step from "rigid AI" to "flexible AI"!

Reflection workflow

The workflow of Reflection mode is actually quite simple, just like how we humans solve problems:

  1. 1.  Initial response : Give a preliminary plan first, a bit like a draft
  2. 2.  Self-assessment : Check yourself first to see where the problem is
  3. 3.  Reflection : Think deeply about where the problems are and why they occur
  4. 4.  Revision : Modify the plan based on the results of reflection
  5. 5.  Iteration : Repeat the above steps until you are satisfied

Reflexion Implementation

There is a paper called Reflexion [1] that proposes a very clever method: add a "notebook" to AI to record past mistakes and lessons learned, so that it will not make the same mistakes again next time. This method has been used in products such as GitHub Copilot and Claude, enabling them to learn from past mistakes and improve.

Example: Reflection in Golang unit testing

Let's look at a practical example. Suppose we ask AI to write a unit test for a function that calculates an average:

Step 1: Initial Test Code

func TestCalculateAverage (t *testing.T)  {
    result, _ := CalculateAverage([] float64 { 1.02.03.0 })
    // Floating point comparisons should use an error range instead of directly judging equality
    if  math.Abs(result -  2.0 ) >  0.0001  {
        t.Errorf( "Expected 2.0, actually got %f" , result)
    }
}

This test seems to work fine, but the AI ​​starts to rethink the test code:

Step 2: Self-Assessment

question:
- Only tested normal cases, not edge cases
- No error return value checking
- Too few test cases and insufficient coverage

So AI further improved:

Step 3: Corrected test code

func TestCalculateAverage (t *testing.T)  {
    // Define the error range for floating point comparison
    const  epsilon =  0.0001
    
    // Test normal situation
    t.Run( "Normal data"func (t *testing.T)  {
        result, err := CalculateAverage([] float64 { 1.02.03.0 })
        if  err !=  nil  {
            t.Errorf( "Should not return an error, but got: %v" , err)
        }
        if  math.Abs(result -  2.0 ) > epsilon {
            t.Errorf( "Expected 2.0, actually got %f" , result)
        }
    })
    
    // Test for an empty slice
    t.Run( "empty slice"func (t *testing.T)  {
        _, err := CalculateAverage([] float64 {})
        if  err ==  nil  {
            t.Error( "Expected error, but no" )
        }
    })
    
    // Test for negative numbers
    t.Run( "negative number"func (t *testing.T)  {
        result, err := CalculateAverage([] float64 { -1.0-2.0-3.0 })
        if  err !=  nil  {
            t.Errorf( "Should not return an error, but got: %v" , err)
        }
        if  math.Abs(result - ( -2.0 )) > epsilon {
            t.Errorf( "Expected -2.0, actually got %f" , result)
        }
    })
    
    // Test a single element
    t.Run( "single element"func (t *testing.T)  {
        result, err := CalculateAverage([] float64 { 5.0 })
        if  err !=  nil  {
            t.Errorf( "Should not return an error, but got: %v" , err)
        }
        if  math.Abs(result -  5.0 ) > epsilon {
            t.Errorf( "Expected 5.0, actually got %f" , result)
        }
    })
}

Step 4: Run tests and get feedback

After executing the test, we got the following output:

=== RUN TestCalculateAverage
=== RUN TestCalculateAverage/normal data
=== RUN TestCalculateAverage/empty slice
--- FAIL: TestCalculateAverage (0.00s)
    --- PASS: TestCalculateAverage/Normal data (0.00s)
    --- FAIL: TestCalculateAverage/empty slice (0.00s)
        average_test.go:18: Expected error, but got none
    --- PASS: TestCalculateAverage/negative number (0.00s)
    --- PASS: TestCalculateAverage/single element (0.00s)
FAIL

Step 5: Improve the code again based on feedback

AI found that the empty slice test failed because the original function did not handle the empty slice case. So AI further improved the function implementation:

func CalculateAverage (numbers [] float64 )  ( float64 error ) {
    if len (numbers) ==  0  {
        return 0 , errors.New( "Cannot calculate mean of empty slice" )
    }
    
    var  sum  float64
    for  _, num :=  range  numbers {
        sum += num
    }
    return  sum /  float64 ( len (numbers)),  nil
}

Step 6: Run the test again

=== RUN TestCalculateAverage
=== RUN TestCalculateAverage/normal data
=== RUN TestCalculateAverage/empty slice
=== RUN TestCalculateAverage/negative number
=== RUN TestCalculateAverage/single element
--- PASS: TestCalculateAverage (0.00s)
    --- PASS: TestCalculateAverage/Normal data (0.00s)
    --- PASS: TestCalculateAverage/empty slice (0.00s)
    --- PASS: TestCalculateAverage/negative number (0.00s)
    --- PASS: TestCalculateAverage/single element (0.00s)
PASS

Did you see that? Through reflection, AI not only expanded a simple test case into a comprehensive test suite that covers multiple scenarios such as normal situations, empty slices, negative numbers, and single elements, but also further improved the code implementation based on test feedback. This cycle of " write test-run test-get feedback-improve code-test again " is the essence of the Reflection mode, allowing AI to continuously iterate and optimize its work like human developers.

The following figure summarizes the entire Reflection process in unit testing, clearly showing the cycle of execution, evaluation, improvement, and correction :

This cycle demonstrates the core advantage of the Reflection pattern: through continuous self-assessment, feedback, and improvement, the AI ​​is able to write more robust and comprehensive code, just like an experienced developer.

Advanced Reflection Implementation

In addition to the basic reflection mode, there are some more advanced gameplay:

Recursive Reflection

It's like a nesting doll of thoughts, one layer inside another, going deeper and deeper:

AI will not only reflect on its own answers, but also reflect on its own reflection process, and even reflect on its own reflection process. This recursive reflection ability allows AI to discover deeper problems and propose better solutions.

External feedback reflection

In addition to self-reflection, AI can also reflect on external feedback:

This model is particularly suitable for scenarios that require multiple rounds of interaction, such as code review, document writing, etc. AI continuously improves its output by continuously obtaining user feedback.

Characteristics and application scenarios of Reflection

The best part about the Reflection mode is that it gives AI the ability to " self-reflect ", just like checking your homework after finishing it, it can find mistakes and correct them, saving you from staring at it all the time. It gets smarter the more you use it, because it will remember the mistakes it made before and won't make them next time; and it will tell you the thinking process, it is not a black box that says "I am right, don't ask why". This mode is particularly suitable for solving complex problems, writing code and debugging bugs, creative writing, decision analysis, and educational counseling, because these all require multi-angle thinking and continuous optimization.         Now many products have used this technology, such as GitHub Copilot, which can continuously adjust code suggestions based on your response, Claude, which will check whether there is any deviation in understanding when analyzing long documents, and Devin, the "AI programmer", who writes code, finds bugs, and fixes bugs, all rely on the Reflection mode to support it. AutoGPT can also reflect and adjust strategies when encountering problems during tasks, just like a self-aware assistant.

Summary: Grasp the key to AI evolution and lead the future

Reflection mode is more than just a technology, it represents an important step towards true intelligence. By giving AI the ability to reflect on itself, we are creating artificial intelligence systems that can continuously improve themselves.

Imagine your AI assistant being able to learn from every interaction, remember past mistakes and avoid repeating them, constantly optimizing its performance. This is no longer science fiction, it’s happening now!

For developers : Mastering the Reflection mode will make your AI products stand out, have the ability to continuously learn and self-improve, and provide users with increasingly accurate services.

For enterprises : Adopting AI systems with Reflection capabilities means that your intelligent solutions will become more powerful with use, giving you a continuously growing competitive advantage.

For ordinary users : Understanding Reflection mode will help you identify truly intelligent AI products and choose AI assistants that can understand you, learn your preferences, and continue to improve.

Whether you are a novice or a veteran in the field of AI, the Reflection model is worth your in-depth understanding and application. Because in the future of AI, it is not the bigger model that wins, but the smarter learning method that wins!

Are you ready? Let us embrace this AI evolution revolution and create a smarter, more useful and more humane AI world!