From 4855c83d68c13418bbfea1d15ee7fbd6d5b9d31f Mon Sep 17 00:00:00 2001 From: a2a-cloud Date: Sat, 18 Jul 2026 10:15:21 +0000 Subject: [PATCH] a2a-source-edit: write agent.py --- agent.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/agent.py b/agent.py index b82a2f5..1cbfb33 100644 --- a/agent.py +++ b/agent.py @@ -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: