You're A/B testing three ways to pitch a new service to clients. You want the shortest version that still makes sense — easier to skim in an email. How do you compare three agent responses at once?
Run all three prompts, collect the outputs, then min(..., key=len) to pick the shortest. Same as finding the shortest string in any list.
Exactly. Generate all three outputs first, then apply the reduction:
outputs = [Agent(model).run_sync(p).output for p in prompts]
return min(outputs, key=len)Why collect all outputs first? Can't I use min on the comprehension directly?
You can write it as one expression — min([Agent(model).run_sync(p).output for p in prompts], key=len). Both are equivalent. Separating it is cleaner when you also want to debug the full list. For the entry point, inline is fine:
def shortest_response(prompts: list) -> str:
return min([Agent(model).run_sync(p).output for p in prompts], key=len)So AI outputs are just strings in a list. I can sort them, find the longest, filter by keyword — all standard Python.
That's the Week 3 systems moment. Once you see agent outputs as items in a Python collection, every list operation becomes available. Rank proposals by length, filter summaries that contain a keyword, sort tickets by urgency weight.
One function, three pitches — I pick the concise one and move on. The AI does the drafting; I do the selecting.
Length is one signal. In production you'd combine it with quality checks — but the pattern is always the same: generate, collect, apply a Python reduction.
Agent outputs are strings in a list — all Python reductions apply:
outputs = [Agent(model).run_sync(p).output for p in prompts]
min(outputs, key=len) # shortest response
max(outputs, key=len) # longest response
sorted(outputs, key=len) # all, ranked by lengthkey=len explainedkey=len tells min() (or max(), or sorted()) to use len(element) as the comparison value for each element. The element with the smallest len() value is returned — not its length, but the element itself.
Use length-based selection for A/B prompt testing: generate multiple phrasings, return the most concise version. For quality checks, combine with a minimum length filter to avoid trivially short responses that might be incomplete.
You're A/B testing three ways to pitch a new service to clients. You want the shortest version that still makes sense — easier to skim in an email. How do you compare three agent responses at once?
Run all three prompts, collect the outputs, then min(..., key=len) to pick the shortest. Same as finding the shortest string in any list.
Exactly. Generate all three outputs first, then apply the reduction:
outputs = [Agent(model).run_sync(p).output for p in prompts]
return min(outputs, key=len)Why collect all outputs first? Can't I use min on the comprehension directly?
You can write it as one expression — min([Agent(model).run_sync(p).output for p in prompts], key=len). Both are equivalent. Separating it is cleaner when you also want to debug the full list. For the entry point, inline is fine:
def shortest_response(prompts: list) -> str:
return min([Agent(model).run_sync(p).output for p in prompts], key=len)So AI outputs are just strings in a list. I can sort them, find the longest, filter by keyword — all standard Python.
That's the Week 3 systems moment. Once you see agent outputs as items in a Python collection, every list operation becomes available. Rank proposals by length, filter summaries that contain a keyword, sort tickets by urgency weight.
One function, three pitches — I pick the concise one and move on. The AI does the drafting; I do the selecting.
Length is one signal. In production you'd combine it with quality checks — but the pattern is always the same: generate, collect, apply a Python reduction.
Agent outputs are strings in a list — all Python reductions apply:
outputs = [Agent(model).run_sync(p).output for p in prompts]
min(outputs, key=len) # shortest response
max(outputs, key=len) # longest response
sorted(outputs, key=len) # all, ranked by lengthkey=len explainedkey=len tells min() (or max(), or sorted()) to use len(element) as the comparison value for each element. The element with the smallest len() value is returned — not its length, but the element itself.
Use length-based selection for A/B prompt testing: generate multiple phrasings, return the most concise version. For quality checks, combine with a minimum length filter to avoid trivially short responses that might be incomplete.
Create a free account to get started. Paid plans unlock all tracks.