a2a-source-edit: write agent.py
This commit is contained in:
13
agent.py
13
agent.py
@@ -36,6 +36,8 @@ from a2a_pack import (
|
|||||||
RunContext,
|
RunContext,
|
||||||
State,
|
State,
|
||||||
UploadedFile,
|
UploadedFile,
|
||||||
|
WorkspaceAccess,
|
||||||
|
WorkspaceMode,
|
||||||
)
|
)
|
||||||
|
|
||||||
MAX_INVOICES = 50
|
MAX_INVOICES = 50
|
||||||
@@ -80,6 +82,12 @@ class InvoiceGuardStudioV1(A2AAgent[InvoiceGuardStudioV1Config, PlatformUserAuth
|
|||||||
caller_pays_llm=False,
|
caller_pays_llm=False,
|
||||||
notes="Deterministic invoice validation; no LLM credentials are required.",
|
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")
|
tools_used = ("managed-postgres", "mcp")
|
||||||
platform_resources = AgentPlatformResources(
|
platform_resources = AgentPlatformResources(
|
||||||
databases=(
|
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)
|
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:
|
if not documents:
|
||||||
return _validation_error("no_uploads", "Attach at least one invoice document.")
|
return _validation_error("no_uploads", "Attach at least one invoice document.")
|
||||||
if len(documents) > MAX_UPLOADS:
|
if len(documents) > MAX_UPLOADS:
|
||||||
return _validation_error("too_many_uploads", f"At most {MAX_UPLOADS} uploads are allowed.")
|
return _validation_error("too_many_uploads", f"At most {MAX_UPLOADS} uploads are allowed.")
|
||||||
invoices: list[dict[str, Any]] = []
|
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):
|
if not _safe_filename(document.filename):
|
||||||
return _validation_error("invalid_filename", "Upload filename is missing or unsafe.")
|
return _validation_error("invalid_filename", "Upload filename is missing or unsafe.")
|
||||||
if document.media_type not in ACCEPTED_MEDIA_TYPES:
|
if document.media_type not in ACCEPTED_MEDIA_TYPES:
|
||||||
|
|||||||
Reference in New Issue
Block a user