a2a-source-edit: write agent.py
This commit is contained in:
17
agent.py
17
agent.py
@@ -12,7 +12,6 @@ import io
|
|||||||
import json
|
import json
|
||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
import time
|
|
||||||
import uuid
|
import uuid
|
||||||
from contextlib import contextmanager
|
from contextlib import contextmanager
|
||||||
from datetime import datetime, timezone
|
from datetime import datetime, timezone
|
||||||
@@ -32,6 +31,8 @@ from a2a_pack import (
|
|||||||
Resources,
|
Resources,
|
||||||
RunContext,
|
RunContext,
|
||||||
State,
|
State,
|
||||||
|
WorkspaceAccess,
|
||||||
|
WorkspaceMode,
|
||||||
)
|
)
|
||||||
from a2a_pack.workspace import FileUpload, UploadedFile
|
from a2a_pack.workspace import FileUpload, UploadedFile
|
||||||
|
|
||||||
@@ -130,6 +131,12 @@ class QuoteJudgeStudioV1(A2AAgent[QuoteJudgeStudioV1Config, PlatformUserAuth]):
|
|||||||
caller_pays_llm=False,
|
caller_pays_llm=False,
|
||||||
notes="Deterministic local quote scoring; no LLM credential is required.",
|
notes="Deterministic local quote scoring; no LLM credential is required.",
|
||||||
)
|
)
|
||||||
|
workspace_access = WorkspaceAccess.dynamic(
|
||||||
|
max_files=MAX_UPLOADS,
|
||||||
|
allowed_modes=(WorkspaceMode.READ_ONLY,),
|
||||||
|
require_reason=False,
|
||||||
|
max_total_size_bytes=MAX_UPLOADS * MAX_UPLOAD_BYTES,
|
||||||
|
)
|
||||||
tools_used = ("postgres", "mcp")
|
tools_used = ("postgres", "mcp")
|
||||||
|
|
||||||
@a2a.tool(
|
@a2a.tool(
|
||||||
@@ -305,13 +312,19 @@ class QuoteJudgeStudioV1(A2AAgent[QuoteJudgeStudioV1Config, PlatformUserAuth]):
|
|||||||
"comparison_id": _clean_comparison_id(comparison_id),
|
"comparison_id": _clean_comparison_id(comparison_id),
|
||||||
}
|
}
|
||||||
try:
|
try:
|
||||||
|
grant = await ctx.workspace.request_access(
|
||||||
|
files=[document.path],
|
||||||
|
mode=WorkspaceMode.READ_ONLY,
|
||||||
|
reason="Parse the caller-uploaded quote file for comparison.",
|
||||||
|
purpose="Read uploaded vendor quote file",
|
||||||
|
)
|
||||||
view = await ctx.workspace.open_view(
|
view = await ctx.workspace.open_view(
|
||||||
purpose="Read uploaded vendor quote file",
|
purpose="Read uploaded vendor quote file",
|
||||||
hints=[document.path],
|
hints=[document.path],
|
||||||
max_files=1,
|
max_files=1,
|
||||||
reason="Parse the caller-uploaded quote file for comparison.",
|
reason="Parse the caller-uploaded quote file for comparison.",
|
||||||
)
|
)
|
||||||
raw = await view.read(document.path)
|
raw = await view.read(grant.files[0].path)
|
||||||
except Exception:
|
except Exception:
|
||||||
return {
|
return {
|
||||||
"ok": False,
|
"ok": False,
|
||||||
|
|||||||
Reference in New Issue
Block a user