@tangle-network/agent-eval 2.0.5 → 2.0.9
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.
- package/CHANGELOG.md +24 -0
- package/dist/adapters/http.d.ts +2 -2
- package/dist/{agent-profile-CcOq7bOO.d.ts → agent-profile-ORN4aArD.d.ts} +5 -5
- package/dist/{agent-profile-CcOq7bOO.d.ts.map → agent-profile-ORN4aArD.d.ts.map} +1 -1
- package/dist/analyst/index.d.ts +15 -15
- package/dist/analyst/index.js +18 -14
- package/dist/analyst/index.js.map +1 -1
- package/dist/{analyze-runs-C_9cXPZn.js → analyze-runs-CE_5VKh2.js} +6 -5
- package/dist/{analyze-runs-C_9cXPZn.js.map → analyze-runs-CE_5VKh2.js.map} +1 -1
- package/dist/analyze-runs-DT693FJ7.d.ts +65 -0
- package/dist/analyze-runs-DT693FJ7.d.ts.map +1 -0
- package/dist/app-grade/index.d.ts +4 -4
- package/dist/app-grade/index.js +1 -1
- package/dist/{benchmark-command-MfXRocwZ.js → benchmark-command-DLg8E4y8.js} +16 -9
- package/dist/benchmark-command-DLg8E4y8.js.map +1 -0
- package/dist/benchmarks/index.d.ts +4 -4
- package/dist/benchmarks/index.js +4 -4
- package/dist/builder-eval/index.js +2 -2
- package/dist/calibration-CrORXMWx.d.ts +128 -0
- package/dist/calibration-CrORXMWx.d.ts.map +1 -0
- package/dist/{calibration-Cfoup0xz.js → calibration-Dz8mQb5P.js} +2 -2
- package/dist/{calibration-Cfoup0xz.js.map → calibration-Dz8mQb5P.js.map} +1 -1
- package/dist/campaign/index.d.ts +8 -8
- package/dist/campaign/index.js +12 -11
- package/dist/{campaign-DfSWSreo.js → campaign-C_S3MOYa.js} +1589 -14
- package/dist/campaign-C_S3MOYa.js.map +1 -0
- package/dist/{campaign-evidence-D_oBFfLc.js → campaign-evidence-BTfzZo1u.js} +4 -4
- package/dist/{campaign-evidence-D_oBFfLc.js.map → campaign-evidence-BTfzZo1u.js.map} +1 -1
- package/dist/{campaign-evidence-BmMs8YJt.d.ts → campaign-evidence-CM4FBOkX.d.ts} +5 -5
- package/dist/{campaign-evidence-BmMs8YJt.d.ts.map → campaign-evidence-CM4FBOkX.d.ts.map} +1 -1
- package/dist/{cluster-Bj90LK-1.d.ts → chat-client-uQNXGuO4.d.ts} +3 -240
- package/dist/chat-client-uQNXGuO4.d.ts.map +1 -0
- package/dist/cli.js +6 -6
- package/dist/cluster-C-K0N2br.d.ts +241 -0
- package/dist/cluster-C-K0N2br.d.ts.map +1 -0
- package/dist/{cluster-bootstrap-DPzVy3_K.js → cluster-bootstrap-DXbnIdm8.js} +3 -2
- package/dist/{cluster-bootstrap-DPzVy3_K.js.map → cluster-bootstrap-DXbnIdm8.js.map} +1 -1
- package/dist/{completion-verifier-Cy38EpGE.d.ts → completion-verifier-C7wipJOK.d.ts} +2 -2
- package/dist/{completion-verifier-Cy38EpGE.d.ts.map → completion-verifier-C7wipJOK.d.ts.map} +1 -1
- package/dist/contract/index.d.ts +14 -12
- package/dist/contract/index.js +13 -11
- package/dist/contract/index.js.map +1 -1
- package/dist/{decision-point-C46p-p9v.js → decision-point-CfqtnGop.js} +3 -3
- package/dist/{decision-point-C46p-p9v.js.map → decision-point-CfqtnGop.js.map} +1 -1
- package/dist/{default-registry-CUuorCWZ.d.ts → default-registry-Bskl2HzV.d.ts} +6 -7
- package/dist/default-registry-Bskl2HzV.d.ts.map +1 -0
- package/dist/{default-registry-IkE3byrA.js → default-registry-kps1SOaD.js} +27 -15
- package/dist/default-registry-kps1SOaD.js.map +1 -0
- package/dist/define-agent-eval-Dnh4jXLX.js +96 -0
- package/dist/define-agent-eval-Dnh4jXLX.js.map +1 -0
- package/dist/define-agent-eval-tu3anVlk.d.ts +52 -0
- package/dist/define-agent-eval-tu3anVlk.d.ts.map +1 -0
- package/dist/diagnosis/index.d.ts +3 -3
- package/dist/diagnosis/index.js +1 -1
- package/dist/{dspy-rlm-engine-DE11iBcC.js → dspy-rlm-engine-DQbPdT_o.js} +8 -4
- package/dist/{dspy-rlm-engine-DE11iBcC.js.map → dspy-rlm-engine-DQbPdT_o.js.map} +1 -1
- package/dist/{emitter-BjW3NnX-.js → emitter-xN9wGTVw.js} +9 -2
- package/dist/{emitter-BjW3NnX-.js.map → emitter-xN9wGTVw.js.map} +1 -1
- package/dist/{eval-campaign-Cyk-tkLh.js → eval-campaign-DswSn7Gm.js} +3 -3
- package/dist/{eval-campaign-Cyk-tkLh.js.map → eval-campaign-DswSn7Gm.js.map} +1 -1
- package/dist/{evaluation-DfyLPVL1.d.ts → evaluation-C4-tf3Z_.d.ts} +4 -4
- package/dist/{evaluation-DfyLPVL1.d.ts.map → evaluation-C4-tf3Z_.d.ts.map} +1 -1
- package/dist/evaluation.d.ts +1 -1
- package/dist/{exact-types-CiCXYhNK.d.ts → exact-types-CUsSMW3n.d.ts} +2 -2
- package/dist/{exact-types-CiCXYhNK.d.ts.map → exact-types-CUsSMW3n.d.ts.map} +1 -1
- package/dist/{execution-insight-wUNXxo5Y.d.ts → execution-insight-YihQrSqd.d.ts} +2 -2
- package/dist/{execution-insight-wUNXxo5Y.d.ts.map → execution-insight-YihQrSqd.d.ts.map} +1 -1
- package/dist/experiment/index.d.ts +5 -5
- package/dist/experiment/index.js +10 -184
- package/dist/experiment/index.js.map +1 -1
- package/dist/{external-optimizer-process-4QdcF7Kd.js → external-optimizer-process-CVi1x2nb.js} +2 -2
- package/dist/{external-optimizer-process-4QdcF7Kd.js.map → external-optimizer-process-CVi1x2nb.js.map} +1 -1
- package/dist/{external-optimizer-subprocess-BW0ZWUUr.js → external-optimizer-subprocess-mV-2swJI.js} +3 -357
- package/dist/external-optimizer-subprocess-mV-2swJI.js.map +1 -0
- package/dist/{feedback-trajectory-HJticMDz.d.ts → feedback-trajectory-D7hgL6y5.d.ts} +3 -3
- package/dist/{feedback-trajectory-HJticMDz.d.ts.map → feedback-trajectory-D7hgL6y5.d.ts.map} +1 -1
- package/dist/finding-scope-B_As3F_v.js +359 -0
- package/dist/finding-scope-B_As3F_v.js.map +1 -0
- package/dist/{findings-store-BxpV-hfH.js → findings-store-CZy5kUDo.js} +26 -19
- package/dist/findings-store-CZy5kUDo.js.map +1 -0
- package/dist/fuzz.js +1 -1
- package/dist/{harness-session-lines-CSxKR6no.js → harness-session-lines-CTh1-uOb.js} +21 -19
- package/dist/harness-session-lines-CTh1-uOb.js.map +1 -0
- package/dist/{index-Ucp54Pcl.d.ts → index--vDCtdaj.d.ts} +7 -8
- package/dist/index--vDCtdaj.d.ts.map +1 -0
- package/dist/{index-CKjqN9_U.d.ts → index-CIqYaySd.d.ts} +89 -3
- package/dist/index-CIqYaySd.d.ts.map +1 -0
- package/dist/{index-C6TG1LwA.d.ts → index-Cav3abKy.d.ts} +256 -131
- package/dist/index-Cav3abKy.d.ts.map +1 -0
- package/dist/{index-CR-guIiZ.d.ts → index-DmMHTDjT.d.ts} +10 -8
- package/dist/index-DmMHTDjT.d.ts.map +1 -0
- package/dist/{index-oX0TuJFv.d.ts → index-Er8TKQ3q.d.ts} +4 -4
- package/dist/{index-oX0TuJFv.d.ts.map → index-Er8TKQ3q.d.ts.map} +1 -1
- package/dist/{index-B_k8aY9k.d.ts → index-moZnazVj.d.ts} +22 -21
- package/dist/index-moZnazVj.d.ts.map +1 -0
- package/dist/index.d.ts +33 -30
- package/dist/index.js +27 -24
- package/dist/index.js.map +1 -1
- package/dist/{analyze-runs-Ke0WbAf6.d.ts → insight-report-DYofCMLx.d.ts} +4 -64
- package/dist/insight-report-DYofCMLx.d.ts.map +1 -0
- package/dist/{integrity-B9320cw1.d.ts → integrity-BJGstiCh.d.ts} +2 -2
- package/dist/{integrity-B9320cw1.d.ts.map → integrity-BJGstiCh.d.ts.map} +1 -1
- package/dist/{judge-gate-DqlzOBOm.js → judge-gate-DANg5FLq.js} +2 -2
- package/dist/{judge-gate-DqlzOBOm.js.map → judge-gate-DANg5FLq.js.map} +1 -1
- package/dist/{kind-factory-BDd4rhML.js → kind-factory-B-xCxG7p.js} +33 -5
- package/dist/kind-factory-B-xCxG7p.js.map +1 -0
- package/dist/llm-judge-DFoSy4Qn.js +476 -0
- package/dist/llm-judge-DFoSy4Qn.js.map +1 -0
- package/dist/{matrix-DlSrRl_v.d.ts → matrix-OgdWQBQa.d.ts} +6 -2
- package/dist/matrix-OgdWQBQa.d.ts.map +1 -0
- package/dist/measure-validity-plan-B1_qYlsk.d.ts +143 -0
- package/dist/measure-validity-plan-B1_qYlsk.d.ts.map +1 -0
- package/dist/measure-validity-plan-t0YQRzJQ.js +117 -0
- package/dist/measure-validity-plan-t0YQRzJQ.js.map +1 -0
- package/dist/meta-eval/index.d.ts +5 -3
- package/dist/meta-eval/index.js +664 -14
- package/dist/meta-eval/index.js.map +1 -1
- package/dist/multishot/golden/index.d.ts +1 -1
- package/dist/multishot/index.d.ts +458 -4
- package/dist/multishot/index.d.ts.map +1 -1
- package/dist/multishot/index.js +926 -47
- package/dist/multishot/index.js.map +1 -1
- package/dist/openapi.json +1 -1
- package/dist/{llm-judge-DQJTQx01.js → optimization-method-D4CpYsVA.js} +18 -482
- package/dist/optimization-method-D4CpYsVA.js.map +1 -0
- package/dist/{outcome-observations-DL3CC8w1.js → outcome-observations-DEh8_V_P.js} +31 -6
- package/dist/outcome-observations-DEh8_V_P.js.map +1 -0
- package/dist/outcome-store-CHtuvstd.d.ts +56 -0
- package/dist/outcome-store-CHtuvstd.d.ts.map +1 -0
- package/dist/{paired-arms-DZhH3FGu.js → paired-arms-B6EXnI47.js} +3 -2
- package/dist/{paired-arms-DZhH3FGu.js.map → paired-arms-B6EXnI47.js.map} +1 -1
- package/dist/{paired-promotion-decision-ChHBuuHV.d.ts → paired-promotion-decision-DuvRdnsW.d.ts} +2 -2
- package/dist/{paired-promotion-decision-ChHBuuHV.d.ts.map → paired-promotion-decision-DuvRdnsW.d.ts.map} +1 -1
- package/dist/{paired-promotion-decision-Dn3-jaq4.js → paired-promotion-decision-xYe881cD.js} +3 -2
- package/dist/{paired-promotion-decision-Dn3-jaq4.js.map → paired-promotion-decision-xYe881cD.js.map} +1 -1
- package/dist/{paired-promotion-power-BlzXdgMD.js → paired-promotion-power-DirShsIs.js} +3 -3
- package/dist/{paired-promotion-power-BlzXdgMD.js.map → paired-promotion-power-DirShsIs.js.map} +1 -1
- package/dist/paired-tests-CXcD_B80.js +688 -0
- package/dist/paired-tests-CXcD_B80.js.map +1 -0
- package/dist/pareto-DIVE5D0T.js +81 -0
- package/dist/pareto-DIVE5D0T.js.map +1 -0
- package/dist/pipelines/index.d.ts +2 -1
- package/dist/pipelines/index.d.ts.map +1 -1
- package/dist/pipelines/index.js +1 -1
- package/dist/{sequential-BphITa5b.js → power-DTg6u30w.js} +181 -4
- package/dist/power-DTg6u30w.js.map +1 -0
- package/dist/{prime-protocol-iEaSEGZB.d.ts → prime-protocol-Jm2pWh--.d.ts} +2 -2
- package/dist/{prime-protocol-iEaSEGZB.d.ts.map → prime-protocol-Jm2pWh--.d.ts.map} +1 -1
- package/dist/{promotion-gate-CGkxh36r.d.ts → promotion-gate-BXgcORnM.d.ts} +2 -2
- package/dist/{promotion-gate-CGkxh36r.d.ts.map → promotion-gate-BXgcORnM.d.ts.map} +1 -1
- package/dist/{promotion-policy-CxDIh-9p.js → promotion-policy-Z5E-C32U.js} +4 -4
- package/dist/{promotion-policy-CxDIh-9p.js.map → promotion-policy-Z5E-C32U.js.map} +1 -1
- package/dist/{proposal-findings-DedMih-u.js → proposal-findings-CfRFCFXS.js} +2 -2
- package/dist/{proposal-findings-DedMih-u.js.map → proposal-findings-CfRFCFXS.js.map} +1 -1
- package/dist/{registry-V8o2kZtn.d.ts → registry-DEZDECdr.d.ts} +4 -4
- package/dist/{registry-V8o2kZtn.d.ts.map → registry-DEZDECdr.d.ts.map} +1 -1
- package/dist/{release-confidence-BLHOMK5Q.js → release-confidence-Cndq1hwi.js} +2 -2
- package/dist/{release-confidence-BLHOMK5Q.js.map → release-confidence-Cndq1hwi.js.map} +1 -1
- package/dist/reporting.d.ts +5 -5
- package/dist/reporting.js +6 -5
- package/dist/reporting.js.map +1 -1
- package/dist/{research-report-D6XIK0eK.d.ts → research-report-CIgUe1lv.d.ts} +2 -2
- package/dist/{research-report-D6XIK0eK.d.ts.map → research-report-CIgUe1lv.d.ts.map} +1 -1
- package/dist/{researcher---DhHG4J.d.ts → researcher-CY_byuZl.d.ts} +4 -4
- package/dist/{researcher---DhHG4J.d.ts.map → researcher-CY_byuZl.d.ts.map} +1 -1
- package/dist/{reward-hacking-DKAflk2c.js → reward-hacking-DMTm1OBd.js} +2 -2
- package/dist/{reward-hacking-DKAflk2c.js.map → reward-hacking-DMTm1OBd.js.map} +1 -1
- package/dist/rl.d.ts +9 -8
- package/dist/rl.d.ts.map +1 -1
- package/dist/rl.js +11 -10
- package/dist/rl.js.map +1 -1
- package/dist/rollout/index.d.ts +2 -2
- package/dist/rollout/index.js +2 -2
- package/dist/{rollout-DVwpCHBC.js → rollout-B_lrpd9a.js} +2 -2
- package/dist/{rollout-DVwpCHBC.js.map → rollout-B_lrpd9a.js.map} +1 -1
- package/dist/{rubric-predictive-validity--6z0q8s6.js → rubric-predictive-validity-BXJ92Jp_.js} +3 -9
- package/dist/rubric-predictive-validity-BXJ92Jp_.js.map +1 -0
- package/dist/{rubric-predictive-validity-C9wc7f_D.d.ts → rubric-predictive-validity-DH94_0Q1.d.ts} +3 -56
- package/dist/rubric-predictive-validity-DH94_0Q1.d.ts.map +1 -0
- package/dist/{run-improvement-loop-CtLyPb5-.d.ts → run-improvement-loop-BaPDVbW8.d.ts} +384 -11
- package/dist/run-improvement-loop-BaPDVbW8.d.ts.map +1 -0
- package/dist/{run-record-Bqg0NZ_e.js → run-record-CuO8ErrI.js} +3 -2
- package/dist/run-record-CuO8ErrI.js.map +1 -0
- package/dist/{runtime-rollouts-DdUijr_t.js → runtime-rollouts-Vv-BAqmq.js} +3 -3
- package/dist/{runtime-rollouts-DdUijr_t.js.map → runtime-rollouts-Vv-BAqmq.js.map} +1 -1
- package/dist/search/index.d.ts +2 -2
- package/dist/search/index.js +2 -2
- package/dist/{search-kernel-DXA1EhnN.d.ts → search-kernel-BzTeb89p.d.ts} +3 -3
- package/dist/{search-kernel-DXA1EhnN.d.ts.map → search-kernel-BzTeb89p.d.ts.map} +1 -1
- package/dist/{pareto-Bg75Gajo.js → search-kernel-DOPW08Hx.js} +6 -88
- package/dist/search-kernel-DOPW08Hx.js.map +1 -0
- package/dist/{search-summary-B1x1Vmzh.js → search-summary-CYOHZAAy.js} +4 -4
- package/dist/{search-summary-B1x1Vmzh.js.map → search-summary-CYOHZAAy.js.map} +1 -1
- package/dist/{define-agent-eval-B6uE3gNu.js → self-improve-CIFqccHV.js} +8 -97
- package/dist/self-improve-CIFqccHV.js.map +1 -0
- package/dist/{define-agent-eval-D17XsdAt.d.ts → self-improve-DY8ZY4lY.d.ts} +8 -54
- package/dist/self-improve-DY8ZY4lY.d.ts.map +1 -0
- package/dist/{sequential-BhbTSxpt.d.ts → sequential-B9iROM1S.d.ts} +2 -2
- package/dist/{sequential-BhbTSxpt.d.ts.map → sequential-B9iROM1S.d.ts.map} +1 -1
- package/dist/{sequential-ux_XrjBf.js → sequential-tZjGysXY.js} +3 -3
- package/dist/{sequential-ux_XrjBf.js.map → sequential-tZjGysXY.js.map} +1 -1
- package/dist/{skillopt-optimization-method-D_swD0Cy.js → skillopt-optimization-method-CbHBkopM.js} +9 -8
- package/dist/{skillopt-optimization-method-D_swD0Cy.js.map → skillopt-optimization-method-CbHBkopM.js.map} +1 -1
- package/dist/{statistical-heldout-CaS4T-43.js → statistical-heldout-C7Jjo5nP.js} +3 -3
- package/dist/{statistical-heldout-CaS4T-43.js.map → statistical-heldout-C7Jjo5nP.js.map} +1 -1
- package/dist/{statistics-DSidA5I2.js → statistics-BPl13X3G.js} +208 -700
- package/dist/statistics-BPl13X3G.js.map +1 -0
- package/dist/statistics.d.ts +3 -3
- package/dist/statistics.js +3 -2
- package/dist/{store-otlp-CR9fWum6.js → store-otlp-CdeW7NWq.js} +2 -2
- package/dist/{store-otlp-CR9fWum6.js.map → store-otlp-CdeW7NWq.js.map} +1 -1
- package/dist/{store-tool-spans-tkdUJWup.js → store-tool-spans-CVX-jfkk.js} +3 -3
- package/dist/{store-tool-spans-tkdUJWup.js.map → store-tool-spans-CVX-jfkk.js.map} +1 -1
- package/dist/{store-tool-spans-C47hUUVM.d.ts → store-tool-spans-Dq8r0PbJ.d.ts} +4 -5
- package/dist/store-tool-spans-Dq8r0PbJ.d.ts.map +1 -0
- package/dist/{summary-report-CI4J6gxU.js → summary-report-DzbnK81K.js} +15 -7
- package/dist/summary-report-DzbnK81K.js.map +1 -0
- package/dist/summary-report-figures-CJHygLgw.d.ts.map +1 -1
- package/dist/supervisor-run/index.d.ts +1 -1
- package/dist/supervisor-run/index.js +1 -1
- package/dist/{systemone-MXhFSYdy.d.ts → systemone-BuSZTI88.d.ts} +8 -7
- package/dist/systemone-BuSZTI88.d.ts.map +1 -0
- package/dist/{systemone-review-C9kbs3zD.d.ts → systemone-review-mlfxWdLz.d.ts} +2 -2
- package/dist/{systemone-review-C9kbs3zD.d.ts.map → systemone-review-mlfxWdLz.d.ts.map} +1 -1
- package/dist/systemone.d.ts +3 -3
- package/dist/systemone.js +1 -1
- package/dist/{tool-groups-BSd08M7B.d.ts → tool-groups-PNDX8fd-.d.ts} +2 -3
- package/dist/tool-groups-PNDX8fd-.d.ts.map +1 -0
- package/dist/{tool-waste-u7JJ_BlE.js → tool-waste-783VCo1y.js} +3 -2
- package/dist/{tool-waste-u7JJ_BlE.js.map → tool-waste-783VCo1y.js.map} +1 -1
- package/dist/tool-waste-B01AMpID.d.ts +121 -0
- package/dist/tool-waste-B01AMpID.d.ts.map +1 -0
- package/dist/{trace-questions-CJANeK9P.d.ts → trace-questions-DBtr4jWi.d.ts} +2 -3
- package/dist/trace-questions-DBtr4jWi.d.ts.map +1 -0
- package/dist/trace-repair/index.d.ts +1 -1
- package/dist/trace-repair/index.js +1 -1
- package/dist/traces.d.ts +4 -5
- package/dist/traces.d.ts.map +1 -1
- package/dist/traces.js +4 -4
- package/dist/trajectory-B3o6Ald_.d.ts +100 -0
- package/dist/trajectory-B3o6Ald_.d.ts.map +1 -0
- package/dist/trajectory-replay/index.js +1 -1
- package/dist/{tree-DQMlcNFI.js → tree-CtlQQL1w.js} +6 -4
- package/dist/{tree-DQMlcNFI.js.map → tree-CtlQQL1w.js.map} +1 -1
- package/dist/{types-DD1eUTLn.d.ts → types-BO948H-U.d.ts} +7 -4
- package/dist/{types-DD1eUTLn.d.ts.map → types-BO948H-U.d.ts.map} +1 -1
- package/dist/{types-AGUuvnae.d.ts → types-CKNAzCSA.d.ts} +158 -3
- package/dist/types-CKNAzCSA.d.ts.map +1 -0
- package/dist/{types-BLv2Ngla.d.ts → types-D-WF1KM3.d.ts} +2 -2
- package/dist/{types-BLv2Ngla.d.ts.map → types-D-WF1KM3.d.ts.map} +1 -1
- package/dist/types-DK4vNv5q.js.map +1 -1
- package/dist/{types-CE9JMZhk.d.ts → types-DbeIGi73.d.ts} +2 -2
- package/dist/{types-CE9JMZhk.d.ts.map → types-DbeIGi73.d.ts.map} +1 -1
- package/dist/types-_tlhWGUq.js.map +1 -1
- package/dist/wire/index.d.ts +4 -4
- package/dist/world/index.d.ts +529 -0
- package/dist/world/index.d.ts.map +1 -0
- package/dist/world/index.js +1356 -0
- package/dist/world/index.js.map +1 -0
- package/docs/campaign-proposers.md +7 -0
- package/docs/concepts.md +2 -0
- package/docs/design/statistics-decisions.md +31 -0
- package/docs/eval-surface-map.md +4 -1
- package/docs/feature-guide.md +2 -0
- package/docs/multi-turn-optimization.md +80 -0
- package/docs/outcome-validity.md +69 -0
- package/docs/public-api.md +86 -31
- package/docs/trace-analysis.md +1 -0
- package/docs/world.md +104 -0
- package/package.json +7 -2
- package/dist/analyze-runs-Ke0WbAf6.d.ts.map +0 -1
- package/dist/benchmark-command-MfXRocwZ.js.map +0 -1
- package/dist/campaign-DfSWSreo.js.map +0 -1
- package/dist/cluster-Bj90LK-1.d.ts.map +0 -1
- package/dist/default-registry-CUuorCWZ.d.ts.map +0 -1
- package/dist/default-registry-IkE3byrA.js.map +0 -1
- package/dist/define-agent-eval-B6uE3gNu.js.map +0 -1
- package/dist/define-agent-eval-D17XsdAt.d.ts.map +0 -1
- package/dist/engine-BZVXOc6n.d.ts +0 -152
- package/dist/engine-BZVXOc6n.d.ts.map +0 -1
- package/dist/external-optimizer-subprocess-BW0ZWUUr.js.map +0 -1
- package/dist/findings-store-BxpV-hfH.js.map +0 -1
- package/dist/harness-session-lines-CSxKR6no.js.map +0 -1
- package/dist/index-B_k8aY9k.d.ts.map +0 -1
- package/dist/index-C6TG1LwA.d.ts.map +0 -1
- package/dist/index-CKjqN9_U.d.ts.map +0 -1
- package/dist/index-CR-guIiZ.d.ts.map +0 -1
- package/dist/index-Ucp54Pcl.d.ts.map +0 -1
- package/dist/interval-CWyxqDpE.d.ts +0 -43
- package/dist/interval-CWyxqDpE.d.ts.map +0 -1
- package/dist/kind-factory-BDd4rhML.js.map +0 -1
- package/dist/llm-judge-DQJTQx01.js.map +0 -1
- package/dist/matrix-DlSrRl_v.d.ts.map +0 -1
- package/dist/outcome-observations-DL3CC8w1.js.map +0 -1
- package/dist/pareto-Bg75Gajo.js.map +0 -1
- package/dist/rubric-predictive-validity--6z0q8s6.js.map +0 -1
- package/dist/rubric-predictive-validity-C9wc7f_D.d.ts.map +0 -1
- package/dist/run-improvement-loop-CtLyPb5-.d.ts.map +0 -1
- package/dist/run-record-Bqg0NZ_e.js.map +0 -1
- package/dist/sequential-BphITa5b.js.map +0 -1
- package/dist/statistics-DSidA5I2.js.map +0 -1
- package/dist/store-tool-spans-C47hUUVM.d.ts.map +0 -1
- package/dist/summary-report-CI4J6gxU.js.map +0 -1
- package/dist/systemone-MXhFSYdy.d.ts.map +0 -1
- package/dist/tool-groups-BSd08M7B.d.ts.map +0 -1
- package/dist/tool-waste-CIhtU1ad.d.ts +0 -217
- package/dist/tool-waste-CIhtU1ad.d.ts.map +0 -1
- package/dist/trace-questions-CJANeK9P.d.ts.map +0 -1
- package/dist/types-AGUuvnae.d.ts.map +0 -1
package/dist/multishot/index.js
CHANGED
|
@@ -1,10 +1,198 @@
|
|
|
1
|
+
import { a as hashCanonical, o as jsonDocument } from "../canonical-DKgL_Wby.js";
|
|
2
|
+
import { S as makeRng } from "../paired-tests-CXcD_B80.js";
|
|
3
|
+
import { L as defaultProductionGate } from "../optimization-method-D4CpYsVA.js";
|
|
1
4
|
import { d as estimateCost, p as isModelPriced } from "../cost-ledger-C5CCidPm.js";
|
|
5
|
+
import { _ as EMITTED_EVIDENCE_MAX_CHARS, y as excerptEvidence } from "../campaign-evidence-BTfzZo1u.js";
|
|
6
|
+
import { n as selfImprove } from "../self-improve-CIFqccHV.js";
|
|
7
|
+
import { n as runTaskId } from "../emitter-xN9wGTVw.js";
|
|
2
8
|
import { t as DEFAULT_JUDGE_MODEL } from "../chat-client-CvyDOQBv.js";
|
|
9
|
+
import { i as decisionQuestionDigest, r as decisionPoint } from "../decision-point-CfqtnGop.js";
|
|
10
|
+
import { t as clusterBootstrapMean } from "../cluster-bootstrap-DXbnIdm8.js";
|
|
3
11
|
import { n as withCellSpend } from "../cell-spend-zxmzg4GH.js";
|
|
4
12
|
import { t as runAgentMatrix } from "../matrix-CgpX8wdm.js";
|
|
5
13
|
import { n as MultishotFatalToolError, r as assertMultishotShotResult, t as MultishotDriverEmptyError } from "../types-DK4vNv5q.js";
|
|
6
14
|
import { mkdirSync, writeFileSync } from "node:fs";
|
|
7
15
|
import { join } from "node:path";
|
|
16
|
+
// src/multishot/conversation-conditions.ts
|
|
17
|
+
/** Paired conversations did not meet the same simulated user on the same seed. */
|
|
18
|
+
var SimulatedUserMismatchError = class extends Error {
|
|
19
|
+
mismatches;
|
|
20
|
+
constructor(mismatches) {
|
|
21
|
+
const shown = listSome(mismatches.map((row) => `${row.cellId}: ${row.detail}`), "; ");
|
|
22
|
+
super(`${mismatches.length} paired conversation(s) did not meet the same simulated user on the same seed, so the comparison is refused (${shown})`);
|
|
23
|
+
this.name = "SimulatedUserMismatchError";
|
|
24
|
+
this.mismatches = mismatches;
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
/** A score on the agent's success was asked to read a conversation whose
|
|
28
|
+
* user side was the candidate. Optimizing the user to raise the agent's
|
|
29
|
+
* success would teach it to be easy; the user side's objective is the
|
|
30
|
+
* agent's failure rate, through `improveAdversarialUser` only. */
|
|
31
|
+
var UserSideObjectiveError = class extends Error {
|
|
32
|
+
constructor(message) {
|
|
33
|
+
super(message);
|
|
34
|
+
this.name = "UserSideObjectiveError";
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
/** A scenario an adversarial-user search emitted reached a held-out split. */
|
|
38
|
+
var AdversarialScenarioInHeldOutError = class extends Error {
|
|
39
|
+
scenarioIds;
|
|
40
|
+
constructor(scenarioIds) {
|
|
41
|
+
super(`held-out split contains ${scenarioIds.length} scenario(s) an adversarial-user search emitted (${listSome(scenarioIds)}); they train the agent side and never measure it`);
|
|
42
|
+
this.name = "AdversarialScenarioInHeldOutError";
|
|
43
|
+
this.scenarioIds = scenarioIds;
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
/**
|
|
47
|
+
* Refuse a comparison whose paired conversations (same cell id) met different
|
|
48
|
+
* simulated users or ran on different seeds, or carry no identity to show it.
|
|
49
|
+
*/
|
|
50
|
+
function assertSameSimulatedUser(baseline, candidate) {
|
|
51
|
+
const mismatches = [];
|
|
52
|
+
for (const [cellId, other] of candidate) {
|
|
53
|
+
const base = baseline.get(cellId);
|
|
54
|
+
if (base === void 0) continue;
|
|
55
|
+
const missing = ["baseline", "candidate"].filter((arm) => !hasIdentity(arm === "baseline" ? base : other));
|
|
56
|
+
if (missing.length > 0) mismatches.push({
|
|
57
|
+
cellId,
|
|
58
|
+
reason: "missing",
|
|
59
|
+
detail: `${missing.join(" and ")} carries no simulated-user identity`
|
|
60
|
+
});
|
|
61
|
+
else if (base.simulatedUser.digest !== other.simulatedUser.digest) mismatches.push({
|
|
62
|
+
cellId,
|
|
63
|
+
reason: "simulated-user",
|
|
64
|
+
detail: `baseline user ${base.simulatedUser.digest} (${base.simulatedUser.model}), candidate user ${other.simulatedUser.digest} (${other.simulatedUser.model})`
|
|
65
|
+
});
|
|
66
|
+
else if (base.seed !== other.seed) mismatches.push({
|
|
67
|
+
cellId,
|
|
68
|
+
reason: "seed",
|
|
69
|
+
detail: `baseline seed ${base.seed}, candidate seed ${other.seed}`
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
if (mismatches.length > 0) throw new SimulatedUserMismatchError(mismatches);
|
|
73
|
+
}
|
|
74
|
+
/** The first three items, and an ellipsis when there are more. Package-internal. */
|
|
75
|
+
function listSome(items, separator = ", ") {
|
|
76
|
+
return [...items.slice(0, 3), ...items.length > 3 ? ["…"] : []].join(separator);
|
|
77
|
+
}
|
|
78
|
+
function hasIdentity(artifact) {
|
|
79
|
+
return typeof artifact?.simulatedUser?.digest === "string" && artifact.simulatedUser.digest.length > 0 && Number.isFinite(artifact.seed);
|
|
80
|
+
}
|
|
81
|
+
/** Refuse a held-out split that contains an adversarial-user scenario. Run it
|
|
82
|
+
* on the test cases of any comparison that does not go through `conversationGate`. */
|
|
83
|
+
function assertHeldOutExcludesAdversarial(scenarios) {
|
|
84
|
+
const emitted = scenarios.filter((scenario) => scenario.origin?.kind === "adversarial-user");
|
|
85
|
+
if (emitted.length > 0) throw new AdversarialScenarioInHeldOutError(emitted.map((scenario) => scenario.id));
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Score the agent side of a conversation: 0 when the code-checked outcome
|
|
89
|
+
* failed, else 1, or the semantic judge's composite when one is given. The
|
|
90
|
+
* `outcome` dimension is always the code check. Refuses a conversation whose
|
|
91
|
+
* user side was the candidate.
|
|
92
|
+
*/
|
|
93
|
+
function conversationJudge(opts = {}) {
|
|
94
|
+
const semantic = opts.semantic;
|
|
95
|
+
return {
|
|
96
|
+
name: "conversation-outcome",
|
|
97
|
+
judgeVersion: `agent-eval:conversation-outcome:v1${semantic ? `+${semantic.name}:${semantic.judgeVersion ?? "unversioned"}` : ""}`,
|
|
98
|
+
dimensions: [{
|
|
99
|
+
key: "outcome",
|
|
100
|
+
description: "1 when the code-checked outcome passed, else 0"
|
|
101
|
+
}, ...(semantic?.dimensions ?? []).filter((dimension) => dimension.key !== "outcome")],
|
|
102
|
+
score(input) {
|
|
103
|
+
if (input.artifact.optimizedRole !== "agent") throw new UserSideObjectiveError(`conversation '${input.scenario.id}' optimized the user side; the agent-success score reads agent-side conversations only, and improveAdversarialUser scores the user side on the agent's failure rate`);
|
|
104
|
+
const { passed, detail } = input.artifact.outcome;
|
|
105
|
+
if (!passed || !semantic) return {
|
|
106
|
+
dimensions: { outcome: passed ? 1 : 0 },
|
|
107
|
+
composite: passed ? 1 : 0,
|
|
108
|
+
notes: detail
|
|
109
|
+
};
|
|
110
|
+
return Promise.resolve(semantic.score(input)).then((score) => ({
|
|
111
|
+
...score,
|
|
112
|
+
dimensions: {
|
|
113
|
+
...score.dimensions,
|
|
114
|
+
outcome: 1
|
|
115
|
+
},
|
|
116
|
+
notes: `${detail}\n${score.notes}`
|
|
117
|
+
}));
|
|
118
|
+
}
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* The promotion gate for conversations: refuses a held-out split containing
|
|
123
|
+
* adversarial-user scenarios and any comparison whose arms met different
|
|
124
|
+
* simulated users or seeds, then decides with `inner`.
|
|
125
|
+
*/
|
|
126
|
+
function conversationGate(opts = {}) {
|
|
127
|
+
return {
|
|
128
|
+
name: "conversation",
|
|
129
|
+
async decide(ctx) {
|
|
130
|
+
assertHeldOutExcludesAdversarial(ctx.scenarios);
|
|
131
|
+
if (ctx.baselineArtifacts === void 0) throw new SimulatedUserMismatchError([{
|
|
132
|
+
cellId: "*",
|
|
133
|
+
reason: "missing",
|
|
134
|
+
detail: "the baseline arm carries no simulated-user identity: no baseline artifacts"
|
|
135
|
+
}]);
|
|
136
|
+
assertSameSimulatedUser(ctx.baselineArtifacts, ctx.candidateArtifacts);
|
|
137
|
+
if (ctx.neutralizedArtifacts) assertSameSimulatedUser(ctx.baselineArtifacts, ctx.neutralizedArtifacts);
|
|
138
|
+
const result = await (opts.inner ?? defaultProductionGate({
|
|
139
|
+
holdoutScenarios: ctx.scenarios,
|
|
140
|
+
deltaThreshold: opts.deltaThreshold ?? .05,
|
|
141
|
+
...opts.independentUnitByScenarioId ? { independentUnitByScenarioId: opts.independentUnitByScenarioId } : {}
|
|
142
|
+
})).decide(ctx);
|
|
143
|
+
return {
|
|
144
|
+
...result,
|
|
145
|
+
contributingGates: [{
|
|
146
|
+
name: "simulated-user-identity",
|
|
147
|
+
status: "pass",
|
|
148
|
+
detail: { pairedConversations: ctx.candidateArtifacts.size }
|
|
149
|
+
}, ...result.contributingGates]
|
|
150
|
+
};
|
|
151
|
+
}
|
|
152
|
+
};
|
|
153
|
+
}
|
|
154
|
+
// src/multishot/conversation-evidence.ts
|
|
155
|
+
const DETAIL_MAX_CHARS = 400;
|
|
156
|
+
const TOOL_RESULT_MAX_CHARS = 300;
|
|
157
|
+
/** The evidence a reflection reads for one conversation. */
|
|
158
|
+
function describeConversation(artifact) {
|
|
159
|
+
const base = {
|
|
160
|
+
outcome: {
|
|
161
|
+
passed: artifact.outcome.passed,
|
|
162
|
+
detail: excerptEvidence(artifact.outcome.detail, DETAIL_MAX_CHARS)
|
|
163
|
+
},
|
|
164
|
+
ending: {
|
|
165
|
+
kind: artifact.ending.kind,
|
|
166
|
+
turn: artifact.ending.turn
|
|
167
|
+
},
|
|
168
|
+
agentTurns: artifact.agentTurns,
|
|
169
|
+
firstPushbackTurn: artifact.pushback.determined ? artifact.pushback.firstTurn : "undetermined",
|
|
170
|
+
transcript: ""
|
|
171
|
+
};
|
|
172
|
+
const full = renderTranscript(artifact.transcript);
|
|
173
|
+
let budget = EMITTED_EVIDENCE_MAX_CHARS - JSON.stringify(base).length;
|
|
174
|
+
let evidence = {
|
|
175
|
+
...base,
|
|
176
|
+
transcript: excerptEvidence(full, Math.max(0, budget))
|
|
177
|
+
};
|
|
178
|
+
for (let length = JSON.stringify(evidence).length; length > 2e3 && budget > 0; length = JSON.stringify(evidence).length) {
|
|
179
|
+
budget -= length - EMITTED_EVIDENCE_MAX_CHARS;
|
|
180
|
+
evidence = {
|
|
181
|
+
...base,
|
|
182
|
+
transcript: excerptEvidence(full, Math.max(0, budget))
|
|
183
|
+
};
|
|
184
|
+
}
|
|
185
|
+
return evidence;
|
|
186
|
+
}
|
|
187
|
+
function renderTranscript(transcript) {
|
|
188
|
+
return transcript.map((message) => {
|
|
189
|
+
if (message.role === "tool") return `tool: ${excerptEvidence(message.content, TOOL_RESULT_MAX_CHARS)}`;
|
|
190
|
+
if (message.role === "user") return `user: ${message.content}`;
|
|
191
|
+
const calls = message.toolCalls?.map((call) => call.name) ?? [];
|
|
192
|
+
const called = calls.length > 0 ? ` [called ${calls.join(", ")}]` : "";
|
|
193
|
+
return `agent: ${message.content}${called}`;
|
|
194
|
+
}).join("\n");
|
|
195
|
+
}
|
|
8
196
|
// src/multishot/cost.ts
|
|
9
197
|
/**
|
|
10
198
|
* Rough per-model cost estimate from token counts. Underestimates Anthropic,
|
|
@@ -354,57 +542,37 @@ function openConversation(opts, meter) {
|
|
|
354
542
|
}
|
|
355
543
|
async function driverTurn(turn) {
|
|
356
544
|
const usdBefore = meter.costUsd;
|
|
357
|
-
const driverMessages = [{
|
|
358
|
-
role: "system",
|
|
359
|
-
content: driverSystemPrompt
|
|
360
|
-
}];
|
|
361
|
-
for (const msg of transcript) {
|
|
362
|
-
if (msg.role === "tool") continue;
|
|
363
|
-
const content = driverVisibleContent(msg);
|
|
364
|
-
if (!content) continue;
|
|
365
|
-
if (msg.role === "assistant") driverMessages.push({
|
|
366
|
-
role: "user",
|
|
367
|
-
content
|
|
368
|
-
});
|
|
369
|
-
else if (msg.role === "user") driverMessages.push({
|
|
370
|
-
role: "assistant",
|
|
371
|
-
content
|
|
372
|
-
});
|
|
373
|
-
}
|
|
374
545
|
const tokens = {
|
|
375
546
|
input: 0,
|
|
376
547
|
output: 0
|
|
377
548
|
};
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
})
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
const content = (message.content ?? "").trim();
|
|
391
|
-
if (content.length > 0) {
|
|
392
|
-
agentMessages.push({
|
|
393
|
-
role: "user",
|
|
394
|
-
content
|
|
395
|
-
});
|
|
396
|
-
transcript.push({
|
|
397
|
-
role: "user",
|
|
398
|
-
content
|
|
399
|
-
});
|
|
400
|
-
return {
|
|
401
|
-
content,
|
|
402
|
-
tokens,
|
|
403
|
-
usd: meter.costUsd - usdBefore
|
|
404
|
-
};
|
|
549
|
+
const content = await requestUserReply({
|
|
550
|
+
models: driverModels,
|
|
551
|
+
messages: driverViewMessages(driverSystemPrompt, transcript),
|
|
552
|
+
transport: driverTransport,
|
|
553
|
+
maxTokens: driverMaxTokens,
|
|
554
|
+
signal: opts.signal,
|
|
555
|
+
turn,
|
|
556
|
+
onResponse: (model, { usage, costUsd }) => {
|
|
557
|
+
meter.costUsd += costUsd ?? estimateMultishotCost(model, usage);
|
|
558
|
+
if (costUsd === void 0 && usage === void 0) meter.uncaptured = true;
|
|
559
|
+
tokens.input += usage?.prompt_tokens ?? 0;
|
|
560
|
+
tokens.output += usage?.completion_tokens ?? 0;
|
|
405
561
|
}
|
|
406
|
-
}
|
|
407
|
-
|
|
562
|
+
});
|
|
563
|
+
agentMessages.push({
|
|
564
|
+
role: "user",
|
|
565
|
+
content
|
|
566
|
+
});
|
|
567
|
+
transcript.push({
|
|
568
|
+
role: "user",
|
|
569
|
+
content
|
|
570
|
+
});
|
|
571
|
+
return {
|
|
572
|
+
content,
|
|
573
|
+
tokens,
|
|
574
|
+
usd: meter.costUsd - usdBefore
|
|
575
|
+
};
|
|
408
576
|
}
|
|
409
577
|
return {
|
|
410
578
|
conversation: {
|
|
@@ -421,6 +589,54 @@ function openConversation(opts, meter) {
|
|
|
421
589
|
toolCalls: () => toolCalls
|
|
422
590
|
};
|
|
423
591
|
}
|
|
592
|
+
/** The simulated user's next message. The driver must never go silent: an
|
|
593
|
+
* empty reply is retried once per model, the models are tried in order, and
|
|
594
|
+
* then `MultishotDriverEmptyError` is thrown. Every response, empty ones
|
|
595
|
+
* included, reaches `onResponse`, because every attempt was billed. The
|
|
596
|
+
* conversation loop and the realism measure both ask the simulated user
|
|
597
|
+
* through here, so a driver measured against recorded turns is sampled the
|
|
598
|
+
* way a rollout samples it. */
|
|
599
|
+
async function requestUserReply(input) {
|
|
600
|
+
for (const model of input.models) for (let attempt = 0; attempt < 2; attempt++) {
|
|
601
|
+
const response = await input.transport({
|
|
602
|
+
model,
|
|
603
|
+
messages: input.messages,
|
|
604
|
+
temperature: .9,
|
|
605
|
+
maxTokens: input.maxTokens,
|
|
606
|
+
signal: input.signal
|
|
607
|
+
});
|
|
608
|
+
input.onResponse?.(model, response);
|
|
609
|
+
const content = (response.message.content ?? "").trim();
|
|
610
|
+
if (content.length > 0) return content;
|
|
611
|
+
}
|
|
612
|
+
throw new MultishotDriverEmptyError(input.turn);
|
|
613
|
+
}
|
|
614
|
+
/** The simulated user's view of a transcript, as the driver request's
|
|
615
|
+
* messages. The agent's `assistant` messages become `user` (the agent talking
|
|
616
|
+
* TO the driver); the driver's prior `user` messages become `assistant` (its
|
|
617
|
+
* own earlier replies). Tool messages are hidden. The conversation loop and
|
|
618
|
+
* the realism measure both build the driver's request here, so a driver
|
|
619
|
+
* measured against recorded turns sees exactly what it sees in a rollout. */
|
|
620
|
+
function driverViewMessages(driverSystemPrompt, transcript) {
|
|
621
|
+
const driverMessages = [{
|
|
622
|
+
role: "system",
|
|
623
|
+
content: driverSystemPrompt
|
|
624
|
+
}];
|
|
625
|
+
for (const msg of transcript) {
|
|
626
|
+
if (msg.role === "tool") continue;
|
|
627
|
+
const content = driverVisibleContent(msg);
|
|
628
|
+
if (!content) continue;
|
|
629
|
+
if (msg.role === "assistant") driverMessages.push({
|
|
630
|
+
role: "user",
|
|
631
|
+
content
|
|
632
|
+
});
|
|
633
|
+
else if (msg.role === "user") driverMessages.push({
|
|
634
|
+
role: "assistant",
|
|
635
|
+
content
|
|
636
|
+
});
|
|
637
|
+
}
|
|
638
|
+
return driverMessages;
|
|
639
|
+
}
|
|
424
640
|
/** Silent tool-calling agent turns surface to the driver as
|
|
425
641
|
* "Agent called tools: …" so the simulated user can react to them. */
|
|
426
642
|
function driverVisibleContent(msg) {
|
|
@@ -431,6 +647,669 @@ function driverVisibleContent(msg) {
|
|
|
431
647
|
if (toolNames.length === 0) return "Agent called tools.";
|
|
432
648
|
return `Agent called ${toolNames.length === 1 ? "tool" : "tools"}: ${toolNames.join(", ")}.`;
|
|
433
649
|
}
|
|
650
|
+
// src/multishot/rollout.ts
|
|
651
|
+
const SIGNED_OFF = "[[signed-off]]";
|
|
652
|
+
const GAVE_UP = "[[gave-up]]";
|
|
653
|
+
/** Ends on `[[signed-off]]` when the user's problem is resolved and on
|
|
654
|
+
* `[[gave-up]]` when the user would stop using the service. */
|
|
655
|
+
const DEFAULT_USER_ENDING = {
|
|
656
|
+
ref: "agent-eval:user-ending-markers:v1",
|
|
657
|
+
instructions: [
|
|
658
|
+
`When your problem is resolved to your standard, end your message with ${SIGNED_OFF}.`,
|
|
659
|
+
`If you would stop using this service now because the agent is not getting anywhere, end your message with ${GAVE_UP}.`,
|
|
660
|
+
"Otherwise use neither marker."
|
|
661
|
+
].join("\n"),
|
|
662
|
+
classify(message) {
|
|
663
|
+
for (const [marker, kind] of [[SIGNED_OFF, "signed-off"], [GAVE_UP, "gave-up"]]) if (message.includes(marker)) return {
|
|
664
|
+
kind,
|
|
665
|
+
message: message.split(marker).join("").trim()
|
|
666
|
+
};
|
|
667
|
+
return { kind: "continue" };
|
|
668
|
+
}
|
|
669
|
+
};
|
|
670
|
+
/** How each rigor level asks the simulated user to push back, as
|
|
671
|
+
* `PersonaRigor` defines them. */
|
|
672
|
+
const RIGOR_STANCE = {
|
|
673
|
+
cooperative: "Your stance: a forgiving early adopter. Accept a reasonable answer and move on; push back only when the agent is clearly wrong or stuck.",
|
|
674
|
+
demanding: "Your stance: an experienced professional. Reject vague or hedged answers and ask for specifics before you accept anything.",
|
|
675
|
+
relentless: "Your stance: you are reviewing this for someone who will hold you to it. Interrogate every claim and accept nothing the agent has not defended."
|
|
676
|
+
};
|
|
677
|
+
/** Builds the simulated user from its options alone. The rollout and the
|
|
678
|
+
* realism measure both build it here, so a measured driver is the driver a
|
|
679
|
+
* rollout runs. */
|
|
680
|
+
function simulatedUserSetup(user, persona, plan) {
|
|
681
|
+
if (user.shape !== void 0 && !user.shapeRef) throw new TypeError("simulated user: a custom shape needs a shapeRef naming its callbacks");
|
|
682
|
+
const rigor = user.rigor ?? "demanding";
|
|
683
|
+
const ending = user.ending ?? DEFAULT_USER_ENDING;
|
|
684
|
+
const shape = defaultShapeFromProfile({
|
|
685
|
+
name: "agent",
|
|
686
|
+
description: user.agentDescription ?? "an AI agent"
|
|
687
|
+
}, user.shape);
|
|
688
|
+
const opener = shape.buildOpener(persona);
|
|
689
|
+
const driverSystemPrompt = [
|
|
690
|
+
shape.buildDriverSystemPrompt(persona),
|
|
691
|
+
RIGOR_STANCE[rigor],
|
|
692
|
+
ending.instructions,
|
|
693
|
+
plan ? `Your plan for this conversation:\n${plan}` : ""
|
|
694
|
+
].filter((block) => block.length > 0).join("\n\n");
|
|
695
|
+
const fields = {
|
|
696
|
+
model: user.model,
|
|
697
|
+
fallbackModels: [...user.fallbackModels ?? []],
|
|
698
|
+
rigor,
|
|
699
|
+
personaId: persona.id,
|
|
700
|
+
personaDigest: hashCanonical(jsonDocument(persona)),
|
|
701
|
+
promptDigest: hashCanonical(driverSystemPrompt),
|
|
702
|
+
openerDigest: hashCanonical(opener),
|
|
703
|
+
endingRef: ending.ref,
|
|
704
|
+
shapeRef: user.shapeRef ?? "agent-eval:default-shape",
|
|
705
|
+
maxTokens: user.maxTokens ?? 600
|
|
706
|
+
};
|
|
707
|
+
return {
|
|
708
|
+
opener,
|
|
709
|
+
driverSystemPrompt,
|
|
710
|
+
identity: {
|
|
711
|
+
digest: hashCanonical(jsonDocument(fields)),
|
|
712
|
+
...fields
|
|
713
|
+
}
|
|
714
|
+
};
|
|
715
|
+
}
|
|
716
|
+
/**
|
|
717
|
+
* Run a multishot conversation as the `agent(surface, scenario, ctx)` dispatch
|
|
718
|
+
* of `selfImprove` and `compareOptimizationMethods`. Pass `dispatchRef` along
|
|
719
|
+
* with `agent`, score with `conversationJudge`, gate with `conversationGate`
|
|
720
|
+
* and show the optimizer `describeConversation`.
|
|
721
|
+
*/
|
|
722
|
+
function multishotRollout(opts) {
|
|
723
|
+
const profileOf = opts.profile ?? textSurfaceProfile;
|
|
724
|
+
return {
|
|
725
|
+
agent: async (surface, scenario, ctx) => converse(opts, profileOf(surface, scenario), scenario, scenario.userPlan, "agent", ctx),
|
|
726
|
+
dispatchRef: rolloutDispatchRef(opts, "agent"),
|
|
727
|
+
simulatedUser: (scenario) => simulatedUserSetup(opts.user, scenario.persona, scenario.userPlan).identity
|
|
728
|
+
};
|
|
729
|
+
}
|
|
730
|
+
/** The user side of the same conversation: the agent profile is fixed and the
|
|
731
|
+
* candidate surface is the simulated user's plan. Package-internal; the only
|
|
732
|
+
* public way to optimize it is `improveAdversarialUser`, whose objective is
|
|
733
|
+
* fixed to the agent's failure rate. */
|
|
734
|
+
function userSideRollout(opts, agentProfile) {
|
|
735
|
+
return {
|
|
736
|
+
agent: async (surface, scenario, ctx) => {
|
|
737
|
+
if (typeof surface !== "string") throw new TypeError("adversarial user: the plan surface must be text");
|
|
738
|
+
return converse(opts, agentProfile, scenario, [scenario.userPlan, surface].filter(Boolean).join("\n\n"), "user", ctx);
|
|
739
|
+
},
|
|
740
|
+
dispatchRef: rolloutDispatchRef({
|
|
741
|
+
...opts,
|
|
742
|
+
profileDigest: hashCanonical(jsonDocument(agentProfile))
|
|
743
|
+
}, "user")
|
|
744
|
+
};
|
|
745
|
+
}
|
|
746
|
+
function textSurfaceProfile(surface) {
|
|
747
|
+
if (typeof surface !== "string") throw new TypeError("multishotRollout: a non-text surface needs a `profile` mapping it to an AgentProfile");
|
|
748
|
+
return {
|
|
749
|
+
name: "agent",
|
|
750
|
+
prompt: { systemPrompt: surface }
|
|
751
|
+
};
|
|
752
|
+
}
|
|
753
|
+
function rolloutDispatchRef(opts, role) {
|
|
754
|
+
const ending = opts.user.ending ?? DEFAULT_USER_ENDING;
|
|
755
|
+
return `multishot-rollout:${hashCanonical(jsonDocument({
|
|
756
|
+
role,
|
|
757
|
+
maxTurns: opts.maxTurns,
|
|
758
|
+
revision: opts.revision,
|
|
759
|
+
profileDigest: opts.profileDigest,
|
|
760
|
+
agent: {
|
|
761
|
+
model: opts.agent.model,
|
|
762
|
+
tools: opts.agent.tools ?? [],
|
|
763
|
+
maxTokens: opts.agent.maxTokens,
|
|
764
|
+
toolFollowupMaxTokens: opts.agent.toolFollowupMaxTokens,
|
|
765
|
+
maxToolDispatches: opts.agent.maxToolDispatches
|
|
766
|
+
},
|
|
767
|
+
user: {
|
|
768
|
+
model: opts.user.model,
|
|
769
|
+
fallbackModels: opts.user.fallbackModels ?? [],
|
|
770
|
+
rigor: opts.user.rigor ?? "demanding",
|
|
771
|
+
agentDescription: opts.user.agentDescription ?? "an AI agent",
|
|
772
|
+
shapeRef: opts.user.shapeRef ?? "agent-eval:default-shape",
|
|
773
|
+
maxTokens: opts.user.maxTokens ?? 600,
|
|
774
|
+
endingRef: ending.ref,
|
|
775
|
+
endingInstructions: ending.instructions
|
|
776
|
+
}
|
|
777
|
+
}))}`;
|
|
778
|
+
}
|
|
779
|
+
async function converse(opts, profile, scenario, plan, optimizedRole, ctx) {
|
|
780
|
+
if (!Number.isSafeInteger(opts.maxTurns) || opts.maxTurns < 1) throw new RangeError(`multishotRollout: maxTurns must be a positive integer, got ${opts.maxTurns}`);
|
|
781
|
+
if (opts.agent.tools === void 0 !== (opts.agent.toolExecutors === void 0)) throw new TypeError("multishotRollout: agent tools and toolExecutors go together");
|
|
782
|
+
const user = simulatedUserSetup(opts.user, scenario.persona, plan);
|
|
783
|
+
const ending = opts.user.ending ?? DEFAULT_USER_ENDING;
|
|
784
|
+
const metered = (leg, channel, actor, transport) => {
|
|
785
|
+
return async (req) => {
|
|
786
|
+
const { tools, signal, ...rest } = req;
|
|
787
|
+
const request = {
|
|
788
|
+
...rest,
|
|
789
|
+
...tools && tools.length > 0 ? { tools } : {},
|
|
790
|
+
seed: ctx.seed
|
|
791
|
+
};
|
|
792
|
+
const maximumCharge = opts.maximumCharge?.(leg, request);
|
|
793
|
+
const result = await ctx.cost.runPaidCall({
|
|
794
|
+
channel,
|
|
795
|
+
actor,
|
|
796
|
+
model: request.model,
|
|
797
|
+
signal: signal ?? ctx.signal,
|
|
798
|
+
...maximumCharge === void 0 ? {} : { maximumCharge },
|
|
799
|
+
execute: (callSignal) => transport({
|
|
800
|
+
...request,
|
|
801
|
+
signal: callSignal
|
|
802
|
+
}),
|
|
803
|
+
receipt: (response) => legReceipt(request.model, response)
|
|
804
|
+
});
|
|
805
|
+
if (!result.succeeded) throw result.error;
|
|
806
|
+
return result.value;
|
|
807
|
+
};
|
|
808
|
+
};
|
|
809
|
+
const close = {};
|
|
810
|
+
const result = await runMultishotConversation({
|
|
811
|
+
profile,
|
|
812
|
+
persona: scenario.persona,
|
|
813
|
+
shape: {
|
|
814
|
+
buildOpener: () => user.opener,
|
|
815
|
+
buildDriverSystemPrompt: () => user.driverSystemPrompt
|
|
816
|
+
},
|
|
817
|
+
tools: opts.agent.tools ?? [],
|
|
818
|
+
toolExecutors: opts.agent.toolExecutors ?? {},
|
|
819
|
+
artifactTypeFor: opts.agent.artifactTypeFor,
|
|
820
|
+
maxTurns: opts.maxTurns,
|
|
821
|
+
agentModel: opts.agent.model,
|
|
822
|
+
driverModel: opts.user.model,
|
|
823
|
+
driverFallbackModels: opts.user.fallbackModels,
|
|
824
|
+
agentMaxTokens: opts.agent.maxTokens,
|
|
825
|
+
toolFollowupMaxTokens: opts.agent.toolFollowupMaxTokens,
|
|
826
|
+
driverMaxTokens: user.identity.maxTokens,
|
|
827
|
+
maxToolDispatches: opts.agent.maxToolDispatches,
|
|
828
|
+
agentTransport: metered("agent", "agent", "agent", opts.agent.transport),
|
|
829
|
+
driverTransport: metered("user", "driver", "simulated-user", opts.user.transport),
|
|
830
|
+
toolTransport: metered("tool", "agent", "tool", opts.agent.toolTransport ?? opts.agent.transport),
|
|
831
|
+
signal: ctx.signal
|
|
832
|
+
}, async (conversation) => {
|
|
833
|
+
for (let turn = 0; turn < conversation.maxTurns; turn++) {
|
|
834
|
+
await conversation.agentTurn(turn);
|
|
835
|
+
if (turn === conversation.maxTurns - 1) {
|
|
836
|
+
close.ending = {
|
|
837
|
+
kind: "turn-cap",
|
|
838
|
+
turn
|
|
839
|
+
};
|
|
840
|
+
return;
|
|
841
|
+
}
|
|
842
|
+
const { content } = await conversation.driverTurn(turn);
|
|
843
|
+
const classified = ending.classify(content);
|
|
844
|
+
if (classified.kind !== "continue") {
|
|
845
|
+
close.ending = {
|
|
846
|
+
kind: classified.kind,
|
|
847
|
+
turn
|
|
848
|
+
};
|
|
849
|
+
close.message = classified.message;
|
|
850
|
+
return;
|
|
851
|
+
}
|
|
852
|
+
}
|
|
853
|
+
});
|
|
854
|
+
const ended = close.ending;
|
|
855
|
+
if (ended === void 0) throw new Error("multishotRollout: the conversation never ended");
|
|
856
|
+
const transcript = result.transcript.map((message) => ({ ...message }));
|
|
857
|
+
if (close.message !== void 0) transcript[transcript.length - 1].content = close.message;
|
|
858
|
+
const userMessages = transcript.filter((message) => message.role === "user").slice(1);
|
|
859
|
+
const firstPushback = opts.user.pushback ? userMessages.findIndex((message) => opts.user.pushback(message.content)) : void 0;
|
|
860
|
+
const record = {
|
|
861
|
+
transcript,
|
|
862
|
+
artifacts: result.artifacts,
|
|
863
|
+
ending: ended
|
|
864
|
+
};
|
|
865
|
+
const outcome = opts.outcome(record, scenario);
|
|
866
|
+
if (typeof outcome?.passed !== "boolean" || typeof outcome.detail !== "string") throw new TypeError("multishotRollout: outcome must return { passed: boolean, detail: string }");
|
|
867
|
+
return {
|
|
868
|
+
transcript,
|
|
869
|
+
artifacts: result.artifacts,
|
|
870
|
+
toolCalls: result.toolCalls,
|
|
871
|
+
agentTurns: ended.turn + 1,
|
|
872
|
+
ending: ended,
|
|
873
|
+
outcome: {
|
|
874
|
+
passed: outcome.passed,
|
|
875
|
+
detail: outcome.detail
|
|
876
|
+
},
|
|
877
|
+
pushback: firstPushback === void 0 ? { determined: false } : {
|
|
878
|
+
determined: true,
|
|
879
|
+
firstTurn: firstPushback < 0 ? null : firstPushback
|
|
880
|
+
},
|
|
881
|
+
simulatedUser: user.identity,
|
|
882
|
+
seed: ctx.seed,
|
|
883
|
+
optimizedRole
|
|
884
|
+
};
|
|
885
|
+
}
|
|
886
|
+
function legReceipt(requested, response) {
|
|
887
|
+
const usage = response.usage;
|
|
888
|
+
return {
|
|
889
|
+
model: response.model ?? requested,
|
|
890
|
+
inputTokens: usage?.prompt_tokens ?? 0,
|
|
891
|
+
outputTokens: usage?.completion_tokens ?? 0,
|
|
892
|
+
...usage === void 0 ? { usageUnknown: true } : {},
|
|
893
|
+
...response.costUsd === void 0 ? {} : { actualCostUsd: response.costUsd }
|
|
894
|
+
};
|
|
895
|
+
}
|
|
896
|
+
// src/multishot/realism.ts
|
|
897
|
+
/** The shared-context identity of a user turn: its task and visible context. */
|
|
898
|
+
function userTurnContextDigest(input) {
|
|
899
|
+
return hashCanonical(jsonDocument({
|
|
900
|
+
taskId: input.taskId,
|
|
901
|
+
context: input.context
|
|
902
|
+
}));
|
|
903
|
+
}
|
|
904
|
+
/**
|
|
905
|
+
* The real user turns of one recorded conversation, from its trajectory: each
|
|
906
|
+
* model call whose input ends in a user message that answers an agent message
|
|
907
|
+
* is one turn. System and tool messages are not part of what the user saw. A
|
|
908
|
+
* run without a task identity yields rows without a context digest.
|
|
909
|
+
*/
|
|
910
|
+
function recordedUserTurns(trajectory, run) {
|
|
911
|
+
const taskId = runTaskId(run);
|
|
912
|
+
const turns = [];
|
|
913
|
+
const seen = /* @__PURE__ */ new Set();
|
|
914
|
+
for (const step of trajectory.steps) {
|
|
915
|
+
const span = step.span;
|
|
916
|
+
if (span.kind !== "llm") continue;
|
|
917
|
+
const last = span.messages.at(-1);
|
|
918
|
+
if (last?.role !== "user" || last.content.trim().length === 0) continue;
|
|
919
|
+
const context = span.messages.slice(0, -1).filter((message) => (message.role === "user" || message.role === "assistant") && message.content.trim().length > 0).map((message) => ({
|
|
920
|
+
role: message.role,
|
|
921
|
+
content: message.content
|
|
922
|
+
}));
|
|
923
|
+
if (context.at(-1)?.role !== "assistant") continue;
|
|
924
|
+
const turn = context.filter((message) => message.role === "user").length;
|
|
925
|
+
if (seen.has(turn)) continue;
|
|
926
|
+
seen.add(turn);
|
|
927
|
+
turns.push({
|
|
928
|
+
conversationId: trajectory.runId,
|
|
929
|
+
...taskId === void 0 ? {} : {
|
|
930
|
+
taskId,
|
|
931
|
+
contextDigest: userTurnContextDigest({
|
|
932
|
+
taskId,
|
|
933
|
+
context
|
|
934
|
+
})
|
|
935
|
+
},
|
|
936
|
+
turn,
|
|
937
|
+
context,
|
|
938
|
+
realMessage: last.content,
|
|
939
|
+
evidenceRefs: [{
|
|
940
|
+
kind: "span",
|
|
941
|
+
uri: span.spanId
|
|
942
|
+
}]
|
|
943
|
+
});
|
|
944
|
+
}
|
|
945
|
+
return turns;
|
|
946
|
+
}
|
|
947
|
+
/** A recorded turn carries no proof of a shared context, or a proof its
|
|
948
|
+
* context does not match. */
|
|
949
|
+
var SharedContextIdentityError = class extends Error {
|
|
950
|
+
conversationId;
|
|
951
|
+
turn;
|
|
952
|
+
constructor(row, reason) {
|
|
953
|
+
super(`recorded user turn ${row.conversationId}#${row.turn} ${reason}; a realism comparison needs the identity that proves the driver saw the real user's context`);
|
|
954
|
+
this.name = "SharedContextIdentityError";
|
|
955
|
+
this.conversationId = row.conversationId;
|
|
956
|
+
this.turn = row.turn;
|
|
957
|
+
}
|
|
958
|
+
};
|
|
959
|
+
function assertSharedContext(row) {
|
|
960
|
+
if (!row.taskId || !row.contextDigest) throw new SharedContextIdentityError(row, "has no task identity and context digest");
|
|
961
|
+
if (userTurnContextDigest({
|
|
962
|
+
taskId: row.taskId,
|
|
963
|
+
context: row.context
|
|
964
|
+
}) !== row.contextDigest) throw new SharedContextIdentityError(row, "has a context digest its context does not match");
|
|
965
|
+
}
|
|
966
|
+
/**
|
|
967
|
+
* The simulated user a rollout runs, as a realism driver: the same prompt,
|
|
968
|
+
* the same driver point of view on the recorded context, the same model
|
|
969
|
+
* rotation. An ending marker is removed, as a rollout removes it.
|
|
970
|
+
*/
|
|
971
|
+
function simulatedUserDriver(opts) {
|
|
972
|
+
const ending = opts.user.ending ?? DEFAULT_USER_ENDING;
|
|
973
|
+
const models = [opts.user.model, ...opts.user.fallbackModels ?? []];
|
|
974
|
+
return {
|
|
975
|
+
identity: `simulated-user:${hashCanonical(jsonDocument({
|
|
976
|
+
models,
|
|
977
|
+
rigor: opts.user.rigor ?? "demanding",
|
|
978
|
+
agentDescription: opts.user.agentDescription ?? "an AI agent",
|
|
979
|
+
shapeRef: opts.user.shapeRef ?? "agent-eval:default-shape",
|
|
980
|
+
maxTokens: opts.user.maxTokens ?? 600,
|
|
981
|
+
endingRef: ending.ref,
|
|
982
|
+
endingInstructions: ending.instructions,
|
|
983
|
+
plan: opts.plan
|
|
984
|
+
}))}`,
|
|
985
|
+
async next({ turn, signal, costLedger }) {
|
|
986
|
+
const setup = simulatedUserSetup(opts.user, opts.persona(turn), opts.plan);
|
|
987
|
+
const messages = driverViewMessages(setup.driverSystemPrompt, turn.context);
|
|
988
|
+
const transport = costLedger ? async (req) => {
|
|
989
|
+
const result = await costLedger.runPaidCall({
|
|
990
|
+
channel: "driver",
|
|
991
|
+
phase: "realism.driver",
|
|
992
|
+
actor: "simulated-user",
|
|
993
|
+
model: req.model,
|
|
994
|
+
signal: req.signal,
|
|
995
|
+
execute: (callSignal) => opts.user.transport({
|
|
996
|
+
...req,
|
|
997
|
+
signal: callSignal
|
|
998
|
+
}),
|
|
999
|
+
receipt: (response) => ({
|
|
1000
|
+
model: response.model ?? req.model,
|
|
1001
|
+
inputTokens: response.usage?.prompt_tokens ?? 0,
|
|
1002
|
+
outputTokens: response.usage?.completion_tokens ?? 0,
|
|
1003
|
+
...response.usage === void 0 ? { usageUnknown: true } : {},
|
|
1004
|
+
...response.costUsd === void 0 ? {} : { actualCostUsd: response.costUsd }
|
|
1005
|
+
})
|
|
1006
|
+
});
|
|
1007
|
+
if (!result.succeeded) throw result.error;
|
|
1008
|
+
return result.value;
|
|
1009
|
+
} : opts.user.transport;
|
|
1010
|
+
const content = await requestUserReply({
|
|
1011
|
+
models,
|
|
1012
|
+
messages,
|
|
1013
|
+
transport,
|
|
1014
|
+
maxTokens: setup.identity.maxTokens,
|
|
1015
|
+
signal,
|
|
1016
|
+
turn: turn.turn
|
|
1017
|
+
});
|
|
1018
|
+
const classified = ending.classify(content);
|
|
1019
|
+
return classified.kind === "continue" ? content : classified.message;
|
|
1020
|
+
}
|
|
1021
|
+
};
|
|
1022
|
+
}
|
|
1023
|
+
/** The realism question: which of two messages did the real user write. */
|
|
1024
|
+
const SIMULATOR_REALISM_QUESTIONS = { real: {
|
|
1025
|
+
type: "choice",
|
|
1026
|
+
instructions: "The state holds a conversation between a user and an AI agent up to the user's next message, and two candidate next messages, a and b. A real user wrote one; a simulator wrote the other. Choose the one the real user wrote. Judge voice, length, specificity, what the user would know, and how a person reacts to the agent's last message. Neither position is more likely.",
|
|
1027
|
+
criteria: {
|
|
1028
|
+
a: "The real user wrote message a.",
|
|
1029
|
+
b: "The real user wrote message b."
|
|
1030
|
+
}
|
|
1031
|
+
} };
|
|
1032
|
+
/** The realism judge as a System One decision point at the turn layer. */
|
|
1033
|
+
function simulatorRealismJudge(opts) {
|
|
1034
|
+
const questionDigest = decisionQuestionDigest({
|
|
1035
|
+
id: opts.id,
|
|
1036
|
+
version: opts.version,
|
|
1037
|
+
model: opts.model,
|
|
1038
|
+
servedModel: opts.calibration?.servedModel ?? opts.model,
|
|
1039
|
+
name: "real",
|
|
1040
|
+
question: SIMULATOR_REALISM_QUESTIONS.real
|
|
1041
|
+
});
|
|
1042
|
+
const point = decisionPoint({
|
|
1043
|
+
id: opts.id,
|
|
1044
|
+
version: opts.version,
|
|
1045
|
+
layers: ["turn"],
|
|
1046
|
+
model: opts.model,
|
|
1047
|
+
questions: SIMULATOR_REALISM_QUESTIONS,
|
|
1048
|
+
policy: { real: {
|
|
1049
|
+
minimumProbability: opts.minimumProbability ?? .6,
|
|
1050
|
+
minimumMargin: opts.minimumMargin ?? .2,
|
|
1051
|
+
options: {
|
|
1052
|
+
a: { action: "record" },
|
|
1053
|
+
b: { action: "record" }
|
|
1054
|
+
},
|
|
1055
|
+
...opts.calibration ? { calibration: opts.calibration } : {}
|
|
1056
|
+
} },
|
|
1057
|
+
ledger: opts.ledger,
|
|
1058
|
+
evaluator: opts.evaluator
|
|
1059
|
+
});
|
|
1060
|
+
return {
|
|
1061
|
+
id: point.id,
|
|
1062
|
+
definitionDigest: point.definitionDigest,
|
|
1063
|
+
questionDigest,
|
|
1064
|
+
calibrated: opts.calibration !== void 0 && opts.calibration.kappa >= .77 && opts.calibration.questionDigest === questionDigest,
|
|
1065
|
+
decide: point.decide
|
|
1066
|
+
};
|
|
1067
|
+
}
|
|
1068
|
+
/** Measure how often a judge tells the driver's message from the real user's. */
|
|
1069
|
+
async function measureSimulatorRealism(opts) {
|
|
1070
|
+
if (opts.turns.length === 0) throw new RangeError("measureSimulatorRealism: no recorded turns");
|
|
1071
|
+
for (const row of opts.turns) assertSharedContext(row);
|
|
1072
|
+
const at = opts.at ?? (/* @__PURE__ */ new Date()).toISOString();
|
|
1073
|
+
const turns = sampleTurns(opts.turns, opts.sample, opts.seed);
|
|
1074
|
+
const correctByConversation = /* @__PURE__ */ new Map();
|
|
1075
|
+
const reasons = {};
|
|
1076
|
+
const probabilitiesOnReal = [];
|
|
1077
|
+
let failedJudgments = 0;
|
|
1078
|
+
for (const row of turns) {
|
|
1079
|
+
const simulated = await opts.driver.next({
|
|
1080
|
+
turn: row,
|
|
1081
|
+
...opts.signal ? { signal: opts.signal } : {},
|
|
1082
|
+
...opts.costLedger ? { costLedger: opts.costLedger } : {}
|
|
1083
|
+
});
|
|
1084
|
+
for (const order of ["real-first", "real-second"]) {
|
|
1085
|
+
const realOption = order === "real-first" ? "a" : "b";
|
|
1086
|
+
const unit = `${row.conversationId}:${row.turn}`;
|
|
1087
|
+
const answer = judgedAnswer(await opts.judge.decide({
|
|
1088
|
+
runId: opts.runId,
|
|
1089
|
+
invocationId: `${unit}:${order}`,
|
|
1090
|
+
layer: "turn",
|
|
1091
|
+
consumer: "simulator-realism",
|
|
1092
|
+
state: {
|
|
1093
|
+
context: row.context,
|
|
1094
|
+
a: order === "real-first" ? row.realMessage : simulated,
|
|
1095
|
+
b: order === "real-first" ? simulated : row.realMessage
|
|
1096
|
+
},
|
|
1097
|
+
scope: {
|
|
1098
|
+
population: [unit],
|
|
1099
|
+
n: 1,
|
|
1100
|
+
window: {
|
|
1101
|
+
from: at,
|
|
1102
|
+
to: at
|
|
1103
|
+
}
|
|
1104
|
+
},
|
|
1105
|
+
at,
|
|
1106
|
+
evidenceRefs: row.evidenceRefs?.length ? row.evidenceRefs : [{
|
|
1107
|
+
kind: "event",
|
|
1108
|
+
uri: `user-turn:${unit}`
|
|
1109
|
+
}]
|
|
1110
|
+
}, {
|
|
1111
|
+
...opts.signal ? { signal: opts.signal } : {},
|
|
1112
|
+
...opts.costLedger ? { costLedger: opts.costLedger } : {},
|
|
1113
|
+
channel: "judge",
|
|
1114
|
+
actor: "simulator-realism-judge",
|
|
1115
|
+
costPhase: "realism.judge"
|
|
1116
|
+
}));
|
|
1117
|
+
if (!answer) {
|
|
1118
|
+
failedJudgments += 1;
|
|
1119
|
+
continue;
|
|
1120
|
+
}
|
|
1121
|
+
reasons[answer.reason] = (reasons[answer.reason] ?? 0) + 1;
|
|
1122
|
+
probabilitiesOnReal.push(answer.probabilities[realOption] ?? 0);
|
|
1123
|
+
const list = correctByConversation.get(row.conversationId) ?? [];
|
|
1124
|
+
list.push(answer.choice === realOption ? 1 : 0);
|
|
1125
|
+
correctByConversation.set(row.conversationId, list);
|
|
1126
|
+
}
|
|
1127
|
+
}
|
|
1128
|
+
if (correctByConversation.size === 0) throw new Error("measureSimulatorRealism: no presentation was judged");
|
|
1129
|
+
const interval = clusterBootstrapMean([...correctByConversation].map(([conversationId, list]) => ({
|
|
1130
|
+
cluster: conversationId,
|
|
1131
|
+
value: list.reduce((sum, value) => sum + value, 0) / list.length
|
|
1132
|
+
})), {
|
|
1133
|
+
...opts.confidence === void 0 ? {} : { confidence: opts.confidence },
|
|
1134
|
+
...opts.resamples === void 0 ? {} : { resamples: opts.resamples },
|
|
1135
|
+
...opts.seed === void 0 ? {} : { seed: opts.seed }
|
|
1136
|
+
});
|
|
1137
|
+
const onCalibratedModel = Object.keys(reasons).every((reason) => reason === "threshold" || reason === "uncertain");
|
|
1138
|
+
return {
|
|
1139
|
+
driver: opts.driver.identity,
|
|
1140
|
+
judge: {
|
|
1141
|
+
id: opts.judge.id,
|
|
1142
|
+
definitionDigest: opts.judge.definitionDigest,
|
|
1143
|
+
calibrated: opts.judge.calibrated && onCalibratedModel,
|
|
1144
|
+
reasons
|
|
1145
|
+
},
|
|
1146
|
+
conversations: correctByConversation.size,
|
|
1147
|
+
turns: turns.length,
|
|
1148
|
+
presentations: probabilitiesOnReal.length,
|
|
1149
|
+
failedJudgments,
|
|
1150
|
+
accuracy: {
|
|
1151
|
+
mean: interval.mean,
|
|
1152
|
+
low: interval.low,
|
|
1153
|
+
high: interval.high,
|
|
1154
|
+
confidence: interval.confidence,
|
|
1155
|
+
resamples: interval.resamples
|
|
1156
|
+
},
|
|
1157
|
+
meanProbabilityOnReal: probabilitiesOnReal.reduce((sum, value) => sum + value, 0) / probabilitiesOnReal.length,
|
|
1158
|
+
indistinguishable: interval.low <= .5 && interval.high >= .5
|
|
1159
|
+
};
|
|
1160
|
+
}
|
|
1161
|
+
function judgedAnswer(judged) {
|
|
1162
|
+
if (!judged.succeeded) return void 0;
|
|
1163
|
+
const record = judged.value.record;
|
|
1164
|
+
if (!record || record.error) return void 0;
|
|
1165
|
+
return record.answers.real;
|
|
1166
|
+
}
|
|
1167
|
+
function sampleTurns(turns, sample, seed) {
|
|
1168
|
+
if (sample === void 0 || sample >= turns.length) return [...turns];
|
|
1169
|
+
if (!Number.isSafeInteger(sample) || sample < 1) throw new RangeError(`measureSimulatorRealism: sample must be a positive integer, got ${sample}`);
|
|
1170
|
+
const random = makeRng(seed ?? 0);
|
|
1171
|
+
const order = turns.map((_, index) => index);
|
|
1172
|
+
for (let index = order.length - 1; index > 0; index--) {
|
|
1173
|
+
const swap = Math.floor(random() * (index + 1));
|
|
1174
|
+
[order[index], order[swap]] = [order[swap], order[index]];
|
|
1175
|
+
}
|
|
1176
|
+
return order.slice(0, sample).sort((left, right) => left - right).map((index) => turns[index]);
|
|
1177
|
+
}
|
|
1178
|
+
// src/multishot/adversarial-user.ts
|
|
1179
|
+
/** Scenarios for the user-side search would reach the agent's held-out split. */
|
|
1180
|
+
var AdversarialSplitError = class extends Error {
|
|
1181
|
+
scenarioIds;
|
|
1182
|
+
constructor(scenarioIds) {
|
|
1183
|
+
super(`adversarial user search would use ${scenarioIds.length} scenario(s) that share an id or persona with the agent's held-out split (${listSome(scenarioIds)})`);
|
|
1184
|
+
this.name = "AdversarialSplitError";
|
|
1185
|
+
this.scenarioIds = scenarioIds;
|
|
1186
|
+
}
|
|
1187
|
+
};
|
|
1188
|
+
/**
|
|
1189
|
+
* Search for a simulated-user plan that makes a fixed agent fail, admit it
|
|
1190
|
+
* only above a realism floor, and emit what it breaks as agent train scenarios.
|
|
1191
|
+
*/
|
|
1192
|
+
async function improveAdversarialUser(opts) {
|
|
1193
|
+
if ("judge" in opts || "gate" in opts) throw new UserSideObjectiveError("improveAdversarialUser: the user side's objective is the agent's failure rate; it accepts no judge or gate");
|
|
1194
|
+
if (!(opts.realism.maxJudgeAccuracy >= .5 && opts.realism.maxJudgeAccuracy <= 1)) throw new RangeError("improveAdversarialUser: realism.maxJudgeAccuracy must be in [0.5, 1]");
|
|
1195
|
+
assertDisjointFromHeldOut([...opts.scenarios, ...opts.selectionScenarios ?? []], opts.agentHeldOut);
|
|
1196
|
+
const rollout = userSideRollout(opts.rollout, opts.agentProfile);
|
|
1197
|
+
const shared = {
|
|
1198
|
+
agent: rollout.agent,
|
|
1199
|
+
dispatchRef: rollout.dispatchRef,
|
|
1200
|
+
scenarios: opts.scenarios,
|
|
1201
|
+
judge: agentFailureJudge(),
|
|
1202
|
+
describeArtifact: describeConversation,
|
|
1203
|
+
baselineSurface: opts.baselinePlan,
|
|
1204
|
+
...opts.selectionScenarios ? { selectionScenarios: opts.selectionScenarios } : {},
|
|
1205
|
+
...opts.budget ? { budget: opts.budget } : {},
|
|
1206
|
+
...opts.runDir ? { runDir: opts.runDir } : {},
|
|
1207
|
+
...opts.storage ? { storage: opts.storage } : {},
|
|
1208
|
+
...opts.expectUsage ? { expectUsage: opts.expectUsage } : {},
|
|
1209
|
+
...opts.model ? { model: opts.model } : {}
|
|
1210
|
+
};
|
|
1211
|
+
const improvement = opts.method ? await selfImprove({
|
|
1212
|
+
...shared,
|
|
1213
|
+
method: opts.method
|
|
1214
|
+
}) : await selfImprove({
|
|
1215
|
+
...shared,
|
|
1216
|
+
...opts.proposer ? { proposer: opts.proposer } : {}
|
|
1217
|
+
});
|
|
1218
|
+
const plan = String(improvement.winner.surface);
|
|
1219
|
+
if (improvement.gateDecision !== "ship") return {
|
|
1220
|
+
improvement,
|
|
1221
|
+
plan,
|
|
1222
|
+
realism: null,
|
|
1223
|
+
admitted: false,
|
|
1224
|
+
reasons: [`the user-side search did not ship (${improvement.gateDecision})`],
|
|
1225
|
+
trainScenarios: []
|
|
1226
|
+
};
|
|
1227
|
+
const realism = await measureSimulatorRealism({
|
|
1228
|
+
turns: opts.realism.turns,
|
|
1229
|
+
driver: simulatedUserDriver({
|
|
1230
|
+
user: opts.rollout.user,
|
|
1231
|
+
persona: opts.realism.persona,
|
|
1232
|
+
plan
|
|
1233
|
+
}),
|
|
1234
|
+
judge: opts.realism.judge,
|
|
1235
|
+
runId: opts.realism.runId,
|
|
1236
|
+
...pick(opts.realism, [
|
|
1237
|
+
"at",
|
|
1238
|
+
"sample",
|
|
1239
|
+
"confidence",
|
|
1240
|
+
"resamples",
|
|
1241
|
+
"seed",
|
|
1242
|
+
"costLedger"
|
|
1243
|
+
])
|
|
1244
|
+
});
|
|
1245
|
+
const reasons = [];
|
|
1246
|
+
if (!realism.judge.calibrated) reasons.push("realism judge is not calibrated on this question and served model; a plan is admitted only by a calibrated judge");
|
|
1247
|
+
if (realism.accuracy.high > opts.realism.maxJudgeAccuracy) reasons.push(`realism: judge accuracy reaches ${realism.accuracy.high.toFixed(3)} at the interval's upper end, above the floor ${opts.realism.maxJudgeAccuracy}`);
|
|
1248
|
+
const admitted = reasons.length === 0;
|
|
1249
|
+
return {
|
|
1250
|
+
improvement,
|
|
1251
|
+
plan,
|
|
1252
|
+
realism,
|
|
1253
|
+
admitted,
|
|
1254
|
+
reasons,
|
|
1255
|
+
trainScenarios: admitted ? emittedScenarios(improvement, opts.scenarios, plan) : []
|
|
1256
|
+
};
|
|
1257
|
+
}
|
|
1258
|
+
/** Score of the user side: 1 when the agent failed the outcome check. */
|
|
1259
|
+
function agentFailureJudge() {
|
|
1260
|
+
return {
|
|
1261
|
+
name: "agent-failure",
|
|
1262
|
+
judgeVersion: "agent-eval:agent-failure:v1",
|
|
1263
|
+
dimensions: [{
|
|
1264
|
+
key: "agent_failure",
|
|
1265
|
+
description: "1 when the agent failed the code-checked outcome"
|
|
1266
|
+
}],
|
|
1267
|
+
score({ artifact }) {
|
|
1268
|
+
if (artifact.optimizedRole !== "user") throw new UserSideObjectiveError("agent-failure scores user-side conversations only");
|
|
1269
|
+
const failed = artifact.outcome.passed ? 0 : 1;
|
|
1270
|
+
return {
|
|
1271
|
+
dimensions: { agent_failure: failed },
|
|
1272
|
+
composite: failed,
|
|
1273
|
+
notes: artifact.outcome.detail
|
|
1274
|
+
};
|
|
1275
|
+
}
|
|
1276
|
+
};
|
|
1277
|
+
}
|
|
1278
|
+
function assertDisjointFromHeldOut(scenarios, heldOut) {
|
|
1279
|
+
const ids = new Set(heldOut.map((scenario) => scenario.id));
|
|
1280
|
+
const personas = new Set(heldOut.map((scenario) => personaDigest(scenario)));
|
|
1281
|
+
const overlap = scenarios.filter((scenario) => ids.has(scenario.id) || personas.has(personaDigest(scenario))).map((scenario) => scenario.id);
|
|
1282
|
+
if (overlap.length > 0) throw new AdversarialSplitError([...new Set(overlap)]);
|
|
1283
|
+
}
|
|
1284
|
+
function personaDigest(scenario) {
|
|
1285
|
+
return hashCanonical(jsonDocument(scenario.persona));
|
|
1286
|
+
}
|
|
1287
|
+
function emittedScenarios(improvement, scenarios, plan) {
|
|
1288
|
+
const planDigest = hashCanonical(plan);
|
|
1289
|
+
const emitted = /* @__PURE__ */ new Map();
|
|
1290
|
+
for (const cell of improvement.raw.winnerOnHoldout.cells) {
|
|
1291
|
+
if (cell.error !== void 0 || cell.artifact.outcome.passed) continue;
|
|
1292
|
+
if (emitted.has(cell.scenarioId)) continue;
|
|
1293
|
+
const source = scenarios.find((scenario) => scenario.id === cell.scenarioId);
|
|
1294
|
+
if (!source) continue;
|
|
1295
|
+
emitted.set(cell.scenarioId, {
|
|
1296
|
+
...structuredClone(source),
|
|
1297
|
+
id: `${source.id}~adversarial-${planDigest.slice(7, 19)}`,
|
|
1298
|
+
userPlan: [source.userPlan, plan].filter(Boolean).join("\n\n"),
|
|
1299
|
+
origin: {
|
|
1300
|
+
kind: "adversarial-user",
|
|
1301
|
+
sourceScenarioId: source.id,
|
|
1302
|
+
planDigest
|
|
1303
|
+
}
|
|
1304
|
+
});
|
|
1305
|
+
}
|
|
1306
|
+
return [...emitted.values()];
|
|
1307
|
+
}
|
|
1308
|
+
function pick(value, keys) {
|
|
1309
|
+
const picked = {};
|
|
1310
|
+
for (const key of keys) if (value[key] !== void 0) picked[key] = value[key];
|
|
1311
|
+
return picked;
|
|
1312
|
+
}
|
|
434
1313
|
// src/multishot/judges.ts
|
|
435
1314
|
async function runJudge(judge, input) {
|
|
436
1315
|
const model = judge.model ?? "zai/glm-5.3";
|
|
@@ -824,6 +1703,6 @@ function withJudgeMaxTokens(judge, maxTokens) {
|
|
|
824
1703
|
maxTokens
|
|
825
1704
|
};
|
|
826
1705
|
}
|
|
827
|
-
export { DEFAULT_CODER_MODEL, DEFAULT_JUDGE_MODEL, MultishotDriverEmptyError, MultishotFatalToolError, assertMultishotShotResult, computeCellComposite, defaultDelegationTools, defaultShapeFromProfile, estimateMultishotCost, renderDimensions, renderJsonFooter, runJudge, runMultishot, runMultishotConversation, runMultishotMatrix };
|
|
1706
|
+
export { AdversarialScenarioInHeldOutError, AdversarialSplitError, DEFAULT_CODER_MODEL, DEFAULT_JUDGE_MODEL, DEFAULT_USER_ENDING, MultishotDriverEmptyError, MultishotFatalToolError, SIMULATOR_REALISM_QUESTIONS, SharedContextIdentityError, SimulatedUserMismatchError, UserSideObjectiveError, assertHeldOutExcludesAdversarial, assertMultishotShotResult, assertSameSimulatedUser, computeCellComposite, conversationGate, conversationJudge, defaultDelegationTools, defaultShapeFromProfile, describeConversation, estimateMultishotCost, improveAdversarialUser, measureSimulatorRealism, multishotRollout, recordedUserTurns, renderDimensions, renderJsonFooter, runJudge, runMultishot, runMultishotConversation, runMultishotMatrix, simulatedUserDriver, simulatorRealismJudge, userTurnContextDigest };
|
|
828
1707
|
|
|
829
1708
|
//# sourceMappingURL=index.js.map
|