a2a-source-edit: write agent.py
This commit is contained in:
6
agent.py
6
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]
|
||||
|
||||
Reference in New Issue
Block a user