> ## Documentation Index
> Fetch the complete documentation index at: https://praison.ai/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Optimizer

> Automatically improve agent performance

Agents can be optimized automatically - tune prompts and settings for better results.

```mermaid theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
graph LR
    subgraph "Optimization Loop"
        A[🤖 Agent] --> B[📊 Evaluate]
        B --> C[✏️ Adjust]
        C --> D[🎯 Improved]
    end

    classDef agent fill:#8B0000,color:#fff
    classDef tool fill:#189AB4,color:#fff

    class A agent
    class B,C,D tool
```

## Quick Start

<Steps>
  <Step title="Simple Usage">
    ```typescript theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
    import { Agent, Optimizer } from 'praisonai';

    const agent = new Agent({
      instructions: 'You answer questions'
    });

    const optimizer = new Optimizer({
      agent,
      examples: [
        { input: 'What is 2+2?', expected: '4' },
        { input: 'Capital of France?', expected: 'Paris' }
      ]
    });

    await optimizer.run();
    // Agent instructions are now improved
    ```
  </Step>

  <Step title="With Configuration">
    ```typescript theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
    const optimizer = new Optimizer({
      agent,
      examples: myExamples,
      evaluate: (output, expected) => {
        return output.toLowerCase() === expected.toLowerCase();
      }
    });
    ```
  </Step>
</Steps>

***

## User Interaction Flow

```mermaid theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
sequenceDiagram
    participant User
    participant Optimizer
    participant Agent
    
    User->>Optimizer: Start optimization
    loop For each example
        Optimizer->>Agent: Test input
        Agent-->>Optimizer: Output
        Optimizer->>Optimizer: Score result
    end
    Optimizer->>Agent: Update instructions
    Optimizer-->>User: Optimization report
```

***

## Configuration Levels

```typescript theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
// Level 1: Array - Simple examples
const optimizer = new Optimizer({
  agent,
  examples: [
    { input: 'test', expected: 'result' }
  ]
});

// Level 2: Dict - With options
const optimizer = new Optimizer({
  agent,
  examples: myExamples,
  iterations: 5,
  targetScore: 0.9
});

// Level 3: Instance - Full control
const optimizer = new Optimizer({
  agent,
  examples: myExamples,
  iterations: 10,
  evaluate: customEvaluator,
  adjustments: ['instructions', 'temperature'],
  onIteration: (scores) => console.log(scores)
});
```

***

## How It Works

1. **Test**: Run agent on examples
2. **Score**: Evaluate output quality
3. **Adjust**: Modify prompts/settings
4. **Repeat**: Continue until target score

***

## API Reference

<Card title="Eval Module" icon="code" href="/docs/sdk/reference/typescript/modules/eval">
  Evaluation and optimization
</Card>

***

## Best Practices

<AccordionGroup>
  <Accordion title="Use diverse examples">
    Cover different types of inputs the agent will see.
  </Accordion>

  <Accordion title="Set a target score">
    Stop optimization when good enough.
  </Accordion>

  <Accordion title="Review changes">
    Check what the optimizer changed before deploying.
  </Accordion>
</AccordionGroup>

***

## Related

<CardGroup cols={2}>
  <Card title="Criteria" icon="check-double" href="/docs/js/criteria">
    Success conditions
  </Card>

  <Card title="Reflection" icon="rotate" href="/docs/js/reflection">
    Self-improvement
  </Card>
</CardGroup>
