a2a-source-edit: write agent.py

This commit is contained in:
a2a-cloud
2026-07-18 10:15:21 +00:00
parent 3b5c2e01df
commit 4855c83d68

View File

@@ -36,6 +36,8 @@ from a2a_pack import (
RunContext,
State,
UploadedFile,
WorkspaceAccess,
WorkspaceMode,
)
MAX_INVOICES = 50
@@ -80,6 +82,12 @@ class InvoiceGuardStudioV1(A2AAgent[InvoiceGuardStudioV1Config, PlatformUserAuth
caller_pays_llm=False,
notes="Deterministic invoice validation; no LLM credentials are required.",
)
workspace_access = WorkspaceAccess.dynamic(
max_files=8,
allowed_modes=(WorkspaceMode.READ_ONLY, WorkspaceMode.READ_WRITE_OVERLAY),
require_reason=False,
max_total_size_bytes=MAX_UPLOAD_BYTES * MAX_UPLOADS,
)
tools_used = ("managed-postgres", "mcp")
platform_resources = AgentPlatformResources(
databases=(
@@ -325,13 +333,14 @@ def _safe_filename(name: str) -> bool:
return bool(clean and len(clean) <= 180 and "/" not in clean and "\\" not in clean and "\x00" not in clean)
def _parse_browser_documents(documents: list[BrowserDocument]) -> dict[str, Any]:
def _parse_browser_documents(documents: list[BrowserDocument | dict[str, Any]]) -> dict[str, Any]:
if not documents:
return _validation_error("no_uploads", "Attach at least one invoice document.")
if len(documents) > MAX_UPLOADS:
return _validation_error("too_many_uploads", f"At most {MAX_UPLOADS} uploads are allowed.")
invoices: list[dict[str, Any]] = []
for document in documents:
for raw_document in documents:
document = raw_document if isinstance(raw_document, BrowserDocument) else BrowserDocument.model_validate(raw_document)
if not _safe_filename(document.filename):
return _validation_error("invalid_filename", "Upload filename is missing or unsafe.")
if document.media_type not in ACCEPTED_MEDIA_TYPES: