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