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,113 @@
|
|
|
1
|
+
"""Task step that registers agent triggers (urn:agentenv:triggers/v1) on a deployed stakeholder A2A agent."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import logging
|
|
6
|
+
from collections.abc import Iterator
|
|
7
|
+
from typing import Any, ClassVar, Optional
|
|
8
|
+
|
|
9
|
+
import httpx
|
|
10
|
+
|
|
11
|
+
from agent_env.a2a_agent.a2a_agent import A2AAgent
|
|
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 _referenced_env_triggers(when: Any) -> set[tuple[str, str]]:
|
|
20
|
+
"""(env_id, trigger_id) pairs named by env_trigger conditions anywhere in a (possibly all/any-nested) when."""
|
|
21
|
+
refs: set[tuple[str, str]] = set()
|
|
22
|
+
if not isinstance(when, dict):
|
|
23
|
+
return refs
|
|
24
|
+
if when.get("type") == "env_trigger":
|
|
25
|
+
env_id, trigger_id = when.get("env_id"), when.get("trigger_id")
|
|
26
|
+
if isinstance(env_id, str) and env_id and isinstance(trigger_id, str) and trigger_id:
|
|
27
|
+
refs.add((env_id, trigger_id))
|
|
28
|
+
for sub in when.get("of") or []:
|
|
29
|
+
refs |= _referenced_env_triggers(sub)
|
|
30
|
+
return refs
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
def _env_trigger_conditions(when: Any, trail: tuple[str, ...] = ()) -> Iterator[tuple[tuple[str, ...], dict]]:
|
|
34
|
+
"""Every env_trigger condition in a (possibly all/any-nested) when, with its path parts under it."""
|
|
35
|
+
if not isinstance(when, dict):
|
|
36
|
+
return
|
|
37
|
+
if when.get("type") == "env_trigger":
|
|
38
|
+
yield trail, when
|
|
39
|
+
for i, sub in enumerate(when.get("of") or []):
|
|
40
|
+
yield from _env_trigger_conditions(sub, (*trail, f"of[{i}]"))
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
class RegisterAgentTriggersStep(TaskStep):
|
|
44
|
+
type: ClassVar[str] = "register_agent_triggers"
|
|
45
|
+
entity_refs = (EntityRef.env("triggers[].when.env_id", walk=_env_trigger_conditions),)
|
|
46
|
+
|
|
47
|
+
def __init__(
|
|
48
|
+
self,
|
|
49
|
+
id: str,
|
|
50
|
+
version: Optional[int],
|
|
51
|
+
agent_name: str,
|
|
52
|
+
triggers: list[dict],
|
|
53
|
+
depends_on: Optional[list[TaskStepDependency]] = None,
|
|
54
|
+
fail_task_on_error: bool = True,
|
|
55
|
+
):
|
|
56
|
+
super().__init__(id, version, depends_on=depends_on, fail_task_on_error=fail_task_on_error)
|
|
57
|
+
if not isinstance(triggers, list) or not all(isinstance(t, dict) for t in triggers):
|
|
58
|
+
raise ValueError("triggers must be a list of objects")
|
|
59
|
+
self.agent_name = agent_name
|
|
60
|
+
self.triggers = triggers
|
|
61
|
+
|
|
62
|
+
def to_dict(self) -> dict:
|
|
63
|
+
base = super().to_dict()
|
|
64
|
+
base["agent_name"] = self.agent_name
|
|
65
|
+
base["triggers"] = self.triggers
|
|
66
|
+
return base
|
|
67
|
+
|
|
68
|
+
@classmethod
|
|
69
|
+
def from_dict(cls, data: dict) -> RegisterAgentTriggersStep:
|
|
70
|
+
return cls(
|
|
71
|
+
**cls._base_from_dict(data),
|
|
72
|
+
agent_name=data["agent_name"],
|
|
73
|
+
triggers=data["triggers"],
|
|
74
|
+
)
|
|
75
|
+
|
|
76
|
+
async def execute(self, context: TaskStepContext) -> TaskStepContext:
|
|
77
|
+
agent = next((a for a in context.deployed_agents if a.agent_name == self.agent_name), None)
|
|
78
|
+
if agent is None:
|
|
79
|
+
raise RuntimeError(f"Agent '{self.agent_name}' not found in context.deployed_agents")
|
|
80
|
+
card = agent.a2a_card or {}
|
|
81
|
+
ext = A2AAgent.find_extension(card, A2AAgent.EXT_TRIGGERS)
|
|
82
|
+
if ext is None:
|
|
83
|
+
raise RuntimeError(f"Agent '{self.agent_name}' does not advertise {A2AAgent.EXT_TRIGGERS}")
|
|
84
|
+
deployed_env_ids = {d.env_id for d in context.deployed_envs}
|
|
85
|
+
registered_env_triggers: dict[str, set] = {}
|
|
86
|
+
for reg in context.metadata.get("env_trigger_registrations", []):
|
|
87
|
+
registered_env_triggers.setdefault(reg["env_id"], set()).update(reg.get("added", []))
|
|
88
|
+
for t in self.triggers:
|
|
89
|
+
for env_id, trigger_id in _referenced_env_triggers(t.get("when")):
|
|
90
|
+
if env_id not in deployed_env_ids:
|
|
91
|
+
raise RuntimeError(
|
|
92
|
+
f"trigger '{t.get('id', '?')}' references env_trigger env_id '{env_id}' "
|
|
93
|
+
f"not in context.deployed_envs {sorted(deployed_env_ids)}")
|
|
94
|
+
if trigger_id not in registered_env_triggers.get(env_id, set()):
|
|
95
|
+
raise RuntimeError(
|
|
96
|
+
f"trigger '{t.get('id', '?')}' references env_trigger '{trigger_id}' not registered "
|
|
97
|
+
f"on env '{env_id}' by a register_env_triggers step (registered there: "
|
|
98
|
+
f"{sorted(registered_env_triggers.get(env_id, set()))})")
|
|
99
|
+
endpoint = (ext.get("params") or {}).get("endpoint", "/ext/triggers")
|
|
100
|
+
body: dict = {"triggers": self.triggers}
|
|
101
|
+
url = f"{agent.a2a_url or agent.api_url}{endpoint}"
|
|
102
|
+
async with httpx.AsyncClient() as client:
|
|
103
|
+
resp = await client.post(url, json=body, timeout=30)
|
|
104
|
+
if resp.status_code >= 400:
|
|
105
|
+
raise RuntimeError(f"agent trigger registration failed (HTTP {resp.status_code}): {resp.text}")
|
|
106
|
+
result = resp.json()
|
|
107
|
+
logger.info(f"registered agent triggers on agent={self.agent_name}: {result}")
|
|
108
|
+
context.metadata.setdefault("agent_trigger_registrations", []).append({
|
|
109
|
+
"step_id": self.id,
|
|
110
|
+
"agent_name": self.agent_name,
|
|
111
|
+
"added": result.get("added", []),
|
|
112
|
+
})
|
|
113
|
+
return context
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
"""Task step that registers env triggers (urn:agentenv:triggers/v1) on a deployed env's gateway."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import logging
|
|
6
|
+
from typing import ClassVar, Optional
|
|
7
|
+
|
|
8
|
+
import httpx
|
|
9
|
+
|
|
10
|
+
from agent_env.env.gateway.constants import EXT_TRIGGERS_URI
|
|
11
|
+
from agent_env.task_step.context import TaskStepContext
|
|
12
|
+
from agent_env.entity_refs import EntityRef
|
|
13
|
+
from agent_env.task_step.task_step import TaskStep, TaskStepDependency
|
|
14
|
+
|
|
15
|
+
logger = logging.getLogger(__name__)
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
class RegisterEnvTriggersStep(TaskStep):
|
|
19
|
+
type: ClassVar[str] = "register_env_triggers"
|
|
20
|
+
entity_refs = (EntityRef.env("env_id"),)
|
|
21
|
+
|
|
22
|
+
def __init__(
|
|
23
|
+
self,
|
|
24
|
+
id: str,
|
|
25
|
+
version: Optional[int],
|
|
26
|
+
env_id: str,
|
|
27
|
+
triggers: list[dict],
|
|
28
|
+
watch_roles: Optional[list[str]] = None,
|
|
29
|
+
executor_agent_name: Optional[str] = None,
|
|
30
|
+
executor_timeout_seconds: float = 120,
|
|
31
|
+
depends_on: Optional[list[TaskStepDependency]] = None,
|
|
32
|
+
fail_task_on_error: bool = True,
|
|
33
|
+
):
|
|
34
|
+
super().__init__(id, version, depends_on=depends_on, fail_task_on_error=fail_task_on_error)
|
|
35
|
+
if not isinstance(triggers, list) or not all(isinstance(t, dict) for t in triggers):
|
|
36
|
+
raise ValueError("triggers must be a list of objects")
|
|
37
|
+
self.env_id = env_id
|
|
38
|
+
self.triggers = triggers
|
|
39
|
+
self.watch_roles = watch_roles
|
|
40
|
+
self.executor_agent_name = executor_agent_name
|
|
41
|
+
self.executor_timeout_seconds = executor_timeout_seconds
|
|
42
|
+
|
|
43
|
+
def to_dict(self) -> dict:
|
|
44
|
+
base = super().to_dict()
|
|
45
|
+
base["env_id"] = self.env_id
|
|
46
|
+
base["triggers"] = self.triggers
|
|
47
|
+
base["watch_roles"] = self.watch_roles
|
|
48
|
+
base["executor_agent_name"] = self.executor_agent_name
|
|
49
|
+
base["executor_timeout_seconds"] = self.executor_timeout_seconds
|
|
50
|
+
return base
|
|
51
|
+
|
|
52
|
+
@classmethod
|
|
53
|
+
def from_dict(cls, data: dict) -> RegisterEnvTriggersStep:
|
|
54
|
+
return cls(
|
|
55
|
+
**cls._base_from_dict(data),
|
|
56
|
+
env_id=data["env_id"],
|
|
57
|
+
triggers=data["triggers"],
|
|
58
|
+
watch_roles=data.get("watch_roles"),
|
|
59
|
+
executor_agent_name=data.get("executor_agent_name"),
|
|
60
|
+
executor_timeout_seconds=data.get("executor_timeout_seconds", 120),
|
|
61
|
+
)
|
|
62
|
+
|
|
63
|
+
async def execute(self, context: TaskStepContext) -> TaskStepContext:
|
|
64
|
+
deployed = next((d for d in context.deployed_envs if d.env_id == self.env_id), None)
|
|
65
|
+
if deployed is None:
|
|
66
|
+
raise RuntimeError(f"Env '{self.env_id}' not found in context.deployed_envs")
|
|
67
|
+
body: dict = {"triggers": self.triggers}
|
|
68
|
+
if self.watch_roles is not None:
|
|
69
|
+
body["watch_roles"] = self.watch_roles
|
|
70
|
+
if self.executor_agent_name is not None:
|
|
71
|
+
agent = next((a for a in context.deployed_agents if a.agent_name == self.executor_agent_name), None)
|
|
72
|
+
if agent is None:
|
|
73
|
+
raise RuntimeError(f"Executor agent '{self.executor_agent_name}' not found in context.deployed_agents")
|
|
74
|
+
if not agent.role:
|
|
75
|
+
raise RuntimeError(
|
|
76
|
+
f"Executor agent '{self.executor_agent_name}' was deployed without an explicit role; "
|
|
77
|
+
f"it would run under the default role and its own tool calls would fire triggers. "
|
|
78
|
+
f"Deploy it with a role outside watch_roles.")
|
|
79
|
+
if self.watch_roles is not None and agent.role in self.watch_roles:
|
|
80
|
+
raise RuntimeError(
|
|
81
|
+
f"Executor agent role '{agent.role}' is in watch_roles {self.watch_roles} — "
|
|
82
|
+
f"the executor's own tool calls would fire triggers (cascade).")
|
|
83
|
+
body["executor"] = {"a2a_url": agent.a2a_url or agent.api_url,
|
|
84
|
+
"timeout_seconds": self.executor_timeout_seconds,
|
|
85
|
+
"role": agent.role}
|
|
86
|
+
try:
|
|
87
|
+
result = await deployed.invoke(EXT_TRIGGERS_URI, "register", body)
|
|
88
|
+
except httpx.HTTPStatusError as e:
|
|
89
|
+
raise RuntimeError(f"trigger registration failed (HTTP {e.response.status_code}): {e.response.text}") from e
|
|
90
|
+
logger.info(f"registered triggers on env={self.env_id}: {result}")
|
|
91
|
+
context.metadata.setdefault("env_trigger_registrations", []).append({
|
|
92
|
+
"step_id": self.id,
|
|
93
|
+
"env_id": self.env_id,
|
|
94
|
+
"added": result.get("added", []),
|
|
95
|
+
"executor_agent_name": self.executor_agent_name,
|
|
96
|
+
})
|
|
97
|
+
return context
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
"""Reset a deployed env to a clean between-tasks state via ``Env.reset()``.
|
|
2
|
+
|
|
3
|
+
Env-agnostic: looks up the deployed env in context and calls its ``reset()``.
|
|
4
|
+
Best-effort by default — a reset failure (including an env that doesn't support
|
|
5
|
+
it) is logged and the run continues. Place right before prompt_agent in a
|
|
6
|
+
warm-reuse task.
|
|
7
|
+
"""
|
|
8
|
+
from __future__ import annotations
|
|
9
|
+
|
|
10
|
+
import logging
|
|
11
|
+
from typing import Optional
|
|
12
|
+
|
|
13
|
+
from agent_env.task_step.context import TaskStepContext
|
|
14
|
+
from agent_env.entity_refs import EntityRef
|
|
15
|
+
from agent_env.task_step.task_step import TaskStep
|
|
16
|
+
|
|
17
|
+
logger = logging.getLogger(__name__)
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
class ResetEnvTaskStep(TaskStep):
|
|
21
|
+
"""Return a deployed env to a clean state via its ``Env.reset()``."""
|
|
22
|
+
|
|
23
|
+
type = "reset_env"
|
|
24
|
+
entity_refs = (EntityRef.env("env_id"),)
|
|
25
|
+
|
|
26
|
+
def __init__(
|
|
27
|
+
self,
|
|
28
|
+
id: str,
|
|
29
|
+
version: Optional[int],
|
|
30
|
+
env_id: str,
|
|
31
|
+
depends_on: Optional[list] = None,
|
|
32
|
+
fail_task_on_error: bool = False,
|
|
33
|
+
):
|
|
34
|
+
if not env_id:
|
|
35
|
+
raise ValueError("reset_env requires an env_id (the env to reset)")
|
|
36
|
+
super().__init__(id, version, depends_on=depends_on, fail_task_on_error=fail_task_on_error)
|
|
37
|
+
self.env_id = env_id
|
|
38
|
+
|
|
39
|
+
def to_dict(self) -> dict:
|
|
40
|
+
base = super().to_dict()
|
|
41
|
+
base["env_id"] = self.env_id
|
|
42
|
+
return base
|
|
43
|
+
|
|
44
|
+
@classmethod
|
|
45
|
+
def from_dict(cls, data: dict) -> "ResetEnvTaskStep":
|
|
46
|
+
if not data.get("env_id"):
|
|
47
|
+
raise ValueError("reset_env step requires 'env_id'")
|
|
48
|
+
base = cls._base_from_dict(data)
|
|
49
|
+
# Stay best-effort when unset: _base_from_dict would otherwise default it to True.
|
|
50
|
+
base["fail_task_on_error"] = data.get("fail_task_on_error", False)
|
|
51
|
+
return cls(**base, env_id=data["env_id"])
|
|
52
|
+
|
|
53
|
+
async def execute(self, context: TaskStepContext) -> TaskStepContext:
|
|
54
|
+
from agent_env.env.env import Env
|
|
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
|
+
logger.warning("reset_env: no deployed env '%s' in context; skipping", self.env_id)
|
|
59
|
+
return context
|
|
60
|
+
try:
|
|
61
|
+
env = Env.get(deployed.env_id, deployed.env_version)
|
|
62
|
+
await env.reset(deployed)
|
|
63
|
+
logger.info("reset_env: reset env '%s'", self.env_id)
|
|
64
|
+
except NotImplementedError:
|
|
65
|
+
# Env doesn't support reset — not an error.
|
|
66
|
+
logger.info("reset_env: env '%s' does not support reset; skipping", self.env_id)
|
|
67
|
+
except Exception as e:
|
|
68
|
+
logger.warning("reset_env: reset failed (%s); continuing", repr(e)[:160])
|
|
69
|
+
if self.fail_task_on_error:
|
|
70
|
+
raise
|
|
71
|
+
return context
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
"""Human-in-the-loop review: pause the task until an operator continues or aborts.
|
|
2
|
+
|
|
3
|
+
Registers an ``awaiting`` review and blocks (heartbeating to keep the activity
|
|
4
|
+
alive) until the hub records a decision or the timeout elapses — continue returns
|
|
5
|
+
normally, abort raises so downstream steps don't run. The wait holds no sandbox,
|
|
6
|
+
so place it after the agent's output is persisted and before ``collect_artifacts``
|
|
7
|
+
(an abort then excludes the run's artifacts).
|
|
8
|
+
"""
|
|
9
|
+
|
|
10
|
+
from __future__ import annotations
|
|
11
|
+
|
|
12
|
+
import asyncio
|
|
13
|
+
import json
|
|
14
|
+
import logging
|
|
15
|
+
from typing import Any, ClassVar, Optional
|
|
16
|
+
|
|
17
|
+
from agent_env.task_step.context import TaskStepContext
|
|
18
|
+
from agent_env.task_step.task_step import TaskStep, TaskStepDependency
|
|
19
|
+
|
|
20
|
+
logger = logging.getLogger(__name__)
|
|
21
|
+
|
|
22
|
+
DEFAULT_TIMEOUT_SECONDS = 10800 # 3h
|
|
23
|
+
DEFAULT_POLL_INTERVAL_SECONDS = 5
|
|
24
|
+
_UPSTREAM_RESPONSE_MAX_CHARS = 4000
|
|
25
|
+
_UPSTREAM_STRUCTURED_MAX_CHARS = 16000
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
class ReviewAbortedError(RuntimeError):
|
|
29
|
+
"""Raised when an operator chooses not to continue past a review."""
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
def _bound_structured(value: Any) -> Any:
|
|
33
|
+
"""Return `value` as-is when small, else a truncated preview so a huge output can't bloat the polled review doc."""
|
|
34
|
+
try:
|
|
35
|
+
serialized = json.dumps(value, default=str)
|
|
36
|
+
except (TypeError, ValueError):
|
|
37
|
+
serialized = str(value)
|
|
38
|
+
if len(serialized) <= _UPSTREAM_STRUCTURED_MAX_CHARS:
|
|
39
|
+
return value
|
|
40
|
+
return {
|
|
41
|
+
"_truncated": True,
|
|
42
|
+
"note": "output truncated for review; full output in the trajectory",
|
|
43
|
+
"preview": serialized[:_UPSTREAM_STRUCTURED_MAX_CHARS],
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
class ReviewTaskStep(TaskStep):
|
|
48
|
+
type: ClassVar[str] = "review"
|
|
49
|
+
entity_refs = ()
|
|
50
|
+
|
|
51
|
+
def __init__(
|
|
52
|
+
self,
|
|
53
|
+
id: str,
|
|
54
|
+
version: Optional[int],
|
|
55
|
+
label: Optional[str] = None,
|
|
56
|
+
timeout_seconds: int = DEFAULT_TIMEOUT_SECONDS,
|
|
57
|
+
poll_interval_seconds: int = DEFAULT_POLL_INTERVAL_SECONDS,
|
|
58
|
+
depends_on: Optional[list[TaskStepDependency]] = None,
|
|
59
|
+
fail_task_on_error: bool = True,
|
|
60
|
+
):
|
|
61
|
+
super().__init__(id, version, depends_on=depends_on, fail_task_on_error=fail_task_on_error)
|
|
62
|
+
self.label = label
|
|
63
|
+
self.timeout_seconds = timeout_seconds
|
|
64
|
+
self.poll_interval_seconds = poll_interval_seconds
|
|
65
|
+
|
|
66
|
+
def to_dict(self) -> dict:
|
|
67
|
+
base = super().to_dict()
|
|
68
|
+
base["label"] = self.label
|
|
69
|
+
base["timeout_seconds"] = self.timeout_seconds
|
|
70
|
+
base["poll_interval_seconds"] = self.poll_interval_seconds
|
|
71
|
+
return base
|
|
72
|
+
|
|
73
|
+
@classmethod
|
|
74
|
+
def from_dict(cls, data: dict) -> ReviewTaskStep:
|
|
75
|
+
return cls(
|
|
76
|
+
**cls._base_from_dict(data),
|
|
77
|
+
label=data.get("label"),
|
|
78
|
+
timeout_seconds=data.get("timeout_seconds", DEFAULT_TIMEOUT_SECONDS),
|
|
79
|
+
poll_interval_seconds=data.get("poll_interval_seconds", DEFAULT_POLL_INTERVAL_SECONDS),
|
|
80
|
+
)
|
|
81
|
+
|
|
82
|
+
def _upstream_summary(self, context: TaskStepContext) -> dict[str, Any]:
|
|
83
|
+
"""Most recent prior step's output for the operator to review — structured verdict if present, else trimmed text. Bounded (polled by the UI)."""
|
|
84
|
+
for response in reversed(context.prompt_responses):
|
|
85
|
+
if response.structured_output is not None:
|
|
86
|
+
return {
|
|
87
|
+
"step_id": response.step_id,
|
|
88
|
+
"structured_output": _bound_structured(response.structured_output),
|
|
89
|
+
}
|
|
90
|
+
if context.prompt_responses:
|
|
91
|
+
last = context.prompt_responses[-1]
|
|
92
|
+
return {"step_id": last.step_id, "response": (last.response or "")[:_UPSTREAM_RESPONSE_MAX_CHARS]}
|
|
93
|
+
return {}
|
|
94
|
+
|
|
95
|
+
async def execute(self, context: TaskStepContext) -> TaskStepContext:
|
|
96
|
+
if not context.instance_id:
|
|
97
|
+
raise RuntimeError("review: context has no instance_id — cannot register a decision")
|
|
98
|
+
store = self._register_awaiting(context)
|
|
99
|
+
record = await self._await_decision(store, context)
|
|
100
|
+
return self._apply_decision(context, record)
|
|
101
|
+
|
|
102
|
+
def _register_awaiting(self, context: TaskStepContext):
|
|
103
|
+
from agent_env.task_step.review_store import get_review_store
|
|
104
|
+
|
|
105
|
+
store = get_review_store()
|
|
106
|
+
store.put_awaiting(
|
|
107
|
+
context.instance_id, self.id, label=self.label, upstream=self._upstream_summary(context)
|
|
108
|
+
)
|
|
109
|
+
logger.info(f"review '{self.id}' awaiting operator decision (timeout={self.timeout_seconds}s)")
|
|
110
|
+
return store
|
|
111
|
+
|
|
112
|
+
async def _await_decision(self, store, context: TaskStepContext) -> dict:
|
|
113
|
+
"""Poll until decided (return the record) or the wall-clock deadline (raise TimeoutError)."""
|
|
114
|
+
from agent_env.task_step.review_store import ABORT, CONTINUE
|
|
115
|
+
|
|
116
|
+
heartbeat = context.metadata.get("_heartbeat_fn")
|
|
117
|
+
loop = asyncio.get_running_loop()
|
|
118
|
+
deadline = loop.time() + self.timeout_seconds # wall-clock, so a non-positive interval can't spin forever
|
|
119
|
+
interval = self.poll_interval_seconds if self.poll_interval_seconds > 0 else DEFAULT_POLL_INTERVAL_SECONDS
|
|
120
|
+
while loop.time() < deadline:
|
|
121
|
+
self._beat(heartbeat)
|
|
122
|
+
record = store.get(context.instance_id, self.id) or {}
|
|
123
|
+
if record.get("state") in (CONTINUE, ABORT):
|
|
124
|
+
return record
|
|
125
|
+
await asyncio.sleep(min(interval, max(0.0, deadline - loop.time())))
|
|
126
|
+
raise TimeoutError(
|
|
127
|
+
f"review '{self.id}' timed out after {self.timeout_seconds}s awaiting a decision"
|
|
128
|
+
)
|
|
129
|
+
|
|
130
|
+
def _apply_decision(self, context: TaskStepContext, record: dict) -> TaskStepContext:
|
|
131
|
+
from agent_env.task_step.review_store import CONTINUE
|
|
132
|
+
|
|
133
|
+
decided_by = record.get("decided_by")
|
|
134
|
+
if record.get("state") == CONTINUE:
|
|
135
|
+
logger.info(f"review '{self.id}': operator chose continue")
|
|
136
|
+
context.metadata.setdefault("review_decisions", {})[self.id] = {
|
|
137
|
+
"decision": CONTINUE,
|
|
138
|
+
"decided_by": decided_by,
|
|
139
|
+
}
|
|
140
|
+
return context
|
|
141
|
+
logger.info(f"review '{self.id}': operator chose abort")
|
|
142
|
+
raise ReviewAbortedError(
|
|
143
|
+
f"review '{self.id}' aborted by operator" + (f" ({decided_by})" if decided_by else "")
|
|
144
|
+
)
|
|
145
|
+
|
|
146
|
+
@staticmethod
|
|
147
|
+
def _beat(heartbeat) -> None:
|
|
148
|
+
if callable(heartbeat):
|
|
149
|
+
try:
|
|
150
|
+
heartbeat()
|
|
151
|
+
except Exception: # best-effort; never fail the wait on it
|
|
152
|
+
pass
|