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.
Files changed (312) hide show
  1. agent_env/__init__.py +0 -0
  2. agent_env/a2a_agent/__init__.py +23 -0
  3. agent_env/a2a_agent/a2a_agent.py +600 -0
  4. agent_env/a2a_agent/conversation_store.py +356 -0
  5. agent_env/a2a_agent/object_transfer.py +609 -0
  6. agent_env/a2a_agent/protocol.py +238 -0
  7. agent_env/a2a_agent/store.py +201 -0
  8. agent_env/a2a_agent/validator.py +901 -0
  9. agent_env/artifact/__init__.py +48 -0
  10. agent_env/artifact/artifact.py +74 -0
  11. agent_env/artifact/artifacts/__init__.py +0 -0
  12. agent_env/artifact/artifacts/cli.py +83 -0
  13. agent_env/artifact/artifacts/docker_image.py +457 -0
  14. agent_env/artifact/artifacts/environment.py +89 -0
  15. agent_env/artifact/artifacts/environment_universe.py +156 -0
  16. agent_env/artifact/artifacts/file.py +214 -0
  17. agent_env/artifact/artifacts/file_artifact_universe.py +206 -0
  18. agent_env/artifact/artifacts/skill.py +206 -0
  19. agent_env/artifact/artifacts/vm_image.py +95 -0
  20. agent_env/artifact/ref.py +15 -0
  21. agent_env/artifact/registry.py +251 -0
  22. agent_env/artifact/store.py +295 -0
  23. agent_env/artifact/universe.py +38 -0
  24. agent_env/attribution.py +41 -0
  25. agent_env/bundle/__init__.py +4 -0
  26. agent_env/bundle/_fs.py +128 -0
  27. agent_env/bundle/authoring.py +239 -0
  28. agent_env/bundle/installed.py +175 -0
  29. agent_env/bundle/ledger.py +269 -0
  30. agent_env/bundle/materialize.py +204 -0
  31. agent_env/bundle/parse.py +594 -0
  32. agent_env/bundle/plan.py +414 -0
  33. agent_env/bundle/resolve.py +404 -0
  34. agent_env/bundle/run.py +361 -0
  35. agent_env/cli/__init__.py +69 -0
  36. agent_env/cli/__main__.py +10 -0
  37. agent_env/cli/_installers.py +576 -0
  38. agent_env/cli/_plugin_changes.py +947 -0
  39. agent_env/cli/a2a_agent/__init__.py +22 -0
  40. agent_env/cli/a2a_agent/add_skill.py +97 -0
  41. agent_env/cli/a2a_agent/deploy.py +60 -0
  42. agent_env/cli/a2a_agent/get.py +15 -0
  43. agent_env/cli/a2a_agent/get_instance.py +26 -0
  44. agent_env/cli/a2a_agent/put.py +78 -0
  45. agent_env/cli/a2a_agent/validate.py +56 -0
  46. agent_env/cli/artifact/__init__.py +20 -0
  47. agent_env/cli/artifact/cli.py +83 -0
  48. agent_env/cli/artifact/environment.py +44 -0
  49. agent_env/cli/artifact/environment_universe.py +163 -0
  50. agent_env/cli/artifact/file_artifact_universe.py +281 -0
  51. agent_env/cli/artifact/skill.py +128 -0
  52. agent_env/cli/banner.py +25 -0
  53. agent_env/cli/config.py +263 -0
  54. agent_env/cli/env/__init__.py +31 -0
  55. agent_env/cli/env/deploy.py +112 -0
  56. agent_env/cli/env/gateway.py +57 -0
  57. agent_env/cli/env/get_instance.py +40 -0
  58. agent_env/cli/env/mcp_server.py +410 -0
  59. agent_env/cli/env/multi.py +282 -0
  60. agent_env/cli/env/service_db.py +99 -0
  61. agent_env/cli/env/snapshot.py +35 -0
  62. agent_env/cli/env/state/__init__.py +6 -0
  63. agent_env/cli/env/state/init.py +108 -0
  64. agent_env/cli/env/state/teardown.py +44 -0
  65. agent_env/cli/env/website.py +216 -0
  66. agent_env/cli/env/website_browser.py +67 -0
  67. agent_env/cli/eval/__init__.py +16 -0
  68. agent_env/cli/eval/add_tasks.py +63 -0
  69. agent_env/cli/eval/create.py +49 -0
  70. agent_env/cli/eval/run.py +194 -0
  71. agent_env/cli/identity/__init__.py +5 -0
  72. agent_env/cli/identity/client_identity.py +37 -0
  73. agent_env/cli/plugin.py +438 -0
  74. agent_env/cli/run.py +285 -0
  75. agent_env/cli/task/__init__.py +21 -0
  76. agent_env/cli/task/create.py +109 -0
  77. agent_env/cli/task/get.py +17 -0
  78. agent_env/cli/task/get_instance.py +34 -0
  79. agent_env/cli/task/run.py +615 -0
  80. agent_env/cli/task/validate.py +31 -0
  81. agent_env/cli/up.py +123 -0
  82. agent_env/cli/utils.py +183 -0
  83. agent_env/config/__init__.py +50 -0
  84. agent_env/config/describe.py +1067 -0
  85. agent_env/config/errors.py +13 -0
  86. agent_env/config/loader.py +245 -0
  87. agent_env/config/model.py +154 -0
  88. agent_env/config/paths.py +25 -0
  89. agent_env/config/plugin_tables.py +101 -0
  90. agent_env/config/provenance.py +134 -0
  91. agent_env/config/runtime.py +1064 -0
  92. agent_env/config/snapshot.py +81 -0
  93. agent_env/entity_refs.py +186 -0
  94. agent_env/env/__init__.py +49 -0
  95. agent_env/env/env.py +433 -0
  96. agent_env/env/env_artifact_store.py +87 -0
  97. agent_env/env/envs/__init__.py +7 -0
  98. agent_env/env/envs/_deployment.py +281 -0
  99. agent_env/env/envs/gateway_server.py +32 -0
  100. agent_env/env/envs/mcp_server.py +387 -0
  101. agent_env/env/envs/multi_env.py +780 -0
  102. agent_env/env/envs/service_db/Dockerfile +20 -0
  103. agent_env/env/envs/service_db/Dockerfile.db-mcp +42 -0
  104. agent_env/env/envs/service_db/Dockerfile.db-web +8 -0
  105. agent_env/env/envs/service_db.py +92 -0
  106. agent_env/env/envs/website.py +294 -0
  107. agent_env/env/envs/website_browser/Dockerfile +40 -0
  108. agent_env/env/envs/website_browser/__init__.py +17 -0
  109. agent_env/env/envs/website_browser/entrypoint.sh +13 -0
  110. agent_env/env/gateway/Dockerfile +14 -0
  111. agent_env/env/gateway/__init__.py +37 -0
  112. agent_env/env/gateway/clock.py +184 -0
  113. agent_env/env/gateway/constants.py +190 -0
  114. agent_env/env/gateway/entrypoint.py +156 -0
  115. agent_env/env/gateway/gateway.py +1095 -0
  116. agent_env/env/gateway/get_time.py +60 -0
  117. agent_env/env/gateway/requirements.txt +4 -0
  118. agent_env/env/gateway/triggers.py +1193 -0
  119. agent_env/env/legacy_protocol.py +146 -0
  120. agent_env/env/registry.py +93 -0
  121. agent_env/env/snapshot_store.py +372 -0
  122. agent_env/env/store.py +411 -0
  123. agent_env/eval/__init__.py +14 -0
  124. agent_env/eval/eval.py +68 -0
  125. agent_env/eval/store.py +116 -0
  126. agent_env/examples/hello/README.md +9 -0
  127. agent_env/examples/hello/artifacts/greeting/check.sh +1 -0
  128. agent_env/examples/hello/artifacts/greeting/hello.txt +1 -0
  129. agent_env/examples/hello/tasks/hello.json +10 -0
  130. agent_env/explorer/__init__.py +12 -0
  131. agent_env/explorer/app.py +277 -0
  132. agent_env/explorer/openapi_docs.py +242 -0
  133. agent_env/explorer/plugin.py +95 -0
  134. agent_env/explorer/routers/__init__.py +1 -0
  135. agent_env/explorer/routers/common.py +174 -0
  136. agent_env/explorer/routers/conversations.py +25 -0
  137. agent_env/explorer/routers/objects.py +112 -0
  138. agent_env/explorer/routers/runs.py +475 -0
  139. agent_env/plugins/__init__.py +59 -0
  140. agent_env/plugins/_cli.py +244 -0
  141. agent_env/plugins/_discovery.py +97 -0
  142. agent_env/plugins/_inventory.py +262 -0
  143. agent_env/plugins/_registration.py +268 -0
  144. agent_env/plugins/_report.py +47 -0
  145. agent_env/plugins/_requirements.py +55 -0
  146. agent_env/providers/__init__.py +37 -0
  147. agent_env/providers/env_providers/__init__.py +12 -0
  148. agent_env/providers/env_providers/constants.py +13 -0
  149. agent_env/providers/env_providers/env_gateway_provider.py +1354 -0
  150. agent_env/providers/env_providers/env_provider.py +237 -0
  151. agent_env/providers/env_providers/env_server_provider.py +133 -0
  152. agent_env/providers/env_state/__init__.py +49 -0
  153. agent_env/providers/env_state/env_state_provider.py +554 -0
  154. agent_env/providers/env_state/local_postgres.py +390 -0
  155. agent_env/providers/env_state/store.py +112 -0
  156. agent_env/providers/sandbox_providers/__init__.py +29 -0
  157. agent_env/providers/sandbox_providers/chained_sandbox_provider.py +93 -0
  158. agent_env/providers/sandbox_providers/e2b/__init__.py +6 -0
  159. agent_env/providers/sandbox_providers/e2b/provider.py +376 -0
  160. agent_env/providers/sandbox_providers/e2b/sandbox.py +342 -0
  161. agent_env/providers/sandbox_providers/e2b/template.py +158 -0
  162. agent_env/providers/sandbox_providers/local_sandbox.py +408 -0
  163. agent_env/providers/sandbox_providers/modal_sandbox.py +500 -0
  164. agent_env/providers/sandbox_providers/modal_vm_sandbox.py +466 -0
  165. agent_env/providers/sandbox_providers/sandbox.py +387 -0
  166. agent_env/providers/sandbox_providers/sandbox_provider.py +614 -0
  167. agent_env/py.typed +0 -0
  168. agent_env/runner/__init__.py +16 -0
  169. agent_env/runner/local_runner.py +190 -0
  170. agent_env/runner/runner.py +127 -0
  171. agent_env/runner/store.py +94 -0
  172. agent_env/store/__init__.py +126 -0
  173. agent_env/store/_google.py +68 -0
  174. agent_env/store/base.py +33 -0
  175. agent_env/store/document_store/__init__.py +60 -0
  176. agent_env/store/document_store/document_store.py +519 -0
  177. agent_env/store/document_store/dynamodb_document_store.py +306 -0
  178. agent_env/store/document_store/evaluation.py +199 -0
  179. agent_env/store/document_store/firestore_mongo_document_store.py +242 -0
  180. agent_env/store/document_store/mongo_document_store.py +259 -0
  181. agent_env/store/document_store/sqlite_document_store.py +314 -0
  182. agent_env/store/ids.py +123 -0
  183. agent_env/store/image_store/__init__.py +34 -0
  184. agent_env/store/image_store/ecr_image_store.py +131 -0
  185. agent_env/store/image_store/google_credentials.py +113 -0
  186. agent_env/store/image_store/image_store.py +113 -0
  187. agent_env/store/image_store/local_registry_image_store.py +106 -0
  188. agent_env/store/image_store/oci_registry_credentials.py +196 -0
  189. agent_env/store/local_state.py +27 -0
  190. agent_env/store/object_store/__init__.py +24 -0
  191. agent_env/store/object_store/gcs_object_store.py +415 -0
  192. agent_env/store/object_store/local_object_store.py +143 -0
  193. agent_env/store/object_store/object_store.py +198 -0
  194. agent_env/store/object_store/s3_object_store.py +354 -0
  195. agent_env/store/query.py +112 -0
  196. agent_env/store/routing.py +609 -0
  197. agent_env/store/secret_store/__init__.py +19 -0
  198. agent_env/store/secret_store/aws_secrets_manager_secret_store.py +293 -0
  199. agent_env/store/secret_store/gcp_secret_manager_secret_store.py +319 -0
  200. agent_env/store/secret_store/local_secret_store.py +47 -0
  201. agent_env/store/secret_store/secret_store.py +19 -0
  202. agent_env/task/__init__.py +27 -0
  203. agent_env/task/interrupts.py +109 -0
  204. agent_env/task/registry.py +27 -0
  205. agent_env/task/step_journal.py +99 -0
  206. agent_env/task/store.py +940 -0
  207. agent_env/task/task.py +815 -0
  208. agent_env/task/teardown.py +142 -0
  209. agent_env/task_step/__init__.py +47 -0
  210. agent_env/task_step/context.py +195 -0
  211. agent_env/task_step/context_ops.py +224 -0
  212. agent_env/task_step/registry.py +182 -0
  213. agent_env/task_step/review_store.py +118 -0
  214. agent_env/task_step/snapshot_utils/__init__.py +2 -0
  215. agent_env/task_step/snapshot_utils/agent_state_capture.py +261 -0
  216. agent_env/task_step/snapshot_utils/snapshot_series.py +631 -0
  217. agent_env/task_step/store.py +129 -0
  218. agent_env/task_step/task_step.py +173 -0
  219. agent_env/task_step/task_steps/__init__.py +27 -0
  220. agent_env/task_step/task_steps/a2a_agent_validator/__init__.py +31 -0
  221. agent_env/task_step/task_steps/a2a_agent_validator/fixtures/README.md +158 -0
  222. agent_env/task_step/task_steps/a2a_agent_validator/fixtures/clip.m4a +0 -0
  223. agent_env/task_step/task_steps/a2a_agent_validator/fixtures/clip.mp3 +0 -0
  224. agent_env/task_step/task_steps/a2a_agent_validator/fixtures/clip.mp4 +0 -0
  225. agent_env/task_step/task_steps/a2a_agent_validator/fixtures/clip.ogg +0 -0
  226. agent_env/task_step/task_steps/a2a_agent_validator/fixtures/clip.wav +0 -0
  227. agent_env/task_step/task_steps/a2a_agent_validator/fixtures/document.pdf +0 -0
  228. agent_env/task_step/task_steps/a2a_agent_validator/fixtures/red.gif +0 -0
  229. agent_env/task_step/task_steps/a2a_agent_validator/fixtures/red.jpg +0 -0
  230. agent_env/task_step/task_steps/a2a_agent_validator/fixtures/red.png +0 -0
  231. agent_env/task_step/task_steps/a2a_agent_validator/verify_a2a_agent_card.py +103 -0
  232. agent_env/task_step/task_steps/a2a_agent_validator/verify_a2a_agent_config_identity.py +69 -0
  233. agent_env/task_step/task_steps/a2a_agent_validator/verify_a2a_agent_mcp.py +178 -0
  234. agent_env/task_step/task_steps/a2a_agent_validator/verify_a2a_core_protocol.py +67 -0
  235. agent_env/task_step/task_steps/a2a_agent_validator/verify_a2a_install.py +115 -0
  236. agent_env/task_step/task_steps/a2a_agent_validator/verify_a2a_litellm_attribution.py +124 -0
  237. agent_env/task_step/task_steps/a2a_agent_validator/verify_a2a_litellm_attribution_runtime.py +173 -0
  238. agent_env/task_step/task_steps/a2a_agent_validator/verify_a2a_modalities.py +270 -0
  239. agent_env/task_step/task_steps/a2a_agent_validator/verify_a2a_peer_agents.py +102 -0
  240. agent_env/task_step/task_steps/a2a_agent_validator/verify_a2a_role.py +151 -0
  241. agent_env/task_step/task_steps/a2a_agent_validator/verify_a2a_skill_config.py +194 -0
  242. agent_env/task_step/task_steps/a2a_agent_validator/verify_a2a_snapshot.py +111 -0
  243. agent_env/task_step/task_steps/a2a_agent_validator/verify_a2a_system_prompt.py +215 -0
  244. agent_env/task_step/task_steps/a2a_agent_validator/verify_a2a_trajectory.py +164 -0
  245. agent_env/task_step/task_steps/add_skills.py +240 -0
  246. agent_env/task_step/task_steps/apply_server_config.py +288 -0
  247. agent_env/task_step/task_steps/collect_artifacts.py +940 -0
  248. agent_env/task_step/task_steps/deploy_agent.py +626 -0
  249. agent_env/task_step/task_steps/deploy_env.py +197 -0
  250. agent_env/task_step/task_steps/deploy_human_agent.py +100 -0
  251. agent_env/task_step/task_steps/deploy_sandbox.py +170 -0
  252. agent_env/task_step/task_steps/env_card_validator/__init__.py +4 -0
  253. agent_env/task_step/task_steps/env_card_validator/verify_env_card.py +109 -0
  254. agent_env/task_step/task_steps/env_card_validator/verify_env_core_protocol.py +108 -0
  255. agent_env/task_step/task_steps/install_agent.py +376 -0
  256. agent_env/task_step/task_steps/load_artifact.py +775 -0
  257. agent_env/task_step/task_steps/mcp_cli_builder/__init__.py +4 -0
  258. agent_env/task_step/task_steps/mcp_cli_builder/build_mcp_cli.py +201 -0
  259. agent_env/task_step/task_steps/mcp_cli_builder/codegen.py +627 -0
  260. agent_env/task_step/task_steps/mcp_env_validator/__init__.py +44 -0
  261. agent_env/task_step/task_steps/mcp_env_validator/validation_gate_aggregator.py +102 -0
  262. agent_env/task_step/task_steps/mcp_env_validator/verify_mcp_env_assessment.py +78 -0
  263. agent_env/task_step/task_steps/mcp_env_validator/verify_mcp_tool_schema.py +152 -0
  264. agent_env/task_step/task_steps/mcp_env_validator/verify_spec_conformance.py +486 -0
  265. agent_env/task_step/task_steps/modify_env_tool_access.py +80 -0
  266. agent_env/task_step/task_steps/multienv_validator/__init__.py +3 -0
  267. agent_env/task_step/task_steps/multienv_validator/combine_universe_verdicts.py +107 -0
  268. agent_env/task_step/task_steps/multienv_validator/universe_comparison.py +253 -0
  269. agent_env/task_step/task_steps/multienv_validator/verify_universe_agent_judge.py +180 -0
  270. agent_env/task_step/task_steps/multienv_validator/verify_universe_roundtrip.py +241 -0
  271. agent_env/task_step/task_steps/peer_agents.py +92 -0
  272. agent_env/task_step/task_steps/prompt_agent.py +900 -0
  273. agent_env/task_step/task_steps/register_agent_triggers.py +113 -0
  274. agent_env/task_step/task_steps/register_env_triggers.py +97 -0
  275. agent_env/task_step/task_steps/reset_env.py +71 -0
  276. agent_env/task_step/task_steps/review.py +152 -0
  277. agent_env/task_step/task_steps/run_code.py +461 -0
  278. agent_env/task_step/task_steps/run_code_runner.py +52 -0
  279. agent_env/task_step/task_steps/run_docker_container.py +380 -0
  280. agent_env/task_step/task_steps/sandbox_utils/__init__.py +0 -0
  281. agent_env/task_step/task_steps/sandbox_utils/sandbox_utils.py +79 -0
  282. agent_env/task_step/task_steps/snapshot_agent_state.py +205 -0
  283. agent_env/task_step/task_steps/snapshot_env.py +637 -0
  284. agent_env/task_step/task_steps/sync_env_clock.py +132 -0
  285. agent_env/task_step/task_steps/teardown_sandboxes.py +170 -0
  286. agent_env/task_step/task_steps/verifiers/__init__.py +23 -0
  287. agent_env/task_step/task_steps/verifiers/agent_prompt_response_verifier.py +166 -0
  288. agent_env/task_step/task_steps/verifiers/aggregate_verifiers.py +90 -0
  289. agent_env/task_step/task_steps/verifiers/env_outcome_verifier.py +127 -0
  290. agent_env/task_step/task_steps/verifiers/judge_utils/__init__.py +2 -0
  291. agent_env/task_step/task_steps/verifiers/judge_utils/frame_selection.py +377 -0
  292. agent_env/task_step/task_steps/verifiers/judge_utils/judge_output_format.py +1293 -0
  293. agent_env/task_step/task_steps/verifiers/judge_utils/trajectory_filter.py +514 -0
  294. agent_env/task_step/task_steps/verifiers/rubrics_verifier.py +1318 -0
  295. agent_env/task_step/task_steps/verifiers/run_container_unit_tests_verifier.py +434 -0
  296. agent_env/task_step/task_steps/verifiers/scoring.py +40 -0
  297. agent_env/task_step/task_steps/verifiers/verify_sandbox.py +308 -0
  298. agent_env/task_step/thread_work.py +61 -0
  299. agent_env/utils/__init__.py +0 -0
  300. agent_env/utils/card_naming.py +108 -0
  301. agent_env/utils/deprecation.py +109 -0
  302. agent_env/utils/docker_build.py +29 -0
  303. agent_env/utils/exec_retry.py +77 -0
  304. agent_env/utils/litellm_attribution.py +59 -0
  305. agent_env/utils/paths.py +20 -0
  306. agentenv_framework-0.9.1254.dist-info/METADATA +394 -0
  307. agentenv_framework-0.9.1254.dist-info/RECORD +312 -0
  308. agentenv_framework-0.9.1254.dist-info/WHEEL +4 -0
  309. agentenv_framework-0.9.1254.dist-info/entry_points.txt +5 -0
  310. agentenv_framework-0.9.1254.dist-info/licenses/LICENSE +202 -0
  311. agentenv_framework-0.9.1254.dist-info/licenses/NOTICE +4 -0
  312. agentenv_framework-0.9.1254.dist-info/licenses/THIRD_PARTY_NOTICES.md +7665 -0
@@ -0,0 +1,216 @@
1
+ import asyncio
2
+ import os
3
+ import sys
4
+ from pathlib import Path
5
+
6
+ import click
7
+
8
+ from agent_env.artifact import DockerImageArtifact, EnvironmentArtifact
9
+ from agent_env.cli.utils import (
10
+ deployed_env_from_instance,
11
+ build_platform_option,
12
+ detect_env_metadata,
13
+ env_provider_type_option,
14
+ environment_name_options,
15
+ resolve_environment_name,
16
+ skips_local_validation,
17
+ )
18
+ from agent_env.utils.card_naming import card_name_from_github, card_name_from_source
19
+ from agent_env.utils.docker_build import DEFAULT_BUILD_PLATFORM, build_image
20
+ from agent_env.env import Env
21
+ from agent_env.env.envs.website import WebsiteEnv
22
+ from agent_env.providers import get_env_sandbox_provider
23
+
24
+
25
+
26
+ @click.group(name="website")
27
+ def website():
28
+ """Website environment commands."""
29
+ pass
30
+
31
+
32
+ @website.command()
33
+ @click.option("--id", "env_id", required=True, help="Env id")
34
+ @click.option("--backend-dockerfile", default=None, type=click.Path(exists=True), help="Path to backend Dockerfile")
35
+ @click.option("--backend-docker-context", default=None, type=click.Path(exists=True), help="Backend Docker build context (defaults to Dockerfile's directory)")
36
+ @click.option("--backend-dockerfile-github-url", default=None, help="GitHub URL to backend Dockerfile")
37
+ @click.option("--backend-docker-context-github-url", default=None, help="GitHub URL to backend build context directory")
38
+ @click.option("--frontend-dockerfile", default=None, type=click.Path(exists=True), help="Path to frontend Dockerfile")
39
+ @click.option("--frontend-docker-context", default=None, type=click.Path(exists=True), help="Frontend Docker build context (defaults to Dockerfile's directory)")
40
+ @click.option("--frontend-dockerfile-github-url", default=None, help="GitHub URL to frontend Dockerfile")
41
+ @click.option("--frontend-docker-context-github-url", default=None, help="GitHub URL to frontend build context directory")
42
+ @environment_name_options
43
+ @env_provider_type_option("What deploys the env: 'gateway' (a gateway in front of the website), or the type of an installed "
44
+ "agent_env.env_providers plugin", "website")
45
+ @click.option("--metadata", "metadata_pairs", multiple=True, help="Metadata key=value pair (repeatable)")
46
+ @click.option("--skip-validation", is_flag=True, default=False, help="Skip environment validation after registration")
47
+ @build_platform_option
48
+ def put(
49
+ env_id: str,
50
+ backend_dockerfile: str | None,
51
+ backend_docker_context: str | None,
52
+ backend_dockerfile_github_url: str | None,
53
+ backend_docker_context_github_url: str | None,
54
+ frontend_dockerfile: str | None,
55
+ frontend_docker_context: str | None,
56
+ frontend_dockerfile_github_url: str | None,
57
+ frontend_docker_context_github_url: str | None,
58
+ environment_name: str | None,
59
+ env_provider_type: str,
60
+ metadata_pairs: tuple[str, ...],
61
+ skip_validation: bool,
62
+ build_platform: str,
63
+ ):
64
+ """Build and upload a website environment (frontend + backend)."""
65
+ environment_name = resolve_environment_name(environment_name, allow_missing=True)
66
+
67
+ # Validate mutual exclusion
68
+ if backend_dockerfile and backend_dockerfile_github_url:
69
+ click.echo("Error: --backend-dockerfile and --backend-dockerfile-github-url are mutually exclusive", err=True)
70
+ sys.exit(1)
71
+ if not backend_dockerfile and not backend_dockerfile_github_url:
72
+ click.echo("Error: either --backend-dockerfile or --backend-dockerfile-github-url is required", err=True)
73
+ sys.exit(1)
74
+ if frontend_dockerfile and frontend_dockerfile_github_url:
75
+ click.echo("Error: --frontend-dockerfile and --frontend-dockerfile-github-url are mutually exclusive", err=True)
76
+ sys.exit(1)
77
+ if not frontend_dockerfile and not frontend_dockerfile_github_url:
78
+ click.echo("Error: either --frontend-dockerfile or --frontend-dockerfile-github-url is required", err=True)
79
+ sys.exit(1)
80
+ use_github = bool(backend_dockerfile_github_url)
81
+ if use_github != bool(frontend_dockerfile_github_url):
82
+ click.echo("Error: backend and frontend must both use local Dockerfiles or both use GitHub URLs", err=True)
83
+ sys.exit(1)
84
+
85
+ user_metadata = {}
86
+ for pair in metadata_pairs:
87
+ if "=" not in pair:
88
+ click.echo(f"Invalid metadata format '{pair}', expected key=value", err=True)
89
+ sys.exit(1)
90
+ key, value = pair.split("=", 1)
91
+ user_metadata[key] = value
92
+
93
+ if use_github:
94
+ if environment_name is None:
95
+ environment_name = card_name_from_github(backend_dockerfile_github_url, backend_docker_context_github_url, github_token=os.environ.get("GITHUB_TOKEN"))
96
+ if not environment_name:
97
+ click.echo("Error: could not read @environment_card(name=...) from the backend GitHub source; pass --environment-name.", err=True)
98
+ sys.exit(1)
99
+ click.echo(f"Derived environment_name={environment_name!r} from the environment card.")
100
+ if build_platform != DEFAULT_BUILD_PLATFORM:
101
+ click.echo(f"Warning: --platform {build_platform!r} is ignored for --*-dockerfile-github-url builds", err=True)
102
+ backend_status = [""]
103
+ frontend_status = [""]
104
+ lines_printed = [0]
105
+
106
+ def _redraw():
107
+ if lines_printed[0] > 0:
108
+ click.echo(f"\033[{lines_printed[0]}A", nl=False)
109
+ click.echo(f"\033[2K {click.style('Backend:', fg='cyan')} {backend_status[0]}")
110
+ click.echo(f"\033[2K {click.style('Frontend:', fg='magenta')} {frontend_status[0]}")
111
+ lines_printed[0] = 2
112
+
113
+ def _backend_progress(step: str, message: str, percent: int) -> None:
114
+ backend_status[0] = f"[{percent:3d}%] {message}"
115
+ _redraw()
116
+
117
+ def _frontend_progress(step: str, message: str, percent: int) -> None:
118
+ frontend_status[0] = f"[{percent:3d}%] {message}"
119
+ _redraw()
120
+
121
+ env = asyncio.run(WebsiteEnv.put_from_github(
122
+ id=env_id,
123
+ backend_dockerfile_github_url=backend_dockerfile_github_url,
124
+ backend_docker_context_github_url=backend_docker_context_github_url,
125
+ frontend_dockerfile_github_url=frontend_dockerfile_github_url,
126
+ frontend_docker_context_github_url=frontend_docker_context_github_url,
127
+ environment_name=environment_name,
128
+ metadata=user_metadata if user_metadata else None,
129
+ on_backend_progress=_backend_progress,
130
+ on_frontend_progress=_frontend_progress,
131
+ github_token=os.environ.get("GITHUB_TOKEN"),
132
+ env_provider_type=env_provider_type,
133
+ ))
134
+ click.echo(f"Created WebsiteEnv: id={env.id} version={env.version} environment_name={env.environment_name}")
135
+ if not skip_validation and not skips_local_validation(env.id, "env"):
136
+ click.echo("\nValidating environment (use --skip-validation to skip)...")
137
+ instance_id = asyncio.run(env.validate(on_progress=click.echo))
138
+ click.echo(f"Validation task: {instance_id}")
139
+ return
140
+
141
+ # Local Docker build path
142
+ backend_dockerfile_path = Path(backend_dockerfile)
143
+ backend_ctx = Path(backend_docker_context) if backend_docker_context else backend_dockerfile_path.parent
144
+ backend_tag = f"website-backend-{env_id}"
145
+ if environment_name is None:
146
+ environment_name = card_name_from_source(str(backend_dockerfile_path), str(backend_ctx))
147
+ if not environment_name:
148
+ click.echo("Error: no @environment_card(name=...) found in the backend source; pass --environment-name.", err=True)
149
+ sys.exit(1)
150
+ click.echo(f"Derived environment_name={environment_name!r} from the environment card.")
151
+
152
+ click.echo(f"Building website backend Docker image...")
153
+ build_image(backend_dockerfile_path, backend_ctx, backend_tag, platform=build_platform)
154
+
155
+ click.echo(f"Creating backend DockerImageArtifact...")
156
+ backend_artifact = DockerImageArtifact.put(
157
+ id=f"website-backend-{env_id}",
158
+ description="Website backend image created from agent-env CLI",
159
+ image_name=backend_tag,
160
+ )
161
+ click.echo(f"Created backend artifact: id={backend_artifact.id} version={backend_artifact.version}")
162
+
163
+ frontend_dockerfile_path = Path(frontend_dockerfile)
164
+ frontend_ctx = Path(frontend_docker_context) if frontend_docker_context else frontend_dockerfile_path.parent
165
+ frontend_tag = f"website-frontend-{env_id}"
166
+
167
+ click.echo(f"Building website frontend Docker image...")
168
+ build_image(frontend_dockerfile_path, frontend_ctx, frontend_tag, platform=build_platform)
169
+
170
+ click.echo(f"Creating frontend DockerImageArtifact...")
171
+ frontend_artifact = DockerImageArtifact.put(
172
+ id=f"website-frontend-{env_id}",
173
+ description="Website frontend image created from agent-env CLI",
174
+ image_name=frontend_tag,
175
+ )
176
+ click.echo(f"Created frontend artifact: id={frontend_artifact.id} version={frontend_artifact.version}")
177
+
178
+ metadata = detect_env_metadata(backend_dockerfile_path, backend_ctx)
179
+ metadata.update(user_metadata)
180
+
181
+ click.echo(f"Creating WebsiteEnv...")
182
+ env = WebsiteEnv.put(
183
+ id=env_id,
184
+ backend_docker_image_artifact=backend_artifact,
185
+ frontend_docker_image_artifact=frontend_artifact,
186
+ environment_name=environment_name,
187
+ metadata=metadata if metadata else None,
188
+ env_provider_type=env_provider_type,
189
+ )
190
+ click.echo(f"Created WebsiteEnv: id={env.id} version={env.version} environment_name={env.environment_name} env_provider_type={env.env_provider_type}")
191
+ if not skip_validation and not skips_local_validation(env.id, "env"):
192
+ click.echo("\nValidating environment (use --skip-validation to skip)...")
193
+ instance_id = asyncio.run(env.validate(on_progress=click.echo))
194
+ click.echo(f"Validation task: {instance_id}")
195
+
196
+
197
+ @website.command(name="load-environment-artifact")
198
+ @click.option("--id", "env_id", default=None, help="WebsiteEnv id (optional; cross-checked against the instance)")
199
+ @click.option("--environment-artifact-id", "environment_artifact_id",
200
+ required=True, help="EnvironmentArtifact id")
201
+ @click.option("--instance-id", "instance_id", required=True,
202
+ help="Deployed env instance id, as printed by `env deploy`")
203
+ def load_environment_artifact(env_id: str | None, environment_artifact_id: str,
204
+ instance_id: str):
205
+ """Load an environment artifact into a deployed website environment."""
206
+
207
+ env = deployed_env_from_instance(env_id, instance_id)
208
+ click.echo(f"Found env: id={env.id} version={env.version} environment_name={env.environment_name}")
209
+
210
+ click.echo(f"Fetching environment artifact: id={environment_artifact_id}...")
211
+ environment_artifact = EnvironmentArtifact.get(environment_artifact_id)
212
+ click.echo(f"Found environment artifact: id={environment_artifact.id} version={environment_artifact.version} environment_name={environment_artifact.environment_name}")
213
+
214
+ click.echo("Loading environment artifact...")
215
+ asyncio.run(env.load_environment_artifact(environment_artifact))
216
+ click.echo("Loaded environment artifact into env")
@@ -0,0 +1,67 @@
1
+ import sys
2
+ from pathlib import Path
3
+
4
+ import click
5
+
6
+ from agent_env.artifact import DockerImageArtifact
7
+ from agent_env.cli.utils import build_platform_option, detect_env_metadata
8
+ from agent_env.env import MCPServerEnv
9
+ from agent_env.env.envs.website_browser import (
10
+ PLAYWRIGHT_MCP_VERSION,
11
+ WEBSITE_BROWSER_IMAGE_TAG,
12
+ WEBSITE_BROWSER_ENVIRONMENT_NAME,
13
+ )
14
+ from agent_env.utils.docker_build import build_image
15
+
16
+ _PACKAGE_ROOT = Path(__file__).parent.parent.parent
17
+ WEBSITE_BROWSER_DOCKERFILE = _PACKAGE_ROOT / "env" / "envs" / "website_browser" / "Dockerfile"
18
+ WEBSITE_BROWSER_CONTEXT = _PACKAGE_ROOT / "env" / "envs" / "website_browser"
19
+
20
+
21
+ @click.group(name="website-browser")
22
+ def website_browser():
23
+ """Website browser environment commands."""
24
+ pass
25
+
26
+
27
+ @website_browser.command()
28
+ @click.option("--id", "env_id", default=None, help="Env id (default: config default_website_browser_env_id)")
29
+ @click.option("--metadata", "metadata_pairs", multiple=True, help="Metadata key=value pair (repeatable)")
30
+ @build_platform_option
31
+ def put(env_id: str, metadata_pairs: tuple[str, ...], build_platform: str):
32
+ """Build and upload a website browser environment."""
33
+ from agent_env.config import get_config
34
+
35
+ if not env_id:
36
+ env_id = get_config().default_website_browser_env_id
37
+
38
+ click.echo("Building website browser Docker image...")
39
+ build_image(WEBSITE_BROWSER_DOCKERFILE, WEBSITE_BROWSER_CONTEXT, WEBSITE_BROWSER_IMAGE_TAG, platform=build_platform,
40
+ build_args={"PLAYWRIGHT_MCP_VERSION": PLAYWRIGHT_MCP_VERSION})
41
+
42
+ click.echo("Creating DockerImageArtifact...")
43
+ artifact = DockerImageArtifact.put(
44
+ id=f"website-browser-{env_id}",
45
+ description="Website browser MCP server",
46
+ image_name=WEBSITE_BROWSER_IMAGE_TAG,
47
+ )
48
+ click.echo(f"Created artifact: id={artifact.id} version={artifact.version}")
49
+
50
+ user_metadata = {}
51
+ for pair in metadata_pairs:
52
+ if "=" not in pair:
53
+ click.echo(f"Invalid metadata format '{pair}', expected key=value", err=True)
54
+ sys.exit(1)
55
+ key, value = pair.split("=", 1)
56
+ user_metadata[key] = value
57
+ metadata = detect_env_metadata(WEBSITE_BROWSER_DOCKERFILE, WEBSITE_BROWSER_CONTEXT)
58
+ metadata.update(user_metadata)
59
+
60
+ click.echo("Creating MCPServerEnv...")
61
+ env = MCPServerEnv.put(
62
+ id=env_id,
63
+ docker_image_artifact=artifact,
64
+ environment_name=WEBSITE_BROWSER_ENVIRONMENT_NAME,
65
+ metadata=metadata if metadata else None,
66
+ )
67
+ click.echo(f"Created MCPServerEnv: id={env.id} version={env.version} environment_name={env.environment_name}")
@@ -0,0 +1,16 @@
1
+ import click
2
+
3
+ from .add_tasks import add_tasks
4
+ from .create import create
5
+ from .run import run
6
+
7
+
8
+ @click.group()
9
+ def eval():
10
+ """Eval commands."""
11
+ pass
12
+
13
+
14
+ eval.add_command(create)
15
+ eval.add_command(add_tasks)
16
+ eval.add_command(run)
@@ -0,0 +1,63 @@
1
+ """Add tasks to an existing eval, creating a new version."""
2
+
3
+ import json
4
+ from pathlib import Path
5
+
6
+ import click
7
+
8
+
9
+ @click.command("add-tasks")
10
+ @click.argument("filepath", type=click.Path(exists=True, dir_okay=False, path_type=Path))
11
+ @click.option("--id", "eval_id", required=True, help="Eval id")
12
+ @click.option("--version", "eval_version", default=None, type=int, help="Eval version (defaults to latest)")
13
+ def add_tasks(filepath: Path, eval_id: str, eval_version: int | None):
14
+ """Add tasks from a JSON file to an existing eval.
15
+
16
+ Creates a new eval version with the merged task list.
17
+ Duplicate task_ids are replaced with the new entry.
18
+
19
+ \b
20
+ The JSON file should contain a list of task reference dicts, e.g.:
21
+ [
22
+ {"task_id": "new-task", "task_version": 2},
23
+ {"task_id": "another-task"}
24
+ ]
25
+
26
+ task_version is optional; omit it to use the latest version.
27
+ """
28
+ from agent_env.eval import Eval, EvalTask
29
+ from agent_env.task import Task
30
+
31
+ click.echo(f"Fetching eval: id={eval_id} version={eval_version or 'latest'}...")
32
+ existing_eval = Eval.get(eval_id, version=eval_version)
33
+ click.echo(f"Found eval: id={existing_eval.id} version={existing_eval.version} tasks={len(existing_eval.tasks)}")
34
+
35
+ click.echo(f"Reading new tasks from {filepath}...")
36
+ with open(filepath) as f:
37
+ raw_tasks = json.load(f)
38
+
39
+ if not isinstance(raw_tasks, list):
40
+ click.echo("Error: JSON file must contain a list of task reference dicts", err=True)
41
+ raise SystemExit(1)
42
+
43
+ new_tasks: list[EvalTask] = []
44
+ for i, entry in enumerate(raw_tasks):
45
+ task_id = entry.get("task_id")
46
+ if not task_id:
47
+ click.echo(f"Error: entry {i} missing task_id: {entry}", err=True)
48
+ raise SystemExit(1)
49
+ task_version = entry.get("task_version")
50
+
51
+ task = Task.get(task_id, version=task_version)
52
+ click.echo(f" Validated task {i + 1}/{len(raw_tasks)}: {task.id} v{task.version} ({len(task.steps)} steps)")
53
+ new_tasks.append(EvalTask(task_id=task_id, task_version=task_version))
54
+
55
+ # Merge: existing tasks keyed by task_id, overwritten by new entries
56
+ merged: dict[str, EvalTask] = {t.task_id: t for t in existing_eval.tasks}
57
+ for t in new_tasks:
58
+ merged[t.task_id] = t
59
+ merged_tasks = list(merged.values())
60
+
61
+ click.echo(f"Creating new eval version with {len(merged_tasks)} tasks ({len(new_tasks)} added/updated)...")
62
+ eval_obj = Eval.put(id=eval_id, tasks=merged_tasks)
63
+ click.echo(f"Created eval: id={eval_obj.id} version={eval_obj.version} tasks={len(eval_obj.tasks)}")
@@ -0,0 +1,49 @@
1
+ """Create an eval from a JSON file listing tasks."""
2
+
3
+ import json
4
+ from pathlib import Path
5
+
6
+ import click
7
+
8
+
9
+ @click.command()
10
+ @click.argument("filepath", type=click.Path(exists=True, dir_okay=False, path_type=Path))
11
+ @click.option("--id", "eval_id", required=True, help="Eval id")
12
+ def create(filepath: Path, eval_id: str):
13
+ """Create an eval from a JSON file of task references.
14
+
15
+ \b
16
+ The JSON file should contain a list of task reference dicts, e.g.:
17
+ [
18
+ {"task_id": "my-task-1", "task_version": 1},
19
+ {"task_id": "my-task-2"}
20
+ ]
21
+
22
+ task_version is optional; omit it to use the latest version.
23
+ """
24
+ from agent_env.eval import Eval, EvalTask
25
+ from agent_env.task import Task
26
+
27
+ click.echo(f"Reading tasks from {filepath}...")
28
+ with open(filepath) as f:
29
+ raw_tasks = json.load(f)
30
+
31
+ if not isinstance(raw_tasks, list):
32
+ click.echo("Error: JSON file must contain a list of task reference dicts", err=True)
33
+ raise SystemExit(1)
34
+
35
+ eval_tasks: list[EvalTask] = []
36
+ for i, entry in enumerate(raw_tasks):
37
+ task_id = entry.get("task_id")
38
+ if not task_id:
39
+ click.echo(f"Error: entry {i} missing task_id: {entry}", err=True)
40
+ raise SystemExit(1)
41
+ task_version = entry.get("task_version")
42
+
43
+ task = Task.get(task_id, version=task_version)
44
+ click.echo(f" Validated task {i + 1}/{len(raw_tasks)}: {task.id} v{task.version} ({len(task.steps)} steps)")
45
+ eval_tasks.append(EvalTask(task_id=task_id, task_version=task_version))
46
+
47
+ click.echo(f"Creating eval '{eval_id}' with {len(eval_tasks)} tasks...")
48
+ eval_obj = Eval.put(id=eval_id, tasks=eval_tasks)
49
+ click.echo(f"Created eval: id={eval_obj.id} version={eval_obj.version} tasks={len(eval_obj.tasks)}")
@@ -0,0 +1,194 @@
1
+ """Run all tasks in an eval concurrently, tearing down each run's sandboxes as it ends."""
2
+
3
+ import asyncio
4
+ import contextlib
5
+ import copy
6
+ import json
7
+ import os
8
+ from uuid import uuid4
9
+
10
+ import click
11
+
12
+ from agent_env.cli.banner import print_banner
13
+ from agent_env.cli.identity import get_agent_env_client_id
14
+ from agent_env.store.ids import fs_safe
15
+ from agent_env.task.interrupts import Interrupts
16
+ from agent_env.task.teardown import TeardownReport, kind, teardown_run
17
+ from agent_env.task_step.context import TaskStepContext
18
+
19
+
20
+ def _make_callbacks(tag: str):
21
+ """Return (on_step_start, on_step_complete) callbacks with a prefix tag."""
22
+ last_score = None
23
+
24
+ def on_step_start(i, total, step, context):
25
+ click.echo(click.style(
26
+ f"{tag} Running step [{i+1}/{total}]: {step.type} (id={step.id})...",
27
+ fg="yellow",
28
+ ))
29
+
30
+ def on_step_complete(i, total, step, context, duration):
31
+ nonlocal last_score
32
+ click.echo(click.style(
33
+ f"{tag} Completed step [{i+1}/{total}]: {step.type} (id={step.id}) [{duration:.1f}s]",
34
+ fg="green",
35
+ ))
36
+
37
+ score = context.metadata.get("score")
38
+ if score is not None and score != last_score:
39
+ click.echo(click.style(f"{tag} score: {score}", fg="green"))
40
+ last_score = score
41
+
42
+ return on_step_start, on_step_complete
43
+
44
+
45
+ def _write_context(context, task_id, output_dir, prefix=""):
46
+ """Write context JSON to output_dir."""
47
+ os.makedirs(output_dir, exist_ok=True)
48
+ filename = f"{fs_safe(task_id)}_{uuid4().hex[:8]}.json"
49
+ output_path = os.path.join(output_dir, filename)
50
+ with open(output_path, "w") as f:
51
+ json.dump(context.to_safe_dict(), f, indent=2)
52
+ click.echo(click.style(f"{prefix}Output written to: {output_path}", fg="blue"))
53
+
54
+
55
+ def _echo_teardown(tag: str, report: TeardownReport) -> None:
56
+ if report.terminated:
57
+ n = len(report.terminated)
58
+ click.echo(click.style(f"{tag} Tore down {n} sandbox{'es' if n != 1 else ''}", fg="blue"))
59
+ for sandbox, why in report.failed:
60
+ click.echo(click.style(f"{tag} Couldn't tear down {sandbox.sandbox_id}: {why}", fg="red"))
61
+ for sandbox in report.left:
62
+ click.echo(click.style(f"{tag} Still up: {sandbox.sandbox_id} ({kind(sandbox)})", fg="red"))
63
+
64
+
65
+ async def _run_single(task, tag, output_dir, agent_model=None, agent_artifact_id=None, base_metadata=None):
66
+ """Execute a single task run with logging callbacks, then tear down what it deployed, even when it
67
+ raised or was cancelled."""
68
+ on_start, on_complete = _make_callbacks(tag)
69
+ context = TaskStepContext(metadata=copy.deepcopy(base_metadata or {}))
70
+ try:
71
+ await task.run(
72
+ on_step_start=on_start,
73
+ on_step_complete=on_complete,
74
+ agent_model=agent_model,
75
+ agent_artifact_id=agent_artifact_id,
76
+ context=context,
77
+ )
78
+ finally:
79
+ _echo_teardown(tag, await teardown_run(context))
80
+ if output_dir:
81
+ _write_context(context, task.id, output_dir, prefix=f"{tag} ")
82
+ return task.id, tag, context
83
+
84
+
85
+ @click.command()
86
+ @click.option("--id", "eval_id", required=True, help="Eval id")
87
+ @click.option("--version", "eval_version", default=None, type=int, help="Eval version (defaults to latest)")
88
+ @click.option("--output-dir", default=None, type=click.Path(file_okay=False), help="Directory to write per-task context JSON output")
89
+ @click.option("--k", "k", default=1, type=int, help="Number of parallel runs per task")
90
+ @click.option("--max-concurrency", default=None, type=int, help="Maximum number of concurrent task runs")
91
+ @click.option("--agent-model", default=None, type=str, help="Override the model used by prompt_agent steps")
92
+ @click.option("--agent-artifact-id", default=None, type=str, help="Override the agent image artifact for deploy_agent steps")
93
+ def run(eval_id: str, eval_version: int | None, output_dir: str | None, k: int, max_concurrency: int | None, agent_model: str | None, agent_artifact_id: str | None):
94
+ """Run all tasks in an eval concurrently."""
95
+ if k < 1:
96
+ raise click.BadParameter("must be at least 1", param_hint="'--k'")
97
+ if max_concurrency is not None and max_concurrency < 1:
98
+ raise click.BadParameter("must be at least 1", param_hint="'--max-concurrency'")
99
+
100
+ from agent_env.eval import Eval
101
+ from agent_env.task import Task
102
+
103
+ click.echo(f"Fetching eval: id={eval_id} version={eval_version or 'latest'}...")
104
+ eval_obj = Eval.get(eval_id, version=eval_version)
105
+ click.echo(f"Found eval: id={eval_obj.id} version={eval_obj.version} tasks={len(eval_obj.tasks)}")
106
+
107
+ tasks = []
108
+ for et in eval_obj.tasks:
109
+ task = Task.get(et.task_id, version=et.task_version)
110
+ version_note = f" (resolved from latest)" if et.task_version is None else ""
111
+ click.echo(f" Loaded task: {task.id} v{task.version} ({len(task.steps)} steps){version_note}")
112
+ tasks.append(task)
113
+
114
+ print_banner()
115
+
116
+ total_runs = len(tasks) * k
117
+ concurrency_note = f" (max concurrency: {max_concurrency})" if max_concurrency else ""
118
+ click.echo(click.style(
119
+ f"Running {len(tasks)} tasks x {k} run(s) = {total_runs} total runs{concurrency_note}...",
120
+ fg="blue",
121
+ ))
122
+ click.echo()
123
+
124
+ client_id = get_agent_env_client_id()
125
+ base_metadata = {"agent_env_hub": {"caller": client_id}} if client_id else None
126
+
127
+ async def _run_safe(task, tag, slot):
128
+ """Wrap _run_single so failures, and a cancel while it waits for its slot, carry task identity."""
129
+ try:
130
+ async with slot:
131
+ return await _run_single(
132
+ task,
133
+ tag,
134
+ output_dir,
135
+ agent_model=agent_model,
136
+ agent_artifact_id=agent_artifact_id,
137
+ base_metadata=base_metadata,
138
+ )
139
+ except BaseException as exc:
140
+ return (task.id, tag, exc)
141
+
142
+ def _on_signal(count):
143
+ message = "Cancelling the runs and tearing them down (Ctrl-C again to stop now)" if count == 1 else (
144
+ "Stopping the teardown now")
145
+ click.echo(click.style(message, fg="yellow"))
146
+
147
+ async def _run_all(interrupts):
148
+ slot = asyncio.Semaphore(max_concurrency) if max_concurrency else contextlib.nullcontext()
149
+ coros = []
150
+ for task in tasks:
151
+ for run_idx in range(1, k + 1):
152
+ if k > 1:
153
+ tag = f"[{task.id} run {run_idx}]"
154
+ else:
155
+ tag = f"[{task.id}]"
156
+ coros.append(_run_safe(task, tag, slot))
157
+ return [run.result() for run in await interrupts.gather(coros, _on_signal)]
158
+
159
+ with Interrupts() as interrupts:
160
+ results = interrupts.run(_run_all(interrupts))
161
+
162
+ click.echo()
163
+
164
+ # Summarize results
165
+ failures = []
166
+ successes = []
167
+ for result in results:
168
+ task_id, tag, payload = result
169
+ if isinstance(payload, BaseException):
170
+ failures.append((task_id, tag, payload))
171
+ else:
172
+ score = payload.metadata.get("score")
173
+ successes.append((task_id, tag, score))
174
+
175
+ if successes:
176
+ click.echo(click.style("Results:", fg="blue"))
177
+ for task_id, tag, score in successes:
178
+ score_str = f" score={score}" if score is not None else ""
179
+ click.echo(click.style(f" {tag} PASSED{score_str}", fg="green"))
180
+
181
+ if failures:
182
+ for task_id, tag, exc in failures:
183
+ outcome = "CANCELLED" if isinstance(exc, asyncio.CancelledError) else f"FAILED: {exc}"
184
+ click.echo(click.style(f" {tag} {outcome}", fg="red"))
185
+ click.echo(click.style(
186
+ f"\n{len(successes)}/{total_runs} runs completed, {len(failures)}/{total_runs} failed.",
187
+ fg="red",
188
+ ))
189
+ else:
190
+ click.echo(click.style(f"\nAll {total_runs} runs completed!", fg="blue"))
191
+ if interrupts.count:
192
+ raise SystemExit(128 + interrupts.signum)
193
+ if failures:
194
+ raise SystemExit(1)
@@ -0,0 +1,5 @@
1
+ """AgentEnv CLI identity helpers."""
2
+
3
+ from agent_env.cli.identity.client_identity import get_agent_env_client_id
4
+
5
+ __all__ = ["get_agent_env_client_id"]
@@ -0,0 +1,37 @@
1
+ """Caller identity helpers for AgentEnv CLI task contexts."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import re
6
+ import subprocess
7
+
8
+ _CLIENT_ID_PREFIX = "agent-env-cli"
9
+ _INVALID_GITHUB_USERNAME_CHARS_RE = re.compile(r"[^a-z0-9]+")
10
+
11
+
12
+ def get_agent_env_client_id() -> str | None:
13
+ """Best-effort AgentEnv client id for this local CLI process."""
14
+ username = _get_git_username()
15
+ if username is None:
16
+ return None
17
+ return f"{_CLIENT_ID_PREFIX}/{username}"
18
+
19
+
20
+ def _get_git_username() -> str | None:
21
+ """Return git user.name normalized as a GitHub-style username."""
22
+ try:
23
+ result = subprocess.run(
24
+ ["git", "config", "--get", "user.name"],
25
+ capture_output=True,
26
+ text=True,
27
+ timeout=2,
28
+ )
29
+ except Exception:
30
+ return None
31
+ if result.returncode != 0:
32
+ return None
33
+ username = _INVALID_GITHUB_USERNAME_CHARS_RE.sub(
34
+ "-",
35
+ result.stdout.strip().lower(),
36
+ ).strip("-")
37
+ return username or None