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,897 @@
1
+ """Pinned frozen-inference bridge for the official SmartSearch search loop.
2
+
3
+ The released policy, official ``ReCall`` loop, tag parser, and answer parser run
4
+ inside a separately pinned worker. AgentInputLab standardizes only the
5
+ transport, identity, budget, security, trajectory, and evidence contracts. In
6
+ particular, this frozen-inference profile does not invoke training or query
7
+ refinement. Separately metered native training interfaces live in the
8
+ smartsearch curriculum, policy, teacher and GRPO recipe modules.
9
+ """
10
+
11
+ from __future__ import annotations
12
+
13
+ import hashlib
14
+ from collections.abc import Mapping, Sequence
15
+ from dataclasses import asdict, dataclass
16
+ from typing import Any
17
+
18
+ from agentinputlab.contracts import (
19
+ AlgorithmOutputError,
20
+ BudgetExceededError,
21
+ CompositeResult,
22
+ ContextBlock,
23
+ ExecutionTrace,
24
+ FrozenAgentState,
25
+ InputPatch,
26
+ InterventionContext,
27
+ PatchOp,
28
+ PatchOperation,
29
+ SemanticFamily,
30
+ TraceEvent,
31
+ TracePhase,
32
+ ValidationError,
33
+ )
34
+ from agentinputlab.contracts.serialization import content_hash, freeze_mapping
35
+ from agentinputlab.integrations.external_workers import WorkerClient
36
+ from agentinputlab.integrations.external_workers.method import (
37
+ MethodWorkerRequest,
38
+ call_worker,
39
+ finite_number,
40
+ mapping_sequence,
41
+ nonnegative_integer,
42
+ required_text,
43
+ resolve_worker,
44
+ string_tuple,
45
+ worker_fingerprint,
46
+ )
47
+ from agentinputlab.observability import external_usage_counters
48
+
49
+ SMARTSEARCH_UPSTREAM_COMMIT = "5e9e7ec0d6af34f45fad145d4bff442529e7e6ff"
50
+ SMARTSEARCH_MODEL_REPOSITORY = "vvv111222/SmartSearch-3B"
51
+ SMARTSEARCH_CHECKPOINT_REVISION = "82bfe8a845e3e08f0d9d00d8e1e2cfb6d50b5da8"
52
+ SMARTSEARCH_PROTOCOL = "agentinputlab.smartsearch.frozen.v2"
53
+ SMARTSEARCH_PROFILE_ID = "smartsearch.controlled_frozen.v1"
54
+ SMARTSEARCH_COMMON_SUPPORT_RELEASE = "rewrite.smartsearch.common_support_queries"
55
+
56
+ SMARTSEARCH_TOOL_SCHEMA: tuple[Mapping[str, Any], ...] = (
57
+ {
58
+ "type": "function",
59
+ "function": {
60
+ "name": "wikipedia_search",
61
+ "description": "Search Wikipedia for a given query.",
62
+ "parameters": {
63
+ "type": "object",
64
+ "properties": {
65
+ "query": {
66
+ "type": "string",
67
+ "description": "Query to search for.",
68
+ },
69
+ "top_n": {
70
+ "type": "integer",
71
+ "description": ("Number of results to return. The default value is 5."),
72
+ "default": 5,
73
+ },
74
+ },
75
+ "required": ["query"],
76
+ },
77
+ },
78
+ },
79
+ )
80
+ SMARTSEARCH_TOOL_SCHEMA_SHA256 = content_hash(SMARTSEARCH_TOOL_SCHEMA)
81
+
82
+ # The first five values are upstream constants. ``retry_attempts=1`` calls
83
+ # ReCall.run.__wrapped__ so an opaque outer retry cannot replay a whole paid
84
+ # trajectory. One search tag per turn is the fail-closed parser hardening that
85
+ # makes the dynamic retrieval budget bounded. These two disclosed changes are
86
+ # why this profile is a controlled adapter rather than an official-native cell.
87
+ SMARTSEARCH_LOOP_CONTRACT: Mapping[str, Any] = freeze_mapping(
88
+ {
89
+ "max_rounds": 10,
90
+ "max_results_per_search": 5,
91
+ "max_new_tokens": 8192,
92
+ "temperature": 0.0,
93
+ "stop": ("</search>", "</answer>"),
94
+ "retry_attempts": 1,
95
+ "search_tags_per_turn": 1,
96
+ }
97
+ )
98
+ SMARTSEARCH_LOOP_CONTRACT_SHA256 = content_hash(SMARTSEARCH_LOOP_CONTRACT)
99
+ SMARTSEARCH_PARSER_CONTRACT_SHA256 = content_hash(
100
+ {
101
+ "active_pipeline_sha256": (
102
+ "20394e3418b6e30b43057ca96b97a423b4e4d37a3a04901e0a0a0dbc3af221fa"
103
+ ),
104
+ "answer_helpers_sha256": (
105
+ "2697ffa7479a0c9c4e6baf843164b7055b80350c627e01413584ecf4f76476bc"
106
+ ),
107
+ "answer_extractor": "ReCallPipeline.extract_last_assistant_response",
108
+ "boxed_helpers": ("last_boxed_only_string", "remove_boxed"),
109
+ }
110
+ )
111
+
112
+ _HEX_SHA256 = frozenset("0123456789abcdef")
113
+ _ALLOWED_TRANSPORTS = frozenset(
114
+ {"sglang_generate", "openai_completions", "openai_completions_local_snapshot"}
115
+ )
116
+ _FORBIDDEN_INFERENCE_KEYS = frozenset(
117
+ {
118
+ "expected_answer",
119
+ "gold",
120
+ "gold_answer",
121
+ "ground_truth",
122
+ "label",
123
+ "labels",
124
+ "process_reward",
125
+ "reference_answer",
126
+ "reward",
127
+ "reward_signal",
128
+ "rewards",
129
+ "target_answer",
130
+ "test_reward",
131
+ "verifier_score",
132
+ }
133
+ )
134
+
135
+
136
+ def _sha256_text(value: str) -> str:
137
+ return hashlib.sha256(value.encode("utf-8")).hexdigest()
138
+
139
+
140
+ def _validate_sha256(value: str, *, label: str) -> None:
141
+ if (
142
+ not isinstance(value, str)
143
+ or len(value) != 64
144
+ or any(character not in _HEX_SHA256 for character in value.lower())
145
+ ):
146
+ raise ValidationError(f"{label} must be a SHA-256 digest")
147
+
148
+
149
+ @dataclass(frozen=True, slots=True)
150
+ class SmartSearchArtifactIdentity:
151
+ """Content and deployment identities that define one frozen treatment.
152
+
153
+ Upstream did not publish a pinned Wikipedia corpus, retriever checkpoint,
154
+ or index. Callers therefore provide content identities for those assets;
155
+ changing any one produces a different treatment hash and must not be
156
+ reported as paper-level native parity.
157
+ """
158
+
159
+ model_snapshot_manifest_sha256: str
160
+ model_snapshot_tree_sha256: str
161
+ tokenizer_revision: str
162
+ served_model_name: str
163
+ model_deployment_fingerprint_sha256: str
164
+ context_admission_fingerprint_sha256: str
165
+ retriever_revision: str
166
+ retriever_deployment_fingerprint_sha256: str
167
+ corpus_sha256: str
168
+ index_sha256: str
169
+ retrieval_config_sha256: str
170
+ compatibility_manifest_sha256: str
171
+ model_transport: str = "sglang_generate"
172
+ checkpoint_repository: str = SMARTSEARCH_MODEL_REPOSITORY
173
+ checkpoint_revision: str = SMARTSEARCH_CHECKPOINT_REVISION
174
+ profile_id: str = SMARTSEARCH_PROFILE_ID
175
+
176
+ def __post_init__(self) -> None:
177
+ if self.checkpoint_repository != SMARTSEARCH_MODEL_REPOSITORY:
178
+ raise ValidationError("SmartSearch requires the released 3B checkpoint repository")
179
+ if self.checkpoint_revision != SMARTSEARCH_CHECKPOINT_REVISION:
180
+ raise ValidationError("SmartSearch requires the released pinned checkpoint revision")
181
+ if self.tokenizer_revision != SMARTSEARCH_CHECKPOINT_REVISION:
182
+ raise ValidationError("SmartSearch tokenizer revision must match the released snapshot")
183
+ if self.profile_id != SMARTSEARCH_PROFILE_ID:
184
+ raise ValidationError("SmartSearch profile_id is not supported")
185
+ if self.model_transport not in _ALLOWED_TRANSPORTS:
186
+ raise ValidationError(
187
+ "SmartSearch model_transport must be an approved frozen completion transport"
188
+ )
189
+ for name in (
190
+ "served_model_name",
191
+ "retriever_revision",
192
+ ):
193
+ value = getattr(self, name)
194
+ if not isinstance(value, str) or not value.strip():
195
+ raise ValidationError(f"SmartSearch {name} must be non-empty text")
196
+ for name in (
197
+ "model_snapshot_manifest_sha256",
198
+ "model_snapshot_tree_sha256",
199
+ "model_deployment_fingerprint_sha256",
200
+ "context_admission_fingerprint_sha256",
201
+ "retriever_deployment_fingerprint_sha256",
202
+ "corpus_sha256",
203
+ "index_sha256",
204
+ "retrieval_config_sha256",
205
+ "compatibility_manifest_sha256",
206
+ ):
207
+ _validate_sha256(getattr(self, name), label=f"SmartSearch {name}")
208
+
209
+ def as_mapping(self) -> Mapping[str, Any]:
210
+ return freeze_mapping(
211
+ {
212
+ **asdict(self),
213
+ "tool_schema_sha256": SMARTSEARCH_TOOL_SCHEMA_SHA256,
214
+ "loop_contract_sha256": SMARTSEARCH_LOOP_CONTRACT_SHA256,
215
+ "parser_contract_sha256": SMARTSEARCH_PARSER_CONTRACT_SHA256,
216
+ }
217
+ )
218
+
219
+ @property
220
+ def identity_sha256(self) -> str:
221
+ return content_hash(self.as_mapping())
222
+
223
+
224
+ @dataclass(frozen=True, slots=True)
225
+ class SmartSearchControls:
226
+ """Disclosed fixed controls for the hardened official loop."""
227
+
228
+ max_search_rounds: int = 10
229
+ max_results_per_round: int = 5
230
+ max_evidence_documents: int = 50
231
+ max_output_tokens_per_call: int = 8192
232
+
233
+ def __post_init__(self) -> None:
234
+ values = (
235
+ self.max_search_rounds,
236
+ self.max_results_per_round,
237
+ self.max_evidence_documents,
238
+ self.max_output_tokens_per_call,
239
+ )
240
+ if any(isinstance(value, bool) or not isinstance(value, int) for value in values):
241
+ raise ValidationError("SmartSearch limits must be integers")
242
+ if min(*values) < 1:
243
+ raise ValidationError("SmartSearch limits must be positive")
244
+ if values != (10, 5, 50, 8192):
245
+ raise ValidationError("this frozen SmartSearch release fixes controls at 10/5/50/8192")
246
+
247
+
248
+ @dataclass(frozen=True, slots=True)
249
+ class SmartSearchStep:
250
+ index: int
251
+ query: str
252
+ document_ids: tuple[str, ...]
253
+ raw_search_hash: str
254
+ retrieval_request_sha256: str
255
+ retrieval_response_sha256: str
256
+
257
+ @classmethod
258
+ def from_mapping(cls, value: Mapping[str, Any]) -> SmartSearchStep:
259
+ index = nonnegative_integer(value.get("index"), label="SmartSearch step index")
260
+ query = required_text(value, "query", label="SmartSearch step")
261
+ raw_search_text = required_text(value, "raw_search_text", label="SmartSearch step")
262
+ if raw_search_text != query:
263
+ raise AlgorithmOutputError("SmartSearch raw search text must equal the parsed query")
264
+ raw_search_hash = required_text(value, "raw_search_hash", label="SmartSearch step")
265
+ if raw_search_hash.lower() != _sha256_text(raw_search_text):
266
+ raise AlgorithmOutputError("SmartSearch raw_search_hash mismatch")
267
+ if value.get("tag_parse_status") != "ok":
268
+ raise AlgorithmOutputError("SmartSearch requires a successfully parsed <search> tag")
269
+ request_hash = required_text(
270
+ value,
271
+ "retrieval_request_sha256",
272
+ label="SmartSearch step",
273
+ ).lower()
274
+ response_hash = required_text(
275
+ value,
276
+ "retrieval_response_sha256",
277
+ label="SmartSearch step",
278
+ ).lower()
279
+ for digest, label in (
280
+ (request_hash, "retrieval_request_sha256"),
281
+ (response_hash, "retrieval_response_sha256"),
282
+ ):
283
+ if len(digest) != 64 or any(character not in _HEX_SHA256 for character in digest):
284
+ raise AlgorithmOutputError(f"SmartSearch {label} must be a SHA-256 digest")
285
+ return cls(
286
+ index=index,
287
+ query=query,
288
+ document_ids=string_tuple(
289
+ value.get("document_ids"),
290
+ label="SmartSearch step document_ids",
291
+ unique=True,
292
+ ),
293
+ raw_search_hash=raw_search_hash.lower(),
294
+ retrieval_request_sha256=request_hash,
295
+ retrieval_response_sha256=response_hash,
296
+ )
297
+
298
+
299
+ @dataclass(frozen=True, slots=True)
300
+ class _SmartSearchEvidence:
301
+ document_id: str
302
+ text: str
303
+ source: str
304
+ score: float | None
305
+ first_seen_step: int
306
+ corpus_sha256: str
307
+ index_sha256: str
308
+ document_sha256: str
309
+ metadata: Mapping[str, Any]
310
+
311
+ def __post_init__(self) -> None:
312
+ object.__setattr__(self, "metadata", freeze_mapping(self.metadata))
313
+
314
+ @classmethod
315
+ def from_mapping(
316
+ cls,
317
+ value: Mapping[str, Any],
318
+ *,
319
+ artifacts: SmartSearchArtifactIdentity,
320
+ ) -> _SmartSearchEvidence:
321
+ document_id = required_text(value, "document_id", label="SmartSearch evidence")
322
+ text = required_text(value, "text", label="SmartSearch evidence")
323
+ source = required_text(value, "source", label="SmartSearch evidence")
324
+ if source != "smartsearch.wikipedia_search":
325
+ raise AlgorithmOutputError("SmartSearch evidence source is not the pinned search seam")
326
+ score_value = value.get("score")
327
+ score = (
328
+ None
329
+ if score_value is None
330
+ else finite_number(score_value, label="SmartSearch evidence score")
331
+ )
332
+ metadata = value.get("metadata", {})
333
+ if not isinstance(metadata, Mapping):
334
+ raise AlgorithmOutputError("SmartSearch evidence metadata must be a mapping")
335
+ _reject_forbidden_inference_keys(metadata, label="SmartSearch evidence metadata")
336
+ corpus_sha256 = required_text(value, "corpus_sha256", label="SmartSearch evidence")
337
+ index_sha256 = required_text(value, "index_sha256", label="SmartSearch evidence")
338
+ if corpus_sha256 != artifacts.corpus_sha256 or index_sha256 != artifacts.index_sha256:
339
+ raise AlgorithmOutputError("SmartSearch evidence corpus/index identity mismatch")
340
+ document_sha256 = required_text(
341
+ value,
342
+ "document_sha256",
343
+ label="SmartSearch evidence",
344
+ ).lower()
345
+ if document_sha256 != content_hash({"document_id": document_id, "text": text}):
346
+ raise AlgorithmOutputError("SmartSearch evidence document_sha256 mismatch")
347
+ return cls(
348
+ document_id=document_id,
349
+ text=text,
350
+ source=source,
351
+ score=score,
352
+ first_seen_step=nonnegative_integer(
353
+ value.get("first_seen_step"),
354
+ label="SmartSearch evidence first_seen_step",
355
+ ),
356
+ corpus_sha256=corpus_sha256,
357
+ index_sha256=index_sha256,
358
+ document_sha256=document_sha256,
359
+ metadata=dict(metadata),
360
+ )
361
+
362
+ def as_context_block(self) -> ContextBlock:
363
+ return ContextBlock(
364
+ block_id=self.document_id,
365
+ text=self.text,
366
+ source=self.source,
367
+ score=self.score,
368
+ metadata={
369
+ **dict(self.metadata),
370
+ "smartsearch_first_seen_step": self.first_seen_step,
371
+ "corpus_sha256": self.corpus_sha256,
372
+ "index_sha256": self.index_sha256,
373
+ "document_sha256": self.document_sha256,
374
+ },
375
+ )
376
+
377
+
378
+ @dataclass(slots=True)
379
+ class SmartSearchFrozenInference:
380
+ """Run only the released SmartSearch-3B policy's frozen inference path."""
381
+
382
+ artifacts: SmartSearchArtifactIdentity
383
+ client: WorkerClient | None = None
384
+ controls: SmartSearchControls = SmartSearchControls()
385
+ method_id: str = "recipe.smartsearch"
386
+ release_id: str = "recipe.smartsearch.frozen_3b_inference"
387
+ family: SemanticFamily = SemanticFamily.COMPOSITE
388
+
389
+ def __post_init__(self) -> None:
390
+ if not isinstance(self.artifacts, SmartSearchArtifactIdentity):
391
+ raise ValidationError("SmartSearch requires SmartSearchArtifactIdentity")
392
+ if not isinstance(self.controls, SmartSearchControls):
393
+ raise ValidationError("SmartSearch controls must be SmartSearchControls")
394
+
395
+ def run(
396
+ self,
397
+ state: FrozenAgentState,
398
+ context: InterventionContext,
399
+ ) -> CompositeResult:
400
+ if not state.query.strip():
401
+ raise ValidationError("SmartSearch requires a non-empty query")
402
+ if state.instruction.strip() or state.messages or state.context or state.tool_names:
403
+ raise ValidationError(
404
+ "the official SmartSearch frozen profile accepts one question only; "
405
+ "instruction/messages/context/tools require a separate factorial profile"
406
+ )
407
+ remaining_budget = _remaining_budget(state, context)
408
+ if remaining_budget["model_calls"] < 1:
409
+ raise BudgetExceededError("SmartSearch requires one remaining model call")
410
+ if remaining_budget["output_tokens"] < self.controls.max_output_tokens_per_call:
411
+ raise BudgetExceededError(
412
+ "SmartSearch requires 8192 remaining output tokens before its first model call"
413
+ )
414
+ if state.budget.max_cost_usd is not None:
415
+ raise BudgetExceededError(
416
+ "SmartSearch external calls are unpriced; a cost budget cannot be guaranteed"
417
+ )
418
+
419
+ worker = resolve_worker(self.client, context, label="SmartSearch")
420
+ worker_identity = worker_fingerprint(worker, label="SmartSearch")
421
+ artifact_mapping = self.artifacts.as_mapping()
422
+ request = MethodWorkerRequest(
423
+ method_id=self.method_id,
424
+ release_id=self.release_id,
425
+ upstream_commit=SMARTSEARCH_UPSTREAM_COMMIT,
426
+ state_hash=state.state_hash,
427
+ payload={
428
+ "profile_id": self.artifacts.profile_id,
429
+ "task_id": state.task_id,
430
+ "question": state.query,
431
+ "artifacts": artifact_mapping,
432
+ "controls": asdict(self.controls),
433
+ "remaining_budget": remaining_budget,
434
+ "seed": context.seed,
435
+ "inference_contract": {
436
+ "mode": "frozen_inference",
437
+ "allow_training": False,
438
+ "allow_gold_answer": False,
439
+ "allow_test_time_reward": False,
440
+ "allow_external_query_refiner": False,
441
+ },
442
+ },
443
+ dependency_fingerprints={
444
+ "worker": worker_identity,
445
+ "artifacts_sha256": self.artifacts.identity_sha256,
446
+ },
447
+ minimum_reservation={"model_calls": 1},
448
+ protocol_version=SMARTSEARCH_PROTOCOL,
449
+ )
450
+ response = call_worker(worker, request)
451
+ payload = response.payload
452
+ _reject_forbidden_inference_keys(payload, label="SmartSearch response")
453
+
454
+ echoed_artifacts = payload.get("artifacts")
455
+ if not isinstance(echoed_artifacts, Mapping) or content_hash(
456
+ echoed_artifacts
457
+ ) != content_hash(artifact_mapping):
458
+ raise AlgorithmOutputError("SmartSearch artifact identity mismatch")
459
+ if required_text(payload, "profile_id", label="SmartSearch response") != (
460
+ self.artifacts.profile_id
461
+ ):
462
+ raise AlgorithmOutputError("SmartSearch profile identity mismatch")
463
+ if required_text(payload, "artifact_identity_sha256", label="SmartSearch response") != (
464
+ self.artifacts.identity_sha256
465
+ ):
466
+ raise AlgorithmOutputError("SmartSearch artifact identity hash mismatch")
467
+ _require_false(payload, "gold_answer_used")
468
+ _require_false(payload, "test_time_reward_used")
469
+ _require_false(payload, "external_query_refiner_used")
470
+ _require_false(payload, "training_code_loaded")
471
+
472
+ attestation = _validate_runtime_attestation(payload, artifacts=self.artifacts)
473
+ steps = tuple(
474
+ SmartSearchStep.from_mapping(row)
475
+ for row in mapping_sequence(payload.get("trajectory"), label="SmartSearch trajectory")
476
+ )
477
+ evidence_records = tuple(
478
+ _SmartSearchEvidence.from_mapping(row, artifacts=self.artifacts)
479
+ for row in mapping_sequence(payload.get("evidence"), label="SmartSearch evidence")
480
+ )
481
+ _validate_search_lineage(steps, evidence_records, controls=self.controls)
482
+ if response.usage.retrieval_calls != len(steps):
483
+ raise AlgorithmOutputError(
484
+ "SmartSearch retrieval_calls must equal parsed search-tag count"
485
+ )
486
+ if response.usage.model_calls < 1:
487
+ raise AlgorithmOutputError("SmartSearch frozen inference requires a model call")
488
+ if response.usage.model_calls not in {len(steps), len(steps) + 1}:
489
+ raise AlgorithmOutputError("SmartSearch model/search call relationship is invalid")
490
+ _validate_usage_against_sent_budget(response.usage, remaining_budget)
491
+
492
+ final_answer = required_text(payload, "final_answer", label="SmartSearch response")
493
+ termination = required_text(payload, "termination", label="SmartSearch response")
494
+ if termination not in {"answer", "direct_answer", "max_search_rounds"}:
495
+ raise AlgorithmOutputError("SmartSearch returned an unsupported termination reason")
496
+ if termination == "direct_answer" and steps:
497
+ raise AlgorithmOutputError("SmartSearch direct_answer cannot contain search steps")
498
+ if termination == "max_search_rounds" and response.usage.model_calls != (
499
+ self.controls.max_search_rounds
500
+ ):
501
+ raise AlgorithmOutputError(
502
+ "SmartSearch max_search_rounds termination disagrees with model usage"
503
+ )
504
+ transcript_hash = required_text(
505
+ payload,
506
+ "raw_transcript_sha256",
507
+ label="SmartSearch response",
508
+ ).lower()
509
+ if len(transcript_hash) != 64 or any(
510
+ character not in _HEX_SHA256 for character in transcript_hash
511
+ ):
512
+ raise AlgorithmOutputError("SmartSearch raw_transcript_sha256 is invalid")
513
+
514
+ evidence = tuple(record.as_context_block() for record in evidence_records)
515
+ trace_events: list[TraceEvent] = [
516
+ TraceEvent(
517
+ TracePhase.PREPARE,
518
+ "controlled_frozen_inference",
519
+ {
520
+ "profile_id": self.artifacts.profile_id,
521
+ "artifact_identity_sha256": self.artifacts.identity_sha256,
522
+ "checkpoint_revision": self.artifacts.checkpoint_revision,
523
+ "corpus_sha256": self.artifacts.corpus_sha256,
524
+ "index_sha256": self.artifacts.index_sha256,
525
+ "reward_available": False,
526
+ "gold_available": False,
527
+ "external_refiner_available": False,
528
+ "paper_native_parity_claimed": False,
529
+ },
530
+ )
531
+ ]
532
+ trace_events.extend(
533
+ TraceEvent(
534
+ TracePhase.OBSERVE,
535
+ "search_step",
536
+ {
537
+ "index": step.index,
538
+ "query": step.query,
539
+ "document_ids": step.document_ids,
540
+ "raw_search_hash": step.raw_search_hash,
541
+ "retrieval_request_sha256": step.retrieval_request_sha256,
542
+ "retrieval_response_sha256": step.retrieval_response_sha256,
543
+ },
544
+ )
545
+ for step in steps
546
+ )
547
+ trace_events.append(
548
+ TraceEvent(
549
+ TracePhase.FINALIZE,
550
+ "terminal_answer",
551
+ {
552
+ "termination": termination,
553
+ "raw_transcript_sha256": transcript_hash,
554
+ "evidence_document_ids": tuple(block.block_id for block in evidence),
555
+ },
556
+ )
557
+ )
558
+ trace = ExecutionTrace(
559
+ method_id=self.method_id,
560
+ release_id=self.release_id,
561
+ events=tuple(trace_events),
562
+ counters={
563
+ **external_usage_counters(response.usage),
564
+ "worker_calls": 1,
565
+ "search_steps": len(steps),
566
+ "evidence_documents": len(evidence),
567
+ },
568
+ )
569
+ return CompositeResult(
570
+ method_id=self.method_id,
571
+ release_id=self.release_id,
572
+ source_state_hash=state.state_hash,
573
+ final_answer=final_answer,
574
+ evidence=evidence,
575
+ trace=trace,
576
+ implementation_identity=(
577
+ f"thin_external_wrapper:RUC-NLPIR/SmartSearch@{SMARTSEARCH_UPSTREAM_COMMIT}"
578
+ ),
579
+ profile_kind="controlled_adapter",
580
+ metadata={
581
+ "implementation_origin": "thin_external_wrapper",
582
+ "profile_id": self.artifacts.profile_id,
583
+ "artifact_identity_sha256": self.artifacts.identity_sha256,
584
+ "checkpoint_repository": self.artifacts.checkpoint_repository,
585
+ "checkpoint_revision": self.artifacts.checkpoint_revision,
586
+ "retriever_revision": self.artifacts.retriever_revision,
587
+ "corpus_sha256": self.artifacts.corpus_sha256,
588
+ "index_sha256": self.artifacts.index_sha256,
589
+ "termination": termination,
590
+ "raw_transcript_sha256": transcript_hash,
591
+ "worker_fingerprint": worker_identity,
592
+ "runtime_attestation": attestation,
593
+ "paper_native_parity_claimed": False,
594
+ "seed_applied": False,
595
+ "test_time_reward_used": False,
596
+ "gold_answer_used": False,
597
+ "external_query_refiner_used": False,
598
+ },
599
+ )
600
+
601
+
602
+ @dataclass(slots=True)
603
+ class SmartSearchCommonSupportQueries:
604
+ """Expose SmartSearch search refinements to the shared downstream agent.
605
+
606
+ The released SmartSearch checkpoint, prompt, parser, and ``ReCall`` loop run
607
+ unchanged through :class:`SmartSearchFrozenInference`. The component's
608
+ terminal answer and retrieved document text are deliberately discarded.
609
+ Unique search queries from the official trajectory are appended to the
610
+ original request as retrieval refinements. This is the paper-aligned
611
+ reformulation treatment for the common-support arena, not a claim of
612
+ end-to-end SmartSearch paper-result parity.
613
+ """
614
+
615
+ artifacts: SmartSearchArtifactIdentity
616
+ client: WorkerClient | None = None
617
+ controls: SmartSearchControls = SmartSearchControls()
618
+ method_id: str = "smartsearch"
619
+ release_id: str = SMARTSEARCH_COMMON_SUPPORT_RELEASE
620
+ family: SemanticFamily = SemanticFamily.REFORMULATE
621
+
622
+ def __post_init__(self) -> None:
623
+ if not isinstance(self.artifacts, SmartSearchArtifactIdentity):
624
+ raise ValidationError("SmartSearch common support requires frozen artifacts")
625
+ if not isinstance(self.controls, SmartSearchControls):
626
+ raise ValidationError("SmartSearch common-support controls have the wrong type")
627
+
628
+ def propose(self, state: FrozenAgentState, context: InterventionContext) -> InputPatch:
629
+ if not state.query.strip():
630
+ raise ValidationError("SmartSearch common support requires a non-empty query")
631
+ # The official runtime accepts a question and nothing else. Construct a
632
+ # question-only view with the *same* execution budget; evaluator labels,
633
+ # arena tools, prior messages, and captured context never cross the seam.
634
+ component_state = FrozenAgentState(
635
+ query=state.query,
636
+ task_id=state.task_id,
637
+ metadata={
638
+ "common_support_source_state_hash": state.state_hash,
639
+ "common_support_profile": SMARTSEARCH_COMMON_SUPPORT_RELEASE,
640
+ },
641
+ budget=state.budget,
642
+ )
643
+ component = SmartSearchFrozenInference(
644
+ artifacts=self.artifacts,
645
+ client=self.client,
646
+ controls=self.controls,
647
+ ).run(component_state, context)
648
+ refinements: list[str] = []
649
+ for event in component.trace.events:
650
+ query = event.payload.get("query") if event.name == "search_step" else None
651
+ if isinstance(query, str) and query.strip() and query not in refinements:
652
+ refinements.append(query)
653
+ evidence = tuple(component.evidence)
654
+ if refinements:
655
+ value = "SmartSearch retrieval refinements:\n" + "\n".join(
656
+ f"- {query}" for query in refinements
657
+ )
658
+ operation = PatchOperation(
659
+ PatchOp.APPEND_QUERY,
660
+ value,
661
+ target="smartsearch_search_query_refinements",
662
+ rationale=(
663
+ "append unique search queries produced by the released SmartSearch "
664
+ "policy while retaining the original request"
665
+ ),
666
+ )
667
+ else:
668
+ operation = PatchOperation(
669
+ PatchOp.NO_OP,
670
+ target="smartsearch_no_search_refinement",
671
+ rationale="the released SmartSearch policy terminated without a search query",
672
+ )
673
+ events = (
674
+ TraceEvent(
675
+ TracePhase.PREPARE,
676
+ "smartsearch_common_support_boundary",
677
+ {
678
+ "component_release_id": component.release_id,
679
+ "component_state_hash": component_state.state_hash,
680
+ "source_state_hash": state.state_hash,
681
+ "question_only_component": True,
682
+ "terminal_answer_forwarded": False,
683
+ "retrieved_evidence_forwarded": False,
684
+ "original_query_retained": True,
685
+ "paper_result_parity_claimed": False,
686
+ },
687
+ ),
688
+ *component.trace.events,
689
+ TraceEvent(
690
+ TracePhase.FINALIZE,
691
+ "smartsearch_query_refinement_patch",
692
+ {
693
+ "refined_queries": tuple(refinements),
694
+ "refined_queries_sha256": content_hash(refinements),
695
+ "refinement_count": len(refinements),
696
+ "evidence_documents": len(evidence),
697
+ "component_result_sha256": component.result_hash,
698
+ "terminal_answer_sha256": _sha256_text(component.final_answer),
699
+ "terminal_answer_discarded": True,
700
+ },
701
+ ),
702
+ )
703
+ return InputPatch(
704
+ method_id=self.method_id,
705
+ release_id=self.release_id,
706
+ source_state_hash=state.state_hash,
707
+ operations=(operation,),
708
+ trace=ExecutionTrace(
709
+ method_id=self.method_id,
710
+ release_id=self.release_id,
711
+ events=events,
712
+ counters={
713
+ **dict(component.trace.counters),
714
+ "refinement_queries": len(refinements),
715
+ "internal_evidence_documents": len(evidence),
716
+ },
717
+ warnings=(
718
+ *component.trace.warnings,
719
+ "controlled_common_support_query_mapping_not_paper_result_parity",
720
+ ),
721
+ ),
722
+ implementation_identity=(
723
+ "query_refinement_common_support+" + component.implementation_identity
724
+ ),
725
+ profile_kind="controlled_adapter",
726
+ metadata={
727
+ **dict(component.metadata),
728
+ "component_release_id": component.release_id,
729
+ "component_result_sha256": component.result_hash,
730
+ "common_support_adaptation": (
731
+ "discard_terminal_answer_and_evidence_append_search_queries"
732
+ ),
733
+ "terminal_answer_discarded": True,
734
+ "retrieved_evidence_forwarded": False,
735
+ "original_query_retained": True,
736
+ "refined_queries": tuple(refinements),
737
+ "gold_answer_used": False,
738
+ "test_time_reward_used": False,
739
+ "training_called": False,
740
+ "paper_native_parity_claimed": False,
741
+ "paper_result_parity_claimed": False,
742
+ },
743
+ )
744
+
745
+
746
+ def _remaining_budget(
747
+ state: FrozenAgentState,
748
+ context: InterventionContext,
749
+ ) -> Mapping[str, int | None]:
750
+ usage = None
751
+ ledger = context.budget_ledger
752
+ if ledger is not None:
753
+ ledger_budget = getattr(ledger, "budget", None)
754
+ usage = getattr(ledger, "usage", None)
755
+ if ledger_budget != state.budget or usage is None:
756
+ raise ValidationError("SmartSearch received an incompatible budget ledger")
757
+
758
+ def consumed(name: str) -> int:
759
+ value = 0 if usage is None else getattr(usage, name, None)
760
+ if isinstance(value, bool) or not isinstance(value, int) or value < 0:
761
+ raise ValidationError(f"SmartSearch budget usage {name} is invalid")
762
+ return value
763
+
764
+ remaining_context = None
765
+ if state.budget.max_context_tokens is not None:
766
+ remaining_context = max(
767
+ 0,
768
+ state.budget.max_context_tokens - consumed("input_tokens"),
769
+ )
770
+ return freeze_mapping(
771
+ {
772
+ "model_calls": max(0, state.budget.max_model_calls - consumed("model_calls")),
773
+ "retrieval_calls": max(
774
+ 0,
775
+ state.budget.max_retrieval_calls - consumed("retrieval_calls"),
776
+ ),
777
+ "output_tokens": max(
778
+ 0,
779
+ state.budget.max_output_tokens - consumed("output_tokens"),
780
+ ),
781
+ "context_tokens": remaining_context,
782
+ }
783
+ )
784
+
785
+
786
+ def _validate_runtime_attestation(
787
+ payload: Mapping[str, Any],
788
+ *,
789
+ artifacts: SmartSearchArtifactIdentity,
790
+ ) -> Mapping[str, Any]:
791
+ value = payload.get("runtime_attestation")
792
+ if not isinstance(value, Mapping):
793
+ raise AlgorithmOutputError("SmartSearch requires runtime_attestation")
794
+ expected = {
795
+ "source_commit": SMARTSEARCH_UPSTREAM_COMMIT,
796
+ "compatibility_manifest_sha256": artifacts.compatibility_manifest_sha256,
797
+ "model_transport": artifacts.model_transport,
798
+ "model_snapshot_tree_sha256": artifacts.model_snapshot_tree_sha256,
799
+ "context_admission_fingerprint_sha256": (artifacts.context_admission_fingerprint_sha256),
800
+ "contract_hashes_verified": True,
801
+ "immutable_model_identity_handshake_required": True,
802
+ "context_admission_before_generation": True,
803
+ "official_loop_called": True,
804
+ "outer_retry_disabled": True,
805
+ "dangerous_sandbox_used": False,
806
+ "training_code_loaded": False,
807
+ "seed_applied": False,
808
+ }
809
+ for key, expected_value in expected.items():
810
+ if value.get(key) != expected_value:
811
+ raise AlgorithmOutputError(f"SmartSearch runtime attestation {key} mismatch")
812
+ if value.get("source_attestation") not in {"git_checkout", "verified_archive_snapshot"}:
813
+ raise AlgorithmOutputError("SmartSearch source attestation is unsupported")
814
+ return freeze_mapping(value)
815
+
816
+
817
+ def _validate_usage_against_sent_budget(usage: Any, budget: Mapping[str, Any]) -> None:
818
+ for usage_name, budget_name in (
819
+ ("model_calls", "model_calls"),
820
+ ("retrieval_calls", "retrieval_calls"),
821
+ ("output_tokens", "output_tokens"),
822
+ ):
823
+ if getattr(usage, usage_name) > budget[budget_name]:
824
+ raise AlgorithmOutputError(f"SmartSearch worker exceeded sent {budget_name} budget")
825
+ context_cap = budget["context_tokens"]
826
+ if context_cap is not None and usage.input_tokens > context_cap:
827
+ raise AlgorithmOutputError("SmartSearch worker exceeded sent context_tokens budget")
828
+
829
+
830
+ def _validate_search_lineage(
831
+ steps: tuple[SmartSearchStep, ...],
832
+ evidence: tuple[_SmartSearchEvidence, ...],
833
+ *,
834
+ controls: SmartSearchControls,
835
+ ) -> None:
836
+ if len(steps) > controls.max_search_rounds:
837
+ raise AlgorithmOutputError("SmartSearch exceeded max_search_rounds")
838
+ if tuple(step.index for step in steps) != tuple(range(len(steps))):
839
+ raise AlgorithmOutputError("SmartSearch trajectory indices must be contiguous from zero")
840
+ for step in steps:
841
+ if len(step.document_ids) > controls.max_results_per_round:
842
+ raise AlgorithmOutputError("SmartSearch step exceeded max_results_per_round")
843
+ if len(evidence) > controls.max_evidence_documents:
844
+ raise AlgorithmOutputError("SmartSearch exceeded max_evidence_documents")
845
+
846
+ evidence_ids = tuple(item.document_id for item in evidence)
847
+ if len(evidence_ids) != len(set(evidence_ids)):
848
+ raise AlgorithmOutputError("SmartSearch evidence contains duplicate document IDs")
849
+ expected_order: list[str] = []
850
+ first_seen: dict[str, int] = {}
851
+ for step in steps:
852
+ for document_id in step.document_ids:
853
+ if document_id not in first_seen:
854
+ first_seen[document_id] = step.index
855
+ expected_order.append(document_id)
856
+ if evidence_ids != tuple(expected_order):
857
+ raise AlgorithmOutputError(
858
+ "SmartSearch evidence must exactly follow first-seen trajectory order"
859
+ )
860
+ for item in evidence:
861
+ if first_seen[item.document_id] != item.first_seen_step:
862
+ raise AlgorithmOutputError("SmartSearch evidence first_seen_step mismatch")
863
+
864
+
865
+ def _require_false(payload: Mapping[str, Any], key: str) -> None:
866
+ if payload.get(key) is not False:
867
+ raise AlgorithmOutputError(f"SmartSearch response requires {key}=false")
868
+
869
+
870
+ def _reject_forbidden_inference_keys(value: Any, *, label: str) -> None:
871
+ if isinstance(value, Mapping):
872
+ for key, item in value.items():
873
+ normalized = str(key).strip().lower().replace("-", "_")
874
+ if normalized in _FORBIDDEN_INFERENCE_KEYS:
875
+ raise AlgorithmOutputError(f"{label} contains forbidden test-time field {key!r}")
876
+ _reject_forbidden_inference_keys(item, label=label)
877
+ elif isinstance(value, Sequence) and not isinstance(value, (str, bytes)):
878
+ for item in value:
879
+ _reject_forbidden_inference_keys(item, label=label)
880
+
881
+
882
+ __all__ = [
883
+ "SMARTSEARCH_CHECKPOINT_REVISION",
884
+ "SMARTSEARCH_LOOP_CONTRACT",
885
+ "SMARTSEARCH_LOOP_CONTRACT_SHA256",
886
+ "SMARTSEARCH_MODEL_REPOSITORY",
887
+ "SMARTSEARCH_PARSER_CONTRACT_SHA256",
888
+ "SMARTSEARCH_PROFILE_ID",
889
+ "SMARTSEARCH_PROTOCOL",
890
+ "SMARTSEARCH_TOOL_SCHEMA",
891
+ "SMARTSEARCH_TOOL_SCHEMA_SHA256",
892
+ "SMARTSEARCH_UPSTREAM_COMMIT",
893
+ "SmartSearchArtifactIdentity",
894
+ "SmartSearchControls",
895
+ "SmartSearchFrozenInference",
896
+ "SmartSearchStep",
897
+ ]