> ## 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

**1. 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
```

**2. 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();
  }
});
```

***

## 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] [Eval Module](https://praison.ai/docs/sdk/reference/typescript/modules/eval.md)
>
> Evaluation and optimization

***

## Best Practices

> [accordion] Use diverse examples
>
> Cover different types of inputs the agent will see.

> [accordion] Set a target score
>
> Stop optimization when good enough.

> [accordion] Review changes
>
> Check what the optimizer changed before deploying.

***

## Related

> [card] [Criteria](https://praison.ai/docs/js/criteria.md)
>
> Success conditions

> [card] [Reflection](https://praison.ai/docs/js/reflection.md)
>
> Self-improvement


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.