From b4a718519cfac05e6af0866f1a3cb3e1ea818aed Mon Sep 17 00:00:00 2001 From: a2a-cloud Date: Sat, 18 Jul 2026 05:15:35 +0000 Subject: [PATCH] a2a-source-edit: write agent.py --- agent.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/agent.py b/agent.py index 4e2a163..596ff7b 100644 --- a/agent.py +++ b/agent.py @@ -109,7 +109,7 @@ class QuoteJudgeStudioV1(A2AAgent[QuoteJudgeStudioV1Config, PlatformUserAuth]): "weights; persist results; reopen prior comparisons; accept browser " "base64 uploads and typed FileUpload inputs; and persist execution receipts." ) - version = "0.1.2" + version = "0.1.3" config_model = QuoteJudgeStudioV1Config auth_model = PlatformUserAuth @@ -305,6 +305,10 @@ def _validation_result(comparison_id: str, issues: list[ValidationIssue]) -> dic } +def _rank_key(item: dict[str, Any]) -> tuple[float, float, int, int, str]: + return (-item["scores"]["weighted_total"], item["total_price"], item["delivery_days"], -item["warranty_months"], item["vendor"]) + + def _score_quotes(comparison_id: str, quotes: list[QuoteInput], weights: WeightInput) -> dict[str, Any]: total_weight = weights.price + weights.delivery + weights.warranty normalized_weights = { @@ -343,7 +347,7 @@ def _score_quotes(comparison_id: str, quotes: list[QuoteInput], weights: WeightI }, } ) - rows.sort(key=lambda row: (-row["scores"]["weighted_total"], row["total_price"], row["delivery_days"], -row["warranty_months"], row["vendor"])) + rows.sort(key=_rank_key) winner = rows[0] return { "ok": True, @@ -550,7 +554,7 @@ def _parse_document_bytes(filename: str, media_type: str, data: bytes) -> dict[s quotes = [QuoteInput.model_validate(row) for row in rows] elif media_type in {"text/csv", "application/vnd.ms-excel"} or filename.lower().endswith(".csv"): reader = csv.DictReader(io.StringIO(text)) - quotes = [QuoteInput.model_validate(_normalize_quote_row(row)) for row in reader] + quotes = [QuoteInput.model_validate(_normalize_quote_row(csv_row)) for csv_row in reader] else: quotes = _parse_plain_text_quotes(text) return {"ok": True, "quotes": quotes}