a2a-source-edit: write agent.py
This commit is contained in:
11
agent.py
11
agent.py
@@ -5,6 +5,7 @@ bounded browser base64 bridge, managed Postgres persistence, and receipt rows.
|
|||||||
"""
|
"""
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
|
import asyncio
|
||||||
import base64
|
import base64
|
||||||
import csv
|
import csv
|
||||||
import hashlib
|
import hashlib
|
||||||
@@ -94,7 +95,7 @@ class CsvAnswersStudioV1(A2AAgent[CsvAnswersStudioV1Config, PlatformUserAuth]):
|
|||||||
"highest numeric value, persist the grounded answer in user-scoped "
|
"highest numeric value, persist the grounded answer in user-scoped "
|
||||||
"managed Postgres, and reopen it from a polished one-page app."
|
"managed Postgres, and reopen it from a polished one-page app."
|
||||||
)
|
)
|
||||||
version = "0.1.1"
|
version = "0.1.2"
|
||||||
|
|
||||||
config_model = CsvAnswersStudioV1Config
|
config_model = CsvAnswersStudioV1Config
|
||||||
auth_model = PlatformUserAuth
|
auth_model = PlatformUserAuth
|
||||||
@@ -136,7 +137,8 @@ class CsvAnswersStudioV1(A2AAgent[CsvAnswersStudioV1Config, PlatformUserAuth]):
|
|||||||
if not result.ok:
|
if not result.ok:
|
||||||
return result
|
return result
|
||||||
try:
|
try:
|
||||||
saved, receipt_id = _persist_analysis_and_receipt(
|
saved, receipt_id = await asyncio.to_thread(
|
||||||
|
_persist_analysis_and_receipt,
|
||||||
tenant_key=tenant,
|
tenant_key=tenant,
|
||||||
analysis_id=analysis_id,
|
analysis_id=analysis_id,
|
||||||
question=question,
|
question=question,
|
||||||
@@ -220,7 +222,7 @@ class CsvAnswersStudioV1(A2AAgent[CsvAnswersStudioV1Config, PlatformUserAuth]):
|
|||||||
) -> CsvAnalysisResult:
|
) -> CsvAnalysisResult:
|
||||||
tenant = _tenant_key(ctx)
|
tenant = _tenant_key(ctx)
|
||||||
try:
|
try:
|
||||||
record = _load_analysis(tenant, analysis_id)
|
record = await asyncio.to_thread(_load_analysis, tenant, analysis_id)
|
||||||
except Exception: # noqa: BLE001
|
except Exception: # noqa: BLE001
|
||||||
return _error(
|
return _error(
|
||||||
analysis_id,
|
analysis_id,
|
||||||
@@ -245,7 +247,8 @@ class CsvAnswersStudioV1(A2AAgent[CsvAnswersStudioV1Config, PlatformUserAuth]):
|
|||||||
tenant = _tenant_key(ctx)
|
tenant = _tenant_key(ctx)
|
||||||
safe_limit = min(max(int(limit), 1), 50)
|
safe_limit = min(max(int(limit), 1), 50)
|
||||||
try:
|
try:
|
||||||
return CsvAnalysisListResult(ok=True, analyses=_list_analyses(tenant, safe_limit))
|
analyses = await asyncio.to_thread(_list_analyses, tenant, safe_limit)
|
||||||
|
return CsvAnalysisListResult(ok=True, analyses=analyses)
|
||||||
except Exception: # noqa: BLE001
|
except Exception: # noqa: BLE001
|
||||||
return CsvAnalysisListResult(
|
return CsvAnalysisListResult(
|
||||||
ok=False,
|
ok=False,
|
||||||
|
|||||||
Reference in New Issue
Block a user