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,434 @@
|
|
|
1
|
+
"""Run a unit-tests-style verifier inside a deployed task container.
|
|
2
|
+
|
|
3
|
+
Optionally runs setup_commands first (to install verifier dependencies the
|
|
4
|
+
agent's container didn't have). The main command's exit code, stdout/stderr,
|
|
5
|
+
and any extracted result files land on context.metadata["verifications"].
|
|
6
|
+
|
|
7
|
+
stdout and stderr are each persisted as their own FileArtifact in S3 (so the
|
|
8
|
+
verification entry stays small and the full output is addressable via the
|
|
9
|
+
artifact API). Result files declared via `result_paths` are docker-cp'd out of
|
|
10
|
+
the container and stored inline in `extracted_files` (parsed JSON when valid).
|
|
11
|
+
|
|
12
|
+
The command and env are resolved per run from ``step_overrides`` and
|
|
13
|
+
``metadata["seed"]`` (see ``_resolve_command``), so one stored task can be pointed
|
|
14
|
+
at a different input without a new task version.
|
|
15
|
+
|
|
16
|
+
A non-zero exit (or timeout) raises after the entry has been recorded — so the
|
|
17
|
+
run instance has the verification context even when the verifier aborts the
|
|
18
|
+
task. Verifiers that always exit 0 and encode pass/fail inside a result JSON
|
|
19
|
+
(Harbor-style test.sh) will always look "passed" at the step level; downstream
|
|
20
|
+
consumers must read `extracted_files` to grade.
|
|
21
|
+
"""
|
|
22
|
+
|
|
23
|
+
from __future__ import annotations
|
|
24
|
+
|
|
25
|
+
import asyncio
|
|
26
|
+
import json
|
|
27
|
+
import logging
|
|
28
|
+
import os
|
|
29
|
+
import re
|
|
30
|
+
import shlex
|
|
31
|
+
import tempfile
|
|
32
|
+
import time
|
|
33
|
+
import uuid
|
|
34
|
+
from typing import Any, ClassVar, Optional
|
|
35
|
+
|
|
36
|
+
from agent_env.providers.sandbox_providers.sandbox_provider import (
|
|
37
|
+
all_sandbox_container_env,
|
|
38
|
+
registered_sandbox_provider_classes,
|
|
39
|
+
)
|
|
40
|
+
from agent_env.task_step.context import TaskStepContext
|
|
41
|
+
from agent_env.task_step.task_step import TaskStep, TaskStepDependency
|
|
42
|
+
|
|
43
|
+
logger = logging.getLogger(__name__)
|
|
44
|
+
|
|
45
|
+
# How many characters of stdout/stderr to inline on the verification entry as a
|
|
46
|
+
# preview. Full output lives in the FileArtifact uploaded to S3; this is just a
|
|
47
|
+
# convenience for `agent-env task run` / hub UI to show a head without an S3
|
|
48
|
+
# round-trip.
|
|
49
|
+
_OUTPUT_PREVIEW_CHARS = 500
|
|
50
|
+
|
|
51
|
+
# Every env var key — stored, override or seed — reaches the `docker exec` string
|
|
52
|
+
# unquoted (`-e 'K=v'` and `-e K=v` differ to docker), so it must be a POSIX name
|
|
53
|
+
# first. `\Z` not `$`: `$` also matches before a trailing newline, so `"URL\n"` would
|
|
54
|
+
# pass and split the command.
|
|
55
|
+
_SAFE_ENV_KEY = re.compile(r"^[A-Za-z_][A-Za-z0-9_]*\Z")
|
|
56
|
+
|
|
57
|
+
# Names execute() injects before the seed overlay lands. A CSV column that upper-cases
|
|
58
|
+
# onto one of these is almost certainly accidental, and would redirect the verifier's
|
|
59
|
+
# LLM traffic or swap its credentials. An explicit step_params override still wins —
|
|
60
|
+
# that one is deliberate. Keep in sync with the injection block in execute(); the
|
|
61
|
+
# sandbox platforms' own names come from their providers, so a new provider
|
|
62
|
+
# does not need this list edited.
|
|
63
|
+
_RESERVED_ENV_KEYS = frozenset({
|
|
64
|
+
"LITELLM_API_KEY", "ANTHROPIC_API_KEY",
|
|
65
|
+
"LITELLM_BASE_URL", "ANTHROPIC_BASE_URL",
|
|
66
|
+
"PATH", "HOME",
|
|
67
|
+
})
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
class RunContainerUnitTestsVerifierTaskStep(TaskStep):
|
|
71
|
+
type: ClassVar[str] = "run_container_unit_tests_verifier"
|
|
72
|
+
entity_refs = ()
|
|
73
|
+
|
|
74
|
+
def __init__(
|
|
75
|
+
self,
|
|
76
|
+
id: str,
|
|
77
|
+
version: Optional[int],
|
|
78
|
+
sandbox_name: str,
|
|
79
|
+
container_name: str,
|
|
80
|
+
command: str,
|
|
81
|
+
verifier_id: Optional[str] = None,
|
|
82
|
+
setup_commands: Optional[list[str]] = None,
|
|
83
|
+
user: str = "root",
|
|
84
|
+
timeout_sec: int = 300,
|
|
85
|
+
env_vars: Optional[dict[str, str]] = None,
|
|
86
|
+
result_paths: Optional[list[str]] = None,
|
|
87
|
+
reward_path: Optional[str] = None,
|
|
88
|
+
depends_on: Optional[list[TaskStepDependency]] = None,
|
|
89
|
+
fail_task_on_error: bool = True,
|
|
90
|
+
):
|
|
91
|
+
super().__init__(id, version, depends_on=depends_on, fail_task_on_error=fail_task_on_error)
|
|
92
|
+
self.sandbox_name = sandbox_name
|
|
93
|
+
self.container_name = container_name
|
|
94
|
+
self.command = command
|
|
95
|
+
self.verifier_id = verifier_id or id
|
|
96
|
+
self.setup_commands = list(setup_commands or [])
|
|
97
|
+
self.user = user
|
|
98
|
+
self.timeout_sec = timeout_sec
|
|
99
|
+
self.env_vars = dict(env_vars or {})
|
|
100
|
+
for key in self.env_vars:
|
|
101
|
+
if not _SAFE_ENV_KEY.match(key):
|
|
102
|
+
raise ValueError(
|
|
103
|
+
f"env_vars key {key!r} is not a POSIX name ([A-Za-z_][A-Za-z0-9_]*)"
|
|
104
|
+
)
|
|
105
|
+
self.result_paths = list(result_paths or [])
|
|
106
|
+
# When set, the recorded score is the float read from this extracted
|
|
107
|
+
# result file (a Harbor-style reward, 0.0–1.0) instead of the process
|
|
108
|
+
# exit-code surrogate — a test.sh that exits 0 while writing reward 0
|
|
109
|
+
# must NOT be recorded as a pass. Must also appear in `result_paths`.
|
|
110
|
+
self.reward_path = reward_path
|
|
111
|
+
if reward_path and reward_path not in self.result_paths:
|
|
112
|
+
self.result_paths.append(reward_path)
|
|
113
|
+
|
|
114
|
+
def to_dict(self) -> dict:
|
|
115
|
+
base = super().to_dict()
|
|
116
|
+
base["sandbox_name"] = self.sandbox_name
|
|
117
|
+
base["container_name"] = self.container_name
|
|
118
|
+
base["command"] = self.command
|
|
119
|
+
base["verifier_id"] = self.verifier_id
|
|
120
|
+
base["setup_commands"] = self.setup_commands
|
|
121
|
+
base["user"] = self.user
|
|
122
|
+
base["timeout_sec"] = self.timeout_sec
|
|
123
|
+
base["env_vars"] = self.env_vars
|
|
124
|
+
base["result_paths"] = self.result_paths
|
|
125
|
+
base["reward_path"] = self.reward_path
|
|
126
|
+
return base
|
|
127
|
+
|
|
128
|
+
@classmethod
|
|
129
|
+
def from_dict(cls, data: dict) -> RunContainerUnitTestsVerifierTaskStep:
|
|
130
|
+
return cls(
|
|
131
|
+
**cls._base_from_dict(data),
|
|
132
|
+
sandbox_name=data["sandbox_name"],
|
|
133
|
+
container_name=data["container_name"],
|
|
134
|
+
command=data["command"],
|
|
135
|
+
verifier_id=data.get("verifier_id"),
|
|
136
|
+
setup_commands=data.get("setup_commands"),
|
|
137
|
+
user=data.get("user", "root"),
|
|
138
|
+
timeout_sec=data.get("timeout_sec", 300),
|
|
139
|
+
env_vars=data.get("env_vars"),
|
|
140
|
+
result_paths=data.get("result_paths"),
|
|
141
|
+
reward_path=data.get("reward_path"),
|
|
142
|
+
)
|
|
143
|
+
|
|
144
|
+
def _resolve_command(self, context: TaskStepContext) -> tuple[str, dict[str, str]]:
|
|
145
|
+
"""Resolve ``(command, extra_env)`` for this run, so a value can vary without a
|
|
146
|
+
new task version: ``step_params`` for a targeted or resumed run, ``seed`` for
|
|
147
|
+
``task run-batch --seeds`` fan-out. Both are additive to the stored ``env_vars``.
|
|
148
|
+
|
|
149
|
+
Seed values reach the container as env vars rather than by string substitution,
|
|
150
|
+
because ``-e K=<quoted>`` is a separate docker argument and bash expands ``"$K"``
|
|
151
|
+
without re-parsing metacharacters. ``<key>`` placeholders are still rendered for
|
|
152
|
+
rows that vary a flag rather than a value, in one left-to-right pass so
|
|
153
|
+
substituted text is never re-scanned: replacing key-by-key, a value of ``<b>``
|
|
154
|
+
quotes to ``'<b>'`` and a later key ``b`` rewrites the placeholder *inside* those
|
|
155
|
+
quotes, yielding ``''$(id)''`` — quotes that close each other and leave the
|
|
156
|
+
value bare for bash.
|
|
157
|
+
"""
|
|
158
|
+
overrides = self.step_param_overrides(context)
|
|
159
|
+
seed = context.metadata.get("seed") or {}
|
|
160
|
+
|
|
161
|
+
command = overrides.get("command", self.command)
|
|
162
|
+
if seed:
|
|
163
|
+
placeholders = re.compile("|".join(re.escape(f"<{k}>") for k in seed))
|
|
164
|
+
command = placeholders.sub(
|
|
165
|
+
lambda m: shlex.quote(str(seed[m.group(0)[1:-1]])), command
|
|
166
|
+
)
|
|
167
|
+
|
|
168
|
+
extra_env = {}
|
|
169
|
+
for key, value in (overrides.get("env_vars") or {}).items():
|
|
170
|
+
if not _SAFE_ENV_KEY.match(key):
|
|
171
|
+
# Raises where a seed key is skipped: an explicit override is a caller
|
|
172
|
+
# bug, not one odd column of a batch.
|
|
173
|
+
raise ValueError(
|
|
174
|
+
f"step_params env_vars key {key!r} is not a POSIX name "
|
|
175
|
+
f"([A-Za-z_][A-Za-z0-9_]*)"
|
|
176
|
+
)
|
|
177
|
+
extra_env[key] = str(value)
|
|
178
|
+
reserved = _RESERVED_ENV_KEYS | {
|
|
179
|
+
name for cls in registered_sandbox_provider_classes() for name in cls.CONTAINER_ENV
|
|
180
|
+
}
|
|
181
|
+
for key, value in seed.items():
|
|
182
|
+
env_key = key.upper()
|
|
183
|
+
if not _SAFE_ENV_KEY.match(env_key):
|
|
184
|
+
# Still reachable via the <key> placeholder above; skipping keeps one
|
|
185
|
+
# odd CSV column from failing a whole batch.
|
|
186
|
+
logger.warning(
|
|
187
|
+
f"[{self.verifier_id}] seed key {key!r} is not a POSIX name; "
|
|
188
|
+
f"not exported as an env var"
|
|
189
|
+
)
|
|
190
|
+
continue
|
|
191
|
+
if env_key in reserved:
|
|
192
|
+
logger.warning(
|
|
193
|
+
f"[{self.verifier_id}] seed key {key!r} would overwrite {env_key}; "
|
|
194
|
+
f"not exported as an env var"
|
|
195
|
+
)
|
|
196
|
+
continue
|
|
197
|
+
extra_env[env_key] = str(value)
|
|
198
|
+
return command, extra_env
|
|
199
|
+
|
|
200
|
+
async def execute(self, context: TaskStepContext) -> TaskStepContext:
|
|
201
|
+
from agent_env.artifact.artifacts.file import FileArtifact
|
|
202
|
+
from agent_env.providers.sandbox_providers.sandbox_provider import (
|
|
203
|
+
build_sandbox_provider,
|
|
204
|
+
get_sandbox_provider,
|
|
205
|
+
)
|
|
206
|
+
from agent_env.config import ConfigError, get_config
|
|
207
|
+
|
|
208
|
+
# 1. Lookup container + sandbox, rehydrate VmSandbox
|
|
209
|
+
containers = context.metadata.get("deployed_docker_containers", [])
|
|
210
|
+
container_entry = next(
|
|
211
|
+
(
|
|
212
|
+
c for c in containers
|
|
213
|
+
if c.get("container_name") == self.container_name
|
|
214
|
+
and c.get("sandbox_name") == self.sandbox_name
|
|
215
|
+
),
|
|
216
|
+
None,
|
|
217
|
+
)
|
|
218
|
+
if container_entry is None:
|
|
219
|
+
raise RuntimeError(
|
|
220
|
+
f"Container '{self.container_name}' not found on sandbox '{self.sandbox_name}' in "
|
|
221
|
+
f"context.metadata['deployed_docker_containers']"
|
|
222
|
+
)
|
|
223
|
+
ds = next((s for s in context.deployed_sandboxes if s.sandbox_name == self.sandbox_name), None)
|
|
224
|
+
if ds is None:
|
|
225
|
+
raise RuntimeError(f"Sandbox '{self.sandbox_name}' not found in context.deployed_sandboxes")
|
|
226
|
+
|
|
227
|
+
provider = (
|
|
228
|
+
build_sandbox_provider(ds.sandbox_type) if ds.sandbox_type else get_sandbox_provider()
|
|
229
|
+
)
|
|
230
|
+
sandbox = await provider.get_sandbox(ds.sandbox_id)
|
|
231
|
+
|
|
232
|
+
# 2. Build the merged env (auto-injected from agent-env config + user overlay)
|
|
233
|
+
config = get_config()
|
|
234
|
+
merged_env: dict[str, str] = {}
|
|
235
|
+
try:
|
|
236
|
+
litellm_key = config.get_litellm_api_key()
|
|
237
|
+
merged_env["LITELLM_API_KEY"] = litellm_key
|
|
238
|
+
merged_env["ANTHROPIC_API_KEY"] = litellm_key
|
|
239
|
+
except (KeyError, ConfigError):
|
|
240
|
+
logger.warning("LITELLM_API_KEY unavailable; verifier won't have LLM creds")
|
|
241
|
+
try:
|
|
242
|
+
litellm_url = config.get_litellm_base_url()
|
|
243
|
+
merged_env["LITELLM_BASE_URL"] = litellm_url
|
|
244
|
+
merged_env["ANTHROPIC_BASE_URL"] = litellm_url
|
|
245
|
+
except (KeyError, ConfigError):
|
|
246
|
+
logger.warning("LITELLM_BASE_URL unavailable; verifier won't have LLM base URL")
|
|
247
|
+
merged_env.update(all_sandbox_container_env())
|
|
248
|
+
command, extra_env = self._resolve_command(context)
|
|
249
|
+
merged_env.update(self.env_vars)
|
|
250
|
+
merged_env.update(extra_env)
|
|
251
|
+
env_flags = " ".join(f"-e {k}={shlex.quote(v)}" for k, v in merged_env.items())
|
|
252
|
+
|
|
253
|
+
# 3. Run setup_commands (fail loud)
|
|
254
|
+
for i, setup_cmd in enumerate(self.setup_commands, 1):
|
|
255
|
+
logger.info(
|
|
256
|
+
f"[{self.verifier_id}] setup [{i}/{len(self.setup_commands)}]: "
|
|
257
|
+
f"{setup_cmd.splitlines()[0][:140]}"
|
|
258
|
+
)
|
|
259
|
+
await sandbox.exec_script(
|
|
260
|
+
f"sudo docker exec -u {shlex.quote(self.user)} {env_flags} "
|
|
261
|
+
f"{shlex.quote(self.container_name)} bash -c {shlex.quote(setup_cmd)}"
|
|
262
|
+
)
|
|
263
|
+
|
|
264
|
+
# 4. Run main command, bounded by in-container timeout(1)
|
|
265
|
+
logger.info(
|
|
266
|
+
f"[{self.verifier_id}] running verifier (timeout={self.timeout_sec}s) "
|
|
267
|
+
f"in container '{self.container_name}': {command[:160]}"
|
|
268
|
+
)
|
|
269
|
+
wrapped = (
|
|
270
|
+
f"sudo docker exec -u {shlex.quote(self.user)} {env_flags} "
|
|
271
|
+
f"{shlex.quote(self.container_name)} "
|
|
272
|
+
f"timeout --kill-after=10 {self.timeout_sec} bash -c {shlex.quote(command)}"
|
|
273
|
+
)
|
|
274
|
+
exit_code, stdout, stderr = await sandbox.exec_with_output("sudo", "bash", "-c", wrapped)
|
|
275
|
+
timed_out = exit_code in (124, 137)
|
|
276
|
+
logger.info(
|
|
277
|
+
f"[{self.verifier_id}] exit_code={exit_code} timed_out={timed_out} "
|
|
278
|
+
f"stdout_chars={len(stdout)} stderr_chars={len(stderr)}"
|
|
279
|
+
)
|
|
280
|
+
if stdout:
|
|
281
|
+
logger.info(f"[{self.verifier_id}] stdout:\n{stdout}")
|
|
282
|
+
if stderr:
|
|
283
|
+
logger.info(f"[{self.verifier_id}] stderr:\n{stderr}")
|
|
284
|
+
|
|
285
|
+
# 5. Extract result files (docker cp + cat + try JSON parse)
|
|
286
|
+
extracted_files: dict[str, Any] = {}
|
|
287
|
+
for result_path in self.result_paths:
|
|
288
|
+
try:
|
|
289
|
+
content = await self._extract_file(sandbox, result_path)
|
|
290
|
+
try:
|
|
291
|
+
extracted_files[result_path] = json.loads(content)
|
|
292
|
+
except json.JSONDecodeError:
|
|
293
|
+
extracted_files[result_path] = content
|
|
294
|
+
except Exception as e:
|
|
295
|
+
logger.warning(f"[{self.verifier_id}] failed to extract {result_path}: {e}")
|
|
296
|
+
extracted_files[result_path] = None
|
|
297
|
+
|
|
298
|
+
# 7. Persist stdout + stderr as separate FileArtifacts
|
|
299
|
+
# Every execution gets its own key: a retried step keeps its run's instance id, and the
|
|
300
|
+
# outputs are write-once. The instance id and the time only group and order them.
|
|
301
|
+
run = "-".join(filter(None, (context.instance_id, str(int(time.time())), uuid.uuid4().hex[:12])))
|
|
302
|
+
store = config.get_object_store()
|
|
303
|
+
outputs = f"{config.get_artifact_key_prefix()}verifier-outputs/{self.id}/{run}"
|
|
304
|
+
stdout_artifact = await asyncio.to_thread(
|
|
305
|
+
self._upload_text_artifact,
|
|
306
|
+
text=stdout,
|
|
307
|
+
artifact_id=f"verifier-stdout-{self.id}-{run}",
|
|
308
|
+
description=f"stdout of {self.verifier_id} from step {self.id}",
|
|
309
|
+
s3_url=store.object_url(f"{outputs}/stdout.txt"),
|
|
310
|
+
)
|
|
311
|
+
stderr_artifact = await asyncio.to_thread(
|
|
312
|
+
self._upload_text_artifact,
|
|
313
|
+
text=stderr,
|
|
314
|
+
artifact_id=f"verifier-stderr-{self.id}-{run}",
|
|
315
|
+
description=f"stderr of {self.verifier_id} from step {self.id}",
|
|
316
|
+
s3_url=store.object_url(f"{outputs}/stderr.txt"),
|
|
317
|
+
)
|
|
318
|
+
|
|
319
|
+
# 8. Record on context (shape compatible with aggregate_verifiers).
|
|
320
|
+
# Harbor-style verifiers (reward_path set) grade by the reward file, not
|
|
321
|
+
# the exit code: test.sh exits 0 and encodes pass/fail in the reward.
|
|
322
|
+
passed_surrogate = exit_code == 0 and not timed_out
|
|
323
|
+
if self.reward_path is not None:
|
|
324
|
+
reward = self._parse_reward(extracted_files.get(self.reward_path))
|
|
325
|
+
if reward is None:
|
|
326
|
+
score = 0.0
|
|
327
|
+
result_bool = False
|
|
328
|
+
message = (
|
|
329
|
+
f"reward file {self.reward_path!r} missing or non-numeric "
|
|
330
|
+
f"(exit_code={exit_code} timed_out={timed_out})"
|
|
331
|
+
)
|
|
332
|
+
else:
|
|
333
|
+
score = reward
|
|
334
|
+
result_bool = reward >= 1.0
|
|
335
|
+
message = f"reward={reward} (exit_code={exit_code} timed_out={timed_out})"
|
|
336
|
+
result_id = "reward"
|
|
337
|
+
else:
|
|
338
|
+
score = 1.0 if passed_surrogate else 0.0
|
|
339
|
+
result_bool = passed_surrogate
|
|
340
|
+
message = f"exit_code={exit_code} timed_out={timed_out}"
|
|
341
|
+
result_id = "exit_code"
|
|
342
|
+
context.metadata.setdefault("verifications", {})[self.verifier_id] = {
|
|
343
|
+
"results": [
|
|
344
|
+
{
|
|
345
|
+
"id": result_id,
|
|
346
|
+
"score": score,
|
|
347
|
+
"result": result_bool,
|
|
348
|
+
"message": message,
|
|
349
|
+
},
|
|
350
|
+
],
|
|
351
|
+
"score": score,
|
|
352
|
+
"command": command,
|
|
353
|
+
"exit_code": exit_code,
|
|
354
|
+
"timed_out": timed_out,
|
|
355
|
+
"stdout_artifact": {
|
|
356
|
+
"id": stdout_artifact.id,
|
|
357
|
+
"version": stdout_artifact.version,
|
|
358
|
+
"s3_url": stdout_artifact.object_url,
|
|
359
|
+
},
|
|
360
|
+
"stderr_artifact": {
|
|
361
|
+
"id": stderr_artifact.id,
|
|
362
|
+
"version": stderr_artifact.version,
|
|
363
|
+
"s3_url": stderr_artifact.object_url,
|
|
364
|
+
},
|
|
365
|
+
"stdout_head": stdout[:_OUTPUT_PREVIEW_CHARS],
|
|
366
|
+
"stderr_head": stderr[:_OUTPUT_PREVIEW_CHARS],
|
|
367
|
+
"extracted_files": extracted_files,
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
# 9. Raise on timeout / non-zero exit AFTER recording. In reward mode a
|
|
371
|
+
# non-zero exit is a graded failure (already recorded as score 0), not a
|
|
372
|
+
# step error — only an unfinished (timed-out) run is unreliable.
|
|
373
|
+
if timed_out:
|
|
374
|
+
raise RuntimeError(
|
|
375
|
+
f"Verifier '{self.verifier_id}' timed out after {self.timeout_sec}s"
|
|
376
|
+
)
|
|
377
|
+
if exit_code != 0 and self.reward_path is None:
|
|
378
|
+
raise RuntimeError(
|
|
379
|
+
f"Verifier '{self.verifier_id}' exited {exit_code}; "
|
|
380
|
+
f"stderr (last 1500 chars):\n{stderr[-1500:]}"
|
|
381
|
+
)
|
|
382
|
+
|
|
383
|
+
return context
|
|
384
|
+
|
|
385
|
+
@staticmethod
|
|
386
|
+
def _parse_reward(raw: Any) -> Optional[float]:
|
|
387
|
+
"""Coerce an extracted reward file's content to a float in [0, 1], or None.
|
|
388
|
+
|
|
389
|
+
``raw`` is whatever ``extracted_files`` holds — a JSON-parsed number
|
|
390
|
+
(``0``/``1``/``0.5``) or a raw string (``"0\\n"``). Returns None when the
|
|
391
|
+
value is missing or non-numeric so the caller can record a hard 0.
|
|
392
|
+
"""
|
|
393
|
+
if raw is None or isinstance(raw, bool):
|
|
394
|
+
return None
|
|
395
|
+
try:
|
|
396
|
+
value = float(str(raw).strip())
|
|
397
|
+
except (TypeError, ValueError):
|
|
398
|
+
return None
|
|
399
|
+
return max(0.0, min(1.0, value))
|
|
400
|
+
|
|
401
|
+
@staticmethod
|
|
402
|
+
def _upload_text_artifact(text: str, artifact_id: str, description: str, s3_url: str):
|
|
403
|
+
from agent_env.artifact.artifacts.file import FileArtifact
|
|
404
|
+
|
|
405
|
+
with tempfile.NamedTemporaryFile(mode="w", suffix=".txt", delete=False) as tmp:
|
|
406
|
+
tmp.write(text)
|
|
407
|
+
tmp_path = tmp.name
|
|
408
|
+
try:
|
|
409
|
+
return FileArtifact.put_at(
|
|
410
|
+
id=artifact_id,
|
|
411
|
+
description=description,
|
|
412
|
+
file_path=tmp_path,
|
|
413
|
+
object_url=s3_url,
|
|
414
|
+
)
|
|
415
|
+
finally:
|
|
416
|
+
try:
|
|
417
|
+
os.unlink(tmp_path)
|
|
418
|
+
except OSError:
|
|
419
|
+
pass
|
|
420
|
+
|
|
421
|
+
async def _extract_file(self, sandbox, path_in_container: str) -> str:
|
|
422
|
+
"""`docker cp` a file out of the container, read it from the VM, return text."""
|
|
423
|
+
vm_temp = f"/tmp/_verifier_out_{uuid.uuid4().hex[:8]}"
|
|
424
|
+
await sandbox.exec_script(
|
|
425
|
+
f"sudo docker cp {shlex.quote(self.container_name)}:{shlex.quote(path_in_container)} "
|
|
426
|
+
f"{shlex.quote(vm_temp)}"
|
|
427
|
+
)
|
|
428
|
+
try:
|
|
429
|
+
exit_code, stdout, stderr = await sandbox.exec_with_output("sudo", "cat", vm_temp)
|
|
430
|
+
if exit_code != 0:
|
|
431
|
+
raise RuntimeError(f"cat {vm_temp} failed (exit {exit_code}): {stderr}")
|
|
432
|
+
return stdout
|
|
433
|
+
finally:
|
|
434
|
+
await sandbox.exec_script(f"rm -f {shlex.quote(vm_temp)}")
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"""Score aggregation shared by every verifier step.
|
|
2
|
+
|
|
3
|
+
A verifier records per-criterion result rows; ``aggregate_score`` folds them into the
|
|
4
|
+
single ``score`` written to ``context.metadata["verifications"][verifier_id]``.
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
from __future__ import annotations
|
|
8
|
+
|
|
9
|
+
from enum import Enum
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class ScoreAggregator(Enum):
|
|
13
|
+
ALL_PASS = "all_pass"
|
|
14
|
+
ANY_PASS = "any_pass"
|
|
15
|
+
WEIGHTED_AVERAGE = "weighted_average"
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
def aggregate_score(results: list[dict], aggregator: ScoreAggregator) -> float:
|
|
19
|
+
if not results:
|
|
20
|
+
return 0.0
|
|
21
|
+
if aggregator == ScoreAggregator.ALL_PASS:
|
|
22
|
+
return 1.0 if all(r.get("result") is True for r in results) else 0.0
|
|
23
|
+
elif aggregator == ScoreAggregator.ANY_PASS:
|
|
24
|
+
return 1.0 if any(r.get("result") is True for r in results) else 0.0
|
|
25
|
+
elif aggregator == ScoreAggregator.WEIGHTED_AVERAGE:
|
|
26
|
+
pos_num = 0.0
|
|
27
|
+
pos_den = 0.0
|
|
28
|
+
neg_penalty = 0.0
|
|
29
|
+
for r in results:
|
|
30
|
+
score = r.get("score", 1.0 if r.get("result") else 0.0)
|
|
31
|
+
weight = float(r.get("weight", 1.0))
|
|
32
|
+
if weight > 0:
|
|
33
|
+
pos_num += score * weight
|
|
34
|
+
pos_den += weight
|
|
35
|
+
elif weight < 0:
|
|
36
|
+
neg_penalty += (1.0 - score) * abs(weight)
|
|
37
|
+
if pos_den == 0:
|
|
38
|
+
return 0.0
|
|
39
|
+
return max(0.0, min(1.0, (pos_num - neg_penalty) / pos_den))
|
|
40
|
+
raise ValueError(f"Unknown aggregator: {aggregator}")
|