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,478 @@
1
+ """Controlled DecomP-ODQA adapter for the common-support paper arenas."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import json
6
+ import re
7
+ from dataclasses import dataclass
8
+ from typing import Any
9
+
10
+ from agentinputlab.backends.llm import GenerationRequest, LLMBackend
11
+ from agentinputlab.backends.retrieval import RetrievalResult, Retriever
12
+ from agentinputlab.contracts import (
13
+ AlgorithmOutputError,
14
+ BudgetExceededError,
15
+ ContextBlock,
16
+ ExecutionTrace,
17
+ ExternalDependencyError,
18
+ FrozenAgentState,
19
+ InputPatch,
20
+ InterventionContext,
21
+ PatchOp,
22
+ PatchOperation,
23
+ SemanticFamily,
24
+ TraceEvent,
25
+ TracePhase,
26
+ ValidationError,
27
+ )
28
+ from agentinputlab.contracts.serialization import content_hash
29
+
30
+ DECOMP_ODQA_REVISION = "9e0f7e717f6243a8b58b22a86eba4843088c2151"
31
+ DECOMP_COMMON_SUPPORT_RELEASE = "plan.decomp.common_support_odqa"
32
+ _HEX64 = re.compile(r"^[0-9a-f]{64}$")
33
+ _COMMAND = re.compile(
34
+ r"^\((?P<operation>select)\) \[(?P<handler>retrieve_odqa|multihop_titleqa)\] "
35
+ r"(?P<question>.+)$"
36
+ )
37
+ _DECOMPOSER_CHAT_SYSTEM = (
38
+ "You are the DecomP controller. Continue only the final QS line using the "
39
+ "demonstrated syntax. On the first step, always emit exactly (select) "
40
+ "[retrieve_odqa] <one self-contained evidence-seeking subquestion>. After "
41
+ "evidence exists, emit another retrieve_odqa step only if needed; otherwise "
42
+ "emit (select) [multihop_titleqa] <aggregation question>. Never answer the "
43
+ "user, explain, emit [EOQ] on the first step, or add a QS prefix."
44
+ )
45
+ _HANDLER_CHAT_SYSTEM = (
46
+ "You are the DecomP retrieve_odqa handler. Answer the final question using "
47
+ "only the supplied retrieved passages. Return one concise answer line, "
48
+ "without explanation, labels, or markup."
49
+ )
50
+
51
+
52
+ @dataclass(frozen=True, slots=True)
53
+ class DecompCommonSupportConfig:
54
+ """Frozen DecomP-ODQA prompt and bounded common-support controls."""
55
+
56
+ demonstrations: str
57
+ prompt_source_sha256: str
58
+ demonstrations_sha256: str
59
+ max_steps: int = 3
60
+ retrieval_top_k: int = 2
61
+ max_decomposer_tokens: int = 160
62
+ max_handler_tokens: int = 128
63
+ temperature: float = 0.0
64
+
65
+ def __post_init__(self) -> None:
66
+ if not self.demonstrations.strip():
67
+ raise ValidationError("DecomP common support requires frozen demonstrations")
68
+ for label, value in (
69
+ ("prompt_source_sha256", self.prompt_source_sha256),
70
+ ("demonstrations_sha256", self.demonstrations_sha256),
71
+ ):
72
+ if _HEX64.fullmatch(value) is None:
73
+ raise ValidationError(f"DecomP {label} must be a SHA-256 digest")
74
+ if content_hash(self.demonstrations) != self.demonstrations_sha256:
75
+ raise ValidationError("DecomP demonstrations hash does not match the content")
76
+ for label, value in (
77
+ ("max_steps", self.max_steps),
78
+ ("retrieval_top_k", self.retrieval_top_k),
79
+ ("max_decomposer_tokens", self.max_decomposer_tokens),
80
+ ("max_handler_tokens", self.max_handler_tokens),
81
+ ):
82
+ if isinstance(value, bool) or not isinstance(value, int) or value < 1:
83
+ raise ValidationError(f"DecomP {label} must be a positive integer")
84
+ if self.max_steps > 8:
85
+ raise ValidationError("DecomP max_steps must not exceed the ODQA source cap")
86
+ if self.retrieval_top_k > 100:
87
+ raise ValidationError("DecomP retrieval_top_k must not exceed 100")
88
+ if (
89
+ isinstance(self.temperature, bool)
90
+ or not isinstance(self.temperature, (int, float))
91
+ or not 0 <= self.temperature <= 2
92
+ ):
93
+ raise ValidationError("DecomP temperature must be numeric and in [0, 2]")
94
+
95
+
96
+ @dataclass(frozen=True, slots=True)
97
+ class DecompCommonSupportStep:
98
+ index: int
99
+ command: str
100
+ operation: str
101
+ handler: str
102
+ question: str
103
+ answer: str
104
+ document_ids: tuple[str, ...] = ()
105
+
106
+
107
+ @dataclass(slots=True)
108
+ class DecompCommonSupport:
109
+ """Run the source-locked QC/QS/A controller with shared dependencies.
110
+
111
+ The pinned ODQA system ends by routing the accumulated subtask state to a
112
+ multihop answer handler. In this input-intervention profile that final
113
+ handler is deliberately delegated to the benchmark's common downstream
114
+ agent. The optimizer therefore injects the modular subquestion/handler
115
+ trace and real retrieved evidence, never its own final answer.
116
+ """
117
+
118
+ config: DecompCommonSupportConfig
119
+ method_id: str = "decomp"
120
+ release_id: str = DECOMP_COMMON_SUPPORT_RELEASE
121
+ family: SemanticFamily = SemanticFamily.DECOMPOSE
122
+
123
+ def propose(self, state: FrozenAgentState, context: InterventionContext) -> InputPatch:
124
+ if not state.query.strip():
125
+ raise ValidationError("DecomP common support requires a non-empty query")
126
+ backend = context.backend
127
+ retriever = context.retriever
128
+ if not isinstance(backend, LLMBackend):
129
+ raise ExternalDependencyError("DecomP common support requires an LLMBackend")
130
+ if not isinstance(retriever, Retriever):
131
+ raise ExternalDependencyError("DecomP common support requires a Retriever")
132
+
133
+ steps: list[DecompCommonSupportStep] = []
134
+ documents: dict[str, ContextBlock] = {}
135
+ model_calls = 0
136
+ retrieval_calls = 0
137
+ input_tokens = 0
138
+ output_tokens = 0
139
+ cost_usd = 0.0
140
+ seen_commands: set[str] = set()
141
+ termination = "max_steps"
142
+
143
+ def generate(prompt: str, *, system: str, stage: str, max_tokens: int) -> str:
144
+ nonlocal model_calls, input_tokens, output_tokens, cost_usd
145
+ if model_calls >= state.budget.max_model_calls:
146
+ raise BudgetExceededError("DecomP exhausted max_model_calls")
147
+ remaining = state.budget.max_output_tokens - output_tokens
148
+ if remaining < 1:
149
+ raise BudgetExceededError("DecomP exhausted max_output_tokens")
150
+ response = backend.generate(
151
+ GenerationRequest(
152
+ prompt=prompt,
153
+ system=system,
154
+ temperature=self.config.temperature,
155
+ max_tokens=min(max_tokens, remaining),
156
+ seed=context.seed + model_calls,
157
+ stop=("\n",),
158
+ metadata={
159
+ "method_id": self.method_id,
160
+ "release_id": self.release_id,
161
+ "stage": stage,
162
+ },
163
+ )
164
+ )
165
+ model_calls += 1
166
+ input_tokens += response.usage.input_tokens
167
+ output_tokens += response.usage.output_tokens
168
+ cost_usd += response.usage.cost_usd or 0.0
169
+ if output_tokens > state.budget.max_output_tokens:
170
+ raise BudgetExceededError("DecomP exceeded max_output_tokens")
171
+ if (
172
+ state.budget.max_context_tokens is not None
173
+ and input_tokens > state.budget.max_context_tokens
174
+ ):
175
+ raise BudgetExceededError("DecomP exceeded max_context_tokens")
176
+ if state.budget.max_cost_usd is not None and cost_usd > state.budget.max_cost_usd:
177
+ raise BudgetExceededError("DecomP exceeded max_cost_usd")
178
+ if not isinstance(response.text, str) or not response.text.strip():
179
+ raise AlgorithmOutputError(f"DecomP {stage} returned empty output")
180
+ return response.text.strip()
181
+
182
+ for index in range(self.config.max_steps):
183
+ prompt = _render_decomposer_prompt(
184
+ self.config.demonstrations,
185
+ state.query,
186
+ steps,
187
+ )
188
+ raw = generate(
189
+ prompt,
190
+ system=_DECOMPOSER_CHAT_SYSTEM,
191
+ stage=f"decomposer_{index}",
192
+ max_tokens=self.config.max_decomposer_tokens,
193
+ )
194
+ parsed = parse_decomp_command(raw)
195
+ if parsed is None:
196
+ termination = "eoq"
197
+ break
198
+ operation, handler, question, command = parsed
199
+ if command in seen_commands:
200
+ raise AlgorithmOutputError("DecomP emitted a duplicate controller command")
201
+ seen_commands.add(command)
202
+ if handler == "multihop_titleqa":
203
+ steps.append(
204
+ DecompCommonSupportStep(
205
+ index=index,
206
+ command=command,
207
+ operation=operation,
208
+ handler=handler,
209
+ question=question,
210
+ answer="",
211
+ )
212
+ )
213
+ termination = "aggregation_delegated_to_common_agent"
214
+ break
215
+ if retrieval_calls >= state.budget.max_retrieval_calls:
216
+ raise BudgetExceededError("DecomP exhausted max_retrieval_calls")
217
+ results = _validated_results(
218
+ retriever.retrieve(question, top_k=self.config.retrieval_top_k),
219
+ top_k=self.config.retrieval_top_k,
220
+ )
221
+ retrieval_calls += 1
222
+ if not results:
223
+ raise AlgorithmOutputError("DecomP retrieve_odqa handler returned no documents")
224
+ for result in results:
225
+ block = _document_block(result)
226
+ documents.setdefault(block.block_id, block)
227
+ answer = generate(
228
+ _render_handler_prompt(question, results),
229
+ system=_HANDLER_CHAT_SYSTEM,
230
+ stage=f"retrieve_odqa_handler_{index}",
231
+ max_tokens=self.config.max_handler_tokens,
232
+ )
233
+ answer_payload = json.dumps(
234
+ {
235
+ "titles": [item.document.title or item.document.doc_id for item in results],
236
+ "answer": [answer],
237
+ },
238
+ ensure_ascii=False,
239
+ separators=(",", ":"),
240
+ )
241
+ steps.append(
242
+ DecompCommonSupportStep(
243
+ index=index,
244
+ command=command,
245
+ operation=operation,
246
+ handler=handler,
247
+ question=question,
248
+ answer=answer_payload,
249
+ document_ids=tuple(item.document.doc_id for item in results),
250
+ )
251
+ )
252
+
253
+ if not steps:
254
+ raise AlgorithmOutputError("DecomP produced no executable modular step")
255
+ if not documents:
256
+ raise AlgorithmOutputError(
257
+ "DecomP delegated aggregation before materializing retrieved evidence"
258
+ )
259
+ trace_text = _materialized_trace(state.query, steps, termination)
260
+ trace_block = ContextBlock(
261
+ text=trace_text,
262
+ block_id=f"{state.task_id or state.state_hash}:decomp-trace",
263
+ source="decomp_odqa_common_support",
264
+ metadata={
265
+ "method_id": self.method_id,
266
+ "release_id": self.release_id,
267
+ "termination": termination,
268
+ "final_answer_injected": False,
269
+ "evidence_kind": "decomposition_trace",
270
+ },
271
+ )
272
+ events: list[TraceEvent] = [
273
+ TraceEvent(
274
+ TracePhase.PREPARE,
275
+ "source_locked_odqa_profile",
276
+ {
277
+ "decomp_upstream_revision": DECOMP_REVISION,
278
+ "odqa_upstream_revision": DECOMP_ODQA_REVISION,
279
+ "prompt_source_sha256": self.config.prompt_source_sha256,
280
+ "demonstrations_sha256": self.config.demonstrations_sha256,
281
+ "serialization": "QC/QS/A",
282
+ "controller": "bounded_best_first_single_candidate",
283
+ "decomposer_chat_compatibility_sha256": content_hash(_DECOMPOSER_CHAT_SYSTEM),
284
+ "handler_chat_compatibility_sha256": content_hash(_HANDLER_CHAT_SYSTEM),
285
+ },
286
+ )
287
+ ]
288
+ events.extend(
289
+ TraceEvent(
290
+ TracePhase.OBSERVE,
291
+ "decomp_participant_call",
292
+ {
293
+ "index": step.index,
294
+ "command": step.command,
295
+ "operation": step.operation,
296
+ "handler": step.handler,
297
+ "question": step.question,
298
+ "answer": step.answer,
299
+ "document_ids": step.document_ids,
300
+ },
301
+ )
302
+ for step in steps
303
+ )
304
+ events.append(
305
+ TraceEvent(
306
+ TracePhase.FINALIZE,
307
+ "decomp_common_support_result",
308
+ {
309
+ "termination": termination,
310
+ "trace_block_id": trace_block.block_id,
311
+ "retrieved_document_ids": tuple(documents),
312
+ "final_answer_injected": False,
313
+ "downstream_common_agent_required": True,
314
+ },
315
+ )
316
+ )
317
+ trace = ExecutionTrace(
318
+ method_id=self.method_id,
319
+ release_id=self.release_id,
320
+ events=tuple(events),
321
+ counters={
322
+ "model_calls": model_calls,
323
+ "retrieval_calls": retrieval_calls,
324
+ "input_tokens": input_tokens,
325
+ "output_tokens": output_tokens,
326
+ "participant_calls": len(steps),
327
+ "retrieved_documents": len(documents),
328
+ },
329
+ )
330
+ blocks = (*documents.values(), trace_block)
331
+ return InputPatch(
332
+ method_id=self.method_id,
333
+ release_id=self.release_id,
334
+ source_state_hash=state.state_hash,
335
+ operations=(
336
+ PatchOperation(
337
+ PatchOp.ADD_CONTEXT,
338
+ value=blocks,
339
+ target="decomposition_evidence",
340
+ rationale="materialize DecomP participant trace and real handler evidence",
341
+ ),
342
+ ),
343
+ trace=trace,
344
+ implementation_identity=(
345
+ "controlled_source_locked:allenai/DecomP@"
346
+ f"{DECOMP_REVISION}+HarshTrivedi/DecomP-ODQA@{DECOMP_ODQA_REVISION}"
347
+ ),
348
+ profile_kind="controlled_adapter",
349
+ metadata={
350
+ "implementation_origin": "controlled_source_locked",
351
+ "upstream_qc_qs_a_serialization_preserved": True,
352
+ "upstream_participant_routing_preserved": True,
353
+ "best_first_width": 1,
354
+ "chat_compatibility_wrapper": True,
355
+ "final_answer_injected": False,
356
+ "aggregation_delegated_to_common_agent": True,
357
+ "termination": termination,
358
+ "backend_fingerprint": dict(backend.fingerprint()),
359
+ "retriever_fingerprint": dict(retriever.fingerprint()),
360
+ },
361
+ )
362
+
363
+
364
+ def parse_decomp_command(raw: Any) -> tuple[str, str, str, str] | None:
365
+ if not isinstance(raw, str):
366
+ raise AlgorithmOutputError("DecomP decomposer returned non-text output")
367
+ line = raw.strip().splitlines()[0].strip()
368
+ if line.startswith("QS:"):
369
+ line = line.removeprefix("QS:").strip()
370
+ if line == "[EOQ]":
371
+ return None
372
+ match = _COMMAND.fullmatch(line)
373
+ if match is None:
374
+ raise AlgorithmOutputError("DecomP command violates the source router grammar")
375
+ question = match.group("question").strip()
376
+ if not question:
377
+ raise AlgorithmOutputError("DecomP command contains an empty subquestion")
378
+ return match.group("operation"), match.group("handler"), question, line
379
+
380
+
381
+ def _render_decomposer_prompt(
382
+ demonstrations: str,
383
+ query: str,
384
+ steps: list[DecompCommonSupportStep],
385
+ ) -> str:
386
+ value = f"{demonstrations.rstrip()}\n\n\nQC: {query.strip()}"
387
+ for step in steps:
388
+ value += f"\nQS: {step.command}"
389
+ if step.answer:
390
+ value += f"\nA: {step.answer}"
391
+ return f"{value}\nQS:"
392
+
393
+
394
+ def _render_handler_prompt(question: str, results: tuple[RetrievalResult, ...]) -> str:
395
+ context = "\n\n".join(
396
+ f"Title: {item.document.title or item.document.doc_id}\n{item.document.text}"
397
+ for item in results
398
+ )
399
+ return f"{context}\n\nQ: {question}\nA:"
400
+
401
+
402
+ def _validated_results(raw: Any, *, top_k: int) -> tuple[RetrievalResult, ...]:
403
+ try:
404
+ results = tuple(raw)
405
+ except TypeError as exc:
406
+ raise AlgorithmOutputError("DecomP retriever returned a non-sequence") from exc
407
+ if not all(isinstance(item, RetrievalResult) for item in results):
408
+ raise AlgorithmOutputError("DecomP retriever returned a non-RetrievalResult item")
409
+ if len(results) > top_k:
410
+ raise AlgorithmOutputError("DecomP retriever returned more than top_k documents")
411
+ ids = tuple(item.document.doc_id for item in results)
412
+ if len(ids) != len(set(ids)):
413
+ raise AlgorithmOutputError("DecomP retriever returned duplicate document IDs")
414
+ if tuple(item.rank for item in results) != tuple(range(1, len(results) + 1)):
415
+ raise AlgorithmOutputError("DecomP retriever ranks must be contiguous and one-based")
416
+ return results
417
+
418
+
419
+ def _document_block(result: RetrievalResult) -> ContextBlock:
420
+ document = result.document
421
+ if not document.corpus_revision:
422
+ raise AlgorithmOutputError("DecomP documents require a corpus revision")
423
+ reserved = {
424
+ "corpus_revision",
425
+ "document_id",
426
+ "evidence_kind",
427
+ "rank",
428
+ "retrieval_features",
429
+ "title",
430
+ }
431
+ if reserved & set(document.metadata):
432
+ raise AlgorithmOutputError("DecomP document metadata uses reserved provenance keys")
433
+ return ContextBlock(
434
+ block_id=document.doc_id,
435
+ text=document.text,
436
+ source=document.corpus_revision,
437
+ score=float(result.score),
438
+ metadata={
439
+ **dict(document.metadata),
440
+ "document_id": document.doc_id,
441
+ "title": document.title,
442
+ "corpus_revision": document.corpus_revision,
443
+ "rank": result.rank,
444
+ "retrieval_features": dict(result.features),
445
+ "evidence_kind": "real_corpus_document",
446
+ },
447
+ )
448
+
449
+
450
+ def _materialized_trace(
451
+ query: str,
452
+ steps: list[DecompCommonSupportStep],
453
+ termination: str,
454
+ ) -> str:
455
+ lines = [
456
+ "Decomposed Prompting modular execution trace (QC/QS/A protocol).",
457
+ f"QC: {query}",
458
+ ]
459
+ for step in steps:
460
+ lines.append(f"QS: {step.command}")
461
+ if step.answer:
462
+ lines.append(f"A: {step.answer}")
463
+ lines.append(f"Termination: {termination}")
464
+ lines.append("Use the subtask evidence above to complete the original task.")
465
+ return "\n".join(lines)
466
+
467
+
468
+ # Imported late to avoid a circular import through the package __init__.
469
+ from .worker_bridge import DECOMP_REVISION # noqa: E402
470
+
471
+ __all__ = [
472
+ "DECOMP_COMMON_SUPPORT_RELEASE",
473
+ "DECOMP_ODQA_REVISION",
474
+ "DecompCommonSupport",
475
+ "DecompCommonSupportConfig",
476
+ "DecompCommonSupportStep",
477
+ "parse_decomp_command",
478
+ ]
@@ -0,0 +1,199 @@
1
+ """One native DecomP planner transition, explicitly not its full solver."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from collections.abc import Mapping
6
+ from dataclasses import dataclass
7
+
8
+ from agentinputlab.contracts import (
9
+ AlgorithmOutputError,
10
+ BudgetExceededError,
11
+ ExecutionTrace,
12
+ ExternalDependencyError,
13
+ FrozenAgentState,
14
+ InputPatch,
15
+ InterventionContext,
16
+ PatchOp,
17
+ PatchOperation,
18
+ SemanticFamily,
19
+ TraceEvent,
20
+ TracePhase,
21
+ ValidationError,
22
+ )
23
+ from agentinputlab.contracts.serialization import content_hash
24
+ from agentinputlab.observability import external_usage_counters, normalize_external_usage
25
+
26
+ from .worker_bridge import DECOMP_REVISION, DecompWorkerRequest, decomp_context_hash
27
+
28
+ DECOMP_PLANNER_SCHEMA = "agentinputlab.decomp.planner.v1"
29
+ DECOMP_PLANNER_RELEASE = "plan.decomp.planner_component"
30
+ DECOMP_PLANNER_MODE = "controlled_native_planner_callbacks.v1"
31
+
32
+
33
+ @dataclass(frozen=True, slots=True)
34
+ class DecompPlannerRequest(DecompWorkerRequest):
35
+ schema_version: str = DECOMP_PLANNER_SCHEMA
36
+
37
+ def __post_init__(self):
38
+ DecompWorkerRequest.__post_init__(self)
39
+ if self.max_steps != 1 or self.schema_version != DECOMP_PLANNER_SCHEMA:
40
+ raise ValidationError("DecomP planner requires its own schema and one transition")
41
+ if self.upstream_revision != DECOMP_REVISION:
42
+ raise ValidationError("DecomP planner requires the pinned source revision")
43
+
44
+
45
+ class DecompPlannerComponent:
46
+ """Attach the unexecuted native next subquestion to the original reader input."""
47
+
48
+ method_id = "decomp"
49
+ release_id = DECOMP_PLANNER_RELEASE
50
+ family = SemanticFamily.DECOMPOSE
51
+
52
+ def __init__(self, *, config_artifact_id: str, profile_kind="controlled_adapter"):
53
+ if not isinstance(config_artifact_id, str) or not config_artifact_id.strip():
54
+ raise ValidationError("DecomP planner requires an explicit native config artifact")
55
+ if profile_kind not in {"controlled_adapter", "factorial_adapter"}:
56
+ raise ValidationError("DecomP planner requires a controlled/factorial profile")
57
+ self.config_artifact_id, self.profile_kind = config_artifact_id, profile_kind
58
+
59
+ def propose(self, state: FrozenAgentState, context: InterventionContext) -> InputPatch:
60
+ if not state.query.strip():
61
+ raise ValidationError("DecomP planner query must be non-empty")
62
+ if state.budget.max_model_calls < 1 or state.budget.max_output_tokens < 1:
63
+ raise BudgetExceededError("DecomP planner has no generation budget")
64
+ runtime = context.external_runtime
65
+ if (
66
+ runtime is None
67
+ or not callable(getattr(runtime, "run", None))
68
+ or not callable(getattr(runtime, "fingerprint", None))
69
+ ):
70
+ raise ExternalDependencyError("DecomP planner requires its dedicated native runtime")
71
+ identity = runtime.fingerprint()
72
+ if identity.get("backend_binding_mode") != DECOMP_PLANNER_MODE:
73
+ raise ValidationError("full DecomP runtime cannot satisfy the planner component")
74
+ if identity.get("upstream_revision") != DECOMP_REVISION:
75
+ raise ValidationError("DecomP planner runtime revision differs")
76
+ input_bound = identity.get("per_call_input_token_bound")
77
+ if state.budget.max_cost_usd is not None or (
78
+ state.budget.max_context_tokens is not None and
79
+ (type(input_bound) is not int or input_bound < 1)):
80
+ raise ValidationError("native DecomP finite input-token/cost ceilings require pre-call estimators")
81
+ if (state.budget.max_context_tokens is not None
82
+ and input_bound > state.budget.max_context_tokens):
83
+ raise BudgetExceededError("DecomP planner input budget cannot reserve the native upper bound")
84
+ backend = context.backend
85
+ if backend is None or not callable(getattr(backend, "fingerprint", None)):
86
+ raise ExternalDependencyError("DecomP planner requires an explicitly bound backend")
87
+ backend_binding = dict(backend.fingerprint())
88
+ if content_hash(identity.get("backend")) != content_hash(backend_binding):
89
+ raise ValidationError("DecomP planner runtime backend differs from context")
90
+ paras = tuple(block.text for block in state.context)
91
+ ids = tuple(block.block_id for block in state.context)
92
+ request = DecompPlannerRequest(
93
+ case_id=state.task_id or state.state_hash,
94
+ question=state.query,
95
+ paras=paras,
96
+ paragraph_ids=ids,
97
+ context_hash=decomp_context_hash(ids, paras),
98
+ config_artifact_id=self.config_artifact_id,
99
+ backend_binding=backend_binding,
100
+ max_steps=1,
101
+ execution_budget=state.budget,
102
+ seed=context.seed,
103
+ )
104
+ response = runtime.run(request)
105
+ request.raise_for_external_status(response)
106
+ if not isinstance(response, Mapping):
107
+ raise AlgorithmOutputError("invalid DecomP planner response")
108
+ expected = {
109
+ "schema_version": DECOMP_PLANNER_SCHEMA,
110
+ "profile_id": self.release_id,
111
+ "case_id": request.case_id,
112
+ "upstream_revision": DECOMP_REVISION,
113
+ "context_hash": request.context_hash,
114
+ "component_only": True,
115
+ "router_executed": False,
116
+ "qa_executed": False,
117
+ }
118
+ if any(response.get(k) != v for k, v in expected.items()) or "final_answer" in response:
119
+ raise AlgorithmOutputError("DecomP planner identity/boundary differs")
120
+ if tuple(response.get("paragraph_ids", ())) != ids:
121
+ raise AlgorithmOutputError("DecomP planner changed paragraph identity")
122
+ selected = response.get("selected")
123
+ if not isinstance(selected, Mapping) or not isinstance(selected.get("question"), str):
124
+ raise AlgorithmOutputError("DecomP planner next question is unavailable")
125
+ question = selected["question"].strip()
126
+ if not question or question == "[EOQ]":
127
+ raise AlgorithmOutputError(
128
+ "native DecomP planner returned no substantive next question"
129
+ )
130
+ candidates = response.get("candidates")
131
+ if not isinstance(candidates, (list, tuple)) or selected not in candidates:
132
+ raise AlgorithmOutputError("selected DecomP plan is outside native candidates")
133
+ artifacts = response.get("native_artifacts")
134
+ if (
135
+ not isinstance(artifacts, Mapping)
136
+ or artifacts.get("config_artifact_id") != self.config_artifact_id
137
+ or artifacts.get("backend_binding_mode") != DECOMP_PLANNER_MODE
138
+ ):
139
+ raise AlgorithmOutputError("DecomP planner config artifact identity differs")
140
+ usage = normalize_external_usage(response.get("usage", {}))
141
+ if usage.model_calls != 1:
142
+ raise AlgorithmOutputError("planner must consume exactly one native generation")
143
+ if content_hash(runtime.fingerprint()) != content_hash(identity):
144
+ raise AlgorithmOutputError("DecomP planner runtime identity changed")
145
+ return InputPatch(
146
+ method_id=self.method_id,
147
+ release_id=self.release_id,
148
+ source_state_hash=state.state_hash,
149
+ operations=(
150
+ PatchOperation(
151
+ PatchOp.APPEND_INSTRUCTION,
152
+ value="Native DecomP next subquestion (unexecuted):\n" + question,
153
+ target="instruction",
154
+ rationale="first native planner transition; router/QA are not executed",
155
+ ),
156
+ ),
157
+ implementation_identity=f"native_decomp_first_planner_transition@{DECOMP_REVISION}",
158
+ profile_kind=self.profile_kind,
159
+ trace=ExecutionTrace(
160
+ method_id=self.method_id,
161
+ release_id=self.release_id,
162
+ events=(
163
+ TraceEvent(
164
+ TracePhase.PROPOSE,
165
+ "native_planner_component",
166
+ {
167
+ "selected": selected,
168
+ "candidates": candidates,
169
+ "native_artifacts": response.get("native_artifacts", {}),
170
+ "context_hash": request.context_hash,
171
+ "paragraph_ids": ids,
172
+ "runtime_identity_hash": content_hash(identity),
173
+ },
174
+ ),
175
+ ),
176
+ counters=external_usage_counters(usage),
177
+ ),
178
+ metadata={
179
+ "component_only": True,
180
+ "full_system": False,
181
+ "selected": selected,
182
+ "native_artifacts": response.get("native_artifacts", {}),
183
+ "router_executed": False,
184
+ "qa_executed": False,
185
+ "solver_executed": False,
186
+ "optimizer_input_projection": "query_and_exact_visible_context",
187
+ "gold_fields_visible_to_optimizer": False,
188
+ "paper_result_parity_claimed": False,
189
+ },
190
+ )
191
+
192
+
193
+ __all__ = [
194
+ "DECOMP_PLANNER_MODE",
195
+ "DECOMP_PLANNER_RELEASE",
196
+ "DECOMP_PLANNER_SCHEMA",
197
+ "DecompPlannerComponent",
198
+ "DecompPlannerRequest",
199
+ ]