This pattern helps AI agents think about their own answers and find ways to improve them. It makes AI smarter by learning from mistakes.
Reflection and self-critique pattern in Agentic AI
Start learning this pattern below
Jump into concepts and practice - no test required
or
Test this pattern10 questions across easy, medium, and hard to know if this pattern is strong
Introduction
Syntax
Agentic AI
def reflect_and_critique(agent_output): reflection = analyze(agent_output) critique = find_errors(reflection) improved_output = fix_errors(agent_output, critique) return improved_output
This is a simple function showing the pattern steps: reflection, critique, and improvement.
Each step helps the AI review and improve its own work.
Examples
Agentic AI
def reflect_and_critique(answer): print('Reflection: Checking answer quality...') if 'error' in answer: print('Critique: Found errors, fixing...') answer = answer.replace('error', 'correct') return answer
Agentic AI
def reflect_and_critique(prediction): confidence = evaluate_confidence(prediction) if confidence < 0.7: prediction = improve_prediction(prediction) return prediction
Sample Model
This program shows an AI agent reflecting on its output, finding a mistake, and fixing it before sharing the final answer.
Agentic AI
def reflect_and_critique(agent_output): # Reflection step: check if output contains mistakes mistakes = [] if 'mistake' in agent_output: mistakes.append('Found the word mistake') # Critique step: decide if output needs fixing if mistakes: improved_output = agent_output.replace('mistake', 'correction') else: improved_output = agent_output return improved_output # Example usage initial_output = 'This is a mistake in the answer.' final_output = reflect_and_critique(initial_output) print('Initial output:', initial_output) print('Final output:', final_output)
Important Notes
Reflection helps AI pause and think about its own work.
Self-critique means finding what can be better or wrong.
Improvement is fixing mistakes to give better answers.
Summary
The reflection and self-critique pattern helps AI improve by reviewing its own answers.
It works by reflecting, finding errors, and fixing them.
This makes AI more reliable and smarter over time.
Practice
1. What is the main purpose of the
Reflection and self-critique pattern in AI?easy
Solution
Step 1: Understand the pattern's goal
The reflection and self-critique pattern is designed to let AI look back at its answers and find mistakes.Step 2: Identify the main benefit
By reviewing its own work, AI can fix errors and improve future responses.Final Answer:
To help AI review and improve its own answers -> Option CQuick Check:
Reflection and self-critique = improve answers [OK]
Hint: Focus on improvement through self-review [OK]
Common Mistakes:
- Confusing speed with accuracy
- Thinking it stores data
- Assuming it creates new models
2. Which of the following is the correct way to describe the reflection step in the pattern?
easy
Solution
Step 1: Define reflection in AI context
Reflection means looking back at past answers to check for errors or improvements.Step 2: Match options to definition
Only AI reviews its previous answers to find mistakes correctly states that AI reviews previous answers to find mistakes.Final Answer:
AI reviews its previous answers to find mistakes -> Option AQuick Check:
Reflection = review past answers [OK]
Hint: Reflection means reviewing past work carefully [OK]
Common Mistakes:
- Thinking reflection means ignoring past answers
- Confusing reflection with deleting data
- Assuming copying answers is reflection
3. Consider this simple AI pseudo-code using reflection and self-critique:
What will
answer = AI.generate_answer(question)
errors = AI.reflect(answer)
if errors:
answer = AI.fix_errors(answer, errors)
print(answer)What will
print(answer) show if the AI finds errors?medium
Solution
Step 1: Understand the code flow
The AI first generates an answer, then reflects to find errors. If errors exist, it fixes them.Step 2: Determine the final printed output
Since errors are fixed before printing, the output is the corrected answer.Final Answer:
The corrected answer after fixing errors -> Option BQuick Check:
Errors fixed before print = corrected answer [OK]
Hint: Errors fixed before print means corrected output [OK]
Common Mistakes:
- Assuming original answer prints despite errors
- Thinking program stops on errors
- Confusing error message with fixed answer
4. You have this AI code snippet:
Why might this code fail to print the corrected answer?
answer = AI.generate_answer(question)
errors = AI.reflect(answer)
if errors:
AI.fix_errors(answer, errors)
print(answer)Why might this code fail to print the corrected answer?
medium
Solution
Step 1: Analyze variable updates
Thefix_errorsfunction is called but its result is not assigned back toanswer.Step 2: Understand impact on output
Sinceansweris unchanged,printshows the original, not corrected, answer.Final Answer:
Because fix_errors does not update answer variable -> Option AQuick Check:
Fix must assign back to answer [OK]
Hint: Assign fixed answer back to variable before printing [OK]
Common Mistakes:
- Assuming reflect never finds errors
- Thinking print is called too early
- Ignoring variable assignment after fixing
5. You want to improve an AI assistant using the reflection and self-critique pattern. Which approach best applies this pattern to reduce repeated mistakes over time?
hard
Solution
Step 1: Identify key steps in the pattern
The pattern involves reviewing answers, finding errors, fixing them, and learning from mistakes.Step 2: Match approach to pattern goals
After each answer, AI reviews its response, identifies errors, fixes them, and updates its knowledge base describes reviewing, fixing, and updating knowledge, which fits the pattern perfectly.Final Answer:
After each answer, AI reviews its response, identifies errors, fixes them, and updates its knowledge base -> Option DQuick Check:
Review + fix + learn = improved AI [OK]
Hint: Choose option with review, fix, and learning steps [OK]
Common Mistakes:
- Ignoring learning from errors
- Choosing random or fixed answers
- Skipping error identification
