a2a-source-edit: write agent.py

This commit is contained in:
a2a-cloud
2026-07-18 06:13:47 +00:00
parent 557cbb446e
commit dcfda8553a

View File

@@ -318,6 +318,10 @@ def _validate_comparison_request(
return None 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]: def _score_quotes(comparison_id: str, quotes: list[QuoteInput], weights: QuoteWeights) -> dict[str, Any]:
total_weight = Decimal(str(weights.price + weights.delivery + weights.warranty)) total_weight = Decimal(str(weights.price + weights.delivery + weights.warranty))
prices = [_money(q.unit_price) for q in quotes] 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): for rank, row in enumerate(rows, start=1):
row["rank"] = rank row["rank"] = rank
recommendation = rows[0] recommendation = rows[0]