Reflection
Agents that improve their own work
Agents can review and improve their own responses before returning.
Quick Start
- 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 - With Configuration
typescript const agent = new Agent({ reflection: { rounds: 2, // Review twice prompt: 'Check for clarity and professionalism' } });
User Interaction Flow
Configuration Levels
// 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
- Generate: Agent creates initial response
- Review: Agent critiques its own work
- Improve: Agent fixes identified issues
- Repeat: Process continues for specified rounds
API Reference
ReflectionConfigComplete 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.