Self Reflection

Enable agents to analyze their own performance

Self-reflection allows agents to analyze and improve their responses.

Diagram

Self Reflection

📤 Output

🔍 Analyze

💡 Insights

📤 Better Output

Quick Start

  1. Create Self-Reflecting Agent
    rust
    use praisonai::Agent;
    
    // Build reflection into instructions
    let agent = Agent::new()
        .name("Writer")
        .instructions("Before providing your final answer:
        1. Draft your initial response
        2. Ask yourself: Is this helpful and accurate?
        3. If not, revise and improve
        4. Provide the improved response")
        .build()?;
    
    let response = agent.chat("Write a summary of AI advances").await?;
    // Agent self-reflects and improves before responding
  2. Two-Stage Reflection
    rust
    use praisonai::Agent;
    
    // First agent generates
    let writer = Agent::new()
        .name("Writer")
        .instructions("Write a helpful response")
        .build()?;
    
    // Second agent reviews
    let reviewer = Agent::new()
        .name("Reviewer")
        .instructions("Review this response. Is it helpful? Suggest improvements.")
        .build()?;
    
    let draft = writer.chat("Explain quantum computing").await?;
    let feedback = reviewer.chat(&format!("Review: {}", draft)).await?;

Related