a2a-source-edit: write agent.py

This commit is contained in:
a2a-cloud
2026-07-18 05:15:35 +00:00
parent 9309f95d5b
commit b4a718519c

View File

@@ -109,7 +109,7 @@ class QuoteJudgeStudioV1(A2AAgent[QuoteJudgeStudioV1Config, PlatformUserAuth]):
"weights; persist results; reopen prior comparisons; accept browser " "weights; persist results; reopen prior comparisons; accept browser "
"base64 uploads and typed FileUpload inputs; and persist execution receipts." "base64 uploads and typed FileUpload inputs; and persist execution receipts."
) )
version = "0.1.2" version = "0.1.3"
config_model = QuoteJudgeStudioV1Config config_model = QuoteJudgeStudioV1Config
auth_model = PlatformUserAuth 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]: def _score_quotes(comparison_id: str, quotes: list[QuoteInput], weights: WeightInput) -> dict[str, Any]:
total_weight = weights.price + weights.delivery + weights.warranty total_weight = weights.price + weights.delivery + weights.warranty
normalized_weights = { 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] winner = rows[0]
return { return {
"ok": True, "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] quotes = [QuoteInput.model_validate(row) for row in rows]
elif media_type in {"text/csv", "application/vnd.ms-excel"} or filename.lower().endswith(".csv"): elif media_type in {"text/csv", "application/vnd.ms-excel"} or filename.lower().endswith(".csv"):
reader = csv.DictReader(io.StringIO(text)) 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: else:
quotes = _parse_plain_text_quotes(text) quotes = _parse_plain_text_quotes(text)
return {"ok": True, "quotes": quotes} return {"ok": True, "quotes": quotes}