a2a-source-edit: write agent.py

This commit is contained in:
a2a-cloud
2026-07-19 19:56:56 +00:00
parent 5cd97159b0
commit 903c719cea

View File

@@ -217,8 +217,8 @@ class ProductionProofV116HighUtili72551(
artifact_media_type=artifact_ref.mime_type, artifact_media_type=artifact_ref.mime_type,
artifact_size=artifact_ref.size_bytes, artifact_size=artifact_ref.size_bytes,
) )
except RuntimeError as exc: except RuntimeError:
await ctx.emit_error(str(exc), code="database_unavailable") await ctx.emit_error("Managed database is not ready for this agent.", code="database_unavailable")
return DashboardResult( return DashboardResult(
status="setup_required", status="setup_required",
run_id=run_id, run_id=run_id,
@@ -238,7 +238,7 @@ class ProductionProofV116HighUtili72551(
size_bytes=artifact_ref.size_bytes, size_bytes=artifact_ref.size_bytes,
content=csv_text, content=csv_text,
), ),
summary=f"{summary} Database persistence needs setup: {exc}", summary=f"{summary} Persistence is not ready yet; retry after managed database provisioning completes.",
) )
await ctx.emit_event( await ctx.emit_event(
@@ -283,8 +283,8 @@ class ProductionProofV116HighUtili72551(
tenant = _tenant_key(ctx) tenant = _tenant_key(ctx)
try: try:
history = _load_history(tenant, limit=limit) history = _load_history(tenant, limit=limit)
except RuntimeError as exc: except RuntimeError:
await ctx.emit_error(str(exc), code="database_unavailable") await ctx.emit_error("Managed database is not ready for this agent.", code="database_unavailable")
return HistoryResult(status="setup_required", history=[]) return HistoryResult(status="setup_required", history=[])
return HistoryResult(status="ok", history=history) return HistoryResult(status="ok", history=history)
@@ -330,15 +330,15 @@ class ProductionProofV116HighUtili72551(
rows=rows, rows=rows,
summary=summary, summary=summary,
) )
except RuntimeError as exc: except RuntimeError:
await ctx.emit_error(str(exc), code="database_unavailable") await ctx.emit_error("Managed database is not ready for this agent.", code="database_unavailable")
return ScheduledRollupResult( return ScheduledRollupResult(
status="setup_required", status="setup_required",
run_key=run_key, run_key=run_key,
run_id=run_id, run_id=run_id,
receipt_id=receipt_id, receipt_id=receipt_id,
already_processed=False, already_processed=False,
summary=f"{summary} Database persistence needs setup: {exc}", summary=f"{summary} Persistence is not ready yet; retry after managed database provisioning completes.",
dashboard_data=rows, dashboard_data=rows,
) )
return ScheduledRollupResult( return ScheduledRollupResult(
@@ -364,11 +364,11 @@ def _tenant_key(ctx: RunContext[PlatformUserAuth]) -> str:
def _db_conn(): def _db_conn():
database_url = os.environ.get("DATABASE_URL") database_url = os.environ.get("DATABASE_URL")
if not database_url: if not database_url:
raise RuntimeError("DATABASE_URL is not configured") raise RuntimeError("database is not configured")
try: try:
import psycopg import psycopg
except Exception as exc: # pragma: no cover - dependency installed in deploy image except Exception as exc: # pragma: no cover - dependency installed in deploy image
raise RuntimeError("psycopg is not installed") from exc raise RuntimeError("database driver is not installed") from exc
options = "-c statement_timeout=5000 -c lock_timeout=3000 -c idle_in_transaction_session_timeout=10000" options = "-c statement_timeout=5000 -c lock_timeout=3000 -c idle_in_transaction_session_timeout=10000"
try: try:
with psycopg.connect(database_url, autocommit=False, options=options) as conn: with psycopg.connect(database_url, autocommit=False, options=options) as conn:
@@ -665,10 +665,13 @@ def _rows_to_csv(rows: list[DashboardRow]) -> str:
def _normalize_status(status: str, update: str) -> str: def _normalize_status(status: str, update: str) -> str:
explicit = (status or "").strip().lower()
if re.fullmatch(r"red|yellow|green", explicit):
return explicit
combined = f"{status} {update}".lower() combined = f"{status} {update}".lower()
if "red" in combined or re.search(r"\b(overdue|blocked|blocker|escalat|critical)\b", combined): if re.search(r"\bred\b", combined) or re.search(r"\b(overdue|blocked|blocker|escalat|critical)\b", combined):
return "red" return "red"
if "yellow" in combined or re.search(r"\b(risk|delay|waiting|watch)\b", combined): if re.search(r"\byellow\b", combined) or re.search(r"\b(risk|delay|waiting|watch)\b", combined):
return "yellow" return "yellow"
return "green" return "green"