a2a-source-edit: write agent.py

This commit is contained in:
a2a-cloud
2026-07-18 05:35:12 +00:00
parent 6cdb58266f
commit 4b3013ec80

View File

@@ -14,7 +14,6 @@ import io
import json import json
import os import os
import re import re
import time
from datetime import UTC, datetime from datetime import UTC, datetime
from typing import Annotated, Any from typing import Annotated, Any
@@ -98,7 +97,7 @@ class QuoteJudgeStudioV1(A2AAgent[QuoteJudgeStudioV1Config, PlatformUserAuth]):
"and warranty scoring, persists results, supports bounded uploads, and " "and warranty scoring, persists results, supports bounded uploads, and "
"exposes typed MCP-compatible A2A tools." "exposes typed MCP-compatible A2A tools."
) )
version = "0.1.0" version = "0.1.1"
config_model = QuoteJudgeStudioV1Config config_model = QuoteJudgeStudioV1Config
auth_model = PlatformUserAuth auth_model = PlatformUserAuth
@@ -653,20 +652,30 @@ def _ensure_schema(conn: Any) -> None:
""" """
CREATE TABLE IF NOT EXISTS quote_judge_receipts ( CREATE TABLE IF NOT EXISTS quote_judge_receipts (
id BIGSERIAL PRIMARY KEY, id BIGSERIAL PRIMARY KEY,
receipt_id TEXT,
tenant_key TEXT NOT NULL, tenant_key TEXT NOT NULL,
comparison_id TEXT, comparison_id TEXT,
skill_name TEXT NOT NULL, skill_name TEXT,
receipt_json JSONB NOT NULL, tool_name TEXT,
status TEXT,
input_hash TEXT,
result_hash TEXT,
receipt_json JSONB,
payload JSONB,
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW() created_at TIMESTAMPTZ NOT NULL DEFAULT NOW()
) )
""" """
) )
conn.execute( conn.execute("ALTER TABLE quote_judge_receipts ADD COLUMN IF NOT EXISTS receipt_id TEXT")
"CREATE INDEX IF NOT EXISTS app_records_tenant_kind_idx ON app_records (tenant_key, record_kind, created_at DESC)" conn.execute("ALTER TABLE quote_judge_receipts ADD COLUMN IF NOT EXISTS skill_name TEXT")
) conn.execute("ALTER TABLE quote_judge_receipts ADD COLUMN IF NOT EXISTS tool_name TEXT")
conn.execute( conn.execute("ALTER TABLE quote_judge_receipts ADD COLUMN IF NOT EXISTS status TEXT")
"CREATE INDEX IF NOT EXISTS quote_judge_receipts_tenant_idx ON quote_judge_receipts (tenant_key, created_at DESC)" conn.execute("ALTER TABLE quote_judge_receipts ADD COLUMN IF NOT EXISTS input_hash TEXT")
) conn.execute("ALTER TABLE quote_judge_receipts ADD COLUMN IF NOT EXISTS result_hash TEXT")
conn.execute("ALTER TABLE quote_judge_receipts ADD COLUMN IF NOT EXISTS receipt_json JSONB")
conn.execute("ALTER TABLE quote_judge_receipts ADD COLUMN IF NOT EXISTS payload JSONB")
conn.execute("CREATE INDEX IF NOT EXISTS app_records_tenant_kind_idx ON app_records (tenant_key, record_kind, created_at DESC)")
conn.execute("CREATE INDEX IF NOT EXISTS quote_judge_receipts_tenant_idx ON quote_judge_receipts (tenant_key, created_at DESC)")
def _load_legacy_comparison(conn: Any, tenant: str, comparison_id: str) -> dict[str, Any] | None: def _load_legacy_comparison(conn: Any, tenant: str, comparison_id: str) -> dict[str, Any] | None:
@@ -710,6 +719,7 @@ async def _persist_receipt(
"agent": QuoteJudgeStudioV1.name, "agent": QuoteJudgeStudioV1.name,
"agent_version": QuoteJudgeStudioV1.version, "agent_version": QuoteJudgeStudioV1.version,
"skill_name": skill_name, "skill_name": skill_name,
"tool_name": skill_name,
"comparison_id": comparison_id, "comparison_id": comparison_id,
"tenant_scope": "user", "tenant_scope": "user",
"task_id": getattr(ctx, "task_id", ""), "task_id": getattr(ctx, "task_id", ""),
@@ -732,10 +742,22 @@ async def _persist_receipt(
conn.execute( conn.execute(
""" """
INSERT INTO quote_judge_receipts INSERT INTO quote_judge_receipts
(tenant_key, comparison_id, skill_name, receipt_json) (receipt_id, tenant_key, comparison_id, skill_name, tool_name,
VALUES (%s, %s, %s, %s) status, input_hash, result_hash, receipt_json, payload)
VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s)
""", """,
(tenant, comparison_id or None, skill_name, Jsonb(receipt)), (
receipt["receipt_id"],
tenant,
comparison_id or None,
skill_name,
skill_name,
receipt["status"],
receipt["input_hash"],
receipt["result_hash"],
Jsonb(receipt),
Jsonb(receipt),
),
) )
return {"persisted": True, "receipt_id": receipt["receipt_id"]} return {"persisted": True, "receipt_id": receipt["receipt_id"]}
except Exception: # noqa: BLE001 except Exception: # noqa: BLE001