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,151 @@
|
|
|
1
|
+
"""Verify A2A agent accepts a `role` in /ext/agent-config and round-trips it via GET.
|
|
2
|
+
|
|
3
|
+
Confirms two coupled pieces of the per-agent role-filtering plumbing:
|
|
4
|
+
1. The agent advertises `role` in agent-config's supported set (the field the
|
|
5
|
+
env gateway's role filter ultimately keys off via the AgentEnv-Role header).
|
|
6
|
+
2. The agent advertises a `get` method on agent-config and that GET returns
|
|
7
|
+
the in-memory config dict so callers (and this validator) can confirm what
|
|
8
|
+
was actually accepted.
|
|
9
|
+
|
|
10
|
+
Catches:
|
|
11
|
+
- Agent silently drops `role` from agent-config POST
|
|
12
|
+
- Agent stores `role` somewhere unreadable / no GET method to confirm
|
|
13
|
+
- Agent regresses on adding new agent-config fields
|
|
14
|
+
|
|
15
|
+
Does NOT catch:
|
|
16
|
+
- Bridge ignores the stored role when building the MCP config (i.e. role is
|
|
17
|
+
accepted but never threaded to the CLI subprocess). End-to-end coverage of
|
|
18
|
+
that lives in the partition experiment task itself — runs that depend on
|
|
19
|
+
role-based filtering will hard-fail if the header never reaches the gateway.
|
|
20
|
+
"""
|
|
21
|
+
from __future__ import annotations
|
|
22
|
+
|
|
23
|
+
import logging
|
|
24
|
+
import uuid
|
|
25
|
+
from typing import ClassVar, Optional
|
|
26
|
+
|
|
27
|
+
import httpx
|
|
28
|
+
|
|
29
|
+
from agent_env.task_step.context import TaskStepContext
|
|
30
|
+
from agent_env.entity_refs import EntityRef
|
|
31
|
+
from agent_env.task_step.task_step import TaskStep, TaskStepDependency
|
|
32
|
+
|
|
33
|
+
logger = logging.getLogger(__name__)
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
class VerifyA2ARoleStep(TaskStep):
|
|
37
|
+
type: ClassVar[str] = "verify_a2a_role"
|
|
38
|
+
entity_refs = (EntityRef.agent("a2a_agent_id", version_field="a2a_agent_version"),)
|
|
39
|
+
|
|
40
|
+
def __init__(
|
|
41
|
+
self,
|
|
42
|
+
id: str,
|
|
43
|
+
version: Optional[int],
|
|
44
|
+
a2a_agent_id: str,
|
|
45
|
+
a2a_agent_version: Optional[int] = None,
|
|
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.a2a_agent_id = a2a_agent_id
|
|
51
|
+
self.a2a_agent_version = a2a_agent_version
|
|
52
|
+
|
|
53
|
+
def to_dict(self) -> dict:
|
|
54
|
+
base = super().to_dict()
|
|
55
|
+
base["a2a_agent_id"] = self.a2a_agent_id
|
|
56
|
+
base["a2a_agent_version"] = self.a2a_agent_version
|
|
57
|
+
return base
|
|
58
|
+
|
|
59
|
+
@classmethod
|
|
60
|
+
def from_dict(cls, data: dict) -> VerifyA2ARoleStep:
|
|
61
|
+
return cls(
|
|
62
|
+
**cls._base_from_dict(data),
|
|
63
|
+
a2a_agent_id=data["a2a_agent_id"],
|
|
64
|
+
a2a_agent_version=data.get("a2a_agent_version"),
|
|
65
|
+
)
|
|
66
|
+
|
|
67
|
+
async def execute(self, context: TaskStepContext) -> TaskStepContext:
|
|
68
|
+
from agent_env.a2a_agent import A2AAgent
|
|
69
|
+
|
|
70
|
+
deployed = next((a for a in context.deployed_agents), None)
|
|
71
|
+
if deployed is None:
|
|
72
|
+
raise RuntimeError("No deployed agent found in context")
|
|
73
|
+
agent = A2AAgent.get(self.a2a_agent_id, self.a2a_agent_version)
|
|
74
|
+
|
|
75
|
+
config_ext = A2AAgent.find_extension(deployed.a2a_card or {}, A2AAgent.EXT_AGENT_CONFIG)
|
|
76
|
+
if config_ext is None:
|
|
77
|
+
self._record(agent, context, {
|
|
78
|
+
"passed": False,
|
|
79
|
+
"reason": f"agent does not advertise {A2AAgent.EXT_AGENT_CONFIG}",
|
|
80
|
+
})
|
|
81
|
+
return context
|
|
82
|
+
|
|
83
|
+
params = config_ext.get("params") or {}
|
|
84
|
+
methods = params.get("methods") or {}
|
|
85
|
+
supported = (methods.get("set") or {}).get("request", {}).get("supported", [])
|
|
86
|
+
role_in_supported = "role" in supported
|
|
87
|
+
get_method_advertised = "get" in methods
|
|
88
|
+
|
|
89
|
+
if not role_in_supported or not get_method_advertised:
|
|
90
|
+
self._record(agent, context, {
|
|
91
|
+
"passed": False,
|
|
92
|
+
"role_in_supported": role_in_supported,
|
|
93
|
+
"get_method_advertised": get_method_advertised,
|
|
94
|
+
"reason": "agent-config extension missing 'role' in supported and/or 'get' method",
|
|
95
|
+
})
|
|
96
|
+
return context
|
|
97
|
+
|
|
98
|
+
endpoint = params.get("endpoint", "/ext/agent-config")
|
|
99
|
+
url = (deployed.a2a_url or deployed.api_url) + endpoint
|
|
100
|
+
test_role = f"validator-role-{uuid.uuid4().hex[:8]}"
|
|
101
|
+
logger.info("Round-tripping role=%r through %s", test_role, url)
|
|
102
|
+
|
|
103
|
+
try:
|
|
104
|
+
async with httpx.AsyncClient(timeout=10.0) as client:
|
|
105
|
+
post_resp = await client.post(url, json={"role": test_role})
|
|
106
|
+
post_resp.raise_for_status()
|
|
107
|
+
get_resp = await client.get(url)
|
|
108
|
+
get_resp.raise_for_status()
|
|
109
|
+
config = (get_resp.json() or {}).get("config") or {}
|
|
110
|
+
except Exception as e:
|
|
111
|
+
self._record(agent, context, {
|
|
112
|
+
"passed": False,
|
|
113
|
+
"role_in_supported": True,
|
|
114
|
+
"get_method_advertised": True,
|
|
115
|
+
"reason": f"agent-config POST/GET round-trip failed: {e}",
|
|
116
|
+
})
|
|
117
|
+
return context
|
|
118
|
+
|
|
119
|
+
observed_role = config.get("role")
|
|
120
|
+
passed = observed_role == test_role
|
|
121
|
+
if passed:
|
|
122
|
+
logger.info("Role round-trip verified for '%s'", self.a2a_agent_id)
|
|
123
|
+
else:
|
|
124
|
+
logger.warning(
|
|
125
|
+
"Role round-trip mismatch for '%s': expected=%r observed=%r",
|
|
126
|
+
self.a2a_agent_id, test_role, observed_role,
|
|
127
|
+
)
|
|
128
|
+
|
|
129
|
+
self._record(agent, context, {
|
|
130
|
+
"passed": passed,
|
|
131
|
+
"role_in_supported": True,
|
|
132
|
+
"get_method_advertised": True,
|
|
133
|
+
"expected_role": test_role,
|
|
134
|
+
"observed_role": observed_role,
|
|
135
|
+
})
|
|
136
|
+
return context
|
|
137
|
+
|
|
138
|
+
def _record(self, agent, context: TaskStepContext, validated: dict) -> None:
|
|
139
|
+
# Write to context FIRST so the verification record is always preserved,
|
|
140
|
+
# even if the agent-metadata CAS fails (other validator steps run in
|
|
141
|
+
# parallel and may have updated metadata between our read and write).
|
|
142
|
+
context.metadata.setdefault("verifications", {})["a2a_role"] = validated
|
|
143
|
+
# Re-fetch fresh to minimize the CAS window. Swallow conflicts — the
|
|
144
|
+
# record in context.metadata is the source of truth; metadata is just
|
|
145
|
+
# a denormalized view for `agent get` inspection.
|
|
146
|
+
from agent_env.a2a_agent import A2AAgent
|
|
147
|
+
try:
|
|
148
|
+
fresh = A2AAgent.get(self.a2a_agent_id, self.a2a_agent_version)
|
|
149
|
+
fresh.update_metadata({**fresh.metadata, "validated_role_via_agent_config": validated})
|
|
150
|
+
except Exception as e:
|
|
151
|
+
logger.warning("Failed to persist validated_role_via_agent_config (CAS conflict?): %s", e)
|
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
"""Verify A2A agent skill-config extension by reading rubric results and listing skills."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import asyncio
|
|
6
|
+
import logging
|
|
7
|
+
from typing import ClassVar, Optional
|
|
8
|
+
|
|
9
|
+
import httpx
|
|
10
|
+
from agentenv_protocol.a2a_agent import SkillAddResponse
|
|
11
|
+
|
|
12
|
+
from agent_env.task_step.context import TaskStepContext
|
|
13
|
+
from agent_env.a2a_agent.object_transfer import (
|
|
14
|
+
TRANSFER_TIMEOUT_SECONDS,
|
|
15
|
+
TransferMode,
|
|
16
|
+
invoke_transfer,
|
|
17
|
+
parse_response,
|
|
18
|
+
skill_add_call,
|
|
19
|
+
)
|
|
20
|
+
from agent_env.config import get_config
|
|
21
|
+
from agent_env.entity_refs import EntityRef
|
|
22
|
+
from agent_env.task_step.task_step import TaskStep, TaskStepDependency
|
|
23
|
+
|
|
24
|
+
logger = logging.getLogger(__name__)
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
class VerifyA2ASkillConfigStep(TaskStep):
|
|
28
|
+
type: ClassVar[str] = "verify_a2a_skill_config"
|
|
29
|
+
entity_refs = (EntityRef.agent("a2a_agent_id"),)
|
|
30
|
+
|
|
31
|
+
def __init__(
|
|
32
|
+
self,
|
|
33
|
+
id: str,
|
|
34
|
+
version: Optional[int],
|
|
35
|
+
a2a_agent_id: str,
|
|
36
|
+
rubric_verifier_id: str,
|
|
37
|
+
depends_on: Optional[list[TaskStepDependency]] = None,
|
|
38
|
+
fail_task_on_error: bool = True,
|
|
39
|
+
skill_bundle_object_url: Optional[str] = None,
|
|
40
|
+
skill_s3_url: Optional[str] = None,
|
|
41
|
+
):
|
|
42
|
+
super().__init__(id, version, depends_on=depends_on, fail_task_on_error=fail_task_on_error)
|
|
43
|
+
self.a2a_agent_id = a2a_agent_id
|
|
44
|
+
self.rubric_verifier_id = rubric_verifier_id
|
|
45
|
+
self.skill_bundle_object_url = skill_bundle_object_url
|
|
46
|
+
self.skill_s3_url = skill_s3_url
|
|
47
|
+
|
|
48
|
+
def to_dict(self) -> dict:
|
|
49
|
+
base = super().to_dict()
|
|
50
|
+
base["a2a_agent_id"] = self.a2a_agent_id
|
|
51
|
+
base["rubric_verifier_id"] = self.rubric_verifier_id
|
|
52
|
+
base["skill_bundle_object_url"] = self.skill_bundle_object_url
|
|
53
|
+
base["skill_s3_url"] = self.skill_s3_url
|
|
54
|
+
return base
|
|
55
|
+
|
|
56
|
+
@classmethod
|
|
57
|
+
def from_dict(cls, data: dict) -> VerifyA2ASkillConfigStep:
|
|
58
|
+
return cls(
|
|
59
|
+
**cls._base_from_dict(data),
|
|
60
|
+
a2a_agent_id=data["a2a_agent_id"],
|
|
61
|
+
rubric_verifier_id=data["rubric_verifier_id"],
|
|
62
|
+
skill_bundle_object_url=data.get("skill_bundle_object_url"),
|
|
63
|
+
skill_s3_url=data.get("skill_s3_url"),
|
|
64
|
+
)
|
|
65
|
+
|
|
66
|
+
async def execute(self, context: TaskStepContext) -> TaskStepContext:
|
|
67
|
+
from agent_env.a2a_agent import A2AAgent
|
|
68
|
+
|
|
69
|
+
deployed_agent = next((a for a in context.deployed_agents), None)
|
|
70
|
+
if deployed_agent is None:
|
|
71
|
+
raise RuntimeError("No deployed agent found in context")
|
|
72
|
+
|
|
73
|
+
card = deployed_agent.a2a_card or {}
|
|
74
|
+
skill_ext = A2AAgent.find_extension(card, A2AAgent.EXT_SKILL_CONFIG)
|
|
75
|
+
|
|
76
|
+
if not skill_ext:
|
|
77
|
+
logger.warning("Skill-config extension not advertised in agent card")
|
|
78
|
+
agent = A2AAgent.get(self.a2a_agent_id)
|
|
79
|
+
validated_ext = agent.metadata.get("validated_a2a_extensions", {})
|
|
80
|
+
validated_ext[A2AAgent.EXT_SKILL_CONFIG] = {"supported": False}
|
|
81
|
+
agent.update_metadata({**agent.metadata, "validated_a2a_extensions": validated_ext})
|
|
82
|
+
context.metadata.setdefault("verifications", {})["a2a_skill_config"] = {"supported": False}
|
|
83
|
+
return context
|
|
84
|
+
|
|
85
|
+
# Read per-criterion rubric results
|
|
86
|
+
rubric_result = context.metadata.get("verifications", {}).get(self.rubric_verifier_id, {})
|
|
87
|
+
results = rubric_result.get("results", [])
|
|
88
|
+
inline_passed = any(r.get("id") == "secret_code_inline" and r.get("score") == 1.0 for r in results)
|
|
89
|
+
add_method, add_path = A2AAgent.operation(skill_ext, "add")
|
|
90
|
+
store = get_config().get_object_store()
|
|
91
|
+
a2a_url = deployed_agent.a2a_url or deployed_agent.api_url
|
|
92
|
+
|
|
93
|
+
async def probe_add(form: TransferMode, name: str, description: str, object_url: str | None) -> bool:
|
|
94
|
+
"""Whether the agent registers an object-backed skill sent in exactly ``form``."""
|
|
95
|
+
if object_url is None:
|
|
96
|
+
return False
|
|
97
|
+
try:
|
|
98
|
+
call = await asyncio.to_thread(
|
|
99
|
+
skill_add_call,
|
|
100
|
+
add_method,
|
|
101
|
+
store,
|
|
102
|
+
name=name,
|
|
103
|
+
description=description,
|
|
104
|
+
object_url=object_url,
|
|
105
|
+
forms=(form,),
|
|
106
|
+
)
|
|
107
|
+
except RuntimeError as exc:
|
|
108
|
+
logger.info("Skill %s request: not sent (%s)", form, exc)
|
|
109
|
+
return False
|
|
110
|
+
except Exception as exc:
|
|
111
|
+
logger.warning("Skill %s request: failed (%s)", form, exc)
|
|
112
|
+
return False
|
|
113
|
+
try:
|
|
114
|
+
answer = await invoke_transfer(
|
|
115
|
+
a2a_url + add_path,
|
|
116
|
+
call,
|
|
117
|
+
verb="POST",
|
|
118
|
+
operation=f"skill add ({form})",
|
|
119
|
+
timeout=TRANSFER_TIMEOUT_SECONDS,
|
|
120
|
+
)
|
|
121
|
+
result = parse_response(SkillAddResponse, answer, operation=f"skill add ({form})")
|
|
122
|
+
if result.name != name:
|
|
123
|
+
raise ValueError("response name does not match the requested skill")
|
|
124
|
+
logger.info("Skill %s request: OK", form)
|
|
125
|
+
return True
|
|
126
|
+
except Exception as exc:
|
|
127
|
+
logger.warning("Skill %s request: failed (%s)", form, exc)
|
|
128
|
+
return False
|
|
129
|
+
|
|
130
|
+
bundle_passed = await probe_add(
|
|
131
|
+
"objects",
|
|
132
|
+
"validator-probe-bundle",
|
|
133
|
+
"Validator probe for the portable skill bundle variant.",
|
|
134
|
+
self.skill_bundle_object_url,
|
|
135
|
+
)
|
|
136
|
+
s3_passed = await probe_add(
|
|
137
|
+
"legacy",
|
|
138
|
+
"validator-probe-s3",
|
|
139
|
+
"Validator probe for the legacy S3 skill variant.",
|
|
140
|
+
self.skill_s3_url,
|
|
141
|
+
)
|
|
142
|
+
logger.info(
|
|
143
|
+
"Skill validation '%s': inline=%s bundle=%s s3=%s",
|
|
144
|
+
self.rubric_verifier_id,
|
|
145
|
+
inline_passed,
|
|
146
|
+
bundle_passed,
|
|
147
|
+
s3_passed,
|
|
148
|
+
)
|
|
149
|
+
|
|
150
|
+
# List skills via GET endpoint
|
|
151
|
+
list_ok = False
|
|
152
|
+
try:
|
|
153
|
+
async with httpx.AsyncClient() as client:
|
|
154
|
+
resp = await client.get(a2a_url + A2AAgent.operation(skill_ext, "list")[1], timeout=30)
|
|
155
|
+
resp.raise_for_status()
|
|
156
|
+
data = resp.json()
|
|
157
|
+
skills = data.get("skills", {})
|
|
158
|
+
list_ok = isinstance(skills, dict) and len(skills) > 0
|
|
159
|
+
logger.info(f"Listed {len(skills)} skill(s): {list(skills.keys())}")
|
|
160
|
+
except Exception as e:
|
|
161
|
+
logger.warning(f"Skill list failed: {e}")
|
|
162
|
+
|
|
163
|
+
# Build validated entry from observed behavior for each request variant.
|
|
164
|
+
add_supported = inline_passed or bundle_passed or s3_passed
|
|
165
|
+
skill_entry = {
|
|
166
|
+
"supported": add_supported or list_ok,
|
|
167
|
+
"methods": {
|
|
168
|
+
"add": {
|
|
169
|
+
"supported": add_supported,
|
|
170
|
+
"options": {
|
|
171
|
+
"name": {"supported": add_supported},
|
|
172
|
+
"description": {"supported": add_supported},
|
|
173
|
+
"skill": {"supported": inline_passed},
|
|
174
|
+
"skill_md": {"supported": inline_passed},
|
|
175
|
+
"skill_bundle": {"supported": bundle_passed},
|
|
176
|
+
"skill_s3_url": {"supported": s3_passed},
|
|
177
|
+
},
|
|
178
|
+
},
|
|
179
|
+
"list": {"supported": list_ok},
|
|
180
|
+
},
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
agent = A2AAgent.get(self.a2a_agent_id)
|
|
184
|
+
validated_ext = agent.metadata.get("validated_a2a_extensions", {})
|
|
185
|
+
validated_ext[A2AAgent.EXT_SKILL_CONFIG] = skill_entry
|
|
186
|
+
agent.update_metadata({**agent.metadata, "validated_a2a_extensions": validated_ext})
|
|
187
|
+
|
|
188
|
+
context.metadata.setdefault("verifications", {})["a2a_skill_config"] = {
|
|
189
|
+
"inline": inline_passed,
|
|
190
|
+
"bundle": bundle_passed,
|
|
191
|
+
"s3": s3_passed,
|
|
192
|
+
"list": list_ok,
|
|
193
|
+
}
|
|
194
|
+
return context
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
"""Verify A2A agent snapshot extension by reading rubric results and recording extension support."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import logging
|
|
6
|
+
from typing import ClassVar, Optional
|
|
7
|
+
|
|
8
|
+
from agent_env.task_step.context import TaskStepContext
|
|
9
|
+
from agent_env.entity_refs import EntityRef
|
|
10
|
+
from agent_env.task_step.task_step import TaskStep, TaskStepDependency
|
|
11
|
+
|
|
12
|
+
logger = logging.getLogger(__name__)
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
class VerifyA2ASnapshotStep(TaskStep):
|
|
16
|
+
"""Record snapshot extension validation results on the agent's metadata.
|
|
17
|
+
|
|
18
|
+
Assumes upstream steps have:
|
|
19
|
+
1. Planted state on agent A via a prompt step,
|
|
20
|
+
2. Captured a snapshot via SnapshotAgentStateTaskStep,
|
|
21
|
+
3. Deployed agent B with the snapshot_files_artifact_id,
|
|
22
|
+
4. Sent a recall prompt to agent B,
|
|
23
|
+
5. Run a RubricsVerifierTaskStep that scored whether the recall worked.
|
|
24
|
+
|
|
25
|
+
This step reads that rubric verifier's result, checks the snapshot
|
|
26
|
+
extension is advertised in both deployed agents, and writes the
|
|
27
|
+
consolidated outcome to agent.metadata['validated_a2a_extensions'][EXT_SNAPSHOT].
|
|
28
|
+
"""
|
|
29
|
+
|
|
30
|
+
type: ClassVar[str] = "verify_a2a_snapshot"
|
|
31
|
+
entity_refs = (EntityRef.agent("a2a_agent_id"),)
|
|
32
|
+
|
|
33
|
+
def __init__(
|
|
34
|
+
self,
|
|
35
|
+
id: str,
|
|
36
|
+
version: Optional[int],
|
|
37
|
+
a2a_agent_id: str,
|
|
38
|
+
rubric_verifier_id: str,
|
|
39
|
+
rubric_criterion_id: str,
|
|
40
|
+
depends_on: Optional[list[TaskStepDependency]] = None,
|
|
41
|
+
fail_task_on_error: bool = True,
|
|
42
|
+
):
|
|
43
|
+
super().__init__(id, version, depends_on=depends_on, fail_task_on_error=fail_task_on_error)
|
|
44
|
+
self.a2a_agent_id = a2a_agent_id
|
|
45
|
+
self.rubric_verifier_id = rubric_verifier_id
|
|
46
|
+
self.rubric_criterion_id = rubric_criterion_id
|
|
47
|
+
|
|
48
|
+
def to_dict(self) -> dict:
|
|
49
|
+
return {**super().to_dict(), "a2a_agent_id": self.a2a_agent_id, "rubric_verifier_id": self.rubric_verifier_id, "rubric_criterion_id": self.rubric_criterion_id}
|
|
50
|
+
|
|
51
|
+
@classmethod
|
|
52
|
+
def from_dict(cls, data: dict) -> VerifyA2ASnapshotStep:
|
|
53
|
+
return cls(
|
|
54
|
+
**cls._base_from_dict(data),
|
|
55
|
+
a2a_agent_id=data["a2a_agent_id"],
|
|
56
|
+
rubric_verifier_id=data["rubric_verifier_id"],
|
|
57
|
+
rubric_criterion_id=data["rubric_criterion_id"],
|
|
58
|
+
)
|
|
59
|
+
|
|
60
|
+
async def execute(self, context: TaskStepContext) -> TaskStepContext:
|
|
61
|
+
from agent_env.a2a_agent import A2AAgent
|
|
62
|
+
|
|
63
|
+
# Extension advertised on at least one deployed agent
|
|
64
|
+
extension_advertised = False
|
|
65
|
+
for deployed in context.deployed_agents:
|
|
66
|
+
card = deployed.a2a_card or {}
|
|
67
|
+
if A2AAgent.find_extension(card, A2AAgent.EXT_SNAPSHOT) is not None:
|
|
68
|
+
extension_advertised = True
|
|
69
|
+
break
|
|
70
|
+
|
|
71
|
+
# Rubric outcome — did recall on the loaded agent contain the planted token?
|
|
72
|
+
rubric_result = context.metadata.get("verifications", {}).get(self.rubric_verifier_id, {})
|
|
73
|
+
results = rubric_result.get("results", []) or []
|
|
74
|
+
recall_passed = any(
|
|
75
|
+
r.get("id") == self.rubric_criterion_id and r.get("score") == 1.0 for r in results
|
|
76
|
+
)
|
|
77
|
+
|
|
78
|
+
# The save+load round-trip succeeded if a snapshot was actually written *and*
|
|
79
|
+
# the recall rubric passed. The snapshot universe id is recorded by the
|
|
80
|
+
# snapshot step in context.metadata['agent_snapshots'].
|
|
81
|
+
snapshots_recorded = bool(context.metadata.get("agent_snapshots") or [])
|
|
82
|
+
save_ok = snapshots_recorded
|
|
83
|
+
load_ok = recall_passed # if recall worked, load (and resume) must have worked
|
|
84
|
+
recall_ok = recall_passed
|
|
85
|
+
|
|
86
|
+
snap_entry = {
|
|
87
|
+
"supported": extension_advertised and save_ok and load_ok and recall_ok,
|
|
88
|
+
"extension_advertised": extension_advertised,
|
|
89
|
+
"methods": {
|
|
90
|
+
"save": {"supported": save_ok},
|
|
91
|
+
"load": {"supported": load_ok},
|
|
92
|
+
},
|
|
93
|
+
"recall_after_load": recall_ok,
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
agent = A2AAgent.get(self.a2a_agent_id)
|
|
97
|
+
validated_ext = agent.metadata.get("validated_a2a_extensions", {})
|
|
98
|
+
validated_ext[A2AAgent.EXT_SNAPSHOT] = snap_entry
|
|
99
|
+
agent.update_metadata({**agent.metadata, "validated_a2a_extensions": validated_ext})
|
|
100
|
+
|
|
101
|
+
context.metadata.setdefault("verifications", {})["a2a_snapshot"] = {
|
|
102
|
+
"extension_advertised": extension_advertised,
|
|
103
|
+
"save": save_ok,
|
|
104
|
+
"load": load_ok,
|
|
105
|
+
"recall": recall_ok,
|
|
106
|
+
}
|
|
107
|
+
logger.info(
|
|
108
|
+
f"Snapshot validation: extension_advertised={extension_advertised} "
|
|
109
|
+
f"save={save_ok} load={load_ok} recall={recall_ok}"
|
|
110
|
+
)
|
|
111
|
+
return context
|
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
"""Verify A2A agent's `system_prompt` agent-config field actually reaches the model.
|
|
2
|
+
|
|
3
|
+
End-to-end behavioral test:
|
|
4
|
+
1. Generate a fresh token per run.
|
|
5
|
+
2. POST `/ext/agent-config` with a system_prompt that instructs the model to
|
|
6
|
+
emit that token in response to a specific trigger question.
|
|
7
|
+
3. Send the trigger question via A2A `message/send`.
|
|
8
|
+
4. Poll until terminal, extract the response text.
|
|
9
|
+
5. Pass if the token appears in the response.
|
|
10
|
+
|
|
11
|
+
Catches things the static `verify_a2a_agent_config_identity` step does NOT:
|
|
12
|
+
- `system_prompt` in `_AGENT_CONFIG_SUPPORTED` but bridge silently drops it
|
|
13
|
+
- claude-code-cli's `--append-system-prompt` flag renamed / removed
|
|
14
|
+
- codex's AGENTS.md not loaded (cwd drift, perms, codex CLI regression) —
|
|
15
|
+
most pertinent for codex since AGENTS.md auto-load is its ONLY system_prompt
|
|
16
|
+
delivery mechanism (no `--system-prompt` flag exists)
|
|
17
|
+
- Any new agent's broken system_prompt plumbing on first put
|
|
18
|
+
|
|
19
|
+
Does NOT catch:
|
|
20
|
+
- Mid-task system_prompt overrides via prompt_agent.system_prompt
|
|
21
|
+
(different code path — could be added as a v2)
|
|
22
|
+
- Whether the system_prompt is exactly applied (this is a contains-check;
|
|
23
|
+
a model that prepends/appends text still passes)
|
|
24
|
+
"""
|
|
25
|
+
from __future__ import annotations
|
|
26
|
+
|
|
27
|
+
import asyncio
|
|
28
|
+
import logging
|
|
29
|
+
import time
|
|
30
|
+
import uuid
|
|
31
|
+
from typing import ClassVar, Optional
|
|
32
|
+
|
|
33
|
+
import httpx
|
|
34
|
+
|
|
35
|
+
from agent_env.task_step.context import TaskStepContext
|
|
36
|
+
from agent_env.entity_refs import EntityRef
|
|
37
|
+
from agent_env.task_step.task_step import TaskStep, TaskStepDependency
|
|
38
|
+
|
|
39
|
+
logger = logging.getLogger(__name__)
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
class VerifyA2ASystemPromptStep(TaskStep):
|
|
43
|
+
type: ClassVar[str] = "verify_a2a_system_prompt"
|
|
44
|
+
entity_refs = (EntityRef.agent("a2a_agent_id", version_field="a2a_agent_version"),)
|
|
45
|
+
|
|
46
|
+
def __init__(
|
|
47
|
+
self,
|
|
48
|
+
id: str,
|
|
49
|
+
version: Optional[int],
|
|
50
|
+
a2a_agent_id: str,
|
|
51
|
+
a2a_agent_version: Optional[int] = None,
|
|
52
|
+
timeout_seconds: int = 300,
|
|
53
|
+
poll_interval_seconds: int = 5,
|
|
54
|
+
depends_on: Optional[list[TaskStepDependency]] = None,
|
|
55
|
+
fail_task_on_error: bool = True,
|
|
56
|
+
):
|
|
57
|
+
super().__init__(id, version, depends_on=depends_on, fail_task_on_error=fail_task_on_error)
|
|
58
|
+
self.a2a_agent_id = a2a_agent_id
|
|
59
|
+
self.a2a_agent_version = a2a_agent_version
|
|
60
|
+
self.timeout_seconds = timeout_seconds
|
|
61
|
+
self.poll_interval_seconds = poll_interval_seconds
|
|
62
|
+
|
|
63
|
+
def to_dict(self) -> dict:
|
|
64
|
+
base = super().to_dict()
|
|
65
|
+
base["a2a_agent_id"] = self.a2a_agent_id
|
|
66
|
+
base["a2a_agent_version"] = self.a2a_agent_version
|
|
67
|
+
base["timeout_seconds"] = self.timeout_seconds
|
|
68
|
+
base["poll_interval_seconds"] = self.poll_interval_seconds
|
|
69
|
+
return base
|
|
70
|
+
|
|
71
|
+
@classmethod
|
|
72
|
+
def from_dict(cls, data: dict) -> VerifyA2ASystemPromptStep:
|
|
73
|
+
return cls(
|
|
74
|
+
**cls._base_from_dict(data),
|
|
75
|
+
a2a_agent_id=data["a2a_agent_id"],
|
|
76
|
+
a2a_agent_version=data.get("a2a_agent_version"),
|
|
77
|
+
timeout_seconds=data.get("timeout_seconds", 300),
|
|
78
|
+
poll_interval_seconds=data.get("poll_interval_seconds", 5),
|
|
79
|
+
)
|
|
80
|
+
|
|
81
|
+
async def execute(self, context: TaskStepContext) -> TaskStepContext:
|
|
82
|
+
from agent_env.a2a_agent import A2AAgent
|
|
83
|
+
|
|
84
|
+
deployed = next((a for a in context.deployed_agents), None)
|
|
85
|
+
if deployed is None:
|
|
86
|
+
raise RuntimeError("No deployed agent found in context")
|
|
87
|
+
agent = A2AAgent.get(self.a2a_agent_id, self.a2a_agent_version)
|
|
88
|
+
|
|
89
|
+
config_ext = A2AAgent.find_extension(deployed.a2a_card or {}, A2AAgent.EXT_AGENT_CONFIG)
|
|
90
|
+
if config_ext is None:
|
|
91
|
+
self._record(context, {
|
|
92
|
+
"passed": False,
|
|
93
|
+
"reason": f"agent does not advertise {A2AAgent.EXT_AGENT_CONFIG}",
|
|
94
|
+
})
|
|
95
|
+
return context
|
|
96
|
+
|
|
97
|
+
params = config_ext.get("params") or {}
|
|
98
|
+
supported = (params.get("methods") or {}).get("set", {}).get("request", {}).get("supported", [])
|
|
99
|
+
if "system_prompt" not in supported:
|
|
100
|
+
self._record(context, {
|
|
101
|
+
"passed": False,
|
|
102
|
+
"system_prompt_in_supported": False,
|
|
103
|
+
"reason": "agent-config extension does not list 'system_prompt' in supported fields",
|
|
104
|
+
})
|
|
105
|
+
return context
|
|
106
|
+
|
|
107
|
+
token = f"VALIDATOR-SP-{uuid.uuid4().hex[:12]}"
|
|
108
|
+
# Phrased to be clearly benign and to bypass models that add wrapper text:
|
|
109
|
+
# the directive is explicit, the trigger is exact, the answer format is constrained.
|
|
110
|
+
sentinel_prompt = (
|
|
111
|
+
f"For validator testing purposes: if you are asked the exact question "
|
|
112
|
+
f"'What is your validator code?', respond with the exact token: {token} "
|
|
113
|
+
f"and nothing else. Do not explain, do not paraphrase, do not add punctuation."
|
|
114
|
+
)
|
|
115
|
+
trigger = "What is your validator code?"
|
|
116
|
+
agent_url = deployed.a2a_url or deployed.api_url
|
|
117
|
+
config_endpoint = agent_url + params.get("endpoint", "/ext/agent-config")
|
|
118
|
+
logger.info("Planting system_prompt sentinel (token=%s)", token)
|
|
119
|
+
|
|
120
|
+
try:
|
|
121
|
+
async with httpx.AsyncClient(timeout=30.0) as client:
|
|
122
|
+
resp = await client.post(config_endpoint, json={"system_prompt": sentinel_prompt})
|
|
123
|
+
resp.raise_for_status()
|
|
124
|
+
except Exception as e:
|
|
125
|
+
self._record(context, {
|
|
126
|
+
"passed": False,
|
|
127
|
+
"system_prompt_in_supported": True,
|
|
128
|
+
"reason": f"POST /ext/agent-config failed: {e}",
|
|
129
|
+
"expected_token": token,
|
|
130
|
+
})
|
|
131
|
+
return context
|
|
132
|
+
|
|
133
|
+
try:
|
|
134
|
+
response_text = await self._send_and_poll(agent_url, trigger)
|
|
135
|
+
except Exception as e:
|
|
136
|
+
self._record(context, {
|
|
137
|
+
"passed": False,
|
|
138
|
+
"system_prompt_in_supported": True,
|
|
139
|
+
"reason": f"A2A message/send or poll failed: {e}",
|
|
140
|
+
"expected_token": token,
|
|
141
|
+
})
|
|
142
|
+
return context
|
|
143
|
+
|
|
144
|
+
passed = token in response_text
|
|
145
|
+
if passed:
|
|
146
|
+
logger.info("system_prompt round-trip verified (token reached model)")
|
|
147
|
+
else:
|
|
148
|
+
logger.warning(
|
|
149
|
+
"system_prompt round-trip mismatch: token=%r not in response=%r",
|
|
150
|
+
token, response_text[:300],
|
|
151
|
+
)
|
|
152
|
+
|
|
153
|
+
self._record(context, {
|
|
154
|
+
"passed": passed,
|
|
155
|
+
"system_prompt_in_supported": True,
|
|
156
|
+
"expected_token": token,
|
|
157
|
+
"observed_response": response_text[:500],
|
|
158
|
+
})
|
|
159
|
+
return context
|
|
160
|
+
|
|
161
|
+
async def _send_and_poll(self, a2a_url: str, prompt_text: str) -> str:
|
|
162
|
+
"""Send a message via A2A and poll until terminal; return concatenated text from response parts."""
|
|
163
|
+
message_id = uuid.uuid4().hex
|
|
164
|
+
async with httpx.AsyncClient(timeout=self.timeout_seconds) as client:
|
|
165
|
+
resp = await client.post(f"{a2a_url}/a2a", json={
|
|
166
|
+
"jsonrpc": "2.0", "id": "1", "method": "message/send",
|
|
167
|
+
"params": {"message": {
|
|
168
|
+
"messageId": message_id,
|
|
169
|
+
"role": "user",
|
|
170
|
+
"parts": [{"kind": "text", "text": prompt_text}],
|
|
171
|
+
}},
|
|
172
|
+
})
|
|
173
|
+
resp.raise_for_status()
|
|
174
|
+
body = resp.json()
|
|
175
|
+
if "error" in body:
|
|
176
|
+
raise RuntimeError(f"message/send returned error: {body['error']}")
|
|
177
|
+
task_id = (body.get("result") or {})["id"]
|
|
178
|
+
|
|
179
|
+
deadline = time.monotonic() + self.timeout_seconds
|
|
180
|
+
while time.monotonic() < deadline:
|
|
181
|
+
await asyncio.sleep(self.poll_interval_seconds)
|
|
182
|
+
try:
|
|
183
|
+
async with httpx.AsyncClient(timeout=30) as client:
|
|
184
|
+
poll = await client.post(f"{a2a_url}/a2a", json={
|
|
185
|
+
"jsonrpc": "2.0", "id": "poll", "method": "tasks/get",
|
|
186
|
+
"params": {"id": task_id},
|
|
187
|
+
})
|
|
188
|
+
poll.raise_for_status()
|
|
189
|
+
data = poll.json()
|
|
190
|
+
if "error" in data:
|
|
191
|
+
logger.warning("A2A poll error (will retry): %s", data["error"])
|
|
192
|
+
continue
|
|
193
|
+
result = data["result"]
|
|
194
|
+
except (httpx.ConnectError, httpx.ReadTimeout, httpx.RemoteProtocolError) as e:
|
|
195
|
+
logger.warning("A2A poll failed (will retry): %s", e)
|
|
196
|
+
continue
|
|
197
|
+
state = result["status"]["state"]
|
|
198
|
+
if state in ("completed", "failed"):
|
|
199
|
+
response_text = ""
|
|
200
|
+
for part in ((result.get("status") or {}).get("message") or {}).get("parts", []):
|
|
201
|
+
if part.get("kind") == "text":
|
|
202
|
+
response_text += part.get("text", "")
|
|
203
|
+
return response_text
|
|
204
|
+
raise TimeoutError(f"A2A task {task_id} did not complete within {self.timeout_seconds}s")
|
|
205
|
+
|
|
206
|
+
def _record(self, context: TaskStepContext, validated: dict) -> None:
|
|
207
|
+
# Context write first so the verification record is always preserved,
|
|
208
|
+
# even if the agent-metadata CAS fails (parallel validator steps).
|
|
209
|
+
context.metadata.setdefault("verifications", {})["a2a_system_prompt"] = validated
|
|
210
|
+
from agent_env.a2a_agent import A2AAgent
|
|
211
|
+
try:
|
|
212
|
+
fresh = A2AAgent.get(self.a2a_agent_id, self.a2a_agent_version)
|
|
213
|
+
fresh.update_metadata({**fresh.metadata, "validated_system_prompt": validated})
|
|
214
|
+
except Exception as e:
|
|
215
|
+
logger.warning("Failed to persist validated_system_prompt (CAS conflict?): %s", e)
|