agentinputlab 0.1.0a1__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 (469) hide show
  1. agentinputlab/__init__.py +28 -0
  2. agentinputlab/algorithms/__init__.py +6 -0
  3. agentinputlab/algorithms/acquire/__init__.py +145 -0
  4. agentinputlab/algorithms/acquire/adaptive_rag/__init__.py +43 -0
  5. agentinputlab/algorithms/acquire/adaptive_rag/replay.py +367 -0
  6. agentinputlab/algorithms/acquire/adaptive_rag/runtime.py +1202 -0
  7. agentinputlab/algorithms/acquire/adaptive_rag_common_support.py +542 -0
  8. agentinputlab/algorithms/acquire/hyde.py +296 -0
  9. agentinputlab/algorithms/acquire/hyde_controlled.py +200 -0
  10. agentinputlab/algorithms/acquire/hyde_external.py +148 -0
  11. agentinputlab/algorithms/acquire/ircot.py +28 -0
  12. agentinputlab/algorithms/acquire/ircot_common_support.py +478 -0
  13. agentinputlab/algorithms/acquire/ircot_native.py +355 -0
  14. agentinputlab/algorithms/acquire/ircot_replay.py +327 -0
  15. agentinputlab/algorithms/acquire/qrag/__init__.py +79 -0
  16. agentinputlab/algorithms/acquire/qrag/bridge.py +828 -0
  17. agentinputlab/algorithms/acquire/qrag/common_support.py +891 -0
  18. agentinputlab/algorithms/acquire/qrag/native_axis.py +71 -0
  19. agentinputlab/algorithms/acquire/qrag/reader_adapter.py +139 -0
  20. agentinputlab/algorithms/acquire/r2ag/__init__.py +57 -0
  21. agentinputlab/algorithms/acquire/r2ag/bridge.py +1312 -0
  22. agentinputlab/algorithms/acquire/r2ag/common_support.py +1029 -0
  23. agentinputlab/algorithms/acquire/r2ag/socket_runtime.py +255 -0
  24. agentinputlab/algorithms/clarify/__init__.py +61 -0
  25. agentinputlab/algorithms/clarify/_structured.py +64 -0
  26. agentinputlab/algorithms/clarify/active_task_disambiguation.py +371 -0
  27. agentinputlab/algorithms/clarify/ask_or_assume/__init__.py +17 -0
  28. agentinputlab/algorithms/clarify/ask_or_assume/monitor.py +410 -0
  29. agentinputlab/algorithms/clarify/future_turns.py +379 -0
  30. agentinputlab/algorithms/clarify/udcs.py +255 -0
  31. agentinputlab/algorithms/clarify/udcs_deterministic.py +196 -0
  32. agentinputlab/algorithms/curate/__init__.py +65 -0
  33. agentinputlab/algorithms/curate/acon/__init__.py +27 -0
  34. agentinputlab/algorithms/curate/acon/common.py +284 -0
  35. agentinputlab/algorithms/curate/acon/common_support.py +136 -0
  36. agentinputlab/algorithms/curate/acon/history_bridge.py +309 -0
  37. agentinputlab/algorithms/curate/acon/observation_bridge.py +290 -0
  38. agentinputlab/algorithms/curate/llmlingua/__init__.py +30 -0
  39. agentinputlab/algorithms/curate/llmlingua/adapters.py +537 -0
  40. agentinputlab/algorithms/curate/llmlingua/budget.py +48 -0
  41. agentinputlab/algorithms/curate/llmlingua/controlled.py +175 -0
  42. agentinputlab/algorithms/curate/llmlingua/multilingual.py +105 -0
  43. agentinputlab/algorithms/curate/llmlingua/span_map.py +167 -0
  44. agentinputlab/algorithms/curate/recomp/__init__.py +47 -0
  45. agentinputlab/algorithms/curate/recomp/external.py +1129 -0
  46. agentinputlab/algorithms/curate/recomp/selective.py +304 -0
  47. agentinputlab/algorithms/decompose/__init__.py +107 -0
  48. agentinputlab/algorithms/decompose/decomp/__init__.py +53 -0
  49. agentinputlab/algorithms/decompose/decomp/common_support.py +478 -0
  50. agentinputlab/algorithms/decompose/decomp/planner_component.py +199 -0
  51. agentinputlab/algorithms/decompose/decomp/worker_bridge.py +416 -0
  52. agentinputlab/algorithms/decompose/llm_compiler/__init__.py +35 -0
  53. agentinputlab/algorithms/decompose/llm_compiler/bridge.py +520 -0
  54. agentinputlab/algorithms/decompose/llm_compiler/common_support.py +504 -0
  55. agentinputlab/algorithms/decompose/plan_and_budget/__init__.py +43 -0
  56. agentinputlab/algorithms/decompose/plan_and_budget/cached_soft_budget.py +362 -0
  57. agentinputlab/algorithms/decompose/plan_and_budget/decomposer_component.py +107 -0
  58. agentinputlab/algorithms/decompose/plan_and_budget/full.py +205 -0
  59. agentinputlab/algorithms/decompose/plan_and_budget/hard_cap.py +246 -0
  60. agentinputlab/algorithms/decompose/plan_and_budget/regenerated_soft_budget.py +448 -0
  61. agentinputlab/algorithms/decompose/plan_and_solve/__init__.py +33 -0
  62. agentinputlab/algorithms/decompose/plan_and_solve/plan_component.py +192 -0
  63. agentinputlab/algorithms/decompose/plan_and_solve/ps_prompt.py +127 -0
  64. agentinputlab/algorithms/decompose/self_ask/__init__.py +27 -0
  65. agentinputlab/algorithms/decompose/self_ask/loop.py +362 -0
  66. agentinputlab/algorithms/decompose/self_ask/planner_component.py +117 -0
  67. agentinputlab/algorithms/reformulate/__init__.py +85 -0
  68. agentinputlab/algorithms/reformulate/infocqr/__init__.py +40 -0
  69. agentinputlab/algorithms/reformulate/infocqr/cache_replay.py +362 -0
  70. agentinputlab/algorithms/reformulate/infocqr/external.py +675 -0
  71. agentinputlab/algorithms/reformulate/infocqr/student.py +189 -0
  72. agentinputlab/algorithms/reformulate/query2doc/__init__.py +42 -0
  73. agentinputlab/algorithms/reformulate/query2doc/controlled_live.py +190 -0
  74. agentinputlab/algorithms/reformulate/query2doc/models.py +95 -0
  75. agentinputlab/algorithms/reformulate/query2doc/official_cached.py +335 -0
  76. agentinputlab/algorithms/reformulate/query2doc/querygym_bridge.py +223 -0
  77. agentinputlab/algorithms/reformulate/query2doc/querygym_runtime.py +326 -0
  78. agentinputlab/algorithms/reformulate/reformer/__init__.py +23 -0
  79. agentinputlab/algorithms/reformulate/reformer/external.py +417 -0
  80. agentinputlab/algorithms/reformulate/rrr.py +696 -0
  81. agentinputlab/annotation/__init__.py +5 -0
  82. agentinputlab/annotation/independent.py +428 -0
  83. agentinputlab/annotation/server.py +233 -0
  84. agentinputlab/annotation/static/app.js +121 -0
  85. agentinputlab/annotation/static/index.html +60 -0
  86. agentinputlab/annotation/static/review.css +2 -0
  87. agentinputlab/annotation/static/review.html +10 -0
  88. agentinputlab/annotation/static/review.js +11 -0
  89. agentinputlab/annotation/static/styles.css +55 -0
  90. agentinputlab/annotation/store.py +444 -0
  91. agentinputlab/api.py +368 -0
  92. agentinputlab/artifacts/__init__.py +15 -0
  93. agentinputlab/artifacts/json_file.py +104 -0
  94. agentinputlab/artifacts/manifest.py +98 -0
  95. agentinputlab/artifacts/store.py +157 -0
  96. agentinputlab/backends/__init__.py +98 -0
  97. agentinputlab/backends/embedding/__init__.py +25 -0
  98. agentinputlab/backends/embedding/base.py +145 -0
  99. agentinputlab/backends/embedding/callable.py +75 -0
  100. agentinputlab/backends/embedding/replay.py +129 -0
  101. agentinputlab/backends/llm/__init__.py +31 -0
  102. agentinputlab/backends/llm/base.py +149 -0
  103. agentinputlab/backends/llm/callable.py +108 -0
  104. agentinputlab/backends/llm/decomp_completion.py +88 -0
  105. agentinputlab/backends/llm/final_content_stop.py +72 -0
  106. agentinputlab/backends/llm/gpt_oss_final_channel.py +84 -0
  107. agentinputlab/backends/llm/openai_compatible.py +332 -0
  108. agentinputlab/backends/llm/transformers.py +171 -0
  109. agentinputlab/backends/retrieval/__init__.py +35 -0
  110. agentinputlab/backends/retrieval/base.py +50 -0
  111. agentinputlab/backends/retrieval/dense.py +777 -0
  112. agentinputlab/backends/retrieval/memory.py +119 -0
  113. agentinputlab/backends/retrieval/sqlite_fts.py +155 -0
  114. agentinputlab/backends/user/__init__.py +15 -0
  115. agentinputlab/backends/user/base.py +66 -0
  116. agentinputlab/backends/user/callable.py +54 -0
  117. agentinputlab/backends/user/replay.py +89 -0
  118. agentinputlab/backends/vector.py +38 -0
  119. agentinputlab/benchmarks/__init__.py +246 -0
  120. agentinputlab/benchmarks/acquisition.py +106 -0
  121. agentinputlab/benchmarks/ale.py +540 -0
  122. agentinputlab/benchmarks/appworld_ul.py +669 -0
  123. agentinputlab/benchmarks/assets.py +226 -0
  124. agentinputlab/benchmarks/base.py +68 -0
  125. agentinputlab/benchmarks/beir_archive.py +235 -0
  126. agentinputlab/benchmarks/beir_sample.py +269 -0
  127. agentinputlab/benchmarks/bfcl_native.py +245 -0
  128. agentinputlab/benchmarks/bfcl_v3.py +607 -0
  129. agentinputlab/benchmarks/cache.py +218 -0
  130. agentinputlab/benchmarks/clariq.py +203 -0
  131. agentinputlab/benchmarks/data/registry.json +321 -0
  132. agentinputlab/benchmarks/data/smoke_assets.json +511 -0
  133. agentinputlab/benchmarks/data/statebench_v0_8_1_task_ids.json +475 -0
  134. agentinputlab/benchmarks/data/toolsandbox_165848b_scenario_names.json +1 -0
  135. agentinputlab/benchmarks/execution.py +1111 -0
  136. agentinputlab/benchmarks/interactive.py +257 -0
  137. agentinputlab/benchmarks/ir_query.py +204 -0
  138. agentinputlab/benchmarks/longbench.py +203 -0
  139. agentinputlab/benchmarks/paired_replay.py +479 -0
  140. agentinputlab/benchmarks/preprocess.py +2313 -0
  141. agentinputlab/benchmarks/production.py +236 -0
  142. agentinputlab/benchmarks/qa.py +963 -0
  143. agentinputlab/benchmarks/registry.py +110 -0
  144. agentinputlab/benchmarks/retrieval.py +459 -0
  145. agentinputlab/benchmarks/runtime.py +509 -0
  146. agentinputlab/benchmarks/statebench.py +938 -0
  147. agentinputlab/benchmarks/tau3.py +725 -0
  148. agentinputlab/benchmarks/toolsandbox.py +626 -0
  149. agentinputlab/benchmarks/trec_dl_sample.py +263 -0
  150. agentinputlab/campaign.py +654 -0
  151. agentinputlab/campaign_runner.py +953 -0
  152. agentinputlab/cli/__init__.py +6 -0
  153. agentinputlab/cli/main.py +933 -0
  154. agentinputlab/connectors/__init__.py +46 -0
  155. agentinputlab/connectors/knowledge/__init__.py +4 -0
  156. agentinputlab/connectors/tools/__init__.py +30 -0
  157. agentinputlab/connectors/tools/base.py +57 -0
  158. agentinputlab/connectors/tools/mcp.py +222 -0
  159. agentinputlab/connectors/tools/memory.py +41 -0
  160. agentinputlab/connectors/tools/openapi.py +695 -0
  161. agentinputlab/connectors/tools/schema.py +102 -0
  162. agentinputlab/contracts/__init__.py +91 -0
  163. agentinputlab/contracts/availability.py +24 -0
  164. agentinputlab/contracts/dependency.py +58 -0
  165. agentinputlab/contracts/enums.py +82 -0
  166. agentinputlab/contracts/errors.py +63 -0
  167. agentinputlab/contracts/evidence.py +43 -0
  168. agentinputlab/contracts/intent.py +110 -0
  169. agentinputlab/contracts/lifecycle.py +164 -0
  170. agentinputlab/contracts/patch.py +167 -0
  171. agentinputlab/contracts/serialization.py +93 -0
  172. agentinputlab/contracts/state.py +127 -0
  173. agentinputlab/contracts/trace.py +59 -0
  174. agentinputlab/contracts/worker.py +42 -0
  175. agentinputlab/core/__init__.py +7 -0
  176. agentinputlab/data/__init__.py +32 -0
  177. agentinputlab/data/checksums.py +9 -0
  178. agentinputlab/data/downloader.py +235 -0
  179. agentinputlab/data/http.py +171 -0
  180. agentinputlab/data/index.py +21 -0
  181. agentinputlab/data/overlap.py +28 -0
  182. agentinputlab/data/preprocess.py +32 -0
  183. agentinputlab/data/storage.py +57 -0
  184. agentinputlab/data/trec_sample.py +427 -0
  185. agentinputlab/evaluation/__init__.py +5 -0
  186. agentinputlab/evaluation/outcomes.py +32 -0
  187. agentinputlab/experiments/__init__.py +278 -0
  188. agentinputlab/experiments/analysis.py +981 -0
  189. agentinputlab/experiments/artifacts.py +687 -0
  190. agentinputlab/experiments/automatic_measurement.py +678 -0
  191. agentinputlab/experiments/auxiliary_matrix.py +203 -0
  192. agentinputlab/experiments/bindings.py +430 -0
  193. agentinputlab/experiments/blueprints.py +147 -0
  194. agentinputlab/experiments/builders/__init__.py +45 -0
  195. agentinputlab/experiments/builders/executable_external_payload.py +423 -0
  196. agentinputlab/experiments/builders/external_process_arena.py +1018 -0
  197. agentinputlab/experiments/builders/registry_intervention.py +463 -0
  198. agentinputlab/experiments/cli.py +158 -0
  199. agentinputlab/experiments/controls.py +340 -0
  200. agentinputlab/experiments/driver_guard.py +205 -0
  201. agentinputlab/experiments/drivers/__init__.py +89 -0
  202. agentinputlab/experiments/drivers/external_arena.py +2908 -0
  203. agentinputlab/experiments/drivers/method_process.py +662 -0
  204. agentinputlab/experiments/drivers/parity_process.py +1484 -0
  205. agentinputlab/experiments/drivers/static_production.py +1574 -0
  206. agentinputlab/experiments/executor.py +448 -0
  207. agentinputlab/experiments/loader.py +605 -0
  208. agentinputlab/experiments/measurement.py +675 -0
  209. agentinputlab/experiments/paper_analysis.py +1818 -0
  210. agentinputlab/experiments/parity_identity.py +605 -0
  211. agentinputlab/experiments/plan.py +277 -0
  212. agentinputlab/experiments/production_builders.py +3739 -0
  213. agentinputlab/experiments/readiness.py +432 -0
  214. agentinputlab/experiments/schema.py +514 -0
  215. agentinputlab/experiments/secrets.py +177 -0
  216. agentinputlab/experiments/stateful_analysis.py +1738 -0
  217. agentinputlab/experiments/transfer_analysis.py +1316 -0
  218. agentinputlab/experiments/unseen_analysis.py +1025 -0
  219. agentinputlab/integrations/__init__.py +1 -0
  220. agentinputlab/integrations/action_space/__init__.py +1 -0
  221. agentinputlab/integrations/external_workers/__init__.py +76 -0
  222. agentinputlab/integrations/external_workers/ace.py +431 -0
  223. agentinputlab/integrations/external_workers/base.py +181 -0
  224. agentinputlab/integrations/external_workers/decomp_live.py +249 -0
  225. agentinputlab/integrations/external_workers/decomp_planner.py +30 -0
  226. agentinputlab/integrations/external_workers/infocqr_student.py +280 -0
  227. agentinputlab/integrations/external_workers/ircot.py +576 -0
  228. agentinputlab/integrations/external_workers/llmcompiler_live.py +360 -0
  229. agentinputlab/integrations/external_workers/longllmlingua.py +162 -0
  230. agentinputlab/integrations/external_workers/method.py +314 -0
  231. agentinputlab/integrations/external_workers/process.py +678 -0
  232. agentinputlab/integrations/external_workers/supervisor.py +1071 -0
  233. agentinputlab/integrations/full_architecture/__init__.py +1 -0
  234. agentinputlab/integrations/full_architecture/hyde.py +212 -0
  235. agentinputlab/integrations/full_architecture/plan_and_budget.py +188 -0
  236. agentinputlab/integrations/live_history.py +222 -0
  237. agentinputlab/integrations/prompt_optimization/__init__.py +1 -0
  238. agentinputlab/integrations/training/__init__.py +1 -0
  239. agentinputlab/metrics/__init__.py +50 -0
  240. agentinputlab/metrics/catalog.py +313 -0
  241. agentinputlab/metrics/harm.py +95 -0
  242. agentinputlab/metrics/paired.py +40 -0
  243. agentinputlab/metrics/qa.py +76 -0
  244. agentinputlab/metrics/text.py +33 -0
  245. agentinputlab/metrics/third_party.py +161 -0
  246. agentinputlab/models/__init__.py +4 -0
  247. agentinputlab/observability/__init__.py +56 -0
  248. agentinputlab/observability/budget.py +316 -0
  249. agentinputlab/observability/instrumentation.py +754 -0
  250. agentinputlab/observability/models.py +403 -0
  251. agentinputlab/observability/monitor.py +380 -0
  252. agentinputlab/optimizers/__init__.py +1 -0
  253. agentinputlab/optimizers/clarify/__init__.py +12 -0
  254. agentinputlab/optimizers/context/__init__.py +22 -0
  255. agentinputlab/optimizers/decompose/__init__.py +64 -0
  256. agentinputlab/optimizers/evidence/__init__.py +22 -0
  257. agentinputlab/optimizers/rewrite/__init__.py +30 -0
  258. agentinputlab/parity/__init__.py +5 -0
  259. agentinputlab/parity/base.py +206 -0
  260. agentinputlab/production_campaign.py +763 -0
  261. agentinputlab/py.typed +1 -0
  262. agentinputlab/recipes/__init__.py +333 -0
  263. agentinputlab/recipes/ace.py +418 -0
  264. agentinputlab/recipes/ace_bfcl.py +273 -0
  265. agentinputlab/recipes/ace_common_support.py +169 -0
  266. agentinputlab/recipes/ace_native_plan.py +322 -0
  267. agentinputlab/recipes/ace_online.py +711 -0
  268. agentinputlab/recipes/ace_retrieval.py +330 -0
  269. agentinputlab/recipes/ace_statebench.py +382 -0
  270. agentinputlab/recipes/ace_tau.py +463 -0
  271. agentinputlab/recipes/ace_toolsandbox.py +432 -0
  272. agentinputlab/recipes/acon_guideline.py +22 -0
  273. agentinputlab/recipes/adaptive_rag.py +822 -0
  274. agentinputlab/recipes/llmlingua2_inference.py +146 -0
  275. agentinputlab/recipes/llmlingua2_training.py +796 -0
  276. agentinputlab/recipes/mce.py +1486 -0
  277. agentinputlab/recipes/mce_final.py +335 -0
  278. agentinputlab/recipes/mce_text_fit.py +499 -0
  279. agentinputlab/recipes/mce_text_only.py +298 -0
  280. agentinputlab/recipes/qrag.py +729 -0
  281. agentinputlab/recipes/qrag_inference.py +364 -0
  282. agentinputlab/recipes/r2ag_features.py +236 -0
  283. agentinputlab/recipes/r2ag_inference.py +503 -0
  284. agentinputlab/recipes/r2ag_training.py +948 -0
  285. agentinputlab/recipes/recomp_abstractive.py +592 -0
  286. agentinputlab/recipes/recomp_extractive.py +525 -0
  287. agentinputlab/recipes/reformer.py +17 -0
  288. agentinputlab/recipes/rqrag.py +1516 -0
  289. agentinputlab/recipes/rqrag_common_support.py +193 -0
  290. agentinputlab/recipes/rqrag_completion.py +147 -0
  291. agentinputlab/recipes/skillopt.py +462 -0
  292. agentinputlab/recipes/skillopt_common_support.py +154 -0
  293. agentinputlab/recipes/skillopt_environment.py +165 -0
  294. agentinputlab/recipes/skillopt_environment_cli.py +5 -0
  295. agentinputlab/recipes/skillopt_retrieval.py +188 -0
  296. agentinputlab/recipes/smartsearch.py +897 -0
  297. agentinputlab/recipes/smartsearch_curriculum.py +283 -0
  298. agentinputlab/recipes/smartsearch_grpo_contracts.py +58 -0
  299. agentinputlab/recipes/smartsearch_grpo_data.py +314 -0
  300. agentinputlab/recipes/smartsearch_grpo_meter.py +324 -0
  301. agentinputlab/recipes/smartsearch_grpo_prefix.py +144 -0
  302. agentinputlab/recipes/smartsearch_grpo_rollout.py +119 -0
  303. agentinputlab/recipes/smartsearch_grpo_tools.py +364 -0
  304. agentinputlab/recipes/smartsearch_grpo_training.py +305 -0
  305. agentinputlab/recipes/smartsearch_grpo_transport.py +248 -0
  306. agentinputlab/recipes/smartsearch_grpo_worker.py +364 -0
  307. agentinputlab/recipes/smartsearch_inference.py +524 -0
  308. agentinputlab/recipes/smartsearch_native_data.py +172 -0
  309. agentinputlab/recipes/smartsearch_policy.py +616 -0
  310. agentinputlab/recipes/smartsearch_policy_worker.py +9 -0
  311. agentinputlab/recipes/smartsearch_sampling.py +232 -0
  312. agentinputlab/recipes/smartsearch_teacher.py +203 -0
  313. agentinputlab/recipes/smartsearch_training.py +265 -0
  314. agentinputlab/registry/__init__.py +46 -0
  315. agentinputlab/registry/beta.py +727 -0
  316. agentinputlab/registry/data/algorithms.json +1959 -0
  317. agentinputlab/registry/data/auxiliary_method_profiles.json +34 -0
  318. agentinputlab/registry/loader.py +100 -0
  319. agentinputlab/registry/result_manifest.py +184 -0
  320. agentinputlab/registry/runtime.py +195 -0
  321. agentinputlab/registry/schema.py +449 -0
  322. agentinputlab/runner/__init__.py +30 -0
  323. agentinputlab/runner/balance.py +248 -0
  324. agentinputlab/runner/cache.py +135 -0
  325. agentinputlab/runner/composite.py +130 -0
  326. agentinputlab/runner/engine.py +285 -0
  327. agentinputlab/runner/runtime_guard.py +268 -0
  328. agentinputlab/runner/worker.py +80 -0
  329. agentinputlab/runtime_bootstrap.py +288 -0
  330. agentinputlab/selectors/__init__.py +196 -0
  331. agentinputlab/selectors/advanced.py +1514 -0
  332. agentinputlab/selectors/artifacts.py +1087 -0
  333. agentinputlab/selectors/base.py +112 -0
  334. agentinputlab/selectors/campaigns.py +1893 -0
  335. agentinputlab/selectors/catalog.py +86 -0
  336. agentinputlab/selectors/discovery.py +1860 -0
  337. agentinputlab/selectors/evaluation.py +1348 -0
  338. agentinputlab/selectors/features.py +383 -0
  339. agentinputlab/selectors/learned.py +502 -0
  340. agentinputlab/selectors/no_op.py +28 -0
  341. agentinputlab/selectors/outcome_table.py +475 -0
  342. agentinputlab/selectors/producer.py +853 -0
  343. agentinputlab/selectors/rules.py +109 -0
  344. agentinputlab/selectors/runtime.py +420 -0
  345. agentinputlab/studies/__init__.py +16 -0
  346. agentinputlab/studies/design.py +165 -0
  347. agentinputlab/studies/paired.py +322 -0
  348. agentinputlab/studio/__init__.py +6 -0
  349. agentinputlab/studio/campaigns.py +819 -0
  350. agentinputlab/studio/engine.py +1408 -0
  351. agentinputlab/studio/model_backends.py +425 -0
  352. agentinputlab/studio/prepared.py +410 -0
  353. agentinputlab/studio/server.py +613 -0
  354. agentinputlab/studio/static/app.js +397 -0
  355. agentinputlab/studio/static/campaigns.html +175 -0
  356. agentinputlab/studio/static/campaigns.js +426 -0
  357. agentinputlab/studio/static/index.html +192 -0
  358. agentinputlab/studio/static/result.html +103 -0
  359. agentinputlab/studio/static/result.js +273 -0
  360. agentinputlab/studio/static/styles.css +467 -0
  361. agentinputlab-0.1.0a1.data/data/share/agentinputlab/CITATION.cff +22 -0
  362. agentinputlab-0.1.0a1.dist-info/METADATA +392 -0
  363. agentinputlab-0.1.0a1.dist-info/RECORD +469 -0
  364. agentinputlab-0.1.0a1.dist-info/WHEEL +5 -0
  365. agentinputlab-0.1.0a1.dist-info/entry_points.txt +6 -0
  366. agentinputlab-0.1.0a1.dist-info/licenses/LICENSE +21 -0
  367. agentinputlab-0.1.0a1.dist-info/licenses/NOTICE +31 -0
  368. agentinputlab-0.1.0a1.dist-info/licenses/THIRD_PARTY_NOTICES.md +94 -0
  369. agentinputlab-0.1.0a1.dist-info/top_level.txt +2 -0
  370. workers/README.md +94 -0
  371. workers/ace/README.md +261 -0
  372. workers/ace/__init__.py +1 -0
  373. workers/ace/compatibility_manifest.json +39 -0
  374. workers/ace/driver.py +1682 -0
  375. workers/acon/README.md +215 -0
  376. workers/acon/__init__.py +5 -0
  377. workers/acon/compatibility_manifest.json +93 -0
  378. workers/acon/driver.py +1859 -0
  379. workers/acon/fitted.py +395 -0
  380. workers/acon/guideline.py +470 -0
  381. workers/acon/guideline_source_manifest.json +20 -0
  382. workers/adaptive_rag/README.md +96 -0
  383. workers/adaptive_rag/__init__.py +15 -0
  384. workers/adaptive_rag/compatibility_manifest.json +61 -0
  385. workers/adaptive_rag/driver.py +1470 -0
  386. workers/adaptive_rag/fixture_runtime.py +163 -0
  387. workers/adaptive_rag/runtime.py +252 -0
  388. workers/ask_or_assume/README.md +124 -0
  389. workers/ask_or_assume/__init__.py +1 -0
  390. workers/ask_or_assume/compatibility_manifest.json +36 -0
  391. workers/ask_or_assume/driver.py +1227 -0
  392. workers/decomp/README.md +133 -0
  393. workers/decomp/UPSTREAM_LICENSE.Apache-2.0.txt +201 -0
  394. workers/decomp/__init__.py +5 -0
  395. workers/decomp/compatibility_manifest.json +205 -0
  396. workers/decomp/driver.py +1015 -0
  397. workers/decomp/live.py +137 -0
  398. workers/decomp/runtime.py +231 -0
  399. workers/infocqr/README.md +106 -0
  400. workers/infocqr/__init__.py +1 -0
  401. workers/infocqr/compatibility_manifest.json +84 -0
  402. workers/infocqr/driver.py +1766 -0
  403. workers/ircot/README.md +167 -0
  404. workers/ircot/__init__.py +7 -0
  405. workers/ircot/compatibility_manifest.json +121 -0
  406. workers/ircot/controlled.py +457 -0
  407. workers/ircot/driver.py +1373 -0
  408. workers/ircot/fixture_bindings.json +39 -0
  409. workers/ircot/fixture_config.json +48 -0
  410. workers/ircot/fixture_prompt.txt +2 -0
  411. workers/ircot/native_qa.py +398 -0
  412. workers/ircot/qa_compatibility_manifest.json +57 -0
  413. workers/ircot/runtime.py +97 -0
  414. workers/llmcompiler/README.md +160 -0
  415. workers/llmcompiler/__init__.py +1 -0
  416. workers/llmcompiler/compatibility_manifest.json +45 -0
  417. workers/llmcompiler/driver.py +1514 -0
  418. workers/llmcompiler/export_prompts.py +74 -0
  419. workers/llmcompiler/live.py +174 -0
  420. workers/llmcompiler/patch_manifest.json +147 -0
  421. workers/mce/README.md +198 -0
  422. workers/mce/__init__.py +29 -0
  423. workers/mce/compatibility_manifest.json +115 -0
  424. workers/mce/driver.py +2585 -0
  425. workers/mce/final_eval.py +173 -0
  426. workers/official_arenas/README.md +25 -0
  427. workers/official_arenas/__init__.py +1 -0
  428. workers/official_arenas/capture_records.py +110 -0
  429. workers/official_arenas/driver.py +619 -0
  430. workers/official_arenas/protocol.py +334 -0
  431. workers/official_arenas/providers/__init__.py +1 -0
  432. workers/official_arenas/providers/_live_history.py +228 -0
  433. workers/official_arenas/providers/_message_compat.py +77 -0
  434. workers/official_arenas/providers/appworld_ul.py +196 -0
  435. workers/official_arenas/providers/fixture.py +112 -0
  436. workers/official_arenas/providers/statebench.py +960 -0
  437. workers/official_arenas/providers/tau3.py +1672 -0
  438. workers/official_arenas/providers/tau_retail.py +586 -0
  439. workers/official_arenas/providers/toolsandbox.py +1321 -0
  440. workers/official_arenas/providers/tooltalk.py +699 -0
  441. workers/official_arenas/retail_capture.py +188 -0
  442. workers/official_arenas/retail_driver.py +275 -0
  443. workers/qrag/README.md +172 -0
  444. workers/qrag/__init__.py +1 -0
  445. workers/qrag/compatibility_manifest.json +64 -0
  446. workers/qrag/driver.py +673 -0
  447. workers/r2ag/README.md +154 -0
  448. workers/r2ag/__init__.py +5 -0
  449. workers/r2ag/compatibility_manifest.json +55 -0
  450. workers/r2ag/driver.py +1287 -0
  451. workers/r2ag/feature_schema.json +8 -0
  452. workers/r2ag/runtime.py +589 -0
  453. workers/recomp/README.md +120 -0
  454. workers/recomp/__init__.py +1 -0
  455. workers/recomp/compatibility_manifest.json +43 -0
  456. workers/recomp/driver.py +1653 -0
  457. workers/reformer/README.md +125 -0
  458. workers/reformer/__init__.py +1 -0
  459. workers/reformer/compatibility_manifest.json +68 -0
  460. workers/reformer/driver.py +1459 -0
  461. workers/reformer/induction.py +457 -0
  462. workers/rrr/README.md +126 -0
  463. workers/rrr/__init__.py +1 -0
  464. workers/rrr/compatibility_manifest.json +57 -0
  465. workers/rrr/driver.py +1133 -0
  466. workers/smartsearch/README.md +331 -0
  467. workers/smartsearch/__init__.py +1 -0
  468. workers/smartsearch/compatibility_manifest.json +41 -0
  469. workers/smartsearch/driver.py +1643 -0
@@ -0,0 +1,188 @@
1
+ #!/usr/bin/env python3
2
+ """Approved, restart-safe Retail capture and partial-inventory projection.
3
+
4
+ No real scope or authorization is manufactured here. Before enabling a scope,
5
+ the operator must verify actual human scope and common-model choices. Successful
6
+ captures become optimizer-visible inventories; capture failures remain in the
7
+ full denominator, without invented checkpoints or automatic retries.
8
+ """
9
+ from __future__ import annotations
10
+
11
+ import argparse
12
+ import json
13
+ import os
14
+ import sys
15
+ from collections.abc import Mapping
16
+ from pathlib import Path
17
+ from types import SimpleNamespace
18
+ from typing import Any
19
+
20
+ if __package__ in {None, ""}:
21
+ sys.path[:0] = [str(Path(__file__).resolve().parents[2] / "src"),
22
+ str(Path(__file__).resolve().parents[2])]
23
+
24
+ from workers.official_arenas.capture_records import _records
25
+ from agentinputlab.experiments.builders import CHECKPOINT_INVENTORY_PROTOCOL
26
+ from workers.official_arenas.protocol import REPLAY_INVENTORY_PROTOCOL, OfficialArenaError, content_hash, sha256_file
27
+ from workers.official_arenas.providers.tau_retail import SOURCE_REVISION, _create_only, _saved_capture, factory
28
+ from workers.official_arenas.retail_driver import _read, _validate_authorizations
29
+
30
+ PROTOCOL = "agentinputlab.retail-capture-scope.v1"
31
+ _FIELDS = frozenset({"schema_version", "protocol", "source_revision", "phase", "execution_enabled",
32
+ "output_root", "provider_config", "provider_config_sha256", "source_sha256",
33
+ "authorizations", "expected_task_ids", "model_slot"})
34
+
35
+
36
+ def _source_pins() -> dict[str, str]:
37
+ root = Path(__file__).resolve().parents[2]
38
+ return {relative: sha256_file(root / relative) for relative in (
39
+ "workers/official_arenas/retail_capture.py", "workers/official_arenas/retail_driver.py",
40
+ "workers/official_arenas/driver.py", "workers/official_arenas/protocol.py",
41
+ "workers/official_arenas/providers/tau_retail.py", "workers/official_arenas/providers/tau3.py",
42
+ "workers/official_arenas/capture_records.py",
43
+ )}
44
+
45
+
46
+ def _validated_scope(path: Path, checksum: str, provider):
47
+ value = _read(path)
48
+ if sha256_file(path) != checksum or set(value) != _FIELDS:
49
+ raise OfficialArenaError("Retail capture scope fields or checksum differ")
50
+ if (type(value["schema_version"]) is not int or value["schema_version"] != 1
51
+ or value["protocol"] != PROTOCOL or value["source_revision"] != SOURCE_REVISION
52
+ or value["execution_enabled"] is not True or value["phase"] not in {"engineering", "formal"}):
53
+ raise OfficialArenaError("Retail capture scope is not enabled or valid")
54
+ _validate_authorizations(value["authorizations"])
55
+ parsed = provider._validate_config(value["provider_config"])
56
+ if value["provider_config_sha256"] != content_hash(parsed) or value["source_sha256"] != _source_pins():
57
+ raise OfficialArenaError("Retail capture source or effective config differs")
58
+ if parsed["task_split_name"] != ("train" if value["phase"] == "engineering" else "test"):
59
+ raise OfficialArenaError("Retail capture phase and official split differ")
60
+ ids = value["expected_task_ids"]
61
+ if (not isinstance(ids, list) or len(ids) != parsed["limit"]
62
+ or any(not isinstance(task_id, str) or not task_id.isdigit() for task_id in ids)
63
+ or len(ids) != len(set(ids))):
64
+ raise OfficialArenaError("Retail capture expected task inventory is invalid")
65
+ if not isinstance(value["model_slot"], str) or not value["model_slot"].strip():
66
+ raise OfficialArenaError("Retail capture model slot is absent")
67
+ root = Path(value["output_root"])
68
+ if (not root.is_absolute() or any(part.is_symlink() for part in (root, *root.parents))
69
+ or not root.is_dir() or root.stat().st_uid != os.getuid() or root.stat().st_mode & 0o077):
70
+ raise OfficialArenaError("Retail capture root must be an existing owned private directory")
71
+ return value, parsed, root
72
+
73
+
74
+ def project_batch(provider, config: Mapping[str, Any], batch: Mapping[str, Any], *, root: Path,
75
+ phase: str, model_slot: str, scope_sha256: str) -> Mapping[str, Any]:
76
+ """Read retained receipts, validate them, and export without generation."""
77
+ binding = content_hash(provider._validate_config(config))
78
+ ids, dispositions, captured = batch["expected_task_ids"], batch["dispositions"], batch["records"]
79
+ if (batch["protocol"] != "retail-capture-batch.v1" or batch["config_binding"] != binding
80
+ or len(ids) != len(set(ids)) or [row["task_id"] for row in dispositions] != ids
81
+ or any(row["status"] not in {"captured", "capture_failed", "reserved_unresolved"}
82
+ or row["retry_permitted"] is not False for row in dispositions)):
83
+ raise OfficialArenaError("Retail capture dispositions differ from the expected inventory")
84
+ records_by_id = {row["checkpoint_id"]: row for row in captured}
85
+ if len(records_by_id) != len(captured):
86
+ raise OfficialArenaError("Retail capture repeats a checkpoint")
87
+ receipt_files = {}
88
+ for row in dispositions:
89
+ task_id = row["task_id"]
90
+ path = root / f"first-capture-{task_id}.json"
91
+ if row["status"] == "reserved_unresolved":
92
+ if task_id in records_by_id or path.exists() or path.is_symlink():
93
+ raise OfficialArenaError("Retail unresolved capture changed during projection")
94
+ start = root / f"first-capture-{task_id}-start.json"
95
+ _read(start)
96
+ receipt_files[start.name] = sha256_file(start)
97
+ continue
98
+ saved = _saved_capture(path, binding=binding, task_id=task_id)
99
+ if row["status"] != saved["terminal"] or row["receipt_sha256"] != saved["receipt_sha256"]:
100
+ raise OfficialArenaError("Retail capture terminal receipt differs")
101
+ receipt_files[path.name] = sha256_file(path)
102
+ if row["status"] == "captured":
103
+ if records_by_id.get(task_id) != saved["record"]:
104
+ raise OfficialArenaError("Retail projected checkpoint differs from its receipt")
105
+ elif task_id in records_by_id:
106
+ raise OfficialArenaError("Retail failed capture cannot have a fabricated checkpoint")
107
+ successful = [row["task_id"] for row in dispositions if row["status"] == "captured"]
108
+ if set(records_by_id) != set(successful):
109
+ raise OfficialArenaError("Retail captured checkpoint inventory differs")
110
+ terminal = all(row["status"] != "reserved_unresolved" for row in dispositions)
111
+ if batch["all_tasks_terminal"] is not terminal:
112
+ raise OfficialArenaError("Retail batch terminality differs")
113
+ output = {"protocol": "retail-capture-inventory-disposition.v1", "scope_sha256": scope_sha256,
114
+ "phase": phase, "benchmark_id": "tau3.retail", "source_revision": SOURCE_REVISION,
115
+ "model_slot": model_slot, "config_binding": binding, "expected_task_ids": ids,
116
+ "expected_denominator": len(ids), "captured_task_ids": successful,
117
+ "dispositions": dispositions, "all_tasks_terminal": terminal,
118
+ "retry_permitted": False, "receipt_files": receipt_files,
119
+ "failure_endpoints": "capture failures are unresolved environment outcomes, not invented agent zeros"}
120
+ artifacts = {}
121
+ if terminal and captured:
122
+ # Reuse only the existing projection/validation, never its capture or
123
+ # replacing writer. Protected simulator history stays in its own file.
124
+ proxy = SimpleNamespace(benchmark_id="tau3.retail", source_revision=SOURCE_REVISION,
125
+ doctor=lambda _config: (), capture=lambda _config, **kwargs: captured)
126
+ visible, protected, units = _records(proxy, config, split=config["task_split_name"], output_root=root)
127
+ artifacts = {
128
+ "checkpoints.json": {"schema_version": 1, "protocol": CHECKPOINT_INVENTORY_PROTOCOL,
129
+ "checkpoint_count": len(visible), "checkpoints": visible},
130
+ "replays.json": {"schema_version": 1, "protocol": REPLAY_INVENTORY_PROTOCOL,
131
+ "benchmark_id": "tau3.retail", "source_revision": SOURCE_REVISION,
132
+ "record_count": len(protected), "records": protected},
133
+ "units.json": units,
134
+ }
135
+ output["inventory_content_sha256"] = {name: content_hash(value) for name, value in artifacts.items()}
136
+ snapshot = root / ("inventory-" + content_hash(output))
137
+ try:
138
+ snapshot.mkdir(mode=0o700)
139
+ except FileExistsError:
140
+ if snapshot.is_symlink() or _read(snapshot / "dispositions.json") != output:
141
+ raise OfficialArenaError("Retail inventory snapshot changed or is interrupted")
142
+ for name, value in artifacts.items():
143
+ path = snapshot / name
144
+ if path.is_symlink() or json.loads(path.read_bytes()) != value:
145
+ raise OfficialArenaError("Retail retained inventory artifact differs")
146
+ return {"snapshot": str(snapshot), "disposition": output}
147
+ for name, value in artifacts.items():
148
+ _create_only(snapshot / name, value)
149
+ _create_only(snapshot / "dispositions.json", output)
150
+ return {"snapshot": str(snapshot), "disposition": output}
151
+
152
+
153
+ def run(path: Path, checksum: str) -> Mapping[str, Any]:
154
+ provider = factory()
155
+ scope, config, root = _validated_scope(path, checksum, provider)
156
+ blockers = provider.doctor(config)
157
+ if blockers:
158
+ raise OfficialArenaError("Retail native capture preflight did not pass")
159
+ from tau2.runner.helpers import get_tasks
160
+ ids = [str(task.id) for task in get_tasks("retail", task_split_name=config["task_split_name"], num_tasks=config["limit"])]
161
+ if ids != scope["expected_task_ids"]:
162
+ raise OfficialArenaError("Retail scoped official task order differs")
163
+ batch = provider.capture_batch(config, output_root=root)
164
+ return project_batch(provider, config, batch, root=root, phase=scope["phase"],
165
+ model_slot=scope["model_slot"], scope_sha256=checksum)
166
+
167
+
168
+ def main() -> int:
169
+ parser = argparse.ArgumentParser(description="Run a bound first-attempt Retail capture batch")
170
+ parser.add_argument("--scope", type=Path, required=True)
171
+ parser.add_argument("--scope-sha256", required=True)
172
+ args = parser.parse_args()
173
+ try:
174
+ result = run(args.scope, args.scope_sha256)
175
+ except Exception as error:
176
+ print(json.dumps({"error": type(error).__name__, "message": "Retail capture rejected; inspect owned receipts"}), file=sys.stderr)
177
+ return 2
178
+ # No protected user history or visible request contents in the console.
179
+ disposition = result["disposition"]
180
+ print(json.dumps({"snapshot": result["snapshot"], "expected": disposition["expected_denominator"],
181
+ "captured": len(disposition["captured_task_ids"]),
182
+ "all_tasks_terminal": disposition["all_tasks_terminal"],
183
+ "formal_inference_started": False}, sort_keys=True))
184
+ return 0
185
+
186
+
187
+ if __name__ == "__main__":
188
+ raise SystemExit(main())
@@ -0,0 +1,275 @@
1
+ #!/usr/bin/env python3
2
+ """Durable, first-attempt-only Retail atomic worker.
3
+
4
+ The original generic worker and historical providers are unchanged. This
5
+ worker reuses their request/budget validators but never uses TemporaryDirectory.
6
+ An operator must bind an immutable scope after verifying the actual human
7
+ scope/environment choices; hash-shaped authorization references alone are not
8
+ proof of consent. No enabled real scope is generated by this module.
9
+ """
10
+ from __future__ import annotations
11
+
12
+ import argparse
13
+ import hashlib
14
+ import json
15
+ import os
16
+ import re
17
+ import sys
18
+ from collections.abc import Mapping
19
+ from pathlib import Path
20
+ from typing import Any
21
+
22
+ if __package__ in {None, ""}:
23
+ sys.path.insert(0, str(Path(__file__).resolve().parents[2]))
24
+
25
+ from workers.official_arenas import driver as shared
26
+ from workers.official_arenas.protocol import (
27
+ OfficialArenaError, content_hash, intervention_usage, materialized_state,
28
+ merge_usage, resolve_shared_budget_config, sha256_file,
29
+ )
30
+ from workers.official_arenas.providers.tau_retail import SOURCE_REVISION, _create_only
31
+
32
+ SCOPE_PATH_ENV = "AILAB_RETAIL_EXECUTION_SCOPE"
33
+ SCOPE_SHA256_ENV = "AILAB_RETAIL_EXECUTION_SCOPE_SHA256"
34
+ SCOPE_PROTOCOL = "agentinputlab.retail-execution-scope.v1"
35
+ PROVIDER_ENTRYPOINT = "workers.official_arenas.providers.tau_retail:factory"
36
+ _SHA = re.compile(r"^[0-9a-f]{64}$")
37
+ _SCOPE_FIELDS = frozenset({"schema_version", "protocol", "source_revision", "phase", "execution_enabled",
38
+ "output_root", "provider_config_sha256", "provider_source_sha256", "worker_support_sha256",
39
+ "worker_source_sha256", "protocol_source_sha256", "provider_helper_sha256",
40
+ "authorizations", "allowed_cell_ids"})
41
+
42
+
43
+ class RetailAttemptUnavailable(OfficialArenaError):
44
+ """Existing live/interrupted/unscored attempt must be inspected, not rerun."""
45
+
46
+
47
+ def _reject_duplicate_keys(pairs):
48
+ result = {}
49
+ for key, value in pairs:
50
+ if key in result:
51
+ raise OfficialArenaError("Retail JSON has duplicate fields")
52
+ result[key] = value
53
+ return result
54
+
55
+
56
+ def _read(path: Path) -> Mapping[str, Any]:
57
+ if path.is_symlink() or not path.is_file():
58
+ raise OfficialArenaError("Retail bound file is absent or symlinked")
59
+ try:
60
+ value = json.loads(path.read_bytes(), object_pairs_hook=_reject_duplicate_keys)
61
+ content_hash(value) # also rejects non-finite numbers
62
+ except (ValueError, TypeError) as error:
63
+ raise OfficialArenaError("Retail bound file is invalid JSON") from error
64
+ if not isinstance(value, Mapping):
65
+ raise OfficialArenaError("Retail bound file must be an object")
66
+ return value
67
+
68
+
69
+ def cell_identity(request: Mapping[str, Any]) -> Mapping[str, Any]:
70
+ """Logical cell identity excludes generated text, not method/budget/locks.
71
+
72
+ If a generated payload changes, its logical identity stays occupied and
73
+ its full request hash conflicts instead of silently becoming a new trial.
74
+ Different factors/intensities require their own frozen arm parameters.
75
+ """
76
+ arms = []
77
+ for arm in sorted(request["arms"], key=lambda item: item["role"]):
78
+ payload = arm["payload"]
79
+ arms.append({"role": arm["role"], "arm_id": arm["arm_id"],
80
+ **{name: payload[name] for name in ("release_id", "profile_kind", "model_slot", "arm_parameters")},
81
+ "budget": materialized_state(payload)["budget"]})
82
+ return {**{name: request[name] for name in ("benchmark_id", "checkpoint_id", "source_revision",
83
+ "origin_state_hash", "replay_identity", "seed", "locked_dependency_hashes")}, "arms": arms}
84
+
85
+
86
+ def _validate_authorizations(approvals: Any) -> None:
87
+ # These are provenance references, not automatic verification of consent.
88
+ # The operator must verify the actual human messages before enabling a scope.
89
+ if not isinstance(approvals, Mapping) or set(approvals) != {"scope", "environment_models"}:
90
+ raise OfficialArenaError("Retail human choice references are incomplete")
91
+ for approval in approvals.values():
92
+ if (not isinstance(approval, Mapping) or set(approval) != {"source_kind", "thread_id", "message_sha256"}
93
+ or approval["source_kind"] != "human_message" or not isinstance(approval["thread_id"], str)
94
+ or not approval["thread_id"].strip() or not isinstance(approval["message_sha256"], str)
95
+ or _SHA.fullmatch(approval["message_sha256"]) is None):
96
+ raise OfficialArenaError("Retail human choice reference is invalid")
97
+
98
+
99
+ def _scope(parameters: Mapping[str, Any], request: Mapping[str, Any]):
100
+ path_text, expected = os.environ.get(SCOPE_PATH_ENV), os.environ.get(SCOPE_SHA256_ENV)
101
+ if not path_text or not expected or _SHA.fullmatch(expected) is None:
102
+ raise OfficialArenaError("Retail requires an explicitly bound execution scope")
103
+ path = Path(path_text)
104
+ value = _read(path)
105
+ if sha256_file(path) != expected or set(value) != _SCOPE_FIELDS:
106
+ raise OfficialArenaError("Retail execution scope differs")
107
+ if (type(value["schema_version"]) is not int or value["schema_version"] != 1
108
+ or value["protocol"] != SCOPE_PROTOCOL or value["source_revision"] != SOURCE_REVISION
109
+ or value["phase"] not in {"engineering", "formal"} or value["execution_enabled"] is not True):
110
+ raise OfficialArenaError("Retail execution scope is not enabled or valid")
111
+ _validate_authorizations(value["authorizations"])
112
+ files = {"provider_source_sha256": Path(__file__).parent / "providers/tau_retail.py",
113
+ "worker_support_sha256": Path(shared.__file__), "worker_source_sha256": Path(__file__),
114
+ "protocol_source_sha256": Path(__file__).parent / "protocol.py",
115
+ "provider_helper_sha256": Path(__file__).parent / "providers/tau3.py"}
116
+ for name, source in files.items():
117
+ if source.is_symlink() or value[name] != sha256_file(source):
118
+ raise OfficialArenaError("Retail worker source closure differs")
119
+ config_hash = content_hash(resolve_shared_budget_config(parameters["provider_config"]))
120
+ if value["provider_config_sha256"] != config_hash:
121
+ raise OfficialArenaError("Retail frozen provider config differs")
122
+ allowed = value["allowed_cell_ids"]
123
+ if (not isinstance(allowed, list) or not allowed
124
+ or any(not isinstance(item, str) or _SHA.fullmatch(item) is None for item in allowed)
125
+ or len(allowed) != len(set(allowed))):
126
+ raise OfficialArenaError("Retail frozen cell inventory is invalid")
127
+ identity = cell_identity(request)
128
+ cell_id = content_hash(identity)
129
+ if cell_id not in allowed:
130
+ raise OfficialArenaError("Retail cell is outside its approved frozen inventory")
131
+ root = Path(value["output_root"])
132
+ if (not root.is_absolute() or any(part.is_symlink() for part in (root, *root.parents))
133
+ or not root.is_dir() or root.stat().st_uid != os.getuid() or root.stat().st_mode & 0o077):
134
+ raise OfficialArenaError("Retail ledger root must be an existing owned private directory")
135
+ return value, expected, root / cell_id, identity
136
+
137
+
138
+ def _sealed(value: Mapping[str, Any]) -> dict[str, Any]:
139
+ return {**value, "receipt_sha256": content_hash(value)}
140
+
141
+
142
+ def _files(root: Path) -> dict[str, str]:
143
+ result = {}
144
+ for path in sorted(root.rglob("*")):
145
+ if path.is_symlink():
146
+ raise OfficialArenaError("Retail attempt contains a symlink")
147
+ if path.is_file() and path != root / "terminal.json":
148
+ result[str(path.relative_to(root))] = sha256_file(path)
149
+ return result
150
+
151
+
152
+ def _cached(root: Path, request_hash: str, scope_sha256: str):
153
+ if root.is_symlink() or not root.is_dir():
154
+ raise OfficialArenaError("Retail logical attempt directory is invalid")
155
+ start = _read(root / "pair-start.json")
156
+ if start.get("request_hash") != request_hash or start.get("scope_sha256") != scope_sha256:
157
+ raise OfficialArenaError("Retail existing logical cell has a different full request or scope")
158
+ if not (root / "terminal.json").exists():
159
+ raise RetailAttemptUnavailable("Retail attempt is live or interrupted; automatic retry is forbidden")
160
+ terminal = _read(root / "terminal.json")
161
+ body = {key: value for key, value in terminal.items() if key != "receipt_sha256"}
162
+ if (terminal.get("receipt_sha256") != content_hash(body) or terminal.get("request_hash") != request_hash
163
+ or terminal.get("scope_sha256") != scope_sha256 or terminal.get("files") != _files(root)):
164
+ raise OfficialArenaError("Retail terminal or raw trajectory evidence differs")
165
+ if terminal.get("status") != "paired_scored":
166
+ raise RetailAttemptUnavailable("Retail failed attempt is retained and terminal; automatic retry is forbidden")
167
+ response = _read(root / "response.json")
168
+ if content_hash(response) != terminal.get("response_sha256"):
169
+ raise OfficialArenaError("Retail retained response differs")
170
+ return response
171
+
172
+
173
+ def run(value: Any) -> Mapping[str, Any]:
174
+ if not isinstance(value, Mapping) or set(value) != shared._ROOT_FIELDS:
175
+ raise OfficialArenaError("Retail atomic envelope fields differ")
176
+ if type(value["schema_version"]) is not int or value["schema_version"] != 1 or value["protocol"] != shared.REQUEST_PROTOCOL:
177
+ raise OfficialArenaError("Retail atomic envelope protocol differs")
178
+ base = {name: value[name] for name in shared._ROOT_FIELDS - {"request_hash"}}
179
+ if value["request_hash"] != content_hash(base):
180
+ raise OfficialArenaError("Retail full request hash differs")
181
+ parameters, request = shared._parameters(value["worker_parameters"]), shared._atomic_request(value["atomic_request"])
182
+ if (parameters["provider_entrypoint"] != PROVIDER_ENTRYPOINT or request["benchmark_id"] != "tau3.retail"
183
+ or request["source_revision"] != SOURCE_REVISION or request["seed"] != 17):
184
+ raise OfficialArenaError("Retail cannot run another provider, domain, source or seed")
185
+ records = shared._inventory(parameters)
186
+ replay = records.get(request["checkpoint_id"])
187
+ if (records["__inventory__"] != {"benchmark_id": "tau3.retail", "source_revision": SOURCE_REVISION}
188
+ or replay is None or any(replay[name] != request[name] for name in ("origin_state_hash", "replay_identity"))):
189
+ raise OfficialArenaError("Retail protected replay identity differs")
190
+ shared._validate_dependency_binding(request=request, parameters=parameters, replay_record=replay)
191
+ _, scope_sha, root, identity = _scope(parameters, request)
192
+ provider = shared._provider(PROVIDER_ENTRYPOINT)
193
+ if (provider.benchmark_id != request["benchmark_id"] or provider.source_revision != SOURCE_REVISION
194
+ or provider.scorer_id != parameters["scorer_id"] or provider.scorer_revision != parameters["scorer_revision"]):
195
+ raise OfficialArenaError("Retail provider identity differs from the worker lock")
196
+ blockers = provider.doctor(parameters["provider_config"])
197
+ if blockers:
198
+ raise OfficialArenaError("Retail native preflight did not pass")
199
+ try:
200
+ root.mkdir(mode=0o700)
201
+ except FileExistsError:
202
+ return _cached(root, value["request_hash"], scope_sha)
203
+ _create_only(root / "pair-start.json", {"request_hash": value["request_hash"], "scope_sha256": scope_sha,
204
+ "cell_identity": identity, "pid": os.getpid(), "uid": os.getuid(), "retry_permitted": False})
205
+ _create_only(root / "request.json", value)
206
+ results, receipts, failures, runtime_ids = [], [], [], set()
207
+ for arm in sorted(request["arms"], key=lambda item: item["role"]):
208
+ role, work = arm["role"], root / arm["role"]
209
+ work.mkdir(mode=0o700)
210
+ try:
211
+ result = provider.run_arm(parameters["provider_config"], replay_record=replay,
212
+ arm_payload=arm["payload"], seed=17, role=role, work_dir=work)
213
+ # Preserve raw evidence even if the following budget/runtime audit fails.
214
+ _create_only(work / "trace.json", dict(result.trace))
215
+ if result.runtime_instance_id in runtime_ids:
216
+ raise OfficialArenaError("Retail paired arms reused one native runtime")
217
+ runtime_ids.add(result.runtime_instance_id)
218
+ usage = merge_usage(intervention_usage(arm["payload"]), result.usage)
219
+ shared._validate_shared_budget_usage(arm["payload"], usage)
220
+ # The host process bridge accepts exactly these five public fields.
221
+ # Additional diagnostics belong in retained private arm evidence,
222
+ # not in a response that the bridge will reject as schema drift.
223
+ row = {"role": role, "arm_id": arm["arm_id"], "metrics": dict(result.metrics),
224
+ "trace_hash": content_hash(result.trace),
225
+ "usage": {name: usage[name] for name in shared._USAGE_FIELDS}}
226
+ results.append(row)
227
+ receipts.append({"role": role, "arm_id": arm["arm_id"], "origin_state_hash": request["origin_state_hash"],
228
+ "replay_identity": request["replay_identity"], "seed": 17, "locked_dependency_hashes": request["locked_dependency_hashes"],
229
+ "runtime_instance_id": result.runtime_instance_id, "completed": True})
230
+ outcome = {"status": "scored_terminal", "result": row,
231
+ "trace_measurement": shared._safe_trace_measurement(result.trace),
232
+ "intervention_failure": shared._intervention_failure(arm["payload"])}
233
+ except Exception as error:
234
+ outcome = {"status": "failed_unscored", "exception_type": type(error).__name__,
235
+ "exception_sha256": hashlib.sha256(str(error).encode()).hexdigest(),
236
+ "retry_permitted": False, "paper_endpoint": None}
237
+ failures.append(role)
238
+ _create_only(work / "arm-outcome.json", _sealed(outcome))
239
+ response = None
240
+ if not failures:
241
+ receipt = {**{name: request[name] for name in ("benchmark_id", "checkpoint_id", "source_revision",
242
+ "origin_state_hash", "replay_identity", "seed", "locked_dependency_hashes")},
243
+ **{name: parameters[name] for name in ("bridge_id", "bridge_revision", "scorer_id", "scorer_revision")}, "arms": receipts}
244
+ response = {"schema_version": 1, "protocol": shared.RESPONSE_PROTOCOL,
245
+ "request_hash": value["request_hash"], "receipt": receipt, "arms": results}
246
+ _create_only(root / "response.json", response)
247
+ terminal = {"protocol": "retail-pair-terminal.v1", "request_hash": value["request_hash"], "scope_sha256": scope_sha,
248
+ "status": "failed_unscored" if failures else "paired_scored", "failed_roles": failures,
249
+ "physical_arm_attempts": 2, "retry_permitted": False, "files": _files(root),
250
+ "response_sha256": content_hash(response) if response else None}
251
+ _create_only(root / "terminal.json", _sealed(terminal))
252
+ if failures:
253
+ raise RetailAttemptUnavailable("Retail arm failure retained; both arms have dispositions, no retry")
254
+ return response
255
+
256
+
257
+ def main() -> int:
258
+ parser = argparse.ArgumentParser(description="Execute one frozen Retail pair, retaining first attempts")
259
+ parser.add_argument("--doctor", action="store_true")
260
+ args = parser.parse_args()
261
+ if args.doctor:
262
+ print(json.dumps({"protocol": shared.WORKER_PROTOCOL, "worker_available": True,
263
+ "scientific_ready": False, "requires_bound_execution_scope": True}))
264
+ return 0
265
+ try:
266
+ response = run(json.load(sys.stdin, object_pairs_hook=_reject_duplicate_keys))
267
+ except Exception as error:
268
+ print(json.dumps({"error": type(error).__name__, "message": "Retail rejected or retained an unscored attempt; inspect owned ledger"}), file=sys.stderr)
269
+ return 2
270
+ print(json.dumps(response, sort_keys=True, ensure_ascii=False, allow_nan=False))
271
+ return 0
272
+
273
+
274
+ if __name__ == "__main__":
275
+ raise SystemExit(main())
workers/qrag/README.md ADDED
@@ -0,0 +1,172 @@
1
+ # Q-RAG frozen-checkpoint sidecar
2
+
3
+ This directory is an **inference-only compatibility bridge** for
4
+ `griver/Q-RAG@e7598130b63eaab868469877e88bcacc59a44efb`. It does not vendor the
5
+ upstream checkout, checkpoint, tokenizer, base embedder, datasets, or reader.
6
+ It does not expose RL/PQN training.
7
+
8
+ The bounded common-support profile is executable with the repository-level
9
+ driver below. It uses the same six BM25 candidates for both paired arms, lets
10
+ the released frozen policy select exactly two real candidate documents, and
11
+ passes only those documents to the shared downstream LLM. This is the profile
12
+ used for cross-family comparison; it remains distinct from paper-result parity.
13
+
14
+ ## Release boundary
15
+
16
+ - Source: user-mounted, read-only, repository license `NOASSERTION`. The
17
+ upstream README claims CC BY 4.0, but there is no root `LICENSE`; the source
18
+ acknowledgement is a risk acknowledgement, not legal clearance.
19
+ - Checkpoint: user-mounted
20
+ `Q-RAG/qrag-ft-e5-on-hotpotqa@e0e48389...`, separately acknowledged as
21
+ CC BY 4.0. `model_best.pt` and `config.yaml` are hash-pinned.
22
+ - Embedder: user-mounted
23
+ `intfloat/multilingual-e5-large@3d7cfbda...`; mutable `main` is rejected.
24
+ - Reader: a separately pinned controlled factor. The base profile records the
25
+ upstream QwQ-32B family, but does not claim that the paper's exact reader
26
+ snapshot is recoverable.
27
+
28
+ Accordingly, the public result is `controlled_adapter`, not end-to-end
29
+ `official_native` parity. The registry's `native_only` status means only the
30
+ released checkpoint treatment is eligible; it is not a parity claim.
31
+
32
+ ## Preserved algorithm path
33
+
34
+ The sidecar runtime must call the official candidate/environment construction,
35
+ `PQN.select_action(..., random=False, evaluate=True)`, and `QAEnv.step`. Every
36
+ step records the available candidate indices, full finite Q-values, selected
37
+ index/Q-value, and accumulated selected document IDs. Q-RAG has no stop action:
38
+ termination is `fixed_step_budget`, `candidate_exhausted`, or
39
+ `empty_candidates`.
40
+
41
+ To avoid evaluation-label leakage, the runtime must construct `answer=""` and
42
+ `sf_idx=[]` internally and use upstream `DummyFeedbackModel`. It must never
43
+ load `GroundTruthFeedback`, compute EM/F1/reward, import `train_q_rag.py`, or
44
+ call optimizer/scheduler/update/save methods. This changes the paper's
45
+ ground-truth-assisted early termination and is why parity is not claimed.
46
+
47
+ ## Security contract
48
+
49
+ The published 20 GB `model_best.pt` is a pickle checkpoint and upstream
50
+ `PQN.load` calls `torch.load(weights_only=False)`. Do **not** call that loader.
51
+ The dedicated runtime must use `torch.load(..., weights_only=True)`, validate
52
+ the expected inference keys, and call inference-module `load_state_dict` with
53
+ `strict=True`; optimizer and scheduler state are ignored. Run as non-root with
54
+ no network during selector construction, read-only mounts, no host secrets,
55
+ and CPU/GPU/memory/time limits. For production, a one-time isolated conversion
56
+ to a tensor-only artifact is preferred and must bind both source and converted
57
+ manifests.
58
+
59
+ The released file also serializes an OmegaConf `ListConfig` inside ignored
60
+ scheduler state. The common-support runtime therefore wraps the weights-only
61
+ load in a scoped allowlist containing only the inert OmegaConf metadata/node
62
+ constructors and built-in containers required by this exact pinned artifact.
63
+ Any other Python global still fails closed; the unsafe upstream loader is never
64
+ called.
65
+
66
+ `QRAGFrozenDriver` performs all license, source, checkpoint, embedder,
67
+ candidate order, profile, horizon, Q-value, usage, and response-attestation
68
+ checks before returning a successful envelope. `runtime_factory` and `reader`
69
+ are explicit dependency seams; the CI fake uses them without weakening the
70
+ production manifest.
71
+
72
+ ### Reader budget configuration (protocol v3)
73
+
74
+ `QRAGControls(max_output_tokens=...)` sets the reader's per-call output ceiling;
75
+ 4000 is the upstream default, not a hard minimum. `ExecutionBudget` independently
76
+ sets cumulative run limits. The effective reader cap is the smaller of the
77
+ configured ceiling and remaining output tokens. With no remaining tokens or
78
+ model calls, execution stops before constructing the selector runtime.
79
+
80
+ The reader callable has the signature
81
+ `reader(question, passages, artifacts, *, max_output_tokens) -> ReaderResult`.
82
+ It must send that effective ceiling to its actual model request, use its pinned
83
+ deployment, and avoid hidden retries. A legacy three-argument reader is rejected
84
+ before selector work. Return actual provider input/output usage, including
85
+ reasoning tokens where reported; do not replace missing usage with zero.
86
+
87
+ Both ends bind and verify the requested/effective budget in the v3 envelope.
88
+ The response records `reader_budget`, including `preset="upstream_default"` or
89
+ `"custom"`; actual usage above the effective ceiling is a consumed failure.
90
+ v2 requests/responses are not silently accepted under this changed contract.
91
+ No checkpoint, selector horizon, prompt or historical result changes with this
92
+ configuration support. End-to-end paper parity is not claimed for either budget.
93
+
94
+ ### Explicit instruction-preserving QA adapter
95
+
96
+ `reader_profile="factorial_instruction_preserving_reader_transfer"` is an
97
+ opt-in transfer variant, with `QRAG_INSTRUCTION_PROMPT_SHA256` and protocol
98
+ `agentinputlab.qrag.instruction_reader.v1`. The original two question-only
99
+ profiles retain protocol v3 and their original prompts. They are not silently
100
+ converted into this adapter.
101
+
102
+ Its callback must accept `max_output_tokens`, `task_instruction` and
103
+ `passage_annotations` as keyword arguments. Call the shipped
104
+ `render_instruction_reader_prompt(question, passages, task_instruction=...,
105
+ passage_annotations=...)` and use `QRAG_INSTRUCTION_SYSTEM_PROMPT` in the
106
+ actual model request. Task instruction and visible passage annotations are
107
+ hash-bound, preserved in selection order, and included only in the reader;
108
+ the frozen selector's question/candidate input is unchanged. This variant
109
+ rejects conversation history and tool execution. No labels reach the policy.
110
+
111
+ The final JSON schema contains `answer` and the three string arrays
112
+ `support_ids`, `evidence_ids`, `evidence_texts`. The parser accepts explicit
113
+ final JSON, not reasoning salvage or automatic evidence inference. Score the
114
+ model's predictions with the original benchmark adapter, retain zero scores
115
+ and malformed outputs, and record actual costs without retries. This is a
116
+ labelled prompt/input adaptation, not upstream native parity.
117
+
118
+ IR native-query decoding is a separate opt-in postprocessor:
119
+ `parse_native_query_reader_answer(final_text)`, identified by
120
+ `QRAG_NATIVE_QUERY_DECODER_ID`/`QRAG_NATIVE_QUERY_DECODER_SHA256`. It accepts
121
+ exact final `{"query": "nonempty text"}` JSON, not a QA wrapper or inferred
122
+ query. The worker's generated text, prompts, budgets and usage stay unchanged.
123
+ Use the returned query with the original corpus/ranker/native scorer, retain
124
+ the raw output and any original QA-decoding rejection, and record the selected
125
+ decoder alongside the new score. This path does not retry generation.
126
+
127
+ The pinned upstream `DummyFeedbackModel` omits the abstract `reset` method and
128
+ therefore cannot be instantiated with current Python ABC enforcement. The
129
+ runtime supplies only that missing lifecycle method by delegating to the
130
+ upstream `AFeedbackModel.reset`; it does not alter feedback, reward,
131
+ termination, candidate construction, Q-values, or the two-step PQN policy.
132
+
133
+ ## Installed common-support API
134
+
135
+ Install the `qrag` extra in the dedicated non-root environment. Source,
136
+ checkpoint and embedder mounts remain operator-provided; acknowledge their
137
+ separate licenses before execution. The public distribution does not include
138
+ research campaign scripts or previous experiment results.
139
+
140
+ The installed API is
141
+ `agentinputlab.algorithms.acquire.qrag.LocalQRAGFrozenPolicyRuntime`. Construct
142
+ it with `source_root`, `checkpoint_root`, `embedder_root`,
143
+ `compatibility_manifest_path`, `compatibility_manifest_sha256`,
144
+ `embedder_manifest_sha256` and an explicit `device` (`cpu` or the operator's
145
+ authorized CUDA device). Both manifest hashes use
146
+ `agentinputlab.contracts.serialization.content_hash` on their parsed JSON
147
+ objects. The compatibility policy ships as
148
+ `workers/qrag/compatibility_manifest.json`; the embedder manifest belongs to
149
+ the mounted snapshot.
150
+
151
+ Pass this runtime as `InterventionContext.external_runtime` and a real
152
+ candidate retriever as `InterventionContext.retriever` when running
153
+ `QRAGCommonSupport` through `InterventionRunner`. The runtime loads only the
154
+ frozen selector; the caller runs and scores its separately bound downstream
155
+ model. Construct one runtime per isolated process to avoid sharing upstream
156
+ global PyTorch device or random state with unrelated applications.
157
+
158
+ `QRAGFrozenDriver` is a separate selector-plus-reader integration class, not a
159
+ ready-made command-line server. `python -m workers.qrag.driver` intentionally
160
+ exits with deployment guidance until an operator supplies its runtime and
161
+ reader. Do not point users at unpublished research-only script paths.
162
+
163
+ ## Checks
164
+
165
+ ```bash
166
+ PYTHONPATH=src:. python -m pytest -q tests/workers/test_qrag_worker_driver.py
167
+ PYTHONPATH=src:. python -m pytest -q tests/algorithms/unit/test_remaining_runtime.py -k qrag
168
+ ```
169
+
170
+ Set `AGENTINPUTLAB_RUN_REAL_QRAG_IMPORT_SMOKE=1` and
171
+ `AGENTINPUTLAB_QRAG_CHECKOUT=/read-only/Q-RAG` to run the opt-in symbol/hash
172
+ smoke. It does not deserialize or download a checkpoint.
@@ -0,0 +1 @@
1
+ """User-mounted Q-RAG frozen-checkpoint worker."""