fix: keep builder artifacts inside workspace grant
All checks were successful
build / build (push) Successful in 21s

This commit is contained in:
robert
2026-05-27 19:31:49 -03:00
parent 4d51ca0623
commit 33d20d3aaa
5 changed files with 45 additions and 6 deletions

View File

@@ -278,4 +278,4 @@ def _find_url(value: Any) -> str | None:
m = _URL_RE.search(value) m = _URL_RE.search(value)
return m.group(0) if m else None return m.group(0) if m else None
return None return None
# rebuild against a2a-pack 0.1.32 for Knative agent manifests # rebuild against a2a-pack 0.1.33 for workspace-backed DeepAgents artifacts

View File

@@ -17,6 +17,7 @@ from .tools import ToolContext, build_tools
BUILDER_SKILL_SOURCE = "/.agent-builder/skills/" BUILDER_SKILL_SOURCE = "/.agent-builder/skills/"
_BUILDER_SKILL_NAMESPACE = ("agent-builder", "skills") _BUILDER_SKILL_NAMESPACE = ("agent-builder", "skills")
_BUILDER_ARTIFACT_DIR = ".agent-builder"
@dataclass(frozen=True) @dataclass(frozen=True)
@@ -324,7 +325,10 @@ def _build_project_backend(ctx: BuilderContext, *, settings: Settings) -> Any |
from a2a_pack.deepagents import WorkspaceBackend from a2a_pack.deepagents import WorkspaceBackend
except Exception: # noqa: BLE001 except Exception: # noqa: BLE001
return _with_builder_skills(StateBackend()) return _with_builder_skills(StateBackend())
return _with_builder_skills(WorkspaceBackend(ctx.workspace)) return _with_builder_skills(
WorkspaceBackend(ctx.workspace),
artifacts_root=f"/{prefix}/{_BUILDER_ARTIFACT_DIR}",
)
try: try:
from a2a_pack import Grant, WorkspaceAccess, WorkspaceMode from a2a_pack import Grant, WorkspaceAccess, WorkspaceMode
from a2a_pack.deepagents import WorkspaceBackend from a2a_pack.deepagents import WorkspaceBackend
@@ -357,10 +361,13 @@ def _build_project_backend(ctx: BuilderContext, *, settings: Settings) -> Any |
write_prefixes=(f"{prefix}/", "outputs/"), write_prefixes=(f"{prefix}/", "outputs/"),
) )
) )
return _with_builder_skills(WorkspaceBackend(workspace)) return _with_builder_skills(
WorkspaceBackend(workspace),
artifacts_root=f"/{prefix}/{_BUILDER_ARTIFACT_DIR}",
)
def _with_builder_skills(default_backend: Any) -> Any: def _with_builder_skills(default_backend: Any, *, artifacts_root: str = "/") -> Any:
skill_store = InMemoryStore() skill_store = InMemoryStore()
for path, content in _builder_skill_files().items(): for path, content in _builder_skill_files().items():
skill_store.put( skill_store.put(
@@ -375,6 +382,7 @@ def _with_builder_skills(default_backend: Any) -> Any:
return CompositeBackend( return CompositeBackend(
default=default_backend, default=default_backend,
routes={BUILDER_SKILL_SOURCE: skill_backend}, routes={BUILDER_SKILL_SOURCE: skill_backend},
artifacts_root=artifacts_root,
) )

View File

@@ -28,7 +28,7 @@ if TYPE_CHECKING:
from .config import Settings from .config import Settings
A2A_PACK_MIN_VERSION = "0.1.32" A2A_PACK_MIN_VERSION = "0.1.33"
@dataclass(frozen=True) @dataclass(frozen=True)

View File

@@ -1,4 +1,4 @@
a2a-pack>=0.1.32 a2a-pack>=0.1.33
httpx>=0.27 httpx>=0.27
boto3>=1.34 boto3>=1.34
deepagents>=0.5.0 deepagents>=0.5.0

View File

@@ -5,10 +5,13 @@ import unittest
from agent_builder.builder import ( from agent_builder.builder import (
BUILDER_SKILL_SOURCE, BUILDER_SKILL_SOURCE,
BuilderContext,
SYSTEM_PROMPT, SYSTEM_PROMPT,
_build_project_backend,
_builder_skill_files, _builder_skill_files,
_with_builder_skills, _with_builder_skills,
) )
from agent_builder.config import Settings
from agent_builder.tools import A2A_PACK_MIN_VERSION from agent_builder.tools import A2A_PACK_MIN_VERSION
from deepagents.backends import StateBackend from deepagents.backends import StateBackend
@@ -128,3 +131,31 @@ class BuilderPromptTests(unittest.TestCase):
paths = [entry["path"] for entry in (listing.entries or [])] paths = [entry["path"] for entry in (listing.entries or [])]
for skill_name in expected: for skill_name in expected:
self.assertIn(f"{BUILDER_SKILL_SOURCE}{skill_name}/", paths) self.assertIn(f"{BUILDER_SKILL_SOURCE}{skill_name}/", paths)
def test_project_backend_keeps_deepagents_artifacts_inside_project_grant(self) -> None:
backend = _build_project_backend(
BuilderContext(
bucket="user-1-files",
project_prefix="agents/svgwrite-agent",
workspace=object(),
),
settings=Settings(
sandbox_url="http://sandbox",
sandbox_timeout_s=1200,
sandbox_token=None,
deploy_wait_timeout_s=900,
litellm_url="http://litellm",
litellm_key="",
litellm_model="gpt-5.5",
cp_url="http://control-plane",
minio_endpoint="http://minio",
minio_access_key="",
minio_secret_key="",
image="python:3.11-slim",
),
)
self.assertEqual(
backend.artifacts_root,
"/agents/svgwrite-agent/.agent-builder",
)