mirror of
https://github.com/wshobson/agents.git
synced 2026-03-18 09:37:15 +00:00
⚡ Bolt: optimize prompt evaluation loop to skip redundant calls (#152)
- Avoid re-evaluating the current prompt if metrics are already available from the previous iteration. - Pass metrics from the best variation to the next iteration. - Reduces N-1 expensive LLM calls in an N-iteration optimization loop. Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com>
This commit is contained in:
committed by
GitHub
parent
fda45604b7
commit
a86384334b
@@ -106,12 +106,18 @@ class PromptOptimizer:
|
||||
current_prompt = base_prompt
|
||||
best_prompt = base_prompt
|
||||
best_score = 0
|
||||
current_metrics = None
|
||||
|
||||
for iteration in range(max_iterations):
|
||||
print(f"\nIteration {iteration + 1}/{max_iterations}")
|
||||
|
||||
# Evaluate current prompt
|
||||
# Bolt Optimization: Avoid re-evaluating if we already have metrics from previous iteration
|
||||
if current_metrics:
|
||||
metrics = current_metrics
|
||||
else:
|
||||
metrics = self.evaluate_prompt(current_prompt)
|
||||
|
||||
print(f"Accuracy: {metrics['avg_accuracy']:.2f}, Latency: {metrics['avg_latency']:.2f}s")
|
||||
|
||||
# Track results
|
||||
@@ -137,14 +143,17 @@ class PromptOptimizer:
|
||||
# Test variations and pick best
|
||||
best_variation = current_prompt
|
||||
best_variation_score = metrics['avg_accuracy']
|
||||
best_variation_metrics = metrics
|
||||
|
||||
for variation in variations:
|
||||
var_metrics = self.evaluate_prompt(variation)
|
||||
if var_metrics['avg_accuracy'] > best_variation_score:
|
||||
best_variation_score = var_metrics['avg_accuracy']
|
||||
best_variation = variation
|
||||
best_variation_metrics = var_metrics
|
||||
|
||||
current_prompt = best_variation
|
||||
current_metrics = best_variation_metrics
|
||||
|
||||
return {
|
||||
'best_prompt': best_prompt,
|
||||
|
||||
Reference in New Issue
Block a user