batch_classify from yesterday applies one agent to every item in a list. Your abstract-note template has a 50-word budget. You have three different summary prompts and want to know which produces the shortest output for a given abstract. How do you compare them?
Run the agent on each prompt, collect the outputs in a list, then use min() with key=len to pick the shortest one. Same pattern as picking the shortest string from any list.
Exactly. One line: build the list with a comprehension, pick the shortest with min(key=len):
agent = Agent(model)
outputs = [agent.run_sync(p).output for p in prompts]
return min(outputs, key=len)What if two outputs have the same length? Does min pick arbitrarily?
min returns the first minimum-length string it encounters when there's a tie. For finding the most concise summary, ties are fine — either output fits the word budget. If you needed deterministic tie-breaking, sort the list and pick index 0. For this use case, first-minimum is the correct behaviour.
So I can run three prompt variants, compare their output lengths, and always send the most compact summary to the literature note. That's the automated prompt A/B test I've been doing manually.
min(outputs, key=len) is your evaluation function. The prompt that produces the shortest output wins the budget constraint test.
I could run this on my entire prompt library — ten variants, same abstract, pick the one that consistently produces the shortest summaries. That's prompt optimisation without manual reading.
The comparison is direct:
prompts = ["Summarize briefly.", "One sentence:", "TL;DR:"]
best = shortest_response(prompts)
print(f"Shortest output: {best}")Length is one quality dimension. Validate a sample for accuracy before automating the selection.
agent = Agent(model)
outputs = [agent.run_sync(p).output for p in prompts]
return min(outputs, key=len)min(key=len) not sorted()[0]min(key=len) is O(n) — one pass through the list. sorted() is O(n log n). For finding a single minimum, min is always preferred.
Run shortest_response on a library of prompt variants for each section of your abstract note template (background, method, finding). The shortest consistent response becomes your production prompt. This is automated prompt A/B testing — measure first, then lock in the winner.
batch_classify from yesterday applies one agent to every item in a list. Your abstract-note template has a 50-word budget. You have three different summary prompts and want to know which produces the shortest output for a given abstract. How do you compare them?
Run the agent on each prompt, collect the outputs in a list, then use min() with key=len to pick the shortest one. Same pattern as picking the shortest string from any list.
Exactly. One line: build the list with a comprehension, pick the shortest with min(key=len):
agent = Agent(model)
outputs = [agent.run_sync(p).output for p in prompts]
return min(outputs, key=len)What if two outputs have the same length? Does min pick arbitrarily?
min returns the first minimum-length string it encounters when there's a tie. For finding the most concise summary, ties are fine — either output fits the word budget. If you needed deterministic tie-breaking, sort the list and pick index 0. For this use case, first-minimum is the correct behaviour.
So I can run three prompt variants, compare their output lengths, and always send the most compact summary to the literature note. That's the automated prompt A/B test I've been doing manually.
min(outputs, key=len) is your evaluation function. The prompt that produces the shortest output wins the budget constraint test.
I could run this on my entire prompt library — ten variants, same abstract, pick the one that consistently produces the shortest summaries. That's prompt optimisation without manual reading.
The comparison is direct:
prompts = ["Summarize briefly.", "One sentence:", "TL;DR:"]
best = shortest_response(prompts)
print(f"Shortest output: {best}")Length is one quality dimension. Validate a sample for accuracy before automating the selection.
agent = Agent(model)
outputs = [agent.run_sync(p).output for p in prompts]
return min(outputs, key=len)min(key=len) not sorted()[0]min(key=len) is O(n) — one pass through the list. sorted() is O(n log n). For finding a single minimum, min is always preferred.
Run shortest_response on a library of prompt variants for each section of your abstract note template (background, method, finding). The shortest consistent response becomes your production prompt. This is automated prompt A/B testing — measure first, then lock in the winner.
Create a free account to get started. Paid plans unlock all tracks.