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,102 @@
|
|
|
1
|
+
"""Rolls the per-verifier verdicts under ``context.metadata["verifications"]``
|
|
2
|
+
(``mcp_tool_schema``, ``mcp_tool_correctness``) into one
|
|
3
|
+
``validation_gate`` verdict, persisted to context + env metadata so ``mcp-server put``
|
|
4
|
+
reads a single field.
|
|
5
|
+
|
|
6
|
+
Record-only: never raises, so ``validate()`` runs to completion and enforcement stays
|
|
7
|
+
in one place (``put``). A required gate with no verdict is a failure (fail-closed); a
|
|
8
|
+
gate that reported itself ``skipped`` (nothing to check) is advisory and does not block.
|
|
9
|
+
"""
|
|
10
|
+
|
|
11
|
+
from __future__ import annotations
|
|
12
|
+
|
|
13
|
+
import logging
|
|
14
|
+
from typing import ClassVar, Optional
|
|
15
|
+
|
|
16
|
+
from agent_env.task_step.context import TaskStepContext
|
|
17
|
+
from agent_env.entity_refs import EntityRef
|
|
18
|
+
from agent_env.task_step.task_step import TaskStep, TaskStepDependency
|
|
19
|
+
|
|
20
|
+
logger = logging.getLogger(__name__)
|
|
21
|
+
|
|
22
|
+
# Live-server gates required to publish. Unit tests are checked separately at `put`.
|
|
23
|
+
# (build-time artifact); the environment card is advisory and not required here.
|
|
24
|
+
DEFAULT_REQUIRED_GATES = ("mcp_tool_schema", "mcp_tool_correctness")
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
def aggregate_gate(verifications: dict, required_gates) -> dict:
|
|
28
|
+
"""Roll up per-gate verdicts (gate-key → ``{"passed": bool}``) into
|
|
29
|
+
``{passed, required_gates, failed_gates, missing_gates, skipped_gates}``. A gate
|
|
30
|
+
absent from ``verifications`` fails the aggregate; one whose verdict is ``skipped``
|
|
31
|
+
(verifier ran, nothing to check) is advisory and doesn't block.
|
|
32
|
+
"""
|
|
33
|
+
verifications = verifications or {}
|
|
34
|
+
failed, missing, skipped = [], [], []
|
|
35
|
+
for gate in required_gates:
|
|
36
|
+
v = verifications.get(gate)
|
|
37
|
+
if v is None:
|
|
38
|
+
missing.append(gate)
|
|
39
|
+
elif v.get("skipped"):
|
|
40
|
+
skipped.append(gate)
|
|
41
|
+
elif not v.get("passed", False):
|
|
42
|
+
failed.append(gate)
|
|
43
|
+
return {
|
|
44
|
+
"passed": not failed and not missing,
|
|
45
|
+
"required_gates": list(required_gates),
|
|
46
|
+
"failed_gates": failed,
|
|
47
|
+
"missing_gates": missing,
|
|
48
|
+
"skipped_gates": skipped,
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
class ValidationGateAggregatorStep(TaskStep):
|
|
53
|
+
type: ClassVar[str] = "validation_gate_aggregator"
|
|
54
|
+
entity_refs = (EntityRef.env("env_id"),)
|
|
55
|
+
|
|
56
|
+
def __init__(
|
|
57
|
+
self,
|
|
58
|
+
id: str,
|
|
59
|
+
version: Optional[int],
|
|
60
|
+
env_id: str,
|
|
61
|
+
required_gates: Optional[list[str]] = None,
|
|
62
|
+
depends_on: Optional[list[TaskStepDependency]] = None,
|
|
63
|
+
fail_task_on_error: bool = True,
|
|
64
|
+
):
|
|
65
|
+
super().__init__(id, version, depends_on=depends_on, fail_task_on_error=fail_task_on_error)
|
|
66
|
+
self.env_id = env_id
|
|
67
|
+
self.required_gates = list(required_gates) if required_gates else list(DEFAULT_REQUIRED_GATES)
|
|
68
|
+
|
|
69
|
+
def to_dict(self) -> dict:
|
|
70
|
+
base = super().to_dict()
|
|
71
|
+
base["env_id"] = self.env_id
|
|
72
|
+
base["required_gates"] = self.required_gates
|
|
73
|
+
return base
|
|
74
|
+
|
|
75
|
+
@classmethod
|
|
76
|
+
def from_dict(cls, data: dict) -> "ValidationGateAggregatorStep":
|
|
77
|
+
return cls(
|
|
78
|
+
**cls._base_from_dict(data),
|
|
79
|
+
env_id=data["env_id"],
|
|
80
|
+
required_gates=data.get("required_gates"),
|
|
81
|
+
)
|
|
82
|
+
|
|
83
|
+
async def execute(self, context: TaskStepContext) -> TaskStepContext:
|
|
84
|
+
from agent_env.env.env import Env
|
|
85
|
+
|
|
86
|
+
summary = aggregate_gate(context.metadata.get("verifications", {}), self.required_gates)
|
|
87
|
+
logger.info(
|
|
88
|
+
f"Validation gate for '{self.env_id}': passed={summary['passed']} "
|
|
89
|
+
f"failed={summary['failed_gates']} missing={summary['missing_gates']} "
|
|
90
|
+
f"skipped={summary['skipped_gates']}"
|
|
91
|
+
)
|
|
92
|
+
context.metadata["validation_gate"] = summary
|
|
93
|
+
|
|
94
|
+
# Persist to env metadata so `put` / the CLI can read the verdict directly.
|
|
95
|
+
try:
|
|
96
|
+
deployed = next((d for d in context.deployed_envs if d.env_id == self.env_id), None)
|
|
97
|
+
env = Env.get(self.env_id, deployed.env_version if deployed else None)
|
|
98
|
+
env.merge_metadata({"validation_gate": summary})
|
|
99
|
+
except Exception as e: # pragma: no cover - metadata persistence is best-effort
|
|
100
|
+
logger.warning(f"Could not persist validation_gate to env metadata: {e}")
|
|
101
|
+
|
|
102
|
+
return context
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
"""Assess MCP tool correctness from an agent's structured response."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import json
|
|
6
|
+
import logging
|
|
7
|
+
from typing import Any, ClassVar, Optional
|
|
8
|
+
|
|
9
|
+
from agent_env.task_step.context import TaskStepContext
|
|
10
|
+
from agent_env.entity_refs import EntityRef
|
|
11
|
+
from agent_env.task_step.task_step import TaskStep, TaskStepDependency
|
|
12
|
+
|
|
13
|
+
logger = logging.getLogger(__name__)
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
class VerifyMCPEnvAssessmentStep(TaskStep):
|
|
17
|
+
type: ClassVar[str] = "verify_mcp_env_assessment"
|
|
18
|
+
entity_refs = (EntityRef.env("env_id"),)
|
|
19
|
+
|
|
20
|
+
def __init__(
|
|
21
|
+
self,
|
|
22
|
+
id: str,
|
|
23
|
+
version: Optional[int],
|
|
24
|
+
env_id: str,
|
|
25
|
+
prompt_id: str,
|
|
26
|
+
depends_on: Optional[list[TaskStepDependency]] = None,
|
|
27
|
+
fail_task_on_error: bool = True,
|
|
28
|
+
):
|
|
29
|
+
super().__init__(id, version, depends_on=depends_on, fail_task_on_error=fail_task_on_error)
|
|
30
|
+
self.env_id = env_id
|
|
31
|
+
self.prompt_id = prompt_id
|
|
32
|
+
|
|
33
|
+
def to_dict(self) -> dict:
|
|
34
|
+
base = super().to_dict()
|
|
35
|
+
base["env_id"] = self.env_id
|
|
36
|
+
base["prompt_id"] = self.prompt_id
|
|
37
|
+
return base
|
|
38
|
+
|
|
39
|
+
@classmethod
|
|
40
|
+
def from_dict(cls, data: dict) -> VerifyMCPEnvAssessmentStep:
|
|
41
|
+
return cls(**cls._base_from_dict(data), env_id=data["env_id"], prompt_id=data["prompt_id"])
|
|
42
|
+
|
|
43
|
+
async def execute(self, context: TaskStepContext) -> TaskStepContext:
|
|
44
|
+
from agent_env.env.env import Env
|
|
45
|
+
|
|
46
|
+
prompt_response = next((pr for pr in context.prompt_responses if pr.prompt_id == self.prompt_id), None)
|
|
47
|
+
if prompt_response is None:
|
|
48
|
+
raise RuntimeError(f"PromptResponse with prompt_id='{self.prompt_id}' not found in context")
|
|
49
|
+
|
|
50
|
+
if prompt_response.error_type:
|
|
51
|
+
logger.warning(f"Skipping assessment: prompt had error_type={prompt_response.error_type}")
|
|
52
|
+
result: dict[str, Any] = {"passed": False, "error": f"Agent error: {prompt_response.error_type}", "results": []}
|
|
53
|
+
else:
|
|
54
|
+
result = self._parse_response(prompt_response.response)
|
|
55
|
+
|
|
56
|
+
deployed = next((d for d in context.deployed_envs if d.env_id == self.env_id), None)
|
|
57
|
+
if deployed is None:
|
|
58
|
+
raise RuntimeError(f"Env '{self.env_id}' not found in context.deployed_envs")
|
|
59
|
+
env = Env.get(self.env_id, deployed.env_version)
|
|
60
|
+
env.update_metadata({**env.metadata, "mcp_tool_correctness_validation": result})
|
|
61
|
+
|
|
62
|
+
if "verifications" not in context.metadata:
|
|
63
|
+
context.metadata["verifications"] = {}
|
|
64
|
+
context.metadata["verifications"]["mcp_tool_correctness"] = result
|
|
65
|
+
|
|
66
|
+
return context
|
|
67
|
+
|
|
68
|
+
@staticmethod
|
|
69
|
+
def _parse_response(response_text: str) -> dict[str, Any]:
|
|
70
|
+
try:
|
|
71
|
+
parsed = json.loads(response_text.strip())
|
|
72
|
+
except json.JSONDecodeError as e:
|
|
73
|
+
logger.error(f"Failed to parse agent response as JSON: {e}")
|
|
74
|
+
return {"passed": False, "error": f"Invalid JSON response: {e}", "results": []}
|
|
75
|
+
|
|
76
|
+
results = parsed.get("results", []) if isinstance(parsed, dict) else []
|
|
77
|
+
all_passed = all(r.get("passed", False) for r in results) and len(results) > 0
|
|
78
|
+
return {"passed": all_passed, "total_tools": len(results), "results": results}
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
"""Verify MCP tool schemas for a deployed environment."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import logging
|
|
6
|
+
from typing import Any, ClassVar, Optional
|
|
7
|
+
|
|
8
|
+
import httpx
|
|
9
|
+
from mcp import ClientSession
|
|
10
|
+
from mcp.client.streamable_http import streamable_http_client
|
|
11
|
+
|
|
12
|
+
from agent_env.task_step.context import TaskStepContext
|
|
13
|
+
from agent_env.entity_refs import EntityRef
|
|
14
|
+
from agent_env.task_step.task_step import TaskStep, TaskStepDependency
|
|
15
|
+
|
|
16
|
+
logger = logging.getLogger(__name__)
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
def resolve_defs_ref(param_schema: dict, schema: dict) -> dict:
|
|
20
|
+
"""Resolve a ``#/$defs/`` ``$ref`` pointer against ``$defs`` in the top-level schema.
|
|
21
|
+
|
|
22
|
+
Module-level so it can be imported and reused by other verifiers (e.g.
|
|
23
|
+
``verify_spec_conformance``) without coupling to a task-step class.
|
|
24
|
+
"""
|
|
25
|
+
ref = param_schema.get("$ref", "")
|
|
26
|
+
if not ref.startswith("#/$defs/"):
|
|
27
|
+
return param_schema
|
|
28
|
+
def_name = ref[len("#/$defs/"):]
|
|
29
|
+
resolved = schema.get("$defs", {}).get(def_name)
|
|
30
|
+
if resolved is None:
|
|
31
|
+
return param_schema
|
|
32
|
+
# Fields on the original property (e.g. description) override the $defs entry
|
|
33
|
+
merged = {**resolved, **{k: v for k, v in param_schema.items() if k != "$ref"}}
|
|
34
|
+
return merged
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
class VerifyMCPToolSchemaTaskStep(TaskStep):
|
|
38
|
+
type: ClassVar[str] = "verify_mcp_tool_schema"
|
|
39
|
+
entity_refs = (EntityRef.env("env_id"),)
|
|
40
|
+
|
|
41
|
+
def __init__(
|
|
42
|
+
self,
|
|
43
|
+
id: str,
|
|
44
|
+
version: Optional[int],
|
|
45
|
+
env_id: str,
|
|
46
|
+
depends_on: Optional[list[TaskStepDependency]] = None,
|
|
47
|
+
fail_task_on_error: bool = True,
|
|
48
|
+
):
|
|
49
|
+
super().__init__(id, version, depends_on=depends_on, fail_task_on_error=fail_task_on_error)
|
|
50
|
+
self.env_id = env_id
|
|
51
|
+
|
|
52
|
+
def to_dict(self) -> dict:
|
|
53
|
+
base = super().to_dict()
|
|
54
|
+
base["env_id"] = self.env_id
|
|
55
|
+
return base
|
|
56
|
+
|
|
57
|
+
@classmethod
|
|
58
|
+
def from_dict(cls, data: dict) -> VerifyMCPToolSchemaTaskStep:
|
|
59
|
+
return cls(**cls._base_from_dict(data), env_id=data["env_id"])
|
|
60
|
+
|
|
61
|
+
@staticmethod
|
|
62
|
+
def _resolve_ref(param_schema: dict, schema: dict) -> dict:
|
|
63
|
+
"""Resolve a $ref pointer against $defs in the top-level schema.
|
|
64
|
+
|
|
65
|
+
Thin delegator to the module-level :func:`resolve_defs_ref`; kept for
|
|
66
|
+
backward compatibility with existing call sites.
|
|
67
|
+
"""
|
|
68
|
+
return resolve_defs_ref(param_schema, schema)
|
|
69
|
+
|
|
70
|
+
@staticmethod
|
|
71
|
+
def _check_parameter_issues(tool_name: str, schema: dict) -> list[str]:
|
|
72
|
+
"""Check a single tool's inputSchema for parameter quality issues."""
|
|
73
|
+
issues = []
|
|
74
|
+
properties = schema.get("properties", {})
|
|
75
|
+
if not properties:
|
|
76
|
+
return issues
|
|
77
|
+
|
|
78
|
+
if "required" in schema and not schema["required"]:
|
|
79
|
+
issues.append(f"tool '{tool_name}' has empty 'required' array")
|
|
80
|
+
|
|
81
|
+
for param_name, param_schema in properties.items():
|
|
82
|
+
if not param_schema or not isinstance(param_schema, dict):
|
|
83
|
+
issues.append(f"parameter '{param_name}' has empty or invalid schema")
|
|
84
|
+
continue
|
|
85
|
+
param_schema = VerifyMCPToolSchemaTaskStep._resolve_ref(param_schema, schema)
|
|
86
|
+
has_type = "type" in param_schema
|
|
87
|
+
if not has_type and "anyOf" in param_schema:
|
|
88
|
+
resolved_variants = [VerifyMCPToolSchemaTaskStep._resolve_ref(v, schema) if isinstance(v, dict) else v for v in param_schema["anyOf"]]
|
|
89
|
+
has_type = any("type" in v for v in resolved_variants if isinstance(v, dict))
|
|
90
|
+
if not has_type:
|
|
91
|
+
issues.append(f"parameter '{param_name}' missing explicit type")
|
|
92
|
+
if "description" not in param_schema:
|
|
93
|
+
issues.append(f"parameter '{param_name}' missing description")
|
|
94
|
+
if param_schema.get("type") == "array" and "items" not in param_schema:
|
|
95
|
+
issues.append(f"parameter '{param_name}' is array without items type")
|
|
96
|
+
if param_schema.get("type") == "object" and "properties" not in param_schema:
|
|
97
|
+
issues.append(f"parameter '{param_name}' is object without properties")
|
|
98
|
+
if "enum" in param_schema and not param_schema["enum"]:
|
|
99
|
+
issues.append(f"parameter '{param_name}' has empty enum list")
|
|
100
|
+
|
|
101
|
+
return issues
|
|
102
|
+
|
|
103
|
+
@staticmethod
|
|
104
|
+
def validate_tool_descriptions(tools: list) -> dict[str, Any]:
|
|
105
|
+
"""Check tool descriptions and parameter quality. Includes full tool schemas."""
|
|
106
|
+
missing = [t.name for t in tools if not (t.description or "").strip()]
|
|
107
|
+
tool_schemas = [
|
|
108
|
+
{"name": t.name, "description": t.description or "", "input_schema": t.inputSchema or {}}
|
|
109
|
+
for t in tools
|
|
110
|
+
]
|
|
111
|
+
parameter_issues: dict[str, list[str]] = {}
|
|
112
|
+
for t in tools:
|
|
113
|
+
issues = VerifyMCPToolSchemaTaskStep._check_parameter_issues(t.name, t.inputSchema or {})
|
|
114
|
+
if issues:
|
|
115
|
+
parameter_issues[t.name] = issues
|
|
116
|
+
|
|
117
|
+
passed = len(missing) == 0 and len(parameter_issues) == 0
|
|
118
|
+
return {"passed": passed, "total_tools": len(tools), "tools_missing_description": missing, "parameter_issues": parameter_issues, "tools": tool_schemas}
|
|
119
|
+
|
|
120
|
+
async def execute(self, context: TaskStepContext) -> TaskStepContext:
|
|
121
|
+
from agent_env.env.env import Env
|
|
122
|
+
|
|
123
|
+
deployed = next((d for d in context.deployed_envs if d.env_id == self.env_id), None)
|
|
124
|
+
if deployed is None:
|
|
125
|
+
raise RuntimeError(f"Env '{self.env_id}' not found in context.deployed_envs")
|
|
126
|
+
|
|
127
|
+
mcp_url = deployed.mcp_url
|
|
128
|
+
logger.info(f"Connecting to MCP at {mcp_url} to verify tool schemas")
|
|
129
|
+
http_client = httpx.AsyncClient()
|
|
130
|
+
try:
|
|
131
|
+
async with streamable_http_client(mcp_url, http_client=http_client) as (read_stream, write_stream, _):
|
|
132
|
+
async with ClientSession(read_stream, write_stream) as session:
|
|
133
|
+
await session.initialize()
|
|
134
|
+
tools_result = await session.list_tools()
|
|
135
|
+
finally:
|
|
136
|
+
await http_client.aclose()
|
|
137
|
+
|
|
138
|
+
tools = tools_result.tools
|
|
139
|
+
logger.info(f"Retrieved {len(tools)} tool(s) from {mcp_url}")
|
|
140
|
+
|
|
141
|
+
result = self.validate_tool_descriptions(tools)
|
|
142
|
+
logger.info(f"Tool schema validation: passed={result['passed']}, missing_descriptions={result['tools_missing_description']}")
|
|
143
|
+
|
|
144
|
+
# merge_metadata: a sibling verifier writes its own key on the same doc.
|
|
145
|
+
env = Env.get(self.env_id, deployed.env_version)
|
|
146
|
+
env.merge_metadata({"mcp_tool_schema_validation": result})
|
|
147
|
+
|
|
148
|
+
if "verifications" not in context.metadata:
|
|
149
|
+
context.metadata["verifications"] = {}
|
|
150
|
+
context.metadata["verifications"]["mcp_tool_schema"] = result
|
|
151
|
+
|
|
152
|
+
return context
|