Reflection

Agents that improve their own work

Agents can review and improve their own responses before returning.

Diagram

Agent

Review

Output

Quick Start

  1. Simple Usage
    typescript
    import { Agent } from 'praisonai';
    
    const agent = new Agent({
      instructions: 'You write professional content',
      reflection: true
    });
    
    await agent.chat('Write a business proposal');
    // Agent writes, reviews, and improves before returning
  2. With Configuration
    typescript
    const agent = new Agent({
      reflection: {
        rounds: 2,  // Review twice
        prompt: 'Check for clarity and professionalism'
      }
    });

User Interaction Flow

Diagram
Self-ReviewAgentUserSelf-ReviewAgentUser“Write a proposal”Generate draftReview draftImprovementsApply improvementsPolished output

Configuration Levels

typescript
// Level 1: Bool - Enable with defaults
const agent = new Agent({
  reflection: true
});

// Level 2: Dict - With options
const agent = new Agent({
  reflection: {
    rounds: 2,
    prompt: 'Review for errors and clarity'
  }
});

// Level 3: Instance - Full control
const agent = new Agent({
  reflection: {
    rounds: 3,
    prompt: 'Focus on tone and accuracy',
    stopWhen: (output) => output.quality > 0.9
  }
});

How It Works

  1. Generate: Agent creates initial response
  2. Review: Agent critiques its own work
  3. Improve: Agent fixes identified issues
  4. Repeat: Process continues for specified rounds

API Reference

ReflectionConfig

Complete configuration options


Best Practices

Use 1-2 rounds

More rounds don’t always mean better results.

For quality-critical tasks

Enable for proposals, articles, and important content.

Combine with criteria

Use reflection with criteria for validated quality.


Related