Optimizer
Automatically improve agent performance
Agents can be optimized automatically – tune prompts and settings for better results.
Quick Start
- Simple Usage
typescript 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 - With Configuration
typescript const optimizer = new Optimizer({ agent, examples: myExamples, evaluate: (output, expected) => { return output.toLowerCase() === expected.toLowerCase(); } });
User Interaction Flow
Configuration Levels
// 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
- Test: Run agent on examples
- Score: Evaluate output quality
- Adjust: Modify prompts/settings
- Repeat: Continue until target score
API Reference
Eval ModuleEvaluation and optimization
Best Practices
Use diverse examples
Cover different types of inputs the agent will see.
Set a target score
Stop optimization when good enough.
Review changes
Check what the optimizer changed before deploying.