agentenv-framework 0.9.1254__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- agent_env/__init__.py +0 -0
- agent_env/a2a_agent/__init__.py +23 -0
- agent_env/a2a_agent/a2a_agent.py +600 -0
- agent_env/a2a_agent/conversation_store.py +356 -0
- agent_env/a2a_agent/object_transfer.py +609 -0
- agent_env/a2a_agent/protocol.py +238 -0
- agent_env/a2a_agent/store.py +201 -0
- agent_env/a2a_agent/validator.py +901 -0
- agent_env/artifact/__init__.py +48 -0
- agent_env/artifact/artifact.py +74 -0
- agent_env/artifact/artifacts/__init__.py +0 -0
- agent_env/artifact/artifacts/cli.py +83 -0
- agent_env/artifact/artifacts/docker_image.py +457 -0
- agent_env/artifact/artifacts/environment.py +89 -0
- agent_env/artifact/artifacts/environment_universe.py +156 -0
- agent_env/artifact/artifacts/file.py +214 -0
- agent_env/artifact/artifacts/file_artifact_universe.py +206 -0
- agent_env/artifact/artifacts/skill.py +206 -0
- agent_env/artifact/artifacts/vm_image.py +95 -0
- agent_env/artifact/ref.py +15 -0
- agent_env/artifact/registry.py +251 -0
- agent_env/artifact/store.py +295 -0
- agent_env/artifact/universe.py +38 -0
- agent_env/attribution.py +41 -0
- agent_env/bundle/__init__.py +4 -0
- agent_env/bundle/_fs.py +128 -0
- agent_env/bundle/authoring.py +239 -0
- agent_env/bundle/installed.py +175 -0
- agent_env/bundle/ledger.py +269 -0
- agent_env/bundle/materialize.py +204 -0
- agent_env/bundle/parse.py +594 -0
- agent_env/bundle/plan.py +414 -0
- agent_env/bundle/resolve.py +404 -0
- agent_env/bundle/run.py +361 -0
- agent_env/cli/__init__.py +69 -0
- agent_env/cli/__main__.py +10 -0
- agent_env/cli/_installers.py +576 -0
- agent_env/cli/_plugin_changes.py +947 -0
- agent_env/cli/a2a_agent/__init__.py +22 -0
- agent_env/cli/a2a_agent/add_skill.py +97 -0
- agent_env/cli/a2a_agent/deploy.py +60 -0
- agent_env/cli/a2a_agent/get.py +15 -0
- agent_env/cli/a2a_agent/get_instance.py +26 -0
- agent_env/cli/a2a_agent/put.py +78 -0
- agent_env/cli/a2a_agent/validate.py +56 -0
- agent_env/cli/artifact/__init__.py +20 -0
- agent_env/cli/artifact/cli.py +83 -0
- agent_env/cli/artifact/environment.py +44 -0
- agent_env/cli/artifact/environment_universe.py +163 -0
- agent_env/cli/artifact/file_artifact_universe.py +281 -0
- agent_env/cli/artifact/skill.py +128 -0
- agent_env/cli/banner.py +25 -0
- agent_env/cli/config.py +263 -0
- agent_env/cli/env/__init__.py +31 -0
- agent_env/cli/env/deploy.py +112 -0
- agent_env/cli/env/gateway.py +57 -0
- agent_env/cli/env/get_instance.py +40 -0
- agent_env/cli/env/mcp_server.py +410 -0
- agent_env/cli/env/multi.py +282 -0
- agent_env/cli/env/service_db.py +99 -0
- agent_env/cli/env/snapshot.py +35 -0
- agent_env/cli/env/state/__init__.py +6 -0
- agent_env/cli/env/state/init.py +108 -0
- agent_env/cli/env/state/teardown.py +44 -0
- agent_env/cli/env/website.py +216 -0
- agent_env/cli/env/website_browser.py +67 -0
- agent_env/cli/eval/__init__.py +16 -0
- agent_env/cli/eval/add_tasks.py +63 -0
- agent_env/cli/eval/create.py +49 -0
- agent_env/cli/eval/run.py +194 -0
- agent_env/cli/identity/__init__.py +5 -0
- agent_env/cli/identity/client_identity.py +37 -0
- agent_env/cli/plugin.py +438 -0
- agent_env/cli/run.py +285 -0
- agent_env/cli/task/__init__.py +21 -0
- agent_env/cli/task/create.py +109 -0
- agent_env/cli/task/get.py +17 -0
- agent_env/cli/task/get_instance.py +34 -0
- agent_env/cli/task/run.py +615 -0
- agent_env/cli/task/validate.py +31 -0
- agent_env/cli/up.py +123 -0
- agent_env/cli/utils.py +183 -0
- agent_env/config/__init__.py +50 -0
- agent_env/config/describe.py +1067 -0
- agent_env/config/errors.py +13 -0
- agent_env/config/loader.py +245 -0
- agent_env/config/model.py +154 -0
- agent_env/config/paths.py +25 -0
- agent_env/config/plugin_tables.py +101 -0
- agent_env/config/provenance.py +134 -0
- agent_env/config/runtime.py +1064 -0
- agent_env/config/snapshot.py +81 -0
- agent_env/entity_refs.py +186 -0
- agent_env/env/__init__.py +49 -0
- agent_env/env/env.py +433 -0
- agent_env/env/env_artifact_store.py +87 -0
- agent_env/env/envs/__init__.py +7 -0
- agent_env/env/envs/_deployment.py +281 -0
- agent_env/env/envs/gateway_server.py +32 -0
- agent_env/env/envs/mcp_server.py +387 -0
- agent_env/env/envs/multi_env.py +780 -0
- agent_env/env/envs/service_db/Dockerfile +20 -0
- agent_env/env/envs/service_db/Dockerfile.db-mcp +42 -0
- agent_env/env/envs/service_db/Dockerfile.db-web +8 -0
- agent_env/env/envs/service_db.py +92 -0
- agent_env/env/envs/website.py +294 -0
- agent_env/env/envs/website_browser/Dockerfile +40 -0
- agent_env/env/envs/website_browser/__init__.py +17 -0
- agent_env/env/envs/website_browser/entrypoint.sh +13 -0
- agent_env/env/gateway/Dockerfile +14 -0
- agent_env/env/gateway/__init__.py +37 -0
- agent_env/env/gateway/clock.py +184 -0
- agent_env/env/gateway/constants.py +190 -0
- agent_env/env/gateway/entrypoint.py +156 -0
- agent_env/env/gateway/gateway.py +1095 -0
- agent_env/env/gateway/get_time.py +60 -0
- agent_env/env/gateway/requirements.txt +4 -0
- agent_env/env/gateway/triggers.py +1193 -0
- agent_env/env/legacy_protocol.py +146 -0
- agent_env/env/registry.py +93 -0
- agent_env/env/snapshot_store.py +372 -0
- agent_env/env/store.py +411 -0
- agent_env/eval/__init__.py +14 -0
- agent_env/eval/eval.py +68 -0
- agent_env/eval/store.py +116 -0
- agent_env/examples/hello/README.md +9 -0
- agent_env/examples/hello/artifacts/greeting/check.sh +1 -0
- agent_env/examples/hello/artifacts/greeting/hello.txt +1 -0
- agent_env/examples/hello/tasks/hello.json +10 -0
- agent_env/explorer/__init__.py +12 -0
- agent_env/explorer/app.py +277 -0
- agent_env/explorer/openapi_docs.py +242 -0
- agent_env/explorer/plugin.py +95 -0
- agent_env/explorer/routers/__init__.py +1 -0
- agent_env/explorer/routers/common.py +174 -0
- agent_env/explorer/routers/conversations.py +25 -0
- agent_env/explorer/routers/objects.py +112 -0
- agent_env/explorer/routers/runs.py +475 -0
- agent_env/plugins/__init__.py +59 -0
- agent_env/plugins/_cli.py +244 -0
- agent_env/plugins/_discovery.py +97 -0
- agent_env/plugins/_inventory.py +262 -0
- agent_env/plugins/_registration.py +268 -0
- agent_env/plugins/_report.py +47 -0
- agent_env/plugins/_requirements.py +55 -0
- agent_env/providers/__init__.py +37 -0
- agent_env/providers/env_providers/__init__.py +12 -0
- agent_env/providers/env_providers/constants.py +13 -0
- agent_env/providers/env_providers/env_gateway_provider.py +1354 -0
- agent_env/providers/env_providers/env_provider.py +237 -0
- agent_env/providers/env_providers/env_server_provider.py +133 -0
- agent_env/providers/env_state/__init__.py +49 -0
- agent_env/providers/env_state/env_state_provider.py +554 -0
- agent_env/providers/env_state/local_postgres.py +390 -0
- agent_env/providers/env_state/store.py +112 -0
- agent_env/providers/sandbox_providers/__init__.py +29 -0
- agent_env/providers/sandbox_providers/chained_sandbox_provider.py +93 -0
- agent_env/providers/sandbox_providers/e2b/__init__.py +6 -0
- agent_env/providers/sandbox_providers/e2b/provider.py +376 -0
- agent_env/providers/sandbox_providers/e2b/sandbox.py +342 -0
- agent_env/providers/sandbox_providers/e2b/template.py +158 -0
- agent_env/providers/sandbox_providers/local_sandbox.py +408 -0
- agent_env/providers/sandbox_providers/modal_sandbox.py +500 -0
- agent_env/providers/sandbox_providers/modal_vm_sandbox.py +466 -0
- agent_env/providers/sandbox_providers/sandbox.py +387 -0
- agent_env/providers/sandbox_providers/sandbox_provider.py +614 -0
- agent_env/py.typed +0 -0
- agent_env/runner/__init__.py +16 -0
- agent_env/runner/local_runner.py +190 -0
- agent_env/runner/runner.py +127 -0
- agent_env/runner/store.py +94 -0
- agent_env/store/__init__.py +126 -0
- agent_env/store/_google.py +68 -0
- agent_env/store/base.py +33 -0
- agent_env/store/document_store/__init__.py +60 -0
- agent_env/store/document_store/document_store.py +519 -0
- agent_env/store/document_store/dynamodb_document_store.py +306 -0
- agent_env/store/document_store/evaluation.py +199 -0
- agent_env/store/document_store/firestore_mongo_document_store.py +242 -0
- agent_env/store/document_store/mongo_document_store.py +259 -0
- agent_env/store/document_store/sqlite_document_store.py +314 -0
- agent_env/store/ids.py +123 -0
- agent_env/store/image_store/__init__.py +34 -0
- agent_env/store/image_store/ecr_image_store.py +131 -0
- agent_env/store/image_store/google_credentials.py +113 -0
- agent_env/store/image_store/image_store.py +113 -0
- agent_env/store/image_store/local_registry_image_store.py +106 -0
- agent_env/store/image_store/oci_registry_credentials.py +196 -0
- agent_env/store/local_state.py +27 -0
- agent_env/store/object_store/__init__.py +24 -0
- agent_env/store/object_store/gcs_object_store.py +415 -0
- agent_env/store/object_store/local_object_store.py +143 -0
- agent_env/store/object_store/object_store.py +198 -0
- agent_env/store/object_store/s3_object_store.py +354 -0
- agent_env/store/query.py +112 -0
- agent_env/store/routing.py +609 -0
- agent_env/store/secret_store/__init__.py +19 -0
- agent_env/store/secret_store/aws_secrets_manager_secret_store.py +293 -0
- agent_env/store/secret_store/gcp_secret_manager_secret_store.py +319 -0
- agent_env/store/secret_store/local_secret_store.py +47 -0
- agent_env/store/secret_store/secret_store.py +19 -0
- agent_env/task/__init__.py +27 -0
- agent_env/task/interrupts.py +109 -0
- agent_env/task/registry.py +27 -0
- agent_env/task/step_journal.py +99 -0
- agent_env/task/store.py +940 -0
- agent_env/task/task.py +815 -0
- agent_env/task/teardown.py +142 -0
- agent_env/task_step/__init__.py +47 -0
- agent_env/task_step/context.py +195 -0
- agent_env/task_step/context_ops.py +224 -0
- agent_env/task_step/registry.py +182 -0
- agent_env/task_step/review_store.py +118 -0
- agent_env/task_step/snapshot_utils/__init__.py +2 -0
- agent_env/task_step/snapshot_utils/agent_state_capture.py +261 -0
- agent_env/task_step/snapshot_utils/snapshot_series.py +631 -0
- agent_env/task_step/store.py +129 -0
- agent_env/task_step/task_step.py +173 -0
- agent_env/task_step/task_steps/__init__.py +27 -0
- agent_env/task_step/task_steps/a2a_agent_validator/__init__.py +31 -0
- agent_env/task_step/task_steps/a2a_agent_validator/fixtures/README.md +158 -0
- agent_env/task_step/task_steps/a2a_agent_validator/fixtures/clip.m4a +0 -0
- agent_env/task_step/task_steps/a2a_agent_validator/fixtures/clip.mp3 +0 -0
- agent_env/task_step/task_steps/a2a_agent_validator/fixtures/clip.mp4 +0 -0
- agent_env/task_step/task_steps/a2a_agent_validator/fixtures/clip.ogg +0 -0
- agent_env/task_step/task_steps/a2a_agent_validator/fixtures/clip.wav +0 -0
- agent_env/task_step/task_steps/a2a_agent_validator/fixtures/document.pdf +0 -0
- agent_env/task_step/task_steps/a2a_agent_validator/fixtures/red.gif +0 -0
- agent_env/task_step/task_steps/a2a_agent_validator/fixtures/red.jpg +0 -0
- agent_env/task_step/task_steps/a2a_agent_validator/fixtures/red.png +0 -0
- agent_env/task_step/task_steps/a2a_agent_validator/verify_a2a_agent_card.py +103 -0
- agent_env/task_step/task_steps/a2a_agent_validator/verify_a2a_agent_config_identity.py +69 -0
- agent_env/task_step/task_steps/a2a_agent_validator/verify_a2a_agent_mcp.py +178 -0
- agent_env/task_step/task_steps/a2a_agent_validator/verify_a2a_core_protocol.py +67 -0
- agent_env/task_step/task_steps/a2a_agent_validator/verify_a2a_install.py +115 -0
- agent_env/task_step/task_steps/a2a_agent_validator/verify_a2a_litellm_attribution.py +124 -0
- agent_env/task_step/task_steps/a2a_agent_validator/verify_a2a_litellm_attribution_runtime.py +173 -0
- agent_env/task_step/task_steps/a2a_agent_validator/verify_a2a_modalities.py +270 -0
- agent_env/task_step/task_steps/a2a_agent_validator/verify_a2a_peer_agents.py +102 -0
- agent_env/task_step/task_steps/a2a_agent_validator/verify_a2a_role.py +151 -0
- agent_env/task_step/task_steps/a2a_agent_validator/verify_a2a_skill_config.py +194 -0
- agent_env/task_step/task_steps/a2a_agent_validator/verify_a2a_snapshot.py +111 -0
- agent_env/task_step/task_steps/a2a_agent_validator/verify_a2a_system_prompt.py +215 -0
- agent_env/task_step/task_steps/a2a_agent_validator/verify_a2a_trajectory.py +164 -0
- agent_env/task_step/task_steps/add_skills.py +240 -0
- agent_env/task_step/task_steps/apply_server_config.py +288 -0
- agent_env/task_step/task_steps/collect_artifacts.py +940 -0
- agent_env/task_step/task_steps/deploy_agent.py +626 -0
- agent_env/task_step/task_steps/deploy_env.py +197 -0
- agent_env/task_step/task_steps/deploy_human_agent.py +100 -0
- agent_env/task_step/task_steps/deploy_sandbox.py +170 -0
- agent_env/task_step/task_steps/env_card_validator/__init__.py +4 -0
- agent_env/task_step/task_steps/env_card_validator/verify_env_card.py +109 -0
- agent_env/task_step/task_steps/env_card_validator/verify_env_core_protocol.py +108 -0
- agent_env/task_step/task_steps/install_agent.py +376 -0
- agent_env/task_step/task_steps/load_artifact.py +775 -0
- agent_env/task_step/task_steps/mcp_cli_builder/__init__.py +4 -0
- agent_env/task_step/task_steps/mcp_cli_builder/build_mcp_cli.py +201 -0
- agent_env/task_step/task_steps/mcp_cli_builder/codegen.py +627 -0
- agent_env/task_step/task_steps/mcp_env_validator/__init__.py +44 -0
- agent_env/task_step/task_steps/mcp_env_validator/validation_gate_aggregator.py +102 -0
- agent_env/task_step/task_steps/mcp_env_validator/verify_mcp_env_assessment.py +78 -0
- agent_env/task_step/task_steps/mcp_env_validator/verify_mcp_tool_schema.py +152 -0
- agent_env/task_step/task_steps/mcp_env_validator/verify_spec_conformance.py +486 -0
- agent_env/task_step/task_steps/modify_env_tool_access.py +80 -0
- agent_env/task_step/task_steps/multienv_validator/__init__.py +3 -0
- agent_env/task_step/task_steps/multienv_validator/combine_universe_verdicts.py +107 -0
- agent_env/task_step/task_steps/multienv_validator/universe_comparison.py +253 -0
- agent_env/task_step/task_steps/multienv_validator/verify_universe_agent_judge.py +180 -0
- agent_env/task_step/task_steps/multienv_validator/verify_universe_roundtrip.py +241 -0
- agent_env/task_step/task_steps/peer_agents.py +92 -0
- agent_env/task_step/task_steps/prompt_agent.py +900 -0
- agent_env/task_step/task_steps/register_agent_triggers.py +113 -0
- agent_env/task_step/task_steps/register_env_triggers.py +97 -0
- agent_env/task_step/task_steps/reset_env.py +71 -0
- agent_env/task_step/task_steps/review.py +152 -0
- agent_env/task_step/task_steps/run_code.py +461 -0
- agent_env/task_step/task_steps/run_code_runner.py +52 -0
- agent_env/task_step/task_steps/run_docker_container.py +380 -0
- agent_env/task_step/task_steps/sandbox_utils/__init__.py +0 -0
- agent_env/task_step/task_steps/sandbox_utils/sandbox_utils.py +79 -0
- agent_env/task_step/task_steps/snapshot_agent_state.py +205 -0
- agent_env/task_step/task_steps/snapshot_env.py +637 -0
- agent_env/task_step/task_steps/sync_env_clock.py +132 -0
- agent_env/task_step/task_steps/teardown_sandboxes.py +170 -0
- agent_env/task_step/task_steps/verifiers/__init__.py +23 -0
- agent_env/task_step/task_steps/verifiers/agent_prompt_response_verifier.py +166 -0
- agent_env/task_step/task_steps/verifiers/aggregate_verifiers.py +90 -0
- agent_env/task_step/task_steps/verifiers/env_outcome_verifier.py +127 -0
- agent_env/task_step/task_steps/verifiers/judge_utils/__init__.py +2 -0
- agent_env/task_step/task_steps/verifiers/judge_utils/frame_selection.py +377 -0
- agent_env/task_step/task_steps/verifiers/judge_utils/judge_output_format.py +1293 -0
- agent_env/task_step/task_steps/verifiers/judge_utils/trajectory_filter.py +514 -0
- agent_env/task_step/task_steps/verifiers/rubrics_verifier.py +1318 -0
- agent_env/task_step/task_steps/verifiers/run_container_unit_tests_verifier.py +434 -0
- agent_env/task_step/task_steps/verifiers/scoring.py +40 -0
- agent_env/task_step/task_steps/verifiers/verify_sandbox.py +308 -0
- agent_env/task_step/thread_work.py +61 -0
- agent_env/utils/__init__.py +0 -0
- agent_env/utils/card_naming.py +108 -0
- agent_env/utils/deprecation.py +109 -0
- agent_env/utils/docker_build.py +29 -0
- agent_env/utils/exec_retry.py +77 -0
- agent_env/utils/litellm_attribution.py +59 -0
- agent_env/utils/paths.py +20 -0
- agentenv_framework-0.9.1254.dist-info/METADATA +394 -0
- agentenv_framework-0.9.1254.dist-info/RECORD +312 -0
- agentenv_framework-0.9.1254.dist-info/WHEEL +4 -0
- agentenv_framework-0.9.1254.dist-info/entry_points.txt +5 -0
- agentenv_framework-0.9.1254.dist-info/licenses/LICENSE +202 -0
- agentenv_framework-0.9.1254.dist-info/licenses/NOTICE +4 -0
- agentenv_framework-0.9.1254.dist-info/licenses/THIRD_PARTY_NOTICES.md +7665 -0
|
@@ -0,0 +1,404 @@
|
|
|
1
|
+
"""Rewrite each reference in a parsed bundle to the id it names, before anything is built or written.
|
|
2
|
+
|
|
3
|
+
References are the fields step types declare in ``entity_refs`` and the toml keys entity types declare
|
|
4
|
+
in ``toml_refs``. The name of one of this bundle's entities becomes that entity's id, a name an output
|
|
5
|
+
of the same task writes becomes the output's id, and anything else is a store id, left as written;
|
|
6
|
+
whether store ids exist is checked later, with the other checks that read a store.
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
from __future__ import annotations
|
|
10
|
+
|
|
11
|
+
import copy
|
|
12
|
+
import unicodedata
|
|
13
|
+
from collections.abc import Iterator
|
|
14
|
+
from dataclasses import dataclass
|
|
15
|
+
from pathlib import Path
|
|
16
|
+
from typing import Any
|
|
17
|
+
|
|
18
|
+
from agent_env.a2a_agent import A2AAgent
|
|
19
|
+
from agent_env.artifact.registry import canonical_type, get_artifact_registry
|
|
20
|
+
from agent_env.entity_refs import EntityKind, EntityRef, RefRole, RefSite, parse_toml_ref, ref_sites
|
|
21
|
+
from agent_env.env.registry import get_env_registry
|
|
22
|
+
from agent_env.eval.eval import Eval
|
|
23
|
+
from agent_env.plugins import _registration
|
|
24
|
+
from agent_env.store.ids import LOCAL_PREFIX, validate_local_id
|
|
25
|
+
from agent_env.task_step.registry import get_task_step_registry
|
|
26
|
+
from agent_env.task_step.task_step import TaskStep, attach_retry_config
|
|
27
|
+
|
|
28
|
+
from ._fs import fold, relative, show
|
|
29
|
+
from .parse import NAMED_BY, Bundle, BundleEntry, BundleError, BundleKind
|
|
30
|
+
|
|
31
|
+
# Step keys that hold step ids, never entity ids.
|
|
32
|
+
_STEP_ID_KEYS = ("id", "type", "depends_on")
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
@dataclass(frozen=True)
|
|
36
|
+
class BuiltImage:
|
|
37
|
+
"""The image built from an env or agent folder for one of its image keys."""
|
|
38
|
+
|
|
39
|
+
id: str
|
|
40
|
+
entry: BundleEntry
|
|
41
|
+
dockerfile: str # relative to the entry's folder
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
@dataclass(frozen=True)
|
|
45
|
+
class Reference:
|
|
46
|
+
"""A resolved reference: to ``local``, this bundle's entity or built image, or, when ``local`` is
|
|
47
|
+
None, to a store id at ``version`` (None for its latest)."""
|
|
48
|
+
|
|
49
|
+
kind: EntityKind
|
|
50
|
+
id: str
|
|
51
|
+
version: int | None
|
|
52
|
+
local: BundleEntry | BuiltImage | None
|
|
53
|
+
where: str # the referencing field, as problems name it
|
|
54
|
+
artifact_type: str | None # the type the field takes, when it names one
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
@dataclass(frozen=True)
|
|
58
|
+
class Output:
|
|
59
|
+
"""An id a task's step writes, named under the task."""
|
|
60
|
+
|
|
61
|
+
kind: EntityKind
|
|
62
|
+
id: str
|
|
63
|
+
step: int # the writing step's index in the task
|
|
64
|
+
step_id: Any
|
|
65
|
+
artifact_type: str | None
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
@dataclass(frozen=True)
|
|
69
|
+
class ResolvedEntry:
|
|
70
|
+
"""An entry's config as a copy with every declared reference rewritten, what it references, and
|
|
71
|
+
for a task what its steps write."""
|
|
72
|
+
|
|
73
|
+
entry: BundleEntry
|
|
74
|
+
config: Any
|
|
75
|
+
references: tuple[Reference, ...]
|
|
76
|
+
outputs: tuple[Output, ...]
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
@dataclass(frozen=True)
|
|
80
|
+
class ResolvedBundle:
|
|
81
|
+
bundle: Bundle
|
|
82
|
+
entries: tuple[ResolvedEntry, ...]
|
|
83
|
+
built_images: tuple[BuiltImage, ...]
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
def resolve_bundle(bundle: Bundle) -> ResolvedBundle:
|
|
87
|
+
"""Resolve every entry's references. Raises BundleError listing every problem found."""
|
|
88
|
+
return _Resolver(bundle).resolve()
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
class _Skip(Exception):
|
|
92
|
+
"""An entry that can't be resolved; its problem is already recorded."""
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
class _Resolver:
|
|
96
|
+
def __init__(self, bundle: Bundle):
|
|
97
|
+
self.bundle = bundle
|
|
98
|
+
self.problems: list[str] = []
|
|
99
|
+
self.built: list[BuiltImage] = []
|
|
100
|
+
# By kind and exact name or id, by kind and folded name, and by folded name across the kinds a
|
|
101
|
+
# step can name (steps never name tasks or evals).
|
|
102
|
+
self.named: dict[tuple[EntityKind, str], BundleEntry] = {}
|
|
103
|
+
self.folded: dict[tuple[EntityKind, str], BundleEntry] = {}
|
|
104
|
+
stepped = {bundle_kind for kind in (EntityKind.ENV, EntityKind.AGENT, EntityKind.ARTIFACT)
|
|
105
|
+
for bundle_kind in NAMED_BY[kind]}
|
|
106
|
+
self.step_named = {fold(entry.name): entry for entry in bundle.entries if entry.kind in stepped}
|
|
107
|
+
self.ignored: dict[tuple[EntityKind, str], Path] = {}
|
|
108
|
+
for kind, bundle_kinds in NAMED_BY.items():
|
|
109
|
+
for entry in bundle.entries:
|
|
110
|
+
if entry.kind in bundle_kinds:
|
|
111
|
+
self.named[kind, _nfc(entry.name)] = self.named[kind, _nfc(entry.id)] = entry
|
|
112
|
+
self.folded[kind, fold(entry.name)] = self.folded[kind, fold(entry.id)] = entry
|
|
113
|
+
folders = {bundle_kind.value for bundle_kind in bundle_kinds}
|
|
114
|
+
for path in bundle.ignored:
|
|
115
|
+
if len(path.parts) == 2 and path.parts[0] in folders:
|
|
116
|
+
for name in (path.name, path.stem):
|
|
117
|
+
self.ignored[kind, fold(name)] = path
|
|
118
|
+
|
|
119
|
+
def resolve(self) -> ResolvedBundle:
|
|
120
|
+
resolved = []
|
|
121
|
+
for entry in self.bundle.entries:
|
|
122
|
+
try:
|
|
123
|
+
resolved.append(self._task(entry) if entry.kind is BundleKind.TASK else self._toml(entry))
|
|
124
|
+
except _Skip:
|
|
125
|
+
pass
|
|
126
|
+
if self.problems:
|
|
127
|
+
raise BundleError(self.problems)
|
|
128
|
+
return ResolvedBundle(self.bundle, tuple(resolved), tuple(self.built))
|
|
129
|
+
|
|
130
|
+
# One method per kind of config
|
|
131
|
+
|
|
132
|
+
def _toml(self, entry: BundleEntry) -> ResolvedEntry:
|
|
133
|
+
config = copy.deepcopy(entry.config)
|
|
134
|
+
if not isinstance(config, dict):
|
|
135
|
+
return ResolvedEntry(entry, config, (), ())
|
|
136
|
+
references: list[Reference] = []
|
|
137
|
+
refs = []
|
|
138
|
+
for ref in getattr(self._toml_class(entry), "toml_refs", ()):
|
|
139
|
+
if not self._image(entry, config, ref, references):
|
|
140
|
+
refs.append(ref)
|
|
141
|
+
for site in ref_sites(refs, config, inline_pins=True):
|
|
142
|
+
try:
|
|
143
|
+
name, version = parse_toml_ref(site.ref.kind, site.owner if site.version_key else site.value)
|
|
144
|
+
except ValueError as e:
|
|
145
|
+
self._problem(entry, f"{site.path}: {e}")
|
|
146
|
+
continue
|
|
147
|
+
self._resolve(entry, site, site.path, name, version, {}, set(), references)
|
|
148
|
+
if entry.kind is BundleKind.EVAL:
|
|
149
|
+
self._refuse_repeated_tasks(entry, references)
|
|
150
|
+
return ResolvedEntry(entry, config, tuple(references), ())
|
|
151
|
+
|
|
152
|
+
def _refuse_repeated_tasks(self, entry: BundleEntry, references: list[Reference]) -> None:
|
|
153
|
+
first: dict[str, str] = {}
|
|
154
|
+
for ref in references:
|
|
155
|
+
where = ref.where.partition(".")[0]
|
|
156
|
+
if ref.id in first:
|
|
157
|
+
task = f"this bundle's task {ref.local.name!r}" if ref.local is not None else repr(ref.id)
|
|
158
|
+
self._problem(entry, f"{where}: {task} is also {first[ref.id]}; an eval lists each task once "
|
|
159
|
+
"(for repeat runs, use agent-env eval run --k)")
|
|
160
|
+
else:
|
|
161
|
+
first[ref.id] = where
|
|
162
|
+
|
|
163
|
+
def _task(self, entry: BundleEntry) -> ResolvedEntry:
|
|
164
|
+
steps = copy.deepcopy(entry.config)
|
|
165
|
+
registry = get_task_step_registry()
|
|
166
|
+
declared = []
|
|
167
|
+
for index, step in enumerate(steps):
|
|
168
|
+
step_type = step.get("type")
|
|
169
|
+
cls = registry.get(step_type) if isinstance(step_type, str) else None
|
|
170
|
+
if cls is None:
|
|
171
|
+
note = _registration.failure_note(_registration.TASK_STEPS, step_type) if isinstance(step_type, str) else ""
|
|
172
|
+
self._problem(entry, f"step {step.get('id')!r}: {step_type!r} is not a known step type{note}")
|
|
173
|
+
elif self._derived_outputs(entry, step, cls):
|
|
174
|
+
declared.append((index, step, cls))
|
|
175
|
+
outputs = self._outputs(entry, declared)
|
|
176
|
+
upstream = _upstream(steps)
|
|
177
|
+
references: list[Reference] = []
|
|
178
|
+
for index, step, cls in declared:
|
|
179
|
+
where = f"step {step.get('id')!r}: "
|
|
180
|
+
if cls.entity_refs is None:
|
|
181
|
+
self._undeclared(entry, step, cls, outputs, where)
|
|
182
|
+
continue
|
|
183
|
+
for site in ref_sites(cls.entity_refs, step):
|
|
184
|
+
if site.ref.role is RefRole.OUTPUT:
|
|
185
|
+
continue
|
|
186
|
+
if not (isinstance(site.value, str) and site.value):
|
|
187
|
+
self._problem(entry, f"{where}{site.path} must be an id, not {site.value!r}")
|
|
188
|
+
continue
|
|
189
|
+
self._resolve(entry, site, f"{where}{site.path}", site.value, site.version, outputs, upstream[index],
|
|
190
|
+
references)
|
|
191
|
+
return ResolvedEntry(entry, steps, tuple(references), tuple(outputs.values()))
|
|
192
|
+
|
|
193
|
+
# Parts of a config
|
|
194
|
+
|
|
195
|
+
def _toml_class(self, entry: BundleEntry) -> type:
|
|
196
|
+
group = None
|
|
197
|
+
if entry.kind is BundleKind.ENV:
|
|
198
|
+
cls, group = get_env_registry().get(entry.type), _registration.ENVS
|
|
199
|
+
elif entry.kind is BundleKind.AGENT:
|
|
200
|
+
cls = A2AAgent if entry.type == A2AAgent.type else None
|
|
201
|
+
elif entry.kind is BundleKind.EVAL:
|
|
202
|
+
cls = Eval if entry.type == Eval.type else None
|
|
203
|
+
else:
|
|
204
|
+
cls, group = get_artifact_registry().get(canonical_type(entry.type)), _registration.ARTIFACTS
|
|
205
|
+
if cls is None:
|
|
206
|
+
name = canonical_type(entry.type) if group == _registration.ARTIFACTS else entry.type
|
|
207
|
+
note = _registration.failure_note(group, name) if group else ""
|
|
208
|
+
self._problem(entry, f"{entry.type!r} is not a known {entry.kind.store} type{note}")
|
|
209
|
+
raise _Skip
|
|
210
|
+
return cls
|
|
211
|
+
|
|
212
|
+
def _image(self, entry: BundleEntry, config: dict, ref: EntityRef, references: list[Reference]) -> bool:
|
|
213
|
+
"""Record the image an image key builds: the folder's Dockerfile when ``image`` is left out, or
|
|
214
|
+
``{ dockerfile = "<path>" }``. False when the key names an image artifact instead."""
|
|
215
|
+
if ref.artifact_type != "docker_image" or ref.path != ref.field:
|
|
216
|
+
return False
|
|
217
|
+
value = config.get(ref.path)
|
|
218
|
+
if isinstance(value, dict) and "ref" in value:
|
|
219
|
+
self._problem(entry, f"{ref.path}: an external image ({{ ref = ... }}) isn't supported yet")
|
|
220
|
+
return True
|
|
221
|
+
if value is None and ref.path == "image":
|
|
222
|
+
dockerfile = "Dockerfile"
|
|
223
|
+
elif isinstance(value, dict) and value.keys() == {"dockerfile"}:
|
|
224
|
+
dockerfile = value["dockerfile"]
|
|
225
|
+
else:
|
|
226
|
+
return False
|
|
227
|
+
path = entry.path / dockerfile if isinstance(dockerfile, str) and dockerfile else None
|
|
228
|
+
inside = path is not None and not Path(dockerfile).is_absolute() and path.resolve().is_relative_to(entry.path.resolve())
|
|
229
|
+
if not (inside and path.is_file()):
|
|
230
|
+
self._problem(entry, f"{ref.path}: there is no {dockerfile!r} in this folder to build")
|
|
231
|
+
return True
|
|
232
|
+
role = f"{entry.kind.store}_image" if ref.path == "image" else ref.path
|
|
233
|
+
image = BuiltImage(f"{entry.id}__{role}", entry, dockerfile)
|
|
234
|
+
config[ref.path] = image.id
|
|
235
|
+
self.built.append(image)
|
|
236
|
+
references.append(Reference(EntityKind.ARTIFACT, image.id, None, image, ref.path, ref.artifact_type))
|
|
237
|
+
return True
|
|
238
|
+
|
|
239
|
+
def _derived_outputs(self, entry: BundleEntry, step: dict, cls: type) -> bool:
|
|
240
|
+
"""Write in any output id the step's type derives when the field is left out (build_mcp_cli's
|
|
241
|
+
``cli-<env_id>``), so it's named like one written out. False when its type can't read the step."""
|
|
242
|
+
absent = [ref for ref in cls.entity_refs or ()
|
|
243
|
+
if ref.role is RefRole.OUTPUT and ref.path == ref.field and step.get(ref.field) is None]
|
|
244
|
+
if not absent:
|
|
245
|
+
return True
|
|
246
|
+
try:
|
|
247
|
+
read = build_step(step).to_dict()
|
|
248
|
+
except Exception as e:
|
|
249
|
+
self._problem(entry, f"step {step.get('id')!r}: {cls.type} can't read it ({type(e).__name__}: {e})")
|
|
250
|
+
return False
|
|
251
|
+
for ref in absent:
|
|
252
|
+
if read.get(ref.field) is not None:
|
|
253
|
+
step[ref.field] = read[ref.field]
|
|
254
|
+
return True
|
|
255
|
+
|
|
256
|
+
def _outputs(self, entry: BundleEntry, declared: list[tuple[int, dict, type]]) -> dict[tuple[EntityKind, str], Output]:
|
|
257
|
+
"""Name each id a step writes under its task, keyed by kind and the name as written."""
|
|
258
|
+
outputs: dict[tuple[EntityKind, str], Output] = {}
|
|
259
|
+
for index, step, cls in declared:
|
|
260
|
+
refs = [ref for ref in cls.entity_refs or () if ref.role is RefRole.OUTPUT]
|
|
261
|
+
for site in ref_sites(refs, step):
|
|
262
|
+
where, name, kind = f"step {step.get('id')!r}: {site.path}", site.value, site.ref.kind
|
|
263
|
+
if not (isinstance(name, str) and name):
|
|
264
|
+
self._problem(entry, f"{where} must be an id, not {name!r}")
|
|
265
|
+
continue
|
|
266
|
+
name = _nfc(name)
|
|
267
|
+
clash = self.named.get((kind, name)) or self.folded.get((kind, fold(name)))
|
|
268
|
+
if clash is not None:
|
|
269
|
+
self._problem(entry, f"{where}: {name!r} is written by this step and is also this bundle's "
|
|
270
|
+
f"{kind.value} {clash.name!r}; rename one")
|
|
271
|
+
continue
|
|
272
|
+
if (kind, name) in outputs:
|
|
273
|
+
self._problem(entry, f"{where}: {name!r} is also written by step "
|
|
274
|
+
f"{outputs[kind, name].step_id!r}; give each output its own name")
|
|
275
|
+
continue
|
|
276
|
+
output_id = name if name.startswith(LOCAL_PREFIX) else f"{entry.id}/{name}"
|
|
277
|
+
try:
|
|
278
|
+
validate_local_id(output_id)
|
|
279
|
+
except ValueError as e:
|
|
280
|
+
self._problem(entry, f"{where}: {e}")
|
|
281
|
+
continue
|
|
282
|
+
site.rewrite(output_id)
|
|
283
|
+
outputs[kind, name] = Output(kind, output_id, index, step.get("id"), site.ref.artifact_type)
|
|
284
|
+
return outputs
|
|
285
|
+
|
|
286
|
+
def _resolve(self, entry: BundleEntry, site: RefSite, where: str, name: str, version: int | None,
|
|
287
|
+
outputs: dict[tuple[EntityKind, str], Output], upstream: set[int],
|
|
288
|
+
references: list[Reference]) -> None:
|
|
289
|
+
kind, expected, key = site.ref.kind, site.ref.artifact_type, _nfc(name)
|
|
290
|
+
output = outputs.get((kind, key))
|
|
291
|
+
if output is not None:
|
|
292
|
+
if output.step not in upstream:
|
|
293
|
+
self._problem(entry, f"{where}: {name!r} is written by step {output.step_id!r}, which this step "
|
|
294
|
+
"doesn't depend on")
|
|
295
|
+
elif version is not None:
|
|
296
|
+
self._problem(entry, f"{where}: {name!r} is written by this task, so it has no fixed version; "
|
|
297
|
+
"drop the pin")
|
|
298
|
+
elif expected and output.artifact_type and not _same_type(output.artifact_type, expected):
|
|
299
|
+
self._problem(entry, f"{where}: this task writes {name!r} as {output.artifact_type}, but this field "
|
|
300
|
+
f"takes {expected}")
|
|
301
|
+
else:
|
|
302
|
+
site.rewrite(output.id)
|
|
303
|
+
return
|
|
304
|
+
local = self.named.get((kind, key))
|
|
305
|
+
if local is not None:
|
|
306
|
+
if version is not None:
|
|
307
|
+
self._problem(entry, f"{where}: {name!r} is defined in this bundle, so it has no fixed version; "
|
|
308
|
+
"drop the pin")
|
|
309
|
+
elif expected and not _same_type(local.type, expected):
|
|
310
|
+
self._problem(entry, f"{where}: {name!r} is this bundle's {local.type}, but this field takes {expected}")
|
|
311
|
+
else:
|
|
312
|
+
site.rewrite(local.id)
|
|
313
|
+
references.append(Reference(kind, local.id, None, local, where, expected))
|
|
314
|
+
return
|
|
315
|
+
near = self.folded.get((kind, fold(name)))
|
|
316
|
+
if near is not None:
|
|
317
|
+
near_name = near.id if fold(name) == fold(near.id) else near.name
|
|
318
|
+
else:
|
|
319
|
+
near_name = next((n for k, n in outputs if k is kind and fold(n) == fold(name)), None)
|
|
320
|
+
ignored = self.ignored.get((kind, fold(name)))
|
|
321
|
+
if near_name is not None:
|
|
322
|
+
self._problem(entry, f"{where}: {name!r} isn't in this bundle, but {near_name!r} is; names are "
|
|
323
|
+
"case-sensitive")
|
|
324
|
+
elif ignored is not None:
|
|
325
|
+
self._problem(entry, f"{where}: {name!r} names {show(ignored)}, which this bundle ignores")
|
|
326
|
+
else:
|
|
327
|
+
references.append(Reference(kind, name, version, None, where, expected))
|
|
328
|
+
|
|
329
|
+
def _undeclared(self, entry: BundleEntry, step: dict, cls: type, outputs: dict[tuple[EntityKind, str], Output],
|
|
330
|
+
where: str) -> None:
|
|
331
|
+
"""A step type that declares no references passes through, unless it repeats a bundle name that
|
|
332
|
+
it can't have rewritten."""
|
|
333
|
+
written = {fold(name) for _, name in outputs}
|
|
334
|
+
for path, value in _strings(step):
|
|
335
|
+
match = self.step_named.get(fold(value))
|
|
336
|
+
if match is not None:
|
|
337
|
+
named = f"this bundle's {match.kind.store} {match.name!r}"
|
|
338
|
+
elif fold(value) in written:
|
|
339
|
+
named = "an output of this task"
|
|
340
|
+
else:
|
|
341
|
+
continue
|
|
342
|
+
self._problem(entry, f"{where}{path} = {value!r} names {named}, but {cls.type} doesn't declare its "
|
|
343
|
+
"entity_refs, so it can't be rewritten")
|
|
344
|
+
|
|
345
|
+
def _problem(self, entry: BundleEntry, message: str) -> None:
|
|
346
|
+
self.problems.append(f"{relative(self.bundle.root, entry.path)}: {message}")
|
|
347
|
+
|
|
348
|
+
|
|
349
|
+
def build_step(step: dict) -> TaskStep:
|
|
350
|
+
"""The step a task's write puts, built from a copy of ``step``, so the resolved config the ledger hashes
|
|
351
|
+
never changes."""
|
|
352
|
+
step = copy.deepcopy(step)
|
|
353
|
+
return attach_retry_config(get_task_step_registry()[step["type"]].from_dict(step), step)
|
|
354
|
+
|
|
355
|
+
|
|
356
|
+
def _nfc(name: str) -> str:
|
|
357
|
+
"""The form names are compared in: the parser's entity names are NFC, as authored text may not be."""
|
|
358
|
+
return unicodedata.normalize("NFC", name)
|
|
359
|
+
|
|
360
|
+
|
|
361
|
+
def _upstream(steps: list[dict]) -> list[set[int]]:
|
|
362
|
+
"""The indexes of the steps each step runs after: its ``depends_on`` or, when it has none, every
|
|
363
|
+
step before it, followed transitively; the rule the task scheduler runs steps by."""
|
|
364
|
+
index_of: dict[str, int] = {}
|
|
365
|
+
for index, step in enumerate(steps):
|
|
366
|
+
if isinstance(step.get("id"), str):
|
|
367
|
+
index_of.setdefault(step["id"], index)
|
|
368
|
+
direct = []
|
|
369
|
+
for index, step in enumerate(steps):
|
|
370
|
+
raw = step.get("depends_on")
|
|
371
|
+
if raw is None:
|
|
372
|
+
direct.append(set(range(index)))
|
|
373
|
+
continue
|
|
374
|
+
ids = [dep.get("task_step_id") for dep in raw if isinstance(dep, dict)] if isinstance(raw, list) else []
|
|
375
|
+
direct.append({index_of[dep_id] for dep_id in ids if dep_id in index_of})
|
|
376
|
+
upstream = []
|
|
377
|
+
for index in range(len(steps)):
|
|
378
|
+
seen: set[int] = set()
|
|
379
|
+
frontier = list(direct[index])
|
|
380
|
+
while frontier:
|
|
381
|
+
current = frontier.pop()
|
|
382
|
+
if current not in seen:
|
|
383
|
+
seen.add(current)
|
|
384
|
+
frontier.extend(direct[current])
|
|
385
|
+
upstream.append(seen)
|
|
386
|
+
return upstream
|
|
387
|
+
|
|
388
|
+
|
|
389
|
+
def _same_type(artifact_type: str, expected: str) -> bool:
|
|
390
|
+
return canonical_type(artifact_type) == canonical_type(expected)
|
|
391
|
+
|
|
392
|
+
|
|
393
|
+
def _strings(value: Any, path: str = "") -> Iterator[tuple[str, str]]:
|
|
394
|
+
"""Every string in a step with its path, except under the keys that hold step ids."""
|
|
395
|
+
if isinstance(value, str):
|
|
396
|
+
yield path, value
|
|
397
|
+
elif isinstance(value, dict):
|
|
398
|
+
for key, item in value.items():
|
|
399
|
+
if (not path and key in _STEP_ID_KEYS) or str(key).endswith(("_step_id", "_step_ids")):
|
|
400
|
+
continue
|
|
401
|
+
yield from _strings(item, f"{path}.{key}" if path else str(key))
|
|
402
|
+
elif isinstance(value, list):
|
|
403
|
+
for i, item in enumerate(value):
|
|
404
|
+
yield from _strings(item, f"{path}[{i}]")
|