From dcfda8553a7edf0481fb8fb202cb1ba532df5de8 Mon Sep 17 00:00:00 2001 From: a2a-cloud Date: Sat, 18 Jul 2026 06:13:47 +0000 Subject: [PATCH] a2a-source-edit: write agent.py --- agent.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/agent.py b/agent.py index 92175c7..40ec562 100644 --- a/agent.py +++ b/agent.py @@ -318,6 +318,10 @@ def _validate_comparison_request( return None +def _rank_sort_key(row: dict[str, Any]) -> tuple[Any, ...]: + return (-row["score"], row["total_price"], row["delivery_days"], -row["warranty_months"], row["vendor"]) + + def _score_quotes(comparison_id: str, quotes: list[QuoteInput], weights: QuoteWeights) -> dict[str, Any]: total_weight = Decimal(str(weights.price + weights.delivery + weights.warranty)) prices = [_money(q.unit_price) for q in quotes] @@ -351,7 +355,7 @@ def _score_quotes(comparison_id: str, quotes: list[QuoteInput], weights: QuoteWe }, } ) - rows.sort(key=lambda item: (-item["score"], item["total_price"], item["delivery_days"], -item["warranty_months"], item["vendor"])) + rows.sort(key=_rank_sort_key) for rank, row in enumerate(rows, start=1): row["rank"] = rank recommendation = rows[0]