From da0fe8d9b8f8c596b5d8af62125eb8492dfb7f42 Mon Sep 17 00:00:00 2001 From: a2a-cloud Date: Sat, 18 Jul 2026 02:37:02 +0000 Subject: [PATCH] a2a-source-edit: write agent.py --- agent.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/agent.py b/agent.py index 4c67ba7..a601aba 100644 --- a/agent.py +++ b/agent.py @@ -312,6 +312,16 @@ def _score_higher_is_better(value: float, minimum: float, maximum: float) -> flo return ((value - minimum) / (maximum - minimum)) * 100.0 +def _comparison_sort_key(row: dict[str, Any]) -> tuple[Any, ...]: + return ( + -row["weighted_score"], + row["total_price"], + row["delivery_days"], + -row["warranty_months"], + row["vendor"].casefold(), + ) + + def _build_comparison(comparison_id: str, quotes: list[QuoteInput], weights: WeightInput) -> dict[str, Any]: prices = [q.unit_price for q in quotes] deliveries = [q.delivery_days for q in quotes] @@ -338,7 +348,7 @@ def _build_comparison(comparison_id: str, quotes: list[QuoteInput], weights: Wei "weighted_score": round(weighted_score, 4), } ) - rows.sort(key=lambda item: (-item["weighted_score"], item["total_price"], item["delivery_days"], -item["warranty_months"], item["vendor"].casefold())) + rows.sort(key=_comparison_sort_key) winner = rows[0] return { "ok": True,