a2a-source-edit: write agent.py
This commit is contained in:
27
agent.py
27
agent.py
@@ -217,8 +217,8 @@ class ProductionProofV116HighUtili72551(
|
||||
artifact_media_type=artifact_ref.mime_type,
|
||||
artifact_size=artifact_ref.size_bytes,
|
||||
)
|
||||
except RuntimeError as exc:
|
||||
await ctx.emit_error(str(exc), code="database_unavailable")
|
||||
except RuntimeError:
|
||||
await ctx.emit_error("Managed database is not ready for this agent.", code="database_unavailable")
|
||||
return DashboardResult(
|
||||
status="setup_required",
|
||||
run_id=run_id,
|
||||
@@ -238,7 +238,7 @@ class ProductionProofV116HighUtili72551(
|
||||
size_bytes=artifact_ref.size_bytes,
|
||||
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(
|
||||
@@ -283,8 +283,8 @@ class ProductionProofV116HighUtili72551(
|
||||
tenant = _tenant_key(ctx)
|
||||
try:
|
||||
history = _load_history(tenant, limit=limit)
|
||||
except RuntimeError as exc:
|
||||
await ctx.emit_error(str(exc), code="database_unavailable")
|
||||
except RuntimeError:
|
||||
await ctx.emit_error("Managed database is not ready for this agent.", code="database_unavailable")
|
||||
return HistoryResult(status="setup_required", history=[])
|
||||
return HistoryResult(status="ok", history=history)
|
||||
|
||||
@@ -330,15 +330,15 @@ class ProductionProofV116HighUtili72551(
|
||||
rows=rows,
|
||||
summary=summary,
|
||||
)
|
||||
except RuntimeError as exc:
|
||||
await ctx.emit_error(str(exc), code="database_unavailable")
|
||||
except RuntimeError:
|
||||
await ctx.emit_error("Managed database is not ready for this agent.", code="database_unavailable")
|
||||
return ScheduledRollupResult(
|
||||
status="setup_required",
|
||||
run_key=run_key,
|
||||
run_id=run_id,
|
||||
receipt_id=receipt_id,
|
||||
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,
|
||||
)
|
||||
return ScheduledRollupResult(
|
||||
@@ -364,11 +364,11 @@ def _tenant_key(ctx: RunContext[PlatformUserAuth]) -> str:
|
||||
def _db_conn():
|
||||
database_url = os.environ.get("DATABASE_URL")
|
||||
if not database_url:
|
||||
raise RuntimeError("DATABASE_URL is not configured")
|
||||
raise RuntimeError("database is not configured")
|
||||
try:
|
||||
import psycopg
|
||||
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"
|
||||
try:
|
||||
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:
|
||||
explicit = (status or "").strip().lower()
|
||||
if re.fullmatch(r"red|yellow|green", explicit):
|
||||
return explicit
|
||||
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"
|
||||
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 "green"
|
||||
|
||||
|
||||
Reference in New Issue
Block a user