Quick Start
1
Optimise with the LLM Judge
Score each candidate with the built-in Judge using plain-English criteria.
2
Score with a numeric metric
Supply a
metric(output, expected) -> float to replace the Judge with your own gold-data score.3
Preview without applying
Set
apply=False to keep the original instructions and inspect the winner first.How It Works
The optimiser runs in five steps:Configuration Options
agent.optimize_instructions(...) accepts these parameters:
aoptimize_instructions(...) is the async twin — it offloads the synchronous run to a worker thread so async callers never block the event loop.OptimizeResult
optimize_instructions(...) returns an OptimizeResult:
Common Patterns
Judge-based scoring for open-ended tasks
Usecriteria when there is no single gold answer.
Numeric-metric scoring with gold data
Plug in any empirical score — rouge_l, accuracy, latency, or a custom function.Async usage
Dry-run then apply manually
Best Practices
Keep the eval set small (4–10 cases)
Keep the eval set small (4–10 cases)
The optimiser runs the agent
(1 + n_candidates) × len(evalset) times. A small, representative eval keeps cost and latency low while still surfacing the best variant.Prefer a numeric metric when you have gold data
Prefer a numeric metric when you have gold data
A
metric is cheaper and more reproducible than the LLM Judge. Use criteria only for open-ended tasks where no single gold answer exists.Tune n_candidates to your instructions
Tune n_candidates to your instructions
Increase
n_candidates when your instructions are short or generic; decrease it when they are already specific and you only want small refinements.Store result.trials for auditing
Store result.trials for auditing
result.trials lists every candidate and its score. Persist it to review which rewrites were tried and how they compared to the base.Related
Evaluation Loop
Iteratively run, judge, and keep the best output
Learn Skill
Sibling self-improvement method on the Agent

