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

Quick Start

1

Create Self-Reflecting Agent

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

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?;