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.
- agentinputlab/__init__.py +28 -0
- agentinputlab/algorithms/__init__.py +6 -0
- agentinputlab/algorithms/acquire/__init__.py +145 -0
- agentinputlab/algorithms/acquire/adaptive_rag/__init__.py +43 -0
- agentinputlab/algorithms/acquire/adaptive_rag/replay.py +367 -0
- agentinputlab/algorithms/acquire/adaptive_rag/runtime.py +1202 -0
- agentinputlab/algorithms/acquire/adaptive_rag_common_support.py +542 -0
- agentinputlab/algorithms/acquire/hyde.py +296 -0
- agentinputlab/algorithms/acquire/hyde_controlled.py +200 -0
- agentinputlab/algorithms/acquire/hyde_external.py +148 -0
- agentinputlab/algorithms/acquire/ircot.py +28 -0
- agentinputlab/algorithms/acquire/ircot_common_support.py +478 -0
- agentinputlab/algorithms/acquire/ircot_native.py +355 -0
- agentinputlab/algorithms/acquire/ircot_replay.py +327 -0
- agentinputlab/algorithms/acquire/qrag/__init__.py +79 -0
- agentinputlab/algorithms/acquire/qrag/bridge.py +828 -0
- agentinputlab/algorithms/acquire/qrag/common_support.py +891 -0
- agentinputlab/algorithms/acquire/qrag/native_axis.py +71 -0
- agentinputlab/algorithms/acquire/qrag/reader_adapter.py +139 -0
- agentinputlab/algorithms/acquire/r2ag/__init__.py +57 -0
- agentinputlab/algorithms/acquire/r2ag/bridge.py +1312 -0
- agentinputlab/algorithms/acquire/r2ag/common_support.py +1029 -0
- agentinputlab/algorithms/acquire/r2ag/socket_runtime.py +255 -0
- agentinputlab/algorithms/clarify/__init__.py +61 -0
- agentinputlab/algorithms/clarify/_structured.py +64 -0
- agentinputlab/algorithms/clarify/active_task_disambiguation.py +371 -0
- agentinputlab/algorithms/clarify/ask_or_assume/__init__.py +17 -0
- agentinputlab/algorithms/clarify/ask_or_assume/monitor.py +410 -0
- agentinputlab/algorithms/clarify/future_turns.py +379 -0
- agentinputlab/algorithms/clarify/udcs.py +255 -0
- agentinputlab/algorithms/clarify/udcs_deterministic.py +196 -0
- agentinputlab/algorithms/curate/__init__.py +65 -0
- agentinputlab/algorithms/curate/acon/__init__.py +27 -0
- agentinputlab/algorithms/curate/acon/common.py +284 -0
- agentinputlab/algorithms/curate/acon/common_support.py +136 -0
- agentinputlab/algorithms/curate/acon/history_bridge.py +309 -0
- agentinputlab/algorithms/curate/acon/observation_bridge.py +290 -0
- agentinputlab/algorithms/curate/llmlingua/__init__.py +30 -0
- agentinputlab/algorithms/curate/llmlingua/adapters.py +537 -0
- agentinputlab/algorithms/curate/llmlingua/budget.py +48 -0
- agentinputlab/algorithms/curate/llmlingua/controlled.py +175 -0
- agentinputlab/algorithms/curate/llmlingua/multilingual.py +105 -0
- agentinputlab/algorithms/curate/llmlingua/span_map.py +167 -0
- agentinputlab/algorithms/curate/recomp/__init__.py +47 -0
- agentinputlab/algorithms/curate/recomp/external.py +1129 -0
- agentinputlab/algorithms/curate/recomp/selective.py +304 -0
- agentinputlab/algorithms/decompose/__init__.py +107 -0
- agentinputlab/algorithms/decompose/decomp/__init__.py +53 -0
- agentinputlab/algorithms/decompose/decomp/common_support.py +478 -0
- agentinputlab/algorithms/decompose/decomp/planner_component.py +199 -0
- agentinputlab/algorithms/decompose/decomp/worker_bridge.py +416 -0
- agentinputlab/algorithms/decompose/llm_compiler/__init__.py +35 -0
- agentinputlab/algorithms/decompose/llm_compiler/bridge.py +520 -0
- agentinputlab/algorithms/decompose/llm_compiler/common_support.py +504 -0
- agentinputlab/algorithms/decompose/plan_and_budget/__init__.py +43 -0
- agentinputlab/algorithms/decompose/plan_and_budget/cached_soft_budget.py +362 -0
- agentinputlab/algorithms/decompose/plan_and_budget/decomposer_component.py +107 -0
- agentinputlab/algorithms/decompose/plan_and_budget/full.py +205 -0
- agentinputlab/algorithms/decompose/plan_and_budget/hard_cap.py +246 -0
- agentinputlab/algorithms/decompose/plan_and_budget/regenerated_soft_budget.py +448 -0
- agentinputlab/algorithms/decompose/plan_and_solve/__init__.py +33 -0
- agentinputlab/algorithms/decompose/plan_and_solve/plan_component.py +192 -0
- agentinputlab/algorithms/decompose/plan_and_solve/ps_prompt.py +127 -0
- agentinputlab/algorithms/decompose/self_ask/__init__.py +27 -0
- agentinputlab/algorithms/decompose/self_ask/loop.py +362 -0
- agentinputlab/algorithms/decompose/self_ask/planner_component.py +117 -0
- agentinputlab/algorithms/reformulate/__init__.py +85 -0
- agentinputlab/algorithms/reformulate/infocqr/__init__.py +40 -0
- agentinputlab/algorithms/reformulate/infocqr/cache_replay.py +362 -0
- agentinputlab/algorithms/reformulate/infocqr/external.py +675 -0
- agentinputlab/algorithms/reformulate/infocqr/student.py +189 -0
- agentinputlab/algorithms/reformulate/query2doc/__init__.py +42 -0
- agentinputlab/algorithms/reformulate/query2doc/controlled_live.py +190 -0
- agentinputlab/algorithms/reformulate/query2doc/models.py +95 -0
- agentinputlab/algorithms/reformulate/query2doc/official_cached.py +335 -0
- agentinputlab/algorithms/reformulate/query2doc/querygym_bridge.py +223 -0
- agentinputlab/algorithms/reformulate/query2doc/querygym_runtime.py +326 -0
- agentinputlab/algorithms/reformulate/reformer/__init__.py +23 -0
- agentinputlab/algorithms/reformulate/reformer/external.py +417 -0
- agentinputlab/algorithms/reformulate/rrr.py +696 -0
- agentinputlab/annotation/__init__.py +5 -0
- agentinputlab/annotation/independent.py +428 -0
- agentinputlab/annotation/server.py +233 -0
- agentinputlab/annotation/static/app.js +121 -0
- agentinputlab/annotation/static/index.html +60 -0
- agentinputlab/annotation/static/review.css +2 -0
- agentinputlab/annotation/static/review.html +10 -0
- agentinputlab/annotation/static/review.js +11 -0
- agentinputlab/annotation/static/styles.css +55 -0
- agentinputlab/annotation/store.py +444 -0
- agentinputlab/api.py +368 -0
- agentinputlab/artifacts/__init__.py +15 -0
- agentinputlab/artifacts/json_file.py +104 -0
- agentinputlab/artifacts/manifest.py +98 -0
- agentinputlab/artifacts/store.py +157 -0
- agentinputlab/backends/__init__.py +98 -0
- agentinputlab/backends/embedding/__init__.py +25 -0
- agentinputlab/backends/embedding/base.py +145 -0
- agentinputlab/backends/embedding/callable.py +75 -0
- agentinputlab/backends/embedding/replay.py +129 -0
- agentinputlab/backends/llm/__init__.py +31 -0
- agentinputlab/backends/llm/base.py +149 -0
- agentinputlab/backends/llm/callable.py +108 -0
- agentinputlab/backends/llm/decomp_completion.py +88 -0
- agentinputlab/backends/llm/final_content_stop.py +72 -0
- agentinputlab/backends/llm/gpt_oss_final_channel.py +84 -0
- agentinputlab/backends/llm/openai_compatible.py +332 -0
- agentinputlab/backends/llm/transformers.py +171 -0
- agentinputlab/backends/retrieval/__init__.py +35 -0
- agentinputlab/backends/retrieval/base.py +50 -0
- agentinputlab/backends/retrieval/dense.py +777 -0
- agentinputlab/backends/retrieval/memory.py +119 -0
- agentinputlab/backends/retrieval/sqlite_fts.py +155 -0
- agentinputlab/backends/user/__init__.py +15 -0
- agentinputlab/backends/user/base.py +66 -0
- agentinputlab/backends/user/callable.py +54 -0
- agentinputlab/backends/user/replay.py +89 -0
- agentinputlab/backends/vector.py +38 -0
- agentinputlab/benchmarks/__init__.py +246 -0
- agentinputlab/benchmarks/acquisition.py +106 -0
- agentinputlab/benchmarks/ale.py +540 -0
- agentinputlab/benchmarks/appworld_ul.py +669 -0
- agentinputlab/benchmarks/assets.py +226 -0
- agentinputlab/benchmarks/base.py +68 -0
- agentinputlab/benchmarks/beir_archive.py +235 -0
- agentinputlab/benchmarks/beir_sample.py +269 -0
- agentinputlab/benchmarks/bfcl_native.py +245 -0
- agentinputlab/benchmarks/bfcl_v3.py +607 -0
- agentinputlab/benchmarks/cache.py +218 -0
- agentinputlab/benchmarks/clariq.py +203 -0
- agentinputlab/benchmarks/data/registry.json +321 -0
- agentinputlab/benchmarks/data/smoke_assets.json +511 -0
- agentinputlab/benchmarks/data/statebench_v0_8_1_task_ids.json +475 -0
- agentinputlab/benchmarks/data/toolsandbox_165848b_scenario_names.json +1 -0
- agentinputlab/benchmarks/execution.py +1111 -0
- agentinputlab/benchmarks/interactive.py +257 -0
- agentinputlab/benchmarks/ir_query.py +204 -0
- agentinputlab/benchmarks/longbench.py +203 -0
- agentinputlab/benchmarks/paired_replay.py +479 -0
- agentinputlab/benchmarks/preprocess.py +2313 -0
- agentinputlab/benchmarks/production.py +236 -0
- agentinputlab/benchmarks/qa.py +963 -0
- agentinputlab/benchmarks/registry.py +110 -0
- agentinputlab/benchmarks/retrieval.py +459 -0
- agentinputlab/benchmarks/runtime.py +509 -0
- agentinputlab/benchmarks/statebench.py +938 -0
- agentinputlab/benchmarks/tau3.py +725 -0
- agentinputlab/benchmarks/toolsandbox.py +626 -0
- agentinputlab/benchmarks/trec_dl_sample.py +263 -0
- agentinputlab/campaign.py +654 -0
- agentinputlab/campaign_runner.py +953 -0
- agentinputlab/cli/__init__.py +6 -0
- agentinputlab/cli/main.py +933 -0
- agentinputlab/connectors/__init__.py +46 -0
- agentinputlab/connectors/knowledge/__init__.py +4 -0
- agentinputlab/connectors/tools/__init__.py +30 -0
- agentinputlab/connectors/tools/base.py +57 -0
- agentinputlab/connectors/tools/mcp.py +222 -0
- agentinputlab/connectors/tools/memory.py +41 -0
- agentinputlab/connectors/tools/openapi.py +695 -0
- agentinputlab/connectors/tools/schema.py +102 -0
- agentinputlab/contracts/__init__.py +91 -0
- agentinputlab/contracts/availability.py +24 -0
- agentinputlab/contracts/dependency.py +58 -0
- agentinputlab/contracts/enums.py +82 -0
- agentinputlab/contracts/errors.py +63 -0
- agentinputlab/contracts/evidence.py +43 -0
- agentinputlab/contracts/intent.py +110 -0
- agentinputlab/contracts/lifecycle.py +164 -0
- agentinputlab/contracts/patch.py +167 -0
- agentinputlab/contracts/serialization.py +93 -0
- agentinputlab/contracts/state.py +127 -0
- agentinputlab/contracts/trace.py +59 -0
- agentinputlab/contracts/worker.py +42 -0
- agentinputlab/core/__init__.py +7 -0
- agentinputlab/data/__init__.py +32 -0
- agentinputlab/data/checksums.py +9 -0
- agentinputlab/data/downloader.py +235 -0
- agentinputlab/data/http.py +171 -0
- agentinputlab/data/index.py +21 -0
- agentinputlab/data/overlap.py +28 -0
- agentinputlab/data/preprocess.py +32 -0
- agentinputlab/data/storage.py +57 -0
- agentinputlab/data/trec_sample.py +427 -0
- agentinputlab/evaluation/__init__.py +5 -0
- agentinputlab/evaluation/outcomes.py +32 -0
- agentinputlab/experiments/__init__.py +278 -0
- agentinputlab/experiments/analysis.py +981 -0
- agentinputlab/experiments/artifacts.py +687 -0
- agentinputlab/experiments/automatic_measurement.py +678 -0
- agentinputlab/experiments/auxiliary_matrix.py +203 -0
- agentinputlab/experiments/bindings.py +430 -0
- agentinputlab/experiments/blueprints.py +147 -0
- agentinputlab/experiments/builders/__init__.py +45 -0
- agentinputlab/experiments/builders/executable_external_payload.py +423 -0
- agentinputlab/experiments/builders/external_process_arena.py +1018 -0
- agentinputlab/experiments/builders/registry_intervention.py +463 -0
- agentinputlab/experiments/cli.py +158 -0
- agentinputlab/experiments/controls.py +340 -0
- agentinputlab/experiments/driver_guard.py +205 -0
- agentinputlab/experiments/drivers/__init__.py +89 -0
- agentinputlab/experiments/drivers/external_arena.py +2908 -0
- agentinputlab/experiments/drivers/method_process.py +662 -0
- agentinputlab/experiments/drivers/parity_process.py +1484 -0
- agentinputlab/experiments/drivers/static_production.py +1574 -0
- agentinputlab/experiments/executor.py +448 -0
- agentinputlab/experiments/loader.py +605 -0
- agentinputlab/experiments/measurement.py +675 -0
- agentinputlab/experiments/paper_analysis.py +1818 -0
- agentinputlab/experiments/parity_identity.py +605 -0
- agentinputlab/experiments/plan.py +277 -0
- agentinputlab/experiments/production_builders.py +3739 -0
- agentinputlab/experiments/readiness.py +432 -0
- agentinputlab/experiments/schema.py +514 -0
- agentinputlab/experiments/secrets.py +177 -0
- agentinputlab/experiments/stateful_analysis.py +1738 -0
- agentinputlab/experiments/transfer_analysis.py +1316 -0
- agentinputlab/experiments/unseen_analysis.py +1025 -0
- agentinputlab/integrations/__init__.py +1 -0
- agentinputlab/integrations/action_space/__init__.py +1 -0
- agentinputlab/integrations/external_workers/__init__.py +76 -0
- agentinputlab/integrations/external_workers/ace.py +431 -0
- agentinputlab/integrations/external_workers/base.py +181 -0
- agentinputlab/integrations/external_workers/decomp_live.py +249 -0
- agentinputlab/integrations/external_workers/decomp_planner.py +30 -0
- agentinputlab/integrations/external_workers/infocqr_student.py +280 -0
- agentinputlab/integrations/external_workers/ircot.py +576 -0
- agentinputlab/integrations/external_workers/llmcompiler_live.py +360 -0
- agentinputlab/integrations/external_workers/longllmlingua.py +162 -0
- agentinputlab/integrations/external_workers/method.py +314 -0
- agentinputlab/integrations/external_workers/process.py +678 -0
- agentinputlab/integrations/external_workers/supervisor.py +1071 -0
- agentinputlab/integrations/full_architecture/__init__.py +1 -0
- agentinputlab/integrations/full_architecture/hyde.py +212 -0
- agentinputlab/integrations/full_architecture/plan_and_budget.py +188 -0
- agentinputlab/integrations/live_history.py +222 -0
- agentinputlab/integrations/prompt_optimization/__init__.py +1 -0
- agentinputlab/integrations/training/__init__.py +1 -0
- agentinputlab/metrics/__init__.py +50 -0
- agentinputlab/metrics/catalog.py +313 -0
- agentinputlab/metrics/harm.py +95 -0
- agentinputlab/metrics/paired.py +40 -0
- agentinputlab/metrics/qa.py +76 -0
- agentinputlab/metrics/text.py +33 -0
- agentinputlab/metrics/third_party.py +161 -0
- agentinputlab/models/__init__.py +4 -0
- agentinputlab/observability/__init__.py +56 -0
- agentinputlab/observability/budget.py +316 -0
- agentinputlab/observability/instrumentation.py +754 -0
- agentinputlab/observability/models.py +403 -0
- agentinputlab/observability/monitor.py +380 -0
- agentinputlab/optimizers/__init__.py +1 -0
- agentinputlab/optimizers/clarify/__init__.py +12 -0
- agentinputlab/optimizers/context/__init__.py +22 -0
- agentinputlab/optimizers/decompose/__init__.py +64 -0
- agentinputlab/optimizers/evidence/__init__.py +22 -0
- agentinputlab/optimizers/rewrite/__init__.py +30 -0
- agentinputlab/parity/__init__.py +5 -0
- agentinputlab/parity/base.py +206 -0
- agentinputlab/production_campaign.py +763 -0
- agentinputlab/py.typed +1 -0
- agentinputlab/recipes/__init__.py +333 -0
- agentinputlab/recipes/ace.py +418 -0
- agentinputlab/recipes/ace_bfcl.py +273 -0
- agentinputlab/recipes/ace_common_support.py +169 -0
- agentinputlab/recipes/ace_native_plan.py +322 -0
- agentinputlab/recipes/ace_online.py +711 -0
- agentinputlab/recipes/ace_retrieval.py +330 -0
- agentinputlab/recipes/ace_statebench.py +382 -0
- agentinputlab/recipes/ace_tau.py +463 -0
- agentinputlab/recipes/ace_toolsandbox.py +432 -0
- agentinputlab/recipes/acon_guideline.py +22 -0
- agentinputlab/recipes/adaptive_rag.py +822 -0
- agentinputlab/recipes/llmlingua2_inference.py +146 -0
- agentinputlab/recipes/llmlingua2_training.py +796 -0
- agentinputlab/recipes/mce.py +1486 -0
- agentinputlab/recipes/mce_final.py +335 -0
- agentinputlab/recipes/mce_text_fit.py +499 -0
- agentinputlab/recipes/mce_text_only.py +298 -0
- agentinputlab/recipes/qrag.py +729 -0
- agentinputlab/recipes/qrag_inference.py +364 -0
- agentinputlab/recipes/r2ag_features.py +236 -0
- agentinputlab/recipes/r2ag_inference.py +503 -0
- agentinputlab/recipes/r2ag_training.py +948 -0
- agentinputlab/recipes/recomp_abstractive.py +592 -0
- agentinputlab/recipes/recomp_extractive.py +525 -0
- agentinputlab/recipes/reformer.py +17 -0
- agentinputlab/recipes/rqrag.py +1516 -0
- agentinputlab/recipes/rqrag_common_support.py +193 -0
- agentinputlab/recipes/rqrag_completion.py +147 -0
- agentinputlab/recipes/skillopt.py +462 -0
- agentinputlab/recipes/skillopt_common_support.py +154 -0
- agentinputlab/recipes/skillopt_environment.py +165 -0
- agentinputlab/recipes/skillopt_environment_cli.py +5 -0
- agentinputlab/recipes/skillopt_retrieval.py +188 -0
- agentinputlab/recipes/smartsearch.py +897 -0
- agentinputlab/recipes/smartsearch_curriculum.py +283 -0
- agentinputlab/recipes/smartsearch_grpo_contracts.py +58 -0
- agentinputlab/recipes/smartsearch_grpo_data.py +314 -0
- agentinputlab/recipes/smartsearch_grpo_meter.py +324 -0
- agentinputlab/recipes/smartsearch_grpo_prefix.py +144 -0
- agentinputlab/recipes/smartsearch_grpo_rollout.py +119 -0
- agentinputlab/recipes/smartsearch_grpo_tools.py +364 -0
- agentinputlab/recipes/smartsearch_grpo_training.py +305 -0
- agentinputlab/recipes/smartsearch_grpo_transport.py +248 -0
- agentinputlab/recipes/smartsearch_grpo_worker.py +364 -0
- agentinputlab/recipes/smartsearch_inference.py +524 -0
- agentinputlab/recipes/smartsearch_native_data.py +172 -0
- agentinputlab/recipes/smartsearch_policy.py +616 -0
- agentinputlab/recipes/smartsearch_policy_worker.py +9 -0
- agentinputlab/recipes/smartsearch_sampling.py +232 -0
- agentinputlab/recipes/smartsearch_teacher.py +203 -0
- agentinputlab/recipes/smartsearch_training.py +265 -0
- agentinputlab/registry/__init__.py +46 -0
- agentinputlab/registry/beta.py +727 -0
- agentinputlab/registry/data/algorithms.json +1959 -0
- agentinputlab/registry/data/auxiliary_method_profiles.json +34 -0
- agentinputlab/registry/loader.py +100 -0
- agentinputlab/registry/result_manifest.py +184 -0
- agentinputlab/registry/runtime.py +195 -0
- agentinputlab/registry/schema.py +449 -0
- agentinputlab/runner/__init__.py +30 -0
- agentinputlab/runner/balance.py +248 -0
- agentinputlab/runner/cache.py +135 -0
- agentinputlab/runner/composite.py +130 -0
- agentinputlab/runner/engine.py +285 -0
- agentinputlab/runner/runtime_guard.py +268 -0
- agentinputlab/runner/worker.py +80 -0
- agentinputlab/runtime_bootstrap.py +288 -0
- agentinputlab/selectors/__init__.py +196 -0
- agentinputlab/selectors/advanced.py +1514 -0
- agentinputlab/selectors/artifacts.py +1087 -0
- agentinputlab/selectors/base.py +112 -0
- agentinputlab/selectors/campaigns.py +1893 -0
- agentinputlab/selectors/catalog.py +86 -0
- agentinputlab/selectors/discovery.py +1860 -0
- agentinputlab/selectors/evaluation.py +1348 -0
- agentinputlab/selectors/features.py +383 -0
- agentinputlab/selectors/learned.py +502 -0
- agentinputlab/selectors/no_op.py +28 -0
- agentinputlab/selectors/outcome_table.py +475 -0
- agentinputlab/selectors/producer.py +853 -0
- agentinputlab/selectors/rules.py +109 -0
- agentinputlab/selectors/runtime.py +420 -0
- agentinputlab/studies/__init__.py +16 -0
- agentinputlab/studies/design.py +165 -0
- agentinputlab/studies/paired.py +322 -0
- agentinputlab/studio/__init__.py +6 -0
- agentinputlab/studio/campaigns.py +819 -0
- agentinputlab/studio/engine.py +1408 -0
- agentinputlab/studio/model_backends.py +425 -0
- agentinputlab/studio/prepared.py +410 -0
- agentinputlab/studio/server.py +613 -0
- agentinputlab/studio/static/app.js +397 -0
- agentinputlab/studio/static/campaigns.html +175 -0
- agentinputlab/studio/static/campaigns.js +426 -0
- agentinputlab/studio/static/index.html +192 -0
- agentinputlab/studio/static/result.html +103 -0
- agentinputlab/studio/static/result.js +273 -0
- agentinputlab/studio/static/styles.css +467 -0
- agentinputlab-0.1.0a1.data/data/share/agentinputlab/CITATION.cff +22 -0
- agentinputlab-0.1.0a1.dist-info/METADATA +392 -0
- agentinputlab-0.1.0a1.dist-info/RECORD +469 -0
- agentinputlab-0.1.0a1.dist-info/WHEEL +5 -0
- agentinputlab-0.1.0a1.dist-info/entry_points.txt +6 -0
- agentinputlab-0.1.0a1.dist-info/licenses/LICENSE +21 -0
- agentinputlab-0.1.0a1.dist-info/licenses/NOTICE +31 -0
- agentinputlab-0.1.0a1.dist-info/licenses/THIRD_PARTY_NOTICES.md +94 -0
- agentinputlab-0.1.0a1.dist-info/top_level.txt +2 -0
- workers/README.md +94 -0
- workers/ace/README.md +261 -0
- workers/ace/__init__.py +1 -0
- workers/ace/compatibility_manifest.json +39 -0
- workers/ace/driver.py +1682 -0
- workers/acon/README.md +215 -0
- workers/acon/__init__.py +5 -0
- workers/acon/compatibility_manifest.json +93 -0
- workers/acon/driver.py +1859 -0
- workers/acon/fitted.py +395 -0
- workers/acon/guideline.py +470 -0
- workers/acon/guideline_source_manifest.json +20 -0
- workers/adaptive_rag/README.md +96 -0
- workers/adaptive_rag/__init__.py +15 -0
- workers/adaptive_rag/compatibility_manifest.json +61 -0
- workers/adaptive_rag/driver.py +1470 -0
- workers/adaptive_rag/fixture_runtime.py +163 -0
- workers/adaptive_rag/runtime.py +252 -0
- workers/ask_or_assume/README.md +124 -0
- workers/ask_or_assume/__init__.py +1 -0
- workers/ask_or_assume/compatibility_manifest.json +36 -0
- workers/ask_or_assume/driver.py +1227 -0
- workers/decomp/README.md +133 -0
- workers/decomp/UPSTREAM_LICENSE.Apache-2.0.txt +201 -0
- workers/decomp/__init__.py +5 -0
- workers/decomp/compatibility_manifest.json +205 -0
- workers/decomp/driver.py +1015 -0
- workers/decomp/live.py +137 -0
- workers/decomp/runtime.py +231 -0
- workers/infocqr/README.md +106 -0
- workers/infocqr/__init__.py +1 -0
- workers/infocqr/compatibility_manifest.json +84 -0
- workers/infocqr/driver.py +1766 -0
- workers/ircot/README.md +167 -0
- workers/ircot/__init__.py +7 -0
- workers/ircot/compatibility_manifest.json +121 -0
- workers/ircot/controlled.py +457 -0
- workers/ircot/driver.py +1373 -0
- workers/ircot/fixture_bindings.json +39 -0
- workers/ircot/fixture_config.json +48 -0
- workers/ircot/fixture_prompt.txt +2 -0
- workers/ircot/native_qa.py +398 -0
- workers/ircot/qa_compatibility_manifest.json +57 -0
- workers/ircot/runtime.py +97 -0
- workers/llmcompiler/README.md +160 -0
- workers/llmcompiler/__init__.py +1 -0
- workers/llmcompiler/compatibility_manifest.json +45 -0
- workers/llmcompiler/driver.py +1514 -0
- workers/llmcompiler/export_prompts.py +74 -0
- workers/llmcompiler/live.py +174 -0
- workers/llmcompiler/patch_manifest.json +147 -0
- workers/mce/README.md +198 -0
- workers/mce/__init__.py +29 -0
- workers/mce/compatibility_manifest.json +115 -0
- workers/mce/driver.py +2585 -0
- workers/mce/final_eval.py +173 -0
- workers/official_arenas/README.md +25 -0
- workers/official_arenas/__init__.py +1 -0
- workers/official_arenas/capture_records.py +110 -0
- workers/official_arenas/driver.py +619 -0
- workers/official_arenas/protocol.py +334 -0
- workers/official_arenas/providers/__init__.py +1 -0
- workers/official_arenas/providers/_live_history.py +228 -0
- workers/official_arenas/providers/_message_compat.py +77 -0
- workers/official_arenas/providers/appworld_ul.py +196 -0
- workers/official_arenas/providers/fixture.py +112 -0
- workers/official_arenas/providers/statebench.py +960 -0
- workers/official_arenas/providers/tau3.py +1672 -0
- workers/official_arenas/providers/tau_retail.py +586 -0
- workers/official_arenas/providers/toolsandbox.py +1321 -0
- workers/official_arenas/providers/tooltalk.py +699 -0
- workers/official_arenas/retail_capture.py +188 -0
- workers/official_arenas/retail_driver.py +275 -0
- workers/qrag/README.md +172 -0
- workers/qrag/__init__.py +1 -0
- workers/qrag/compatibility_manifest.json +64 -0
- workers/qrag/driver.py +673 -0
- workers/r2ag/README.md +154 -0
- workers/r2ag/__init__.py +5 -0
- workers/r2ag/compatibility_manifest.json +55 -0
- workers/r2ag/driver.py +1287 -0
- workers/r2ag/feature_schema.json +8 -0
- workers/r2ag/runtime.py +589 -0
- workers/recomp/README.md +120 -0
- workers/recomp/__init__.py +1 -0
- workers/recomp/compatibility_manifest.json +43 -0
- workers/recomp/driver.py +1653 -0
- workers/reformer/README.md +125 -0
- workers/reformer/__init__.py +1 -0
- workers/reformer/compatibility_manifest.json +68 -0
- workers/reformer/driver.py +1459 -0
- workers/reformer/induction.py +457 -0
- workers/rrr/README.md +126 -0
- workers/rrr/__init__.py +1 -0
- workers/rrr/compatibility_manifest.json +57 -0
- workers/rrr/driver.py +1133 -0
- workers/smartsearch/README.md +331 -0
- workers/smartsearch/__init__.py +1 -0
- workers/smartsearch/compatibility_manifest.json +41 -0
- workers/smartsearch/driver.py +1643 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"""Full-agent architectures that cannot be represented as thin input patches."""
|
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
"""Execute caller-mounted HyDE source under a checksum-locked shape patch.
|
|
2
|
+
|
|
3
|
+
The package contains no upstream source, native API client, model or index.
|
|
4
|
+
Only the original algorithm and promptor modules are loaded from the mount.
|
|
5
|
+
"""
|
|
6
|
+
from __future__ import annotations
|
|
7
|
+
|
|
8
|
+
import hashlib
|
|
9
|
+
import json
|
|
10
|
+
import time
|
|
11
|
+
from dataclasses import dataclass
|
|
12
|
+
from pathlib import Path
|
|
13
|
+
from typing import Any
|
|
14
|
+
|
|
15
|
+
from agentinputlab.artifacts import load_pinned_json_mapping
|
|
16
|
+
from agentinputlab.backends.llm import GenerationRequest
|
|
17
|
+
from agentinputlab.contracts import (
|
|
18
|
+
AlgorithmOutputError,
|
|
19
|
+
ArtifactError,
|
|
20
|
+
BudgetExceededError,
|
|
21
|
+
ExternalDependencyError,
|
|
22
|
+
Message,
|
|
23
|
+
ValidationError,
|
|
24
|
+
)
|
|
25
|
+
|
|
26
|
+
HYDE_UPSTREAM_REVISION="a2fd8734307612cb0225d71ffbf26e0d225986b8"
|
|
27
|
+
HYDE_PATCH_PROTOCOL="agentinputlab.hyde.external-flatten-encoder.v1"
|
|
28
|
+
HYDE_SOURCE_SHA256={
|
|
29
|
+
"src/hyde/hyde.py":"7a395213842b80052e2d47db45ddfff4ebf416d11197fdc9760997ecb2cf7041",
|
|
30
|
+
"src/hyde/promptor.py":"675a9ccc9336122095b401b6d05dc314fd6a3fbb067f78e4e660024892d78d34",
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
def _sources(source_root):
|
|
35
|
+
root=Path(source_root).expanduser().resolve()
|
|
36
|
+
result={}
|
|
37
|
+
for name,pin in HYDE_SOURCE_SHA256.items():
|
|
38
|
+
try:
|
|
39
|
+
path=root/name
|
|
40
|
+
if path.stat().st_size>65536:
|
|
41
|
+
raise ArtifactError("HyDE source exceeds the checked module size")
|
|
42
|
+
raw=path.read_bytes()
|
|
43
|
+
except OSError as exc:
|
|
44
|
+
raise ArtifactError(f"HyDE external source unavailable: {name}") from exc
|
|
45
|
+
if hashlib.sha256(raw).hexdigest()!=pin:
|
|
46
|
+
raise ArtifactError(f"HyDE external source SHA-256 differs: {name}")
|
|
47
|
+
result[name]=raw
|
|
48
|
+
return result
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
def _patched_source(sources):
|
|
52
|
+
raw=sources["src/hyde/hyde.py"]
|
|
53
|
+
before=b"np.array(c_emb)"
|
|
54
|
+
after=b"np.asarray(c_emb).reshape(-1)"
|
|
55
|
+
if raw.count(before)!=1:
|
|
56
|
+
raise ArtifactError("HyDE reviewed encoder-shape patch site differs")
|
|
57
|
+
return raw.replace(before,after)
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
def _manifest(sources):
|
|
61
|
+
return dict(schema_version=1,protocol=HYDE_PATCH_PROTOCOL,upstream_revision=HYDE_UPSTREAM_REVISION,
|
|
62
|
+
source_sha256=dict(HYDE_SOURCE_SHA256),
|
|
63
|
+
patch=dict(target="src/hyde/hyde.py:HyDE.encode",change="flatten_each_singleton_encoder_vector_before_mean",
|
|
64
|
+
patched_source_sha256=hashlib.sha256(_patched_source(sources)).hexdigest()),
|
|
65
|
+
native_client_module_imported=False,source_modified_on_disk=False,
|
|
66
|
+
source_review_acknowledged=True,source_redistributed_by_toolkit=False,
|
|
67
|
+
substitutions=["observed_serial_generation_draws","observed_dense_embedding","observed_corpus_vector_search"])
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
def write_hyde_patch_manifest(source_root,output,*,accept_source_review=False):
|
|
71
|
+
"""Create-only operator receipt. Source review is not a redistribution grant."""
|
|
72
|
+
if accept_source_review is not True:
|
|
73
|
+
raise ArtifactError("review the mounted HyDE source/terms and acknowledge source review explicitly")
|
|
74
|
+
value=_manifest(_sources(source_root))
|
|
75
|
+
path=Path(output).expanduser().resolve()
|
|
76
|
+
path.parent.mkdir(parents=True,exist_ok=True)
|
|
77
|
+
with path.open("x",encoding="utf-8") as f:
|
|
78
|
+
json.dump(value,f,indent=2,sort_keys=True,allow_nan=False)
|
|
79
|
+
return {"path":str(path),"sha256":hashlib.sha256(path.read_bytes()).hexdigest()}
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
@dataclass(frozen=True,slots=True)
|
|
83
|
+
class HyDEPatchedExecutionRequest:
|
|
84
|
+
"""In-process callbacks are the runner's already-instrumented context objects.
|
|
85
|
+
|
|
86
|
+
This request is not an IPC recipe. Do not serialize or store its executable
|
|
87
|
+
dependencies on an intervention. Native bridge usage is charged there once.
|
|
88
|
+
"""
|
|
89
|
+
query: str
|
|
90
|
+
config: Any
|
|
91
|
+
seed: int
|
|
92
|
+
budget: Any
|
|
93
|
+
backend: Any
|
|
94
|
+
embedder: Any
|
|
95
|
+
searcher: Any
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
class HyDEPatchedSourceRuntime:
|
|
99
|
+
worker_id="agentinputlab.hyde.pinned-native-source.v1"
|
|
100
|
+
|
|
101
|
+
def __init__(self,*,source_root,patch_manifest,expected_manifest_sha256):
|
|
102
|
+
self.source_root=Path(source_root).expanduser().resolve()
|
|
103
|
+
self.patch_manifest=Path(patch_manifest).expanduser().resolve()
|
|
104
|
+
self.expected_manifest_sha256=expected_manifest_sha256
|
|
105
|
+
|
|
106
|
+
def _verified(self):
|
|
107
|
+
sources=_sources(self.source_root)
|
|
108
|
+
receipt=load_pinned_json_mapping(self.patch_manifest,expected_sha256=self.expected_manifest_sha256,max_bytes=65536)
|
|
109
|
+
if dict(receipt)!=_manifest(sources):
|
|
110
|
+
raise ArtifactError("HyDE patch manifest is not the exact reviewed patch/substitution set")
|
|
111
|
+
try:
|
|
112
|
+
import numpy
|
|
113
|
+
except ImportError as exc:
|
|
114
|
+
raise ExternalDependencyError("install agentinputlab[hyde-native] for the external source runtime") from exc
|
|
115
|
+
return sources,numpy
|
|
116
|
+
|
|
117
|
+
def fingerprint(self):
|
|
118
|
+
sources,np=self._verified()
|
|
119
|
+
return {"runtime_id":self.worker_id,"binding_mode":HYDE_PATCH_PROTOCOL,
|
|
120
|
+
"upstream_revision":HYDE_UPSTREAM_REVISION,"source_sha256":dict(HYDE_SOURCE_SHA256),
|
|
121
|
+
"patched_source_sha256":hashlib.sha256(_patched_source(sources)).hexdigest(),
|
|
122
|
+
"patch_manifest_sha256":self.expected_manifest_sha256,"numpy_version":np.__version__,
|
|
123
|
+
"native_generator_client_used":False,"source_redistributed":False,
|
|
124
|
+
"generation_transport":"observed_serial_draws_no_logprob_reordering_no_retry"}
|
|
125
|
+
|
|
126
|
+
def run(self,request):
|
|
127
|
+
from agentinputlab.algorithms.acquire.hyde import _validate_vectors
|
|
128
|
+
from agentinputlab.algorithms.acquire.hyde_external import HyDENativeConfig
|
|
129
|
+
if not isinstance(request,HyDEPatchedExecutionRequest) or not isinstance(request.config,HyDENativeConfig):
|
|
130
|
+
raise ValidationError("HyDE patched runtime requires its typed execution request/config")
|
|
131
|
+
sources,np=self._verified()
|
|
132
|
+
identity=self.fingerprint()
|
|
133
|
+
native_namespace={}
|
|
134
|
+
prompt_namespace={}
|
|
135
|
+
exec(compile(_patched_source(sources),"externally-mounted-hyde-patched","exec"),native_namespace)
|
|
136
|
+
exec(compile(sources["src/hyde/promptor.py"],"externally-mounted-hyde-promptor","exec"),prompt_namespace)
|
|
137
|
+
config=request.config
|
|
138
|
+
if (request.budget.max_model_calls<config.num_hypotheses or request.budget.max_retrieval_calls<1
|
|
139
|
+
or request.budget.max_output_tokens<config.num_hypotheses):
|
|
140
|
+
raise BudgetExceededError("HyDE cannot reserve all hypothesis draws and corpus search")
|
|
141
|
+
outputs=inputs=0
|
|
142
|
+
draws=[]
|
|
143
|
+
encoded=[]
|
|
144
|
+
mean_vectors=[]
|
|
145
|
+
|
|
146
|
+
class GeneratorBridge:
|
|
147
|
+
def generate(self,prompt):
|
|
148
|
+
nonlocal outputs,inputs
|
|
149
|
+
texts=[]
|
|
150
|
+
for index in range(config.num_hypotheses):
|
|
151
|
+
remaining=request.budget.max_output_tokens-outputs
|
|
152
|
+
reserve=config.num_hypotheses-index-1
|
|
153
|
+
if remaining<=reserve:
|
|
154
|
+
raise BudgetExceededError("HyDE output budget cannot cover remaining hypothesis draws")
|
|
155
|
+
generation=GenerationRequest(messages=(Message("user",prompt),),temperature=config.temperature,
|
|
156
|
+
max_tokens=min(config.max_tokens,remaining-reserve),seed=request.seed+index,stop=config.stop,
|
|
157
|
+
metadata={"release_id":"acquire.hyde.official_external_patched","stage":"native_hypothesis",
|
|
158
|
+
"hypothesis_index":index,"native_promptor_task":config.task})
|
|
159
|
+
response=request.backend.generate(generation)
|
|
160
|
+
if not isinstance(response.text,str):
|
|
161
|
+
raise AlgorithmOutputError("HyDE generator returned non-text")
|
|
162
|
+
inputs+=response.usage.input_tokens
|
|
163
|
+
outputs+=response.usage.output_tokens
|
|
164
|
+
if response.usage.output_tokens>generation.max_tokens:
|
|
165
|
+
raise BudgetExceededError("HyDE provider exceeded requested hypothesis output cap")
|
|
166
|
+
texts.append(response.text)
|
|
167
|
+
draws.append(dict(text=response.text,request_hash=generation.request_hash,
|
|
168
|
+
max_tokens=generation.max_tokens,seed=generation.seed,finish_reason=response.finish_reason))
|
|
169
|
+
return texts
|
|
170
|
+
|
|
171
|
+
class EncoderBridge:
|
|
172
|
+
def encode(self,text):
|
|
173
|
+
vectors=_validate_vectors(request.embedder.embed((text,)),expected_count=1)
|
|
174
|
+
encoded.append(vectors[0])
|
|
175
|
+
# Exercise the actual batched-singleton interface requiring the
|
|
176
|
+
# reviewed flatten patch; native code performs the mean itself.
|
|
177
|
+
return np.asarray(vectors)
|
|
178
|
+
|
|
179
|
+
class SearchBridge:
|
|
180
|
+
def search(self,vector,k):
|
|
181
|
+
if vector.ndim!=2 or vector.shape[0]!=1:
|
|
182
|
+
raise AlgorithmOutputError("patched native HyDE returned a non-singleton matrix")
|
|
183
|
+
values=tuple(float(v) for v in vector[0])
|
|
184
|
+
mean_vectors.append(values)
|
|
185
|
+
return request.searcher.search(values,top_k=k)
|
|
186
|
+
|
|
187
|
+
promptor=prompt_namespace["Promptor"](task=config.task,language=config.language)
|
|
188
|
+
native=native_namespace["HyDE"](promptor,GeneratorBridge(),EncoderBridge(),SearchBridge())
|
|
189
|
+
cpu=time.thread_time()
|
|
190
|
+
process_cpu=time.process_time()
|
|
191
|
+
started=time.monotonic()
|
|
192
|
+
hits=native.e2e_search(request.query,k=config.top_k)
|
|
193
|
+
cpu=time.thread_time()-cpu
|
|
194
|
+
if self.fingerprint()!=identity:
|
|
195
|
+
raise ArtifactError("HyDE mounted runtime identity changed during execution")
|
|
196
|
+
return dict(identity=identity,results=hits,hypotheses=tuple(d["text"] for d in draws),draws=tuple(draws),
|
|
197
|
+
mean_vector=mean_vectors[0],encoded_vectors=tuple(encoded),native_prompt=promptor.build_prompt(request.query),
|
|
198
|
+
model_calls=len(draws),embedding_calls=len(encoded),retrieval_calls=1,
|
|
199
|
+
input_tokens=inputs,output_tokens=outputs,wall_seconds=time.monotonic()-started,
|
|
200
|
+
process_cpu_seconds_window=time.process_time()-process_cpu,
|
|
201
|
+
process_cpu_window_is_not_additive_across_concurrent_requests=True,
|
|
202
|
+
calling_thread_cpu_seconds=cpu,
|
|
203
|
+
# Delegated calls/tokens are already ledger-observed. RunMonitor
|
|
204
|
+
# also records its enclosing process CPU window at finish_run;
|
|
205
|
+
# adding the nested thread measurement would count it twice.
|
|
206
|
+
# Keep both measurements diagnostic, not additive usage charges.
|
|
207
|
+
usage=dict(model_calls=0,retrieval_calls=0,input_tokens=0,output_tokens=0,cpu_seconds=0.0),
|
|
208
|
+
usage_scope="calling_thread_cpu_lower_bound_diagnostic; outer monitor owns process CPU accounting; native-worker CPU excluded from thread measure")
|
|
209
|
+
|
|
210
|
+
|
|
211
|
+
__all__=["HYDE_PATCH_PROTOCOL","HYDE_SOURCE_SHA256","HYDE_UPSTREAM_REVISION",
|
|
212
|
+
"HyDEPatchedExecutionRequest","HyDEPatchedSourceRuntime","write_hyde_patch_manifest"]
|
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
"""Source-pinned native P&B prompt construction, with no provider side effects.
|
|
2
|
+
|
|
3
|
+
Only the released allocation functions and reasoning prompt are evaluated. The
|
|
4
|
+
native dotenv/client setup, gold-aware evaluator and retry loop are not imported.
|
|
5
|
+
The composite adapter owns the single, observed solver call after this boundary.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
from __future__ import annotations
|
|
9
|
+
|
|
10
|
+
import ast
|
|
11
|
+
import copy
|
|
12
|
+
import hashlib
|
|
13
|
+
import importlib
|
|
14
|
+
import textwrap
|
|
15
|
+
from dataclasses import dataclass
|
|
16
|
+
from pathlib import Path
|
|
17
|
+
from types import SimpleNamespace
|
|
18
|
+
|
|
19
|
+
from agentinputlab.algorithms.decompose.plan_and_budget.cached_soft_budget import (
|
|
20
|
+
P_AND_B_UPSTREAM_REVISION,
|
|
21
|
+
CachedPlanBudgetRecord,
|
|
22
|
+
DecaySchedule,
|
|
23
|
+
)
|
|
24
|
+
from agentinputlab.contracts import ArtifactError, ExternalDependencyError, ValidationError
|
|
25
|
+
|
|
26
|
+
PAB_NATIVE_PROMPT_MODE = "source_pinned_weighted_prompt.v1"
|
|
27
|
+
PAB_SOURCE_HASHES = {
|
|
28
|
+
"inference/_5_planned_local_weighted_model.py":
|
|
29
|
+
"c4463d2a4e14882d4ff2b060b7b9cc9a93ecc7732ace5814dc72f1432c62c5ed",
|
|
30
|
+
"utils/utils.py":
|
|
31
|
+
"9c448f585251e94302e47c0c87ca61861dc5069d6255d7e106d28c4ca6610fc7",
|
|
32
|
+
}
|
|
33
|
+
_FUNCTIONS = {
|
|
34
|
+
"allocate_tokens", "constant_schedule", "linear_decay", "polynomial_decay",
|
|
35
|
+
"exponential_decay", "cosine_anneal",
|
|
36
|
+
}
|
|
37
|
+
_SCHEDULES = {
|
|
38
|
+
"constant": "constant_schedule", "linear": "linear_decay",
|
|
39
|
+
"polynomial": "polynomial_decay", "exponential": "exponential_decay",
|
|
40
|
+
"cosine": "cosine_anneal",
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
@dataclass(frozen=True, slots=True)
|
|
45
|
+
class PlanBudgetPromptRequest:
|
|
46
|
+
record: CachedPlanBudgetRecord
|
|
47
|
+
instruction: str
|
|
48
|
+
reference: str
|
|
49
|
+
output_format: str
|
|
50
|
+
schedule: str
|
|
51
|
+
|
|
52
|
+
def __post_init__(self):
|
|
53
|
+
if not isinstance(self.record, CachedPlanBudgetRecord):
|
|
54
|
+
raise ValidationError("P&B prompt requires a solver-only cached record")
|
|
55
|
+
if not all(isinstance(x, str) for x in (self.instruction, self.reference)):
|
|
56
|
+
raise ValidationError("P&B instruction/reference must be strings")
|
|
57
|
+
if not isinstance(self.output_format, str) or not self.output_format.strip():
|
|
58
|
+
raise ValidationError("P&B requires an explicit output format")
|
|
59
|
+
object.__setattr__(self, "schedule", DecaySchedule.parse(self.schedule).value)
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
class _PromptBoundary(Exception):
|
|
63
|
+
def __init__(self, messages):
|
|
64
|
+
self.messages = messages
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
class PlanAndBudgetNativePromptRuntime:
|
|
68
|
+
"""Execute the hash-pinned native reasoning prefix up to its provider call.
|
|
69
|
+
|
|
70
|
+
This runtime does not call a model, return a fake response, execute a source
|
|
71
|
+
evaluator, or load the source module's environment/credentials. Source assets
|
|
72
|
+
and NumPy are explicit optional dependencies; nothing is downloaded here.
|
|
73
|
+
"""
|
|
74
|
+
|
|
75
|
+
worker_id = "agentinputlab.plan-and-budget.native-prompt.v1"
|
|
76
|
+
|
|
77
|
+
def __init__(self, *, source_root: str | Path):
|
|
78
|
+
self.source_root = Path(source_root).expanduser().resolve()
|
|
79
|
+
|
|
80
|
+
def _sources(self):
|
|
81
|
+
sources = {}
|
|
82
|
+
for name, expected in PAB_SOURCE_HASHES.items():
|
|
83
|
+
path = self.source_root / name
|
|
84
|
+
try:
|
|
85
|
+
if path.stat().st_size > 128 * 1024:
|
|
86
|
+
raise ArtifactError("P&B native source exceeds the size limit")
|
|
87
|
+
raw = path.read_bytes()
|
|
88
|
+
except OSError as exc:
|
|
89
|
+
raise ArtifactError(f"P&B native source unavailable: {name}") from exc
|
|
90
|
+
if hashlib.sha256(raw).hexdigest() != expected:
|
|
91
|
+
raise ArtifactError(f"P&B native source SHA-256 differs: {name}")
|
|
92
|
+
sources[name] = raw.decode("utf-8")
|
|
93
|
+
return sources
|
|
94
|
+
|
|
95
|
+
def fingerprint(self):
|
|
96
|
+
self._sources()
|
|
97
|
+
try:
|
|
98
|
+
numpy = importlib.import_module("numpy")
|
|
99
|
+
except ImportError as exc:
|
|
100
|
+
raise ExternalDependencyError(
|
|
101
|
+
"P&B native solver requires agentinputlab[plan-and-budget]"
|
|
102
|
+
) from exc
|
|
103
|
+
return {
|
|
104
|
+
"runtime_id": self.worker_id,
|
|
105
|
+
"upstream_revision": P_AND_B_UPSTREAM_REVISION,
|
|
106
|
+
"source_sha256": dict(PAB_SOURCE_HASHES),
|
|
107
|
+
"numpy_version": numpy.__version__,
|
|
108
|
+
"binding_mode": PAB_NATIVE_PROMPT_MODE,
|
|
109
|
+
"model_calls": 0,
|
|
110
|
+
"native_retry_decorator": "removed_at_explicit_provider_boundary",
|
|
111
|
+
"provider_binding": "caller_observed_chat_backend",
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
def run(self, request: PlanBudgetPromptRequest):
|
|
115
|
+
if not isinstance(request, PlanBudgetPromptRequest):
|
|
116
|
+
raise ValidationError("P&B native prompt requires PlanBudgetPromptRequest")
|
|
117
|
+
identity = self.fingerprint()
|
|
118
|
+
sources = self._sources()
|
|
119
|
+
source = ast.parse(sources["inference/_5_planned_local_weighted_model.py"])
|
|
120
|
+
helpers = [n for n in source.body if isinstance(n, ast.FunctionDef)
|
|
121
|
+
and n.name in _FUNCTIONS]
|
|
122
|
+
native_class = next(n for n in source.body if isinstance(n, ast.ClassDef)
|
|
123
|
+
and n.name == "PlannedLocalWeighted_Model")
|
|
124
|
+
prompt = next(n for n in native_class.body if isinstance(n, ast.Assign)
|
|
125
|
+
and any(isinstance(t, ast.Name) and t.id == "_prompt"
|
|
126
|
+
for t in n.targets))
|
|
127
|
+
reasoning = copy.deepcopy(next(
|
|
128
|
+
n for n in native_class.body if isinstance(n, ast.AsyncFunctionDef)
|
|
129
|
+
and n.name == "reasoning"
|
|
130
|
+
))
|
|
131
|
+
# The source body is unchanged. Do not import or invoke its ten-attempt
|
|
132
|
+
# retry decorator around a boundary that may already have spent tokens.
|
|
133
|
+
reasoning.decorator_list = []
|
|
134
|
+
utility = ast.parse(sources["utils/utils.py"])
|
|
135
|
+
level_map = ast.literal_eval(next(
|
|
136
|
+
n.value for n in utility.body if isinstance(n, ast.Assign)
|
|
137
|
+
and any(isinstance(t, ast.Name) and t.id == "level_map" for t in n.targets)
|
|
138
|
+
))
|
|
139
|
+
logger = SimpleNamespace(debug=lambda *_args: None)
|
|
140
|
+
|
|
141
|
+
async def capture(messages, *, logger, return_raw):
|
|
142
|
+
del logger
|
|
143
|
+
if return_raw is not True:
|
|
144
|
+
raise ArtifactError("P&B native provider boundary differs")
|
|
145
|
+
raise _PromptBoundary(messages)
|
|
146
|
+
|
|
147
|
+
namespace = {
|
|
148
|
+
"np": importlib.import_module("numpy"), "textwrap": textwrap,
|
|
149
|
+
"Query": SimpleNamespace, "level_map": level_map, "logger": logger,
|
|
150
|
+
"MODEL_NAME": "agentinputlab-controlled-chat",
|
|
151
|
+
"COMPLETION_LLM": set(), "REASONING_LLM": set(),
|
|
152
|
+
"CHAT_LLM": {"agentinputlab-controlled-chat"}, "generate_response": capture,
|
|
153
|
+
}
|
|
154
|
+
nodes = [*helpers, prompt, reasoning]
|
|
155
|
+
exec(compile(ast.Module(body=nodes, type_ignores=[]),
|
|
156
|
+
"pinned-p-and-b-reasoning-prefix", "exec"), namespace)
|
|
157
|
+
instance = SimpleNamespace(
|
|
158
|
+
_prompt=namespace["_prompt"], instruction=request.instruction,
|
|
159
|
+
output_format=request.output_format, decay=request.schedule, logger=logger,
|
|
160
|
+
)
|
|
161
|
+
record = request.record
|
|
162
|
+
query = SimpleNamespace(description=record.query, reference=request.reference,
|
|
163
|
+
steps=list(record.steps), credits=list(record.credits),
|
|
164
|
+
level=record.level)
|
|
165
|
+
coroutine = namespace["reasoning"](instance, query)
|
|
166
|
+
try:
|
|
167
|
+
# capture() has no await/yield: this enters the genuine native prefix
|
|
168
|
+
# and stops at its first provider call, without an asyncio event loop.
|
|
169
|
+
coroutine.send(None)
|
|
170
|
+
except _PromptBoundary as boundary:
|
|
171
|
+
messages = boundary.messages
|
|
172
|
+
else: # pragma: no cover - fixed source invariant
|
|
173
|
+
raise ArtifactError("P&B native reasoning did not reach its provider boundary")
|
|
174
|
+
finally:
|
|
175
|
+
coroutine.close()
|
|
176
|
+
total_words = level_map[record.level][1]
|
|
177
|
+
allocations = tuple(int(x) for x in namespace["allocate_tokens"](
|
|
178
|
+
record.credits, total_words, namespace[_SCHEDULES[request.schedule]]
|
|
179
|
+
))
|
|
180
|
+
return {
|
|
181
|
+
"messages": messages, "allocations": allocations,
|
|
182
|
+
"soft_word_budget": total_words, "identity": identity,
|
|
183
|
+
"usage": {"model_calls": 0, "retrieval_calls": 0,
|
|
184
|
+
"input_tokens": 0, "output_tokens": 0},
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
|
|
188
|
+
__all__ = ["PlanAndBudgetNativePromptRuntime", "PlanBudgetPromptRequest"]
|
|
@@ -0,0 +1,222 @@
|
|
|
1
|
+
"""ACON history at real agent user-turn boundaries with a shared run budget.
|
|
2
|
+
|
|
3
|
+
The native environment remains authoritative. Only the agent-visible message
|
|
4
|
+
view is compressed; tool databases, simulator state and evaluator data never
|
|
5
|
+
enter this adapter. Tool calls/results are serialized for the text optimizer
|
|
6
|
+
but preserved verbatim whenever retained in the downstream protocol.
|
|
7
|
+
"""
|
|
8
|
+
from __future__ import annotations
|
|
9
|
+
|
|
10
|
+
from collections.abc import Mapping, Sequence
|
|
11
|
+
from copy import deepcopy
|
|
12
|
+
from typing import Any
|
|
13
|
+
|
|
14
|
+
from agentinputlab.contracts import ContextBlock, ExecutionBudget, FrozenAgentState, Message
|
|
15
|
+
from agentinputlab.contracts.errors import ValidationError
|
|
16
|
+
from agentinputlab.contracts.serialization import content_hash, to_jsonable
|
|
17
|
+
from agentinputlab.observability import RunMonitor
|
|
18
|
+
from agentinputlab.runner import InterventionRunner
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
class NativeHistoryInputError(ValidationError):
|
|
22
|
+
"""A native input cannot enter this history interface, before worker/model IO.
|
|
23
|
+
|
|
24
|
+
``code`` is stable for caller-side routing. It does not classify a model
|
|
25
|
+
outcome or make an entire benchmark inapplicable. No message content is
|
|
26
|
+
included in the error metadata.
|
|
27
|
+
"""
|
|
28
|
+
|
|
29
|
+
def __init__(self, code: str, message: str):
|
|
30
|
+
super().__init__(message)
|
|
31
|
+
self.code = code
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
def validate_native_history_prefix(messages, *, prefix_policy="strict_system_user") -> int:
|
|
35
|
+
"""Validate native prefix framing without constructing a worker or model.
|
|
36
|
+
|
|
37
|
+
Return the original first-user index. This check neither inserts a system
|
|
38
|
+
frame nor validates/compresses subsequent tool episodes; the native protocol
|
|
39
|
+
adapter remains responsible for their complete roundtrip.
|
|
40
|
+
"""
|
|
41
|
+
if not isinstance(prefix_policy, str) or prefix_policy not in {
|
|
42
|
+
"strict_system_user", "preserve_pre_user_assistant"}:
|
|
43
|
+
raise NativeHistoryInputError("unknown_prefix_policy", "unknown native history prefix policy")
|
|
44
|
+
if (not isinstance(messages, Sequence) or isinstance(messages, (str, bytes))
|
|
45
|
+
or any(not isinstance(row, Mapping) for row in messages)):
|
|
46
|
+
raise NativeHistoryInputError("invalid_message_sequence", "native history requires a message sequence")
|
|
47
|
+
missing = "live ACON requires the native session to start with system then user"
|
|
48
|
+
if len(messages) < 2 or messages[0].get("role") != "system":
|
|
49
|
+
raise NativeHistoryInputError("native_system_user_boundary_missing", missing)
|
|
50
|
+
if messages[1].get("role") == "user":
|
|
51
|
+
return 1
|
|
52
|
+
if prefix_policy != "preserve_pre_user_assistant":
|
|
53
|
+
raise NativeHistoryInputError("native_system_user_boundary_missing", missing)
|
|
54
|
+
first_user = next((i for i, row in enumerate(messages) if row.get("role") == "user"), None)
|
|
55
|
+
if first_user is None:
|
|
56
|
+
raise NativeHistoryInputError("native_first_user_missing", "native greeting prefix has no first user")
|
|
57
|
+
prefix = messages[1:first_user]
|
|
58
|
+
if not prefix or any(row.get("role") != "assistant"
|
|
59
|
+
or not isinstance(row.get("content"), str) or not row["content"].strip()
|
|
60
|
+
or row.get("tool_calls") or row.get("function_call") for row in prefix):
|
|
61
|
+
raise NativeHistoryInputError("native_greeting_prefix_unsupported",
|
|
62
|
+
"native pre-user prefix must contain only plain assistant greetings")
|
|
63
|
+
return first_user
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
def _view(message: Mapping[str, Any]) -> Message:
|
|
67
|
+
role = message.get("role")
|
|
68
|
+
if not isinstance(role, str) or not role:
|
|
69
|
+
raise ValidationError("native history message has no role")
|
|
70
|
+
content = message.get("content")
|
|
71
|
+
if message.get("tool_calls") or role in {"tool", "function"}:
|
|
72
|
+
# Upstream MemoryManager consumes USER/ASSISTANT text. Preserve tool
|
|
73
|
+
# observations as explicit text in that view, never as hidden metadata.
|
|
74
|
+
from agentinputlab.contracts.serialization import canonical_json
|
|
75
|
+
content = canonical_json(dict(message))
|
|
76
|
+
role = "assistant"
|
|
77
|
+
if not isinstance(content, str):
|
|
78
|
+
raise ValidationError("native text history message has no string content")
|
|
79
|
+
return Message(role=role, content=content, name=message.get("name"))
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
def _balanced_tool_frames(messages: Sequence[Mapping[str, Any]]) -> bool:
|
|
83
|
+
pending = set()
|
|
84
|
+
for message in messages:
|
|
85
|
+
if message.get("function_call") or message.get("role") == "function":
|
|
86
|
+
return False # legacy function framing needs its own explicit adapter
|
|
87
|
+
calls = message.get("tool_calls") or []
|
|
88
|
+
if calls:
|
|
89
|
+
if pending:
|
|
90
|
+
return False
|
|
91
|
+
pending = {call.get("id") for call in calls}
|
|
92
|
+
if None in pending or len(pending) != len(calls):
|
|
93
|
+
return False
|
|
94
|
+
elif message.get("role") == "tool":
|
|
95
|
+
identifier = message.get("tool_call_id")
|
|
96
|
+
if identifier not in pending:
|
|
97
|
+
return False
|
|
98
|
+
pending.remove(identifier)
|
|
99
|
+
elif pending:
|
|
100
|
+
return False
|
|
101
|
+
return not pending
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
class ACONLiveHistory:
|
|
105
|
+
"""One instance per native episode; keep metadata and causal history across turns.
|
|
106
|
+
|
|
107
|
+
The context must bind the real optimizer and native worker. A downstream
|
|
108
|
+
call and its per-call output allowance are reserved before any optimizer
|
|
109
|
+
request. Initial, intra-tool-turn and insufficient-budget branches do not
|
|
110
|
+
consume optimizer calls. Genuine optimizer failures propagate, never become
|
|
111
|
+
successful NO_OPs. ``records`` retains every decision and observed usage.
|
|
112
|
+
"""
|
|
113
|
+
|
|
114
|
+
def __init__(self, method, context, *, per_call_output_tokens: int = 512,
|
|
115
|
+
prefix_policy: str = "strict_system_user"):
|
|
116
|
+
if method.release_id != "curate.acon.history_runtime":
|
|
117
|
+
raise ValidationError("live ACON history requires the exact history runtime release")
|
|
118
|
+
if type(per_call_output_tokens) is not int or per_call_output_tokens < 1:
|
|
119
|
+
raise ValidationError("per-call history output allowance must be positive")
|
|
120
|
+
if not isinstance(prefix_policy, str) or prefix_policy not in {
|
|
121
|
+
"strict_system_user", "preserve_pre_user_assistant"}:
|
|
122
|
+
raise ValidationError("unknown native history prefix policy")
|
|
123
|
+
self.method, self.context = method, context
|
|
124
|
+
self.per_call_output_tokens = per_call_output_tokens
|
|
125
|
+
self.prefix_policy = prefix_policy
|
|
126
|
+
self.records: list[dict] = []
|
|
127
|
+
self._raw: list[dict] = []
|
|
128
|
+
self._logical: list[dict] = []
|
|
129
|
+
self._metadata: dict = {}
|
|
130
|
+
|
|
131
|
+
def fingerprint(self) -> dict:
|
|
132
|
+
fingerprint = {"release": self.method.release_id, "integration": "acon.native_user_boundary.v2",
|
|
133
|
+
"per_call_output_tokens": self.per_call_output_tokens,
|
|
134
|
+
"optimizer_tokenizer": "source-native-bound-not-target-approximation",
|
|
135
|
+
"agent_tool_frames_preserved": True,
|
|
136
|
+
"worker": dict(self.context.external_runtime.fingerprint())}
|
|
137
|
+
if self.prefix_policy != "strict_system_user":
|
|
138
|
+
fingerprint["prefix_policy"] = self.prefix_policy
|
|
139
|
+
return to_jsonable(fingerprint)
|
|
140
|
+
|
|
141
|
+
def _native_optimizer_view(self, logical):
|
|
142
|
+
"""Keep a declared native greeting immutable, outside the optimizer view.
|
|
143
|
+
|
|
144
|
+
No message is invented, moved or dropped from the downstream wire.
|
|
145
|
+
The native optimizer still receives its original system/user framing;
|
|
146
|
+
only plain assistant greetings preceding the first user are excluded
|
|
147
|
+
from that mutable view and reinserted verbatim after materialization.
|
|
148
|
+
"""
|
|
149
|
+
first_user = validate_native_history_prefix(logical, prefix_policy=self.prefix_policy)
|
|
150
|
+
if first_user == 1:
|
|
151
|
+
return logical, []
|
|
152
|
+
prefix = logical[1:first_user]
|
|
153
|
+
return [logical[0], *logical[first_user:]], deepcopy(prefix)
|
|
154
|
+
|
|
155
|
+
def transform(self, messages, *, state, remaining_budget):
|
|
156
|
+
raw = deepcopy(list(messages))
|
|
157
|
+
if self._raw and (len(raw) < len(self._raw) or raw[:len(self._raw)] != self._raw):
|
|
158
|
+
raise ValidationError("native history changed before its append-only boundary")
|
|
159
|
+
logical = deepcopy(self._logical) + raw[len(self._raw):] if self._raw else deepcopy(raw)
|
|
160
|
+
native_logical, immutable_prefix = self._native_optimizer_view(logical)
|
|
161
|
+
initial = {"input_raw_hash": content_hash(raw), "input_logical_hash": content_hash(logical),
|
|
162
|
+
"remaining_budget": dict(remaining_budget)}
|
|
163
|
+
if immutable_prefix:
|
|
164
|
+
initial.update(prefix_policy=self.prefix_policy,
|
|
165
|
+
immutable_native_prefix_hash=content_hash(immutable_prefix),
|
|
166
|
+
immutable_native_prefix_length=len(immutable_prefix))
|
|
167
|
+
reason = None
|
|
168
|
+
if logical[-1].get("role") != "user":
|
|
169
|
+
reason = "intra_user_turn_tool_protocol_preserved"
|
|
170
|
+
elif (remaining_budget["max_model_calls"] < 2
|
|
171
|
+
or remaining_budget["max_output_tokens"] < 2 * self.per_call_output_tokens):
|
|
172
|
+
reason = "downstream_call_and_output_reserved"
|
|
173
|
+
if reason:
|
|
174
|
+
self._raw, self._logical = raw, logical
|
|
175
|
+
record = {**initial, "status": "integration_skip", "reason": reason,
|
|
176
|
+
"usage": {"model_calls": 0, "output_tokens": 0}}
|
|
177
|
+
self.records.append(record)
|
|
178
|
+
return {"messages": deepcopy(logical), "usage": dict(record["usage"])}
|
|
179
|
+
view = tuple(_view(message) for message in native_logical)
|
|
180
|
+
# Reject protocol-orphaning assembly before the optimizer has side effects.
|
|
181
|
+
from agentinputlab.algorithms.curate.acon.common import preserved_turn_indices
|
|
182
|
+
indices = preserved_turn_indices(view, self.method.controls.preserve_last_k_turns)
|
|
183
|
+
candidate_tail = [native_logical[index] for index in indices]
|
|
184
|
+
if not _balanced_tool_frames(candidate_tail):
|
|
185
|
+
self._raw, self._logical = raw, logical
|
|
186
|
+
record = {**initial, "status": "integration_skip", "reason": "preserved_tail_has_unpaired_tool_frames",
|
|
187
|
+
"usage": {"model_calls": 0, "output_tokens": 0}}
|
|
188
|
+
self.records.append(record)
|
|
189
|
+
return {"messages": deepcopy(logical), "usage": dict(record["usage"])}
|
|
190
|
+
frozen = FrozenAgentState(
|
|
191
|
+
query=state["query"], instruction=state.get("instruction", ""),
|
|
192
|
+
task_id=state.get("task_id", ""), messages=view,
|
|
193
|
+
context=tuple(ContextBlock(**block) for block in state.get("context", [])),
|
|
194
|
+
tool_names=tuple(state.get("tool_names", [])),
|
|
195
|
+
metadata={**state.get("metadata", {}), **self._metadata},
|
|
196
|
+
budget=ExecutionBudget(max_model_calls=remaining_budget["max_model_calls"] - 1,
|
|
197
|
+
max_output_tokens=remaining_budget["max_output_tokens"] - self.per_call_output_tokens))
|
|
198
|
+
monitor = RunMonitor()
|
|
199
|
+
try:
|
|
200
|
+
result = InterventionRunner(monitor=monitor).run(self.method, frozen, self.context)
|
|
201
|
+
except Exception as exc:
|
|
202
|
+
self.records.append({**initial, "status": "failed_terminal", "error_type": type(exc).__name__,
|
|
203
|
+
"error": str(exc), "monitor_snapshots": to_jsonable(monitor.list_snapshots())})
|
|
204
|
+
raise
|
|
205
|
+
patched = result.patch.apply(frozen)
|
|
206
|
+
if result.patch.metadata.get("applied"):
|
|
207
|
+
if tuple(patched.messages[2:]) != tuple(view[index] for index in indices):
|
|
208
|
+
raise ValidationError("ACON preserved messages differ from source-bound indices")
|
|
209
|
+
materialized = [dict(native_logical[0], content=patched.messages[0].content),
|
|
210
|
+
*deepcopy(immutable_prefix),
|
|
211
|
+
dict(native_logical[1], content=patched.messages[1].content), *deepcopy(candidate_tail)]
|
|
212
|
+
else:
|
|
213
|
+
materialized = logical
|
|
214
|
+
if not _balanced_tool_frames(materialized):
|
|
215
|
+
raise ValidationError("ACON materialization would orphan a native tool call")
|
|
216
|
+
self._metadata = {key: value for key, value in patched.metadata.items() if key.startswith("acon_")}
|
|
217
|
+
self._raw, self._logical = raw, materialized
|
|
218
|
+
usage = to_jsonable(result.usage)
|
|
219
|
+
self.records.append({**initial, "status": "applied" if result.patch.metadata.get("applied") else "native_threshold_skip",
|
|
220
|
+
"output_logical_hash": content_hash(materialized), "usage": usage,
|
|
221
|
+
"intervention": to_jsonable(result)})
|
|
222
|
+
return {"messages": deepcopy(materialized), "usage": dict(usage)}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"""Optional tuning and context-evolution integrations."""
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"""Training recipes and checkpoint-producing integrations."""
|