agentengine-sdk-python 0.8.8__py3-none-any.whl → 0.8.9__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.
- {agentengine_sdk_python-0.8.8.dist-info → agentengine_sdk_python-0.8.9.dist-info}/METADATA +12 -15
- {agentengine_sdk_python-0.8.8.dist-info → agentengine_sdk_python-0.8.9.dist-info}/RECORD +181 -173
- ksadk/_build_provenance.json +1 -1
- ksadk/agui/agent.py +1 -1
- ksadk/builders/framework_requirements.py +1 -1
- ksadk/cli/cmd_run.py +4 -0
- ksadk/cli/cmd_web.py +4 -0
- ksadk/cli/runtime_logging.py +30 -0
- ksadk/context_engine/capabilities.py +13 -9
- ksadk/conversations/context.py +5 -0
- ksadk/conversations/message_projection.py +28 -19
- ksadk/conversations/runtime_compaction.py +6 -2
- ksadk/conversations/runtime_input.py +4 -0
- ksadk/conversations/runtime_invocation.py +5 -1
- ksadk/conversations/runtime_metadata.py +6 -7
- ksadk/conversations/runtime_payloads.py +5 -1
- ksadk/conversations/runtime_persistence.py +23 -0
- ksadk/conversations/runtime_preparation.py +128 -5
- ksadk/events/adapters/langgraph.py +53 -1
- ksadk/kernel/control.py +16 -22
- ksadk/kernel/history_projection.py +191 -58
- ksadk/kernel/ingress.py +16 -2
- ksadk/kernel/postgres_event_log.py +10 -2
- ksadk/kernel/postgres_store.py +81 -2
- ksadk/kernel/run_references.py +38 -0
- ksadk/kernel/worker_controls.py +11 -1
- ksadk/mcp_runtime/oauth/kernel.py +5 -0
- ksadk/mcp_runtime/oauth/local/broker.py +18 -8
- ksadk/mcp_runtime/oauth/local/protocol.py +3 -11
- ksadk/mcp_runtime/oauth/local/transport.py +9 -2
- ksadk/resource_runtime/contracts.py +39 -1
- ksadk/resource_runtime/managed_projection.py +8 -6
- ksadk/resource_runtime/worker.py +8 -1
- ksadk/runners/_adk_canonical_stream.py +16 -15
- ksadk/runners/_langgraph_answer_contract.py +1 -7
- ksadk/runners/_langgraph_canonical_stream.py +13 -6
- ksadk/runners/_langgraph_context.py +265 -0
- ksadk/runners/_langgraph_model_budget.py +397 -0
- ksadk/runners/_langgraph_runner_streams.py +7 -6
- ksadk/runners/adk_runner.py +13 -21
- ksadk/runners/langgraph_runner.py +130 -8
- ksadk/runners/usage_accumulator.py +40 -0
- ksadk/runtime/conversation_execution.py +26 -4
- ksadk/server/factory.py +3 -1
- ksadk/server/routes/control.py +24 -8
- ksadk/server/routes/history_items.py +157 -0
- ksadk/server/routes/kernel_ingress.py +51 -12
- ksadk/server/routes/local_kernel_control.py +16 -0
- ksadk/server/routes/models.py +26 -0
- ksadk/server/routes/openai_compat.py +10 -3
- ksadk/server/routes/projection.py +4 -0
- ksadk/server/routes/run.py +4 -2
- ksadk/server/routes/sessions.py +20 -1
- ksadk/server/static/assets/{ArtifactsPanel-Cdr5C_vM.js → ArtifactsPanel-iZ_6CAQ2.js} +1 -1
- ksadk/server/static/assets/{CodeBlock-BWRafud9.js → CodeBlock-D6uglm5n.js} +1 -1
- ksadk/server/static/assets/{MathMessageMarkdown-CFKeJIvy.js → MathMessageMarkdown-D6ojdxCG.js} +1 -1
- ksadk/server/static/assets/{MermaidBlock-BneAGUOd.js → MermaidBlock-Csk2ivT7.js} +6 -6
- ksadk/server/static/assets/{NativeTerminalPanel-BHI85zDO.js → NativeTerminalPanel-CCJA1XSH.js} +1 -1
- ksadk/server/static/assets/{OfficialA2uiRenderer-BOmT36lJ.js → OfficialA2uiRenderer-C06jus9N.js} +1 -1
- ksadk/server/static/assets/{abnfDiagram-VCTEODGH-DQvlOsBI.js → abnfDiagram-VCTEODGH-BhrF5tmL.js} +1 -1
- ksadk/server/static/assets/{arc-CGx0e4pN.js → arc-Btsh3kfy.js} +1 -1
- ksadk/server/static/assets/architecture-7GRP2DOG-BSXho3cq.js +1 -0
- ksadk/server/static/assets/{architectureDiagram-5GKGNRK7-WyybcNKX.js → architectureDiagram-5GKGNRK7-Cl8MfAmp.js} +1 -1
- ksadk/server/static/assets/{blockDiagram-NRAW4CY4-C9Cx_GVs.js → blockDiagram-NRAW4CY4-CeHSr8E_.js} +1 -1
- ksadk/server/static/assets/{c4Diagram-UCG6FXSJ-Bh7X3bGr.js → c4Diagram-UCG6FXSJ-BSD7RUKo.js} +1 -1
- ksadk/server/static/assets/channel-BpyDVKis.js +1 -0
- ksadk/server/static/assets/chunk-2Q5K7J3B-HLcpmPI2.js +1 -0
- ksadk/server/static/assets/{chunk-5VM5RSS4-cP9XupZj.js → chunk-5VM5RSS4-wz0pkBjp.js} +1 -1
- ksadk/server/static/assets/{chunk-F27PBJKO-Bm77fvR9.js → chunk-F27PBJKO-shjQ7cPM.js} +1 -1
- ksadk/server/static/assets/{chunk-G27WJ6UU-DDKNPesQ.js → chunk-G27WJ6UU-DL_MfUsu.js} +1 -1
- ksadk/server/static/assets/{chunk-JWPE2WC7-BqiUDB7s.js → chunk-JWPE2WC7-moUdwYpb.js} +1 -1
- ksadk/server/static/assets/{chunk-LCL6LL3I-C528mMZy.js → chunk-LCL6LL3I-B3QcDsZM.js} +1 -1
- ksadk/server/static/assets/{chunk-POPQ4Y6H-CzZ9g_Uf.js → chunk-POPQ4Y6H-BLBKb48A.js} +1 -1
- ksadk/server/static/assets/{chunk-RHFEMEQ7-CXj4tUZ-.js → chunk-RHFEMEQ7-CXR6ZzOx.js} +1 -1
- ksadk/server/static/assets/{chunk-SVP7TREG-BHyd85pS.js → chunk-SVP7TREG-DoR8BxkO.js} +1 -1
- ksadk/server/static/assets/{chunk-XXDRQBXY-Qe29PHGe.js → chunk-XXDRQBXY-8HJaIq0q.js} +1 -1
- ksadk/server/static/assets/classDiagram-DTDB5LWJ-DlNiRtSN.js +1 -0
- ksadk/server/static/assets/classDiagram-v2-JRS7N3AN-DlNiRtSN.js +1 -0
- ksadk/server/static/assets/{cose-bilkent-JH36ORCC-maRKgeec.js → cose-bilkent-JH36ORCC-DnSSHHqS.js} +1 -1
- ksadk/server/static/assets/cynefin-OW5HDTMX-DxNym3qg.js +1 -0
- ksadk/server/static/assets/{cynefinDiagram-5FMLGOSQ-CoD0bEvn.js → cynefinDiagram-5FMLGOSQ-4eCi_Rw5.js} +1 -1
- ksadk/server/static/assets/{dagre-3AP2YEHR-BkpgQqyW.js → dagre-3AP2YEHR-DpPk9jsh.js} +1 -1
- ksadk/server/static/assets/{dagre-BUaTFrYa.js → dagre-G789Mawt.js} +1 -1
- ksadk/server/static/assets/{diagram-S7CK7UJ4-25HdTbjE.js → diagram-S7CK7UJ4-7x2FScRJ.js} +1 -1
- ksadk/server/static/assets/{diagram-UQ7AKVKN-KO-WqOIg.js → diagram-UQ7AKVKN-DGvliWDD.js} +1 -1
- ksadk/server/static/assets/{diagram-VSXAHHWV-B360BkDQ.js → diagram-VSXAHHWV-C0i4uEyS.js} +1 -1
- ksadk/server/static/assets/{diagram-VX7I27RA-COr1Oqsg.js → diagram-VX7I27RA-C7SmgIl5.js} +1 -1
- ksadk/server/static/assets/{diagram-Z3DM3KII-CgaKrIwB.js → diagram-Z3DM3KII-Xca7TB4U.js} +1 -1
- ksadk/server/static/assets/{dist-By-MVndb.js → dist-B3rsrE8r.js} +1 -1
- ksadk/server/static/assets/{dist-Bsuusoi0.js → dist-BM6KIyhr.js} +1 -1
- ksadk/server/static/assets/{dist-DzdXSBJb.js → dist-BMZKBrmN.js} +1 -1
- ksadk/server/static/assets/{dist-DmWw0IXB.js → dist-BUGNcOx8.js} +1 -1
- ksadk/server/static/assets/{dist-DXOlCAay.js → dist-BbIN_x76.js} +1 -1
- ksadk/server/static/assets/{dist--HftQyp9.js → dist-CGB89Aru.js} +1 -1
- ksadk/server/static/assets/{dist-DKG0OYnk.js → dist-CGIWL8mC.js} +1 -1
- ksadk/server/static/assets/{dist-DgJ57sRe.js → dist-CHeuPGXZ.js} +1 -1
- ksadk/server/static/assets/{dist-_0Xgu_07.js → dist-CMJq3QL-.js} +1 -1
- ksadk/server/static/assets/{dist-CwnkOyDn.js → dist-CiUeIDKz.js} +1 -1
- ksadk/server/static/assets/{dist-BoRn8a_t.js → dist-CmaZEf5M.js} +1 -1
- ksadk/server/static/assets/{dist-BQ116UdZ.js → dist-Cq4qlsg3.js} +1 -1
- ksadk/server/static/assets/{dist-CBo9AHUv.js → dist-DDVDyH7h.js} +1 -1
- ksadk/server/static/assets/{dist-DSw5Ju6-.js → dist-DDi9q5bO.js} +1 -1
- ksadk/server/static/assets/{dist-CxIl4t92.js → dist-DJ8mj6p4.js} +1 -1
- ksadk/server/static/assets/{dist-Brbrdmff.js → dist-DRGym1nc.js} +1 -1
- ksadk/server/static/assets/{dist-BEbS8Bag.js → dist-DcrTYAeW.js} +1 -1
- ksadk/server/static/assets/{dist-C9BTMVwS.js → dist-DpuxDDLa.js} +1 -1
- ksadk/server/static/assets/{dist-B3Jp5r1e.js → dist-EFGQ7G_k.js} +1 -1
- ksadk/server/static/assets/{dist-HHvdjADB.js → dist-IyCF0NNA.js} +1 -1
- ksadk/server/static/assets/{dist-Bxcu8Ca0.js → dist-Ny95vkRV.js} +1 -1
- ksadk/server/static/assets/{dist-CR61WJFC.js → dist-s5cohO5C.js} +1 -1
- ksadk/server/static/assets/{ebnfDiagram-PWID7BFC-DogDP2db.js → ebnfDiagram-PWID7BFC-DNwVczAJ.js} +1 -1
- ksadk/server/static/assets/{erDiagram-SSCWMZ5O-CeBDnUjR.js → erDiagram-SSCWMZ5O-OxFlhx6v.js} +1 -1
- ksadk/server/static/assets/eventmodeling-NTZA5JFV-C-gXDupK.js +1 -0
- ksadk/server/static/assets/flowDiagram-A5DVABFB-CkpCYD4e.js +1 -0
- ksadk/server/static/assets/{ganttDiagram-EL5Y4UJY-oIQL3MCp.js → ganttDiagram-EL5Y4UJY-D4krNgUz.js} +1 -1
- ksadk/server/static/assets/gitGraph-4MIJSDKK-0RSkEgC5.js +1 -0
- ksadk/server/static/assets/{gitGraphDiagram-WWUBYQGX-B7qz0cmZ.js → gitGraphDiagram-WWUBYQGX-BUSVPN1s.js} +1 -1
- ksadk/server/static/assets/index-B9UP7He9.css +2 -0
- ksadk/server/static/assets/index-COn4kn-G.js +1135 -0
- ksadk/server/static/assets/info-A6RAGUB7-C6KX7WO4.js +1 -0
- ksadk/server/static/assets/{infoDiagram-RXCK75RN-yQRC41Ya.js → infoDiagram-RXCK75RN-b6w3u3-O.js} +1 -1
- ksadk/server/static/assets/{ishikawaDiagram-5VMMS53U-BCu4HiwL.js → ishikawaDiagram-5VMMS53U-CsC7gzRt.js} +1 -1
- ksadk/server/static/assets/{journeyDiagram-EYS64GPL-JaqmO73K.js → journeyDiagram-EYS64GPL-BATLNoy1.js} +1 -1
- ksadk/server/static/assets/{kanban-definition-3QL26DDD-DQo4X8NO.js → kanban-definition-3QL26DDD-C49zL_s0.js} +1 -1
- ksadk/server/static/assets/{katex-t_DWylQw.js → katex-CDVgGGy2.js} +1 -1
- ksadk/server/static/assets/{linear-DWdnI35B.js → linear-DkyDumSy.js} +1 -1
- ksadk/server/static/assets/{mermaid-parser.core-BHrT2Pfe.js → mermaid-parser.core-BDX-LqSy.js} +2 -2
- ksadk/server/static/assets/{mindmap-definition-FBJOCRG2-PBVAhZYV.js → mindmap-definition-FBJOCRG2-DRPnzL2n.js} +1 -1
- ksadk/server/static/assets/packet-AYTQ26CC-CMMupxPW.js +1 -0
- ksadk/server/static/assets/{pegDiagram-XKGWAZYB-CU_cLfow.js → pegDiagram-XKGWAZYB-Zm-xrNrr.js} +1 -1
- ksadk/server/static/assets/pie-WAS4IAKB-Bfo0pa9v.js +1 -0
- ksadk/server/static/assets/{pieDiagram-E7YTZNPT-B1h0-_pW.js → pieDiagram-E7YTZNPT-a8C1Jxo4.js} +1 -1
- ksadk/server/static/assets/{quadrantDiagram-AXDQQJYC-DEMoGo5a.js → quadrantDiagram-AXDQQJYC-ihH8znBv.js} +1 -1
- ksadk/server/static/assets/radar-RG4KPBEZ-PRBiHoJx.js +1 -0
- ksadk/server/static/assets/railroad-74A4TZTK-BCJ-XMRJ.js +1 -0
- ksadk/server/static/assets/railroad-abnf-HS5TGJTU-Bbttj0Jz.js +1 -0
- ksadk/server/static/assets/railroad-ebnf-LZEXJU2U-Bo18264J.js +1 -0
- ksadk/server/static/assets/railroad-peg-WCYAUIDC-xZDJTFLD.js +1 -0
- ksadk/server/static/assets/{railroadDiagram-O6MQD6OU-BTAob2wg.js → railroadDiagram-O6MQD6OU-DD9lFfXo.js} +1 -1
- ksadk/server/static/assets/{requirementDiagram-EFPCY7ZU-Dl0Q2SuO.js → requirementDiagram-EFPCY7ZU-CGn93Iyb.js} +1 -1
- ksadk/server/static/assets/{sankeyDiagram-P5KCCOFB-DeaTWkur.js → sankeyDiagram-P5KCCOFB-BuyjrHuW.js} +1 -1
- ksadk/server/static/assets/{sequenceDiagram-WJ2MYXX4-gFQYrsOd.js → sequenceDiagram-WJ2MYXX4-D-Iw-30A.js} +1 -1
- ksadk/server/static/assets/{sizeCapture-X5ZJPWSS-pGQzddMB.js → sizeCapture-X5ZJPWSS-B0EHLwrD.js} +1 -1
- ksadk/server/static/assets/{stateDiagram-HBIQ2CUA-DmpYOZt1.js → stateDiagram-HBIQ2CUA-k9Zyg69R.js} +1 -1
- ksadk/server/static/assets/stateDiagram-v2-4QOOHH4V-tUEVnq9-.js +1 -0
- ksadk/server/static/assets/{swimlanes-XN3QIQJK-BfuSAsrr.js → swimlanes-XN3QIQJK-D2BewKmp.js} +1 -1
- ksadk/server/static/assets/swimlanesDiagram-VK2B7HYN-CGBmsrCQ.js +8 -0
- ksadk/server/static/assets/{timeline-definition-24CTP7MA-CgJwrrxf.js → timeline-definition-24CTP7MA-czSzsYbz.js} +1 -1
- ksadk/server/static/assets/treeView-Q6P3EWNA-CrEvfC8M.js +1 -0
- ksadk/server/static/assets/treemap-WGGIJYW6-D1TmShtn.js +1 -0
- ksadk/server/static/assets/{vennDiagram-4TSXK5OY-CBSAgXDd.js → vennDiagram-4TSXK5OY-BJF_qZLF.js} +1 -1
- ksadk/server/static/assets/wardley-WFR3VGLG-0gZiSyL0.js +1 -0
- ksadk/server/static/assets/{wardleyDiagram-VM6X3IG4-013TZ2JZ.js → wardleyDiagram-VM6X3IG4-BfwUuJpr.js} +1 -1
- ksadk/server/static/assets/{xychartDiagram-S5SC5T6Z-u6Frp8xp.js → xychartDiagram-S5SC5T6Z-Ci6Nsp4p.js} +1 -1
- ksadk/server/static/index.html +2 -2
- ksadk/server/static/ui-source.json +6 -6
- ksadk/sessions/_postgres_history_backfill.py +80 -0
- ksadk/sessions/_postgres_schema.py +117 -0
- ksadk/sessions/_postgres_tables.py +6 -0
- ksadk/sessions/base.py +24 -0
- ksadk/sessions/history_tool_refs.py +244 -0
- ksadk/sessions/in_memory.py +42 -0
- ksadk/sessions/local_service.py +78 -0
- ksadk/sessions/model_history.py +20 -0
- ksadk/sessions/postgres_service.py +215 -19
- ksadk/sessions/resilient.py +24 -0
- ksadk/studio/static/assets/{ChannelsPage-Do_mRmVu.js → ChannelsPage-Ot9iV_QP.js} +1 -1
- ksadk/studio/static/assets/{CodeBlock-DMIf4h33-CsO7rJKv.js → CodeBlock-DMIf4h33-Cfs6se0v.js} +1 -1
- ksadk/studio/static/assets/{MathMessageMarkdown-BesSeCYl-CiB60plG.js → MathMessageMarkdown-BesSeCYl-BIBDiQAl.js} +1 -1
- ksadk/studio/static/assets/{MessageMarkdown-CwMTvgFj-BzEmQkHH.js → MessageMarkdown-CwMTvgFj-CWM4n-9K.js} +2 -2
- ksadk/studio/static/assets/{OfficialA2uiRenderer-DI49Kpxu-BBxfdj3P.js → OfficialA2uiRenderer-DI49Kpxu-BZSumE9D.js} +1 -1
- ksadk/studio/static/assets/{TeamsPage-qNVYpcox.js → TeamsPage-CVOpMIMf.js} +2 -2
- ksadk/studio/static/assets/index-CW1D-Kqg.css +2 -0
- ksadk/studio/static/assets/index-DMexeQ1-.js +1155 -0
- ksadk/studio/static/index.html +3 -3
- ksadk/studio/static/ui-source.json +6 -6
- ksadk/version.py +1 -1
- ksadk/server/static/assets/architecture-7GRP2DOG-CFWjFkDL.js +0 -1
- ksadk/server/static/assets/channel-D6Dp_l74.js +0 -1
- ksadk/server/static/assets/chunk-2Q5K7J3B-CwmjhFYK.js +0 -1
- ksadk/server/static/assets/classDiagram-DTDB5LWJ-DsbvkCAV.js +0 -1
- ksadk/server/static/assets/classDiagram-v2-JRS7N3AN-DsbvkCAV.js +0 -1
- ksadk/server/static/assets/cynefin-OW5HDTMX-CBZRVuc4.js +0 -1
- ksadk/server/static/assets/eventmodeling-NTZA5JFV-vXZWMkpn.js +0 -1
- ksadk/server/static/assets/flowDiagram-A5DVABFB-5LRgzKLv.js +0 -1
- ksadk/server/static/assets/gitGraph-4MIJSDKK-BUWSkncI.js +0 -1
- ksadk/server/static/assets/index-4g1ndaxW.js +0 -1132
- ksadk/server/static/assets/index-DEVfafsU.css +0 -2
- ksadk/server/static/assets/info-A6RAGUB7-CzJ_YrOs.js +0 -1
- ksadk/server/static/assets/packet-AYTQ26CC-CXoos6fx.js +0 -1
- ksadk/server/static/assets/pie-WAS4IAKB-CjF9NoIt.js +0 -1
- ksadk/server/static/assets/radar-RG4KPBEZ-BQGWs9nw.js +0 -1
- ksadk/server/static/assets/railroad-74A4TZTK-B6znvLUK.js +0 -1
- ksadk/server/static/assets/railroad-abnf-HS5TGJTU-Bzquz0As.js +0 -1
- ksadk/server/static/assets/railroad-ebnf-LZEXJU2U-1IikGkb5.js +0 -1
- ksadk/server/static/assets/railroad-peg-WCYAUIDC-BKKgHzdc.js +0 -1
- ksadk/server/static/assets/stateDiagram-v2-4QOOHH4V-Dolxgkw3.js +0 -1
- ksadk/server/static/assets/swimlanesDiagram-VK2B7HYN-BuI1erYj.js +0 -8
- ksadk/server/static/assets/treeView-Q6P3EWNA-DtMdDH8N.js +0 -1
- ksadk/server/static/assets/treemap-WGGIJYW6-VoU8QtLZ.js +0 -1
- ksadk/server/static/assets/wardley-WFR3VGLG-YWSRB0Zm.js +0 -1
- ksadk/studio/static/assets/index-Cp9Unfkn.css +0 -2
- ksadk/studio/static/assets/index-HepnaEeR.js +0 -1152
- {agentengine_sdk_python-0.8.8.dist-info → agentengine_sdk_python-0.8.9.dist-info}/WHEEL +0 -0
- {agentengine_sdk_python-0.8.8.dist-info → agentengine_sdk_python-0.8.9.dist-info}/entry_points.txt +0 -0
- {agentengine_sdk_python-0.8.8.dist-info → agentengine_sdk_python-0.8.9.dist-info}/licenses/LICENSE +0 -0
- {agentengine_sdk_python-0.8.8.dist-info → agentengine_sdk_python-0.8.9.dist-info}/top_level.txt +0 -0
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"""Resolve public wire references through the original scoped admission."""
|
|
2
|
+
|
|
3
|
+
from hashlib import sha256
|
|
4
|
+
from typing import TYPE_CHECKING
|
|
5
|
+
|
|
6
|
+
if TYPE_CHECKING:
|
|
7
|
+
from ksadk.kernel.store import AgentKernelStore
|
|
8
|
+
|
|
9
|
+
from ksadk.kernel.execution_grants import execution_grant_run_id
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
async def resolve_public_run_id(
|
|
13
|
+
store: "AgentKernelStore", *, tenant_id: str, agent_instance_id: str,
|
|
14
|
+
session_id: str | None, public_ref: str,
|
|
15
|
+
) -> str | None:
|
|
16
|
+
if not session_id or not public_ref:
|
|
17
|
+
return None
|
|
18
|
+
run = await store.load_run(public_ref)
|
|
19
|
+
if (run is not None and run.session_id == session_id
|
|
20
|
+
and run.agent_instance_id == agent_instance_id
|
|
21
|
+
and run.metadata.get("tenant_id") == tenant_id):
|
|
22
|
+
return run.run_id
|
|
23
|
+
# Hosted AG-UI namespaces its enqueue key; Responses uses the wire ID itself.
|
|
24
|
+
# Neither alias authorizes selecting whichever run happens to be active.
|
|
25
|
+
for key in (public_ref, "agui.enqueue:" + sha256(public_ref.encode()).hexdigest()):
|
|
26
|
+
message = await store.load_by_idempotency(session_id, key)
|
|
27
|
+
command = message.command if message is not None else None
|
|
28
|
+
if (command is None or command.command_type != "enqueue"
|
|
29
|
+
or command.tenant_id != tenant_id
|
|
30
|
+
or command.agent_instance_id != agent_instance_id
|
|
31
|
+
or command.session_id != session_id
|
|
32
|
+
or (key != public_ref and command.source.kind != "agui")):
|
|
33
|
+
continue
|
|
34
|
+
prior = await store.find_command_run(agent_instance_id, session_id, str(command.command_id))
|
|
35
|
+
if prior is not None:
|
|
36
|
+
return prior.run_id
|
|
37
|
+
return execution_grant_run_id(command)
|
|
38
|
+
return None
|
ksadk/kernel/worker_controls.py
CHANGED
|
@@ -112,6 +112,17 @@ class WorkerControlMixin:
|
|
|
112
112
|
fence = activation.fencing_token
|
|
113
113
|
active = await self._store.find_active_run(command.agent_instance_id, command.session_id)
|
|
114
114
|
target_run_id = str(command.payload.get("run_id") or "").strip()
|
|
115
|
+
if (command.command_type == "interrupt" and target_run_id
|
|
116
|
+
and (active is None or active.run_id != target_run_id)
|
|
117
|
+
and command.payload.get("scope_id") is None
|
|
118
|
+
and command.payload.get("a2a_origin_command_id") is None):
|
|
119
|
+
from ksadk.kernel.run_references import resolve_public_run_id
|
|
120
|
+
|
|
121
|
+
target_run_id = await resolve_public_run_id(
|
|
122
|
+
self._store, tenant_id=command.tenant_id,
|
|
123
|
+
agent_instance_id=command.agent_instance_id, session_id=command.session_id,
|
|
124
|
+
public_ref=target_run_id,
|
|
125
|
+
) or target_run_id
|
|
115
126
|
if active is None or (target_run_id and active.run_id != target_run_id):
|
|
116
127
|
# A Studio cancel can race with an admitted enqueue before the
|
|
117
128
|
# worker has materialized its durable RunRecord. Consume the
|
|
@@ -119,7 +130,6 @@ class WorkerControlMixin:
|
|
|
119
130
|
# remains durable instead of falling back to a process-local
|
|
120
131
|
# operation handle.
|
|
121
132
|
if command.command_type == "interrupt" and command.payload.get("scope_id") is None:
|
|
122
|
-
target_run_id = str(command.payload.get("run_id") or "").strip()
|
|
123
133
|
if target_run_id:
|
|
124
134
|
for pending in await self._store.list_pending(
|
|
125
135
|
command.agent_instance_id,
|
|
@@ -536,6 +536,11 @@ class MCPAuthorizationExtension:
|
|
|
536
536
|
# A previous worker may have confirmed connecting before it could
|
|
537
537
|
# reserve the native resume. Only a still-pending row can take over.
|
|
538
538
|
confirmed = row["status"] == "pending" and _connecting_for(command, snapshot)
|
|
539
|
+
# The callback may commit a signed completion after get() returned
|
|
540
|
+
# its snapshot. Keep a newer notice until the next state read;
|
|
541
|
+
# acknowledging it here would permanently lose the only wake-up.
|
|
542
|
+
if not confirmed and command["revision"] > snapshot["revision"]:
|
|
543
|
+
continue
|
|
539
544
|
if not confirmed and (
|
|
540
545
|
command["revision"] != snapshot["revision"]
|
|
541
546
|
or command["status"] != snapshot["status"]
|
|
@@ -268,11 +268,13 @@ class LocalBroker:
|
|
|
268
268
|
await self.notify(wait)
|
|
269
269
|
return self.view(wait)
|
|
270
270
|
|
|
271
|
-
async def registration(self, config):
|
|
271
|
+
async def registration(self, config, *, refresh_metadata=False):
|
|
272
272
|
auth = self.data["clients"].get(config.id)
|
|
273
|
-
if auth is None:
|
|
273
|
+
if auth is None or refresh_metadata:
|
|
274
274
|
metadata = await self.protocol.metadata(config)
|
|
275
|
-
|
|
275
|
+
client = (self.protocol.validate_client(config, auth["client"])
|
|
276
|
+
if auth else await self.protocol.register(config, metadata))
|
|
277
|
+
auth = {"metadata": metadata, "client": client}
|
|
276
278
|
self.data["clients"][config.id] = auth
|
|
277
279
|
self.vault.save()
|
|
278
280
|
return auth
|
|
@@ -293,11 +295,18 @@ class LocalBroker:
|
|
|
293
295
|
raise BrokerError("WAIT_NOT_ACTIONABLE")
|
|
294
296
|
config = self.config(wait)
|
|
295
297
|
tx = self.data["transactions"].get(wait.get("transaction", ""))
|
|
298
|
+
try:
|
|
299
|
+
auth = await self.registration(config, refresh_metadata=True)
|
|
300
|
+
except OAuthError as exc:
|
|
301
|
+
self.change(wait, "authorization_failed", exc.code)
|
|
302
|
+
self.vault.save()
|
|
303
|
+
raise BrokerError(exc.code) from None
|
|
304
|
+
if tx and tx["status"] == "pending" and tx.get("auth") != auth:
|
|
305
|
+
tx["status"] = "cancelled"
|
|
296
306
|
if not tx or tx["status"] != "pending":
|
|
297
307
|
state, verifier = secrets.token_urlsafe(32), secrets.token_urlsafe(48)
|
|
298
308
|
state_hash = digest(state)
|
|
299
309
|
try:
|
|
300
|
-
auth = await self.registration(config)
|
|
301
310
|
url = self.protocol.authorization_url(
|
|
302
311
|
config, auth["metadata"], auth["client"], state, verifier
|
|
303
312
|
)
|
|
@@ -305,7 +314,8 @@ class LocalBroker:
|
|
|
305
314
|
self.change(wait, "authorization_failed", exc.code)
|
|
306
315
|
self.vault.save()
|
|
307
316
|
raise BrokerError(exc.code) from None
|
|
308
|
-
tx = {"wait_id": wait_id, "status": "pending", "verifier": verifier,
|
|
317
|
+
tx = {"wait_id": wait_id, "status": "pending", "verifier": verifier,
|
|
318
|
+
"url": url, "auth": auth}
|
|
309
319
|
self.data["transactions"][state_hash] = tx
|
|
310
320
|
wait["transaction"] = state_hash
|
|
311
321
|
self.change(wait, "awaiting_authorization")
|
|
@@ -352,8 +362,8 @@ class LocalBroker:
|
|
|
352
362
|
self.vault.save()
|
|
353
363
|
return self.view(wait)
|
|
354
364
|
config = self.config(wait)
|
|
355
|
-
auth = self.data["clients"][config.id]
|
|
356
|
-
if (issuer is not None and issuer !=
|
|
365
|
+
auth = tx.get("auth") or self.data["clients"][config.id]
|
|
366
|
+
if (issuer is not None and issuer != auth["metadata"]["issuer"]) or (
|
|
357
367
|
auth["metadata"].get("authorization_response_iss_parameter_supported")
|
|
358
368
|
and not issuer
|
|
359
369
|
):
|
|
@@ -426,7 +436,7 @@ class LocalBroker:
|
|
|
426
436
|
grant["status"] = "refreshing"
|
|
427
437
|
self.vault.save()
|
|
428
438
|
try:
|
|
429
|
-
auth = await self.registration(config)
|
|
439
|
+
auth = await self.registration(config, refresh_metadata=True)
|
|
430
440
|
token = await self.protocol.token(
|
|
431
441
|
config,
|
|
432
442
|
auth["metadata"],
|
|
@@ -194,17 +194,9 @@ class OAuthProtocol:
|
|
|
194
194
|
# A narrowly pinned compatibility profile, not an issuer bypass.
|
|
195
195
|
if config.issuer not in {config.authorization_server, "https://iam.api.ksyun.com"}:
|
|
196
196
|
raise OAuthError("OAUTH_ISSUER_MISMATCH")
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
"token_endpoint": origin + "/oauth/token",
|
|
201
|
-
"registration_endpoint": origin
|
|
202
|
-
+ "/oauth/register"
|
|
203
|
-
+ urlsplit(config.authorization_server).path,
|
|
204
|
-
"revocation_endpoint": origin + "/oauth/revoke",
|
|
205
|
-
}
|
|
206
|
-
if any(data.get(k) and data[k] != v for k, v in expected.items()):
|
|
207
|
-
raise OAuthError("OAUTH_UNTRUSTED_ENDPOINT")
|
|
197
|
+
# Endpoint paths belong to the provider's validated metadata.
|
|
198
|
+
# Keep the issuer/origin checks above; do not infer endpoint paths
|
|
199
|
+
# or MCP ownership from a vendor-specific URL layout.
|
|
208
200
|
return data
|
|
209
201
|
|
|
210
202
|
@staticmethod
|
|
@@ -11,17 +11,24 @@ import httpx
|
|
|
11
11
|
|
|
12
12
|
|
|
13
13
|
class PublicNetworkBackend(httpcore.AsyncNetworkBackend):
|
|
14
|
-
def __init__(self, delegate=None):
|
|
14
|
+
def __init__(self, delegate=None, *, address_allowed=None, absolute_dns=False):
|
|
15
15
|
self.delegate = delegate or httpcore.AnyIOBackend()
|
|
16
|
+
self.address_allowed = address_allowed or (lambda address: ipaddress.ip_address(address).is_global)
|
|
17
|
+
self.absolute_dns = absolute_dns
|
|
16
18
|
|
|
17
19
|
async def connect_tcp(self, host, port, timeout=None, local_address=None, socket_options=None):
|
|
20
|
+
if self.absolute_dns and not host.endswith("."):
|
|
21
|
+
try:
|
|
22
|
+
ipaddress.ip_address(host)
|
|
23
|
+
except ValueError:
|
|
24
|
+
host = host + "."
|
|
18
25
|
try:
|
|
19
26
|
records = await asyncio.wait_for(
|
|
20
27
|
asyncio.get_running_loop().getaddrinfo(host, port, type=socket.SOCK_STREAM),
|
|
21
28
|
timeout=timeout or 10,
|
|
22
29
|
)
|
|
23
30
|
addresses = list(dict.fromkeys(str(record[4][0]) for record in records))
|
|
24
|
-
if not addresses or any(not
|
|
31
|
+
if not addresses or any(not self.address_allowed(ip) for ip in addresses):
|
|
25
32
|
raise httpcore.ConnectError("OAUTH_NON_PUBLIC_ENDPOINT")
|
|
26
33
|
# Dial this address, not the hostname a second time. httpcore keeps
|
|
27
34
|
# the original hostname for certificate verification and TLS SNI.
|
|
@@ -10,7 +10,7 @@ from pydantic import Field, field_validator, model_validator
|
|
|
10
10
|
|
|
11
11
|
from ksadk.plugins.contracts import PluginContractModel
|
|
12
12
|
|
|
13
|
-
Identifier = Annotated[str, Field(strict=True, min_length=1, max_length=
|
|
13
|
+
Identifier = Annotated[str, Field(strict=True, min_length=1, max_length=128, pattern=r"^[A-Za-z0-9][A-Za-z0-9_.:-]{0,127}$")]
|
|
14
14
|
Digest = Annotated[str, Field(pattern=r"^sha256:[0-9a-f]{64}$")]
|
|
15
15
|
ResourceKind = Literal["knowledge-base", "memory-instance", "skill-space"]
|
|
16
16
|
|
|
@@ -45,6 +45,11 @@ class ResourceConfig(PluginContractModel):
|
|
|
45
45
|
schema_version: Literal[1] = 1
|
|
46
46
|
binding: ResourceBinding
|
|
47
47
|
retrieval: RetrievalPolicy | None = None
|
|
48
|
+
# Additional dataset IDs for multi-knowledge-base within a single binding.
|
|
49
|
+
# Only valid for knowledge-base bindings; primary dataset is binding.resource.id.
|
|
50
|
+
additional_dataset_ids: tuple[Identifier, ...] = Field(default=(), max_length=9)
|
|
51
|
+
# Per-dataset retrieval policies for additional datasets.
|
|
52
|
+
additional_retrievals: dict[str, RetrievalPolicy] = Field(default_factory=dict)
|
|
48
53
|
selection_mode: Literal["pinned", "discovery"] | None = None
|
|
49
54
|
selected_skills: tuple[SelectedSkill, ...] = ()
|
|
50
55
|
include_public: bool = Field(default=False, strict=True)
|
|
@@ -62,6 +67,15 @@ class ResourceConfig(PluginContractModel):
|
|
|
62
67
|
kind = self.binding.resource.kind
|
|
63
68
|
if kind != "knowledge-base" and self.retrieval is not None:
|
|
64
69
|
raise ValueError("retrieval is only valid for knowledge-base bindings")
|
|
70
|
+
if kind != "knowledge-base" and (self.additional_dataset_ids or self.additional_retrievals):
|
|
71
|
+
raise ValueError("additional_dataset_ids is only valid for knowledge-base bindings")
|
|
72
|
+
if kind == "knowledge-base":
|
|
73
|
+
all_ids = [self.binding.resource.id, *self.additional_dataset_ids]
|
|
74
|
+
if len(all_ids) != len(set(all_ids)):
|
|
75
|
+
raise ValueError("additional_dataset_ids must not duplicate the primary dataset id")
|
|
76
|
+
extra_keys = set(self.additional_retrievals) - set(self.additional_dataset_ids)
|
|
77
|
+
if extra_keys:
|
|
78
|
+
raise ValueError("additional_retrievals keys must match additional_dataset_ids")
|
|
65
79
|
if kind != "skill-space":
|
|
66
80
|
if (
|
|
67
81
|
self.selection_mode is not None
|
|
@@ -83,6 +97,19 @@ class ResourceConfig(PluginContractModel):
|
|
|
83
97
|
data = self.model_dump(by_alias=True, mode="json", exclude_none=True)
|
|
84
98
|
if self.binding.resource.kind == "knowledge-base":
|
|
85
99
|
data["retrieval"] = (self.retrieval or RetrievalPolicy()).model_dump(by_alias=True)
|
|
100
|
+
# Pop multi-dataset fields that model_dump includes as defaults
|
|
101
|
+
# (empty tuple / empty dict are not None, so exclude_none won't strip them).
|
|
102
|
+
# Only add them back when non-default to preserve digest stability for
|
|
103
|
+
# existing single-KB configs.
|
|
104
|
+
data.pop("additionalDatasetIds", None)
|
|
105
|
+
data.pop("additionalRetrievals", None)
|
|
106
|
+
if self.additional_dataset_ids:
|
|
107
|
+
data["additionalDatasetIds"] = list(self.additional_dataset_ids)
|
|
108
|
+
if self.additional_retrievals:
|
|
109
|
+
data["additionalRetrievals"] = {
|
|
110
|
+
key: policy.model_dump(by_alias=True)
|
|
111
|
+
for key, policy in self.additional_retrievals.items()
|
|
112
|
+
}
|
|
86
113
|
if self.binding.resource.kind == "skill-space":
|
|
87
114
|
data["selectionMode"] = self.selection_mode or "pinned"
|
|
88
115
|
data["executionMode"] = self.execution_mode or "outer-agent"
|
|
@@ -95,6 +122,17 @@ class ResourceConfig(PluginContractModel):
|
|
|
95
122
|
return "sha256:" + hashlib.sha256(self.canonical_bytes()).hexdigest()
|
|
96
123
|
|
|
97
124
|
|
|
125
|
+
|
|
126
|
+
def collect_dataset_instructions(config: ResourceConfig) -> dict[str, str]:
|
|
127
|
+
"""Collect per-dataset custom instructions from retrieval + additional_retrievals."""
|
|
128
|
+
instructions = {}
|
|
129
|
+
if config.retrieval and config.retrieval.custom_instruction:
|
|
130
|
+
instructions[config.binding.resource.id] = config.retrieval.custom_instruction
|
|
131
|
+
for ds_id, policy in config.additional_retrievals.items():
|
|
132
|
+
if policy and policy.custom_instruction:
|
|
133
|
+
instructions[ds_id] = policy.custom_instruction
|
|
134
|
+
return instructions
|
|
135
|
+
|
|
98
136
|
def validate_resource_bindings(configs: tuple[ResourceConfig, ...]) -> None:
|
|
99
137
|
"""Validate resource binding uniqueness and per-kind cardinality."""
|
|
100
138
|
ids = [config.binding.id for config in configs]
|
|
@@ -12,7 +12,7 @@ import sys
|
|
|
12
12
|
from collections.abc import Mapping
|
|
13
13
|
from typing import Any
|
|
14
14
|
|
|
15
|
-
from ksadk.resource_runtime.contracts import ResourceConfig, validate_resource_bindings
|
|
15
|
+
from ksadk.resource_runtime.contracts import ResourceConfig, collect_dataset_instructions, validate_resource_bindings
|
|
16
16
|
from ksadk.resource_runtime.plugin_config import resource_plugin_config
|
|
17
17
|
|
|
18
18
|
_SERVER_NAME = "platform-resources"
|
|
@@ -122,6 +122,11 @@ def project_managed_platform_resources(
|
|
|
122
122
|
kb_items = [item for item in resources if item.binding.resource.kind == "knowledge-base"]
|
|
123
123
|
if kb_items:
|
|
124
124
|
kb_ids = [item.binding.resource.id for item in kb_items]
|
|
125
|
+
# Also collect additional_dataset_ids from single-binding multi-KB configs.
|
|
126
|
+
for item in kb_items:
|
|
127
|
+
kb_ids.extend(item.additional_dataset_ids)
|
|
128
|
+
# Deduplicate while preserving order (cross-binding shared datasets).
|
|
129
|
+
kb_ids = list(dict.fromkeys(kb_ids))
|
|
125
130
|
first_kb = kb_items[0]
|
|
126
131
|
policy = first_kb.retrieval
|
|
127
132
|
projected_env.update(
|
|
@@ -135,11 +140,8 @@ def project_managed_platform_resources(
|
|
|
135
140
|
)
|
|
136
141
|
# Per-knowledge-base custom instructions from retrieval policy.
|
|
137
142
|
for item in kb_items:
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
projected_env[f"KSADK_KB_INSTRUCTION_{item.binding.resource.id}"] = (
|
|
141
|
-
item_policy.custom_instruction
|
|
142
|
-
)
|
|
143
|
+
for ds_id, instruction in collect_dataset_instructions(item).items():
|
|
144
|
+
projected_env[f"KSADK_KB_INSTRUCTION_{ds_id}"] = instruction
|
|
143
145
|
|
|
144
146
|
for item in resources:
|
|
145
147
|
resource = item.binding.resource
|
ksadk/resource_runtime/worker.py
CHANGED
|
@@ -28,6 +28,7 @@ from ksadk.resource_runtime.contracts import (
|
|
|
28
28
|
Identifier,
|
|
29
29
|
InvocationIdentity,
|
|
30
30
|
ResourceConfig,
|
|
31
|
+
collect_dataset_instructions,
|
|
31
32
|
validate_resource_bindings,
|
|
32
33
|
)
|
|
33
34
|
from ksadk.resource_runtime.discovery_receipts import DiscoverySkillReceipt, discovery_scope_key
|
|
@@ -79,8 +80,10 @@ class KnowledgeWorkerBinding(ExplicitWorkerBinding):
|
|
|
79
80
|
self, *, traffic_source: str = DEFAULT_TRAFFIC_SOURCE, component_env: str = ""
|
|
80
81
|
) -> BoundKnowledgeService:
|
|
81
82
|
endpoint = urlsplit(self.endpoint)
|
|
83
|
+
# Collect all dataset IDs: primary binding + additional datasets.
|
|
84
|
+
all_ids = [self.config.binding.resource.id, *self.config.additional_dataset_ids]
|
|
82
85
|
client = KnowledgeBaseClient(
|
|
83
|
-
|
|
86
|
+
dataset_ids=all_ids,
|
|
84
87
|
traffic_source=traffic_source,
|
|
85
88
|
component_env=component_env,
|
|
86
89
|
region=self.config.binding.resource.region,
|
|
@@ -90,6 +93,10 @@ class KnowledgeWorkerBinding(ExplicitWorkerBinding):
|
|
|
90
93
|
secret_key=self.secret_key.get_secret_value(),
|
|
91
94
|
session_token=self.session_token.get_secret_value(),
|
|
92
95
|
)
|
|
96
|
+
# Inject per-dataset custom instructions from retrieval + additional_retrievals.
|
|
97
|
+
instructions = collect_dataset_instructions(self.config)
|
|
98
|
+
if instructions:
|
|
99
|
+
client.dataset_instructions = instructions
|
|
93
100
|
return BoundKnowledgeService(self.config, client)
|
|
94
101
|
|
|
95
102
|
|
|
@@ -32,7 +32,8 @@ from ksadk.events.canonical import (
|
|
|
32
32
|
)
|
|
33
33
|
from ksadk.events.content import DataContent, TextContent, ToolCallContent, ToolResultContent
|
|
34
34
|
from ksadk.events.identity import stable_event_id, stable_scope_id
|
|
35
|
-
from ksadk.runners.usage_accumulator import
|
|
35
|
+
from ksadk.runners.usage_accumulator import ADKUsageAccumulator
|
|
36
|
+
from ksadk.runtime.usage import canonical_usage_payload
|
|
36
37
|
from ksadk.tools.gateway import approval_interrupt_info_from_result
|
|
37
38
|
|
|
38
39
|
|
|
@@ -49,8 +50,8 @@ async def canonical_events(
|
|
|
49
50
|
context = ADKAdapterContext(run_id=run_id)
|
|
50
51
|
adapter = ADKEventAdapter()
|
|
51
52
|
root_scope_id = stable_scope_id("adk", run_id)
|
|
53
|
+
usage_accumulator = ADKUsageAccumulator()
|
|
52
54
|
usage: dict[str, Any] = {}
|
|
53
|
-
last_usage: dict[str, Any] = {}
|
|
54
55
|
approval_ids: set[str] = set()
|
|
55
56
|
message_snapshots: dict[tuple[str, str], dict[str, str]] = {}
|
|
56
57
|
pending_tool_calls = set()
|
|
@@ -62,7 +63,7 @@ async def canonical_events(
|
|
|
62
63
|
framework="adk",
|
|
63
64
|
metadata={
|
|
64
65
|
"session_id": session_id,
|
|
65
|
-
**({"last_usage": last_usage} if last_usage else {}),
|
|
66
|
+
**({"last_usage": usage_accumulator.last_usage} if usage_accumulator.last_usage else {}),
|
|
66
67
|
**({"usage": usage} if usage else {}),
|
|
67
68
|
},
|
|
68
69
|
)
|
|
@@ -99,10 +100,7 @@ async def canonical_events(
|
|
|
99
100
|
if target:
|
|
100
101
|
root_transfer_target = target
|
|
101
102
|
|
|
102
|
-
|
|
103
|
-
if event_usage:
|
|
104
|
-
usage = accumulate_usage(usage, event_usage)
|
|
105
|
-
last_usage = event_usage
|
|
103
|
+
usage_accumulator.observe(native_event, runner._extract_event_usage(native_event))
|
|
106
104
|
|
|
107
105
|
approval_signals = list(runner._extract_approval_signals(native_event))
|
|
108
106
|
for event in adapter.map(native_event, context):
|
|
@@ -243,15 +241,18 @@ async def canonical_events(
|
|
|
243
241
|
)
|
|
244
242
|
context.mark_failed((scope_id, item_id))
|
|
245
243
|
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
cached_tokens=int(usage.get("cached_tokens") or 0),
|
|
253
|
-
reasoning_tokens=int(usage.get("reasoning_tokens") or 0),
|
|
244
|
+
usage = usage_accumulator.total()
|
|
245
|
+
for snapshot in usage_accumulator.snapshots.values():
|
|
246
|
+
fields = envelope("usage.reported", f"{snapshot.invocation_id}:{snapshot.response_id}")
|
|
247
|
+
fields["source"] = SourceRef(
|
|
248
|
+
framework="adk", native_run_id=snapshot.invocation_id or None,
|
|
249
|
+
metadata={"usage_contract": "adk_model_call_delta_v1"},
|
|
254
250
|
)
|
|
251
|
+
if snapshot.timestamp is not None:
|
|
252
|
+
fields["timestamp"] = snapshot.timestamp
|
|
253
|
+
counts = canonical_usage_payload(snapshot.usage, runtime_type="adk")
|
|
254
|
+
del counts["source"]
|
|
255
|
+
yield UsageReported(**fields, **counts)
|
|
255
256
|
|
|
256
257
|
if tunnel_outcome is not None:
|
|
257
258
|
from ksadk.tunnel.failure import failure_events
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"""
|
|
1
|
+
"""Preserve final-answer snapshot precedence without suppressing model tokens."""
|
|
2
2
|
|
|
3
3
|
from collections.abc import Mapping
|
|
4
4
|
|
|
@@ -20,12 +20,6 @@ def has_explicit_answer_field(graph) -> bool:
|
|
|
20
20
|
return "output" in properties or "answer" in properties
|
|
21
21
|
|
|
22
22
|
|
|
23
|
-
def uses_explicit_answer_contract(graph) -> bool:
|
|
24
|
-
"""Use only the graph's public output schema; unknown shapes stay streaming."""
|
|
25
|
-
properties = _output_properties(graph)
|
|
26
|
-
return "messages" not in properties and ("output" in properties or "answer" in properties)
|
|
27
|
-
|
|
28
|
-
|
|
29
23
|
def internal_model_event(event: RuntimeEvent) -> RuntimeEvent:
|
|
30
24
|
"""Keep model traces observable without publishing them as graph answers."""
|
|
31
25
|
if getattr(event, "item_kind", None) not in {"message", "reasoning"}:
|
|
@@ -14,8 +14,8 @@ from ksadk.events.runtime_event import RuntimeEvent
|
|
|
14
14
|
from ksadk.runners._langgraph_answer_contract import (
|
|
15
15
|
has_explicit_answer_field,
|
|
16
16
|
internal_model_event,
|
|
17
|
-
uses_explicit_answer_contract,
|
|
18
17
|
)
|
|
18
|
+
from ksadk.runners._langgraph_model_budget import model_budget_scope
|
|
19
19
|
from ksadk.runners._langgraph_fresh_turn import fresh_memory_input, fresh_user_checkpoint
|
|
20
20
|
from ksadk.runtime.skill_eval_result import skill_eval_response_fields
|
|
21
21
|
from ksadk.runtime.timing import extract_timing
|
|
@@ -62,6 +62,7 @@ class _LangGraphCanonicalStreamMixin:
|
|
|
62
62
|
yield event
|
|
63
63
|
|
|
64
64
|
@fresh_user_checkpoint
|
|
65
|
+
@model_budget_scope
|
|
65
66
|
async def _stream_native_canonical_events(
|
|
66
67
|
self, input_data: Dict[str, Any]
|
|
67
68
|
) -> AsyncIterator[RuntimeEvent]:
|
|
@@ -84,6 +85,7 @@ class _LangGraphCanonicalStreamMixin:
|
|
|
84
85
|
from ksadk.events.canonical import (
|
|
85
86
|
ErrorInfo,
|
|
86
87
|
InteractionRequested,
|
|
88
|
+
ItemStarted,
|
|
87
89
|
OutputRef,
|
|
88
90
|
RunCompleted,
|
|
89
91
|
RunFailed,
|
|
@@ -175,10 +177,8 @@ class _LangGraphCanonicalStreamMixin:
|
|
|
175
177
|
state = resume_value
|
|
176
178
|
elif is_resume and not is_gateway_approval_resume:
|
|
177
179
|
state = self._unwrap_resume_value(resume_value)
|
|
178
|
-
elif self._has_prepare_state_hook():
|
|
179
|
-
state = self._prepare_state_with_hook(payload, session_id, history)
|
|
180
180
|
else:
|
|
181
|
-
state = self.
|
|
181
|
+
state = await self._prepare_new_turn_state(payload, session_id, history, config=config)
|
|
182
182
|
|
|
183
183
|
if not is_resume and not is_checkpoint_resume:
|
|
184
184
|
state = await fresh_memory_input(self._agent, config, state)
|
|
@@ -344,7 +344,6 @@ class _LangGraphCanonicalStreamMixin:
|
|
|
344
344
|
from ksadk.runners._langgraph_final_answer import answer_update_fields
|
|
345
345
|
|
|
346
346
|
updated_answer_fields: set[str] = set()
|
|
347
|
-
explicit_answer = uses_explicit_answer_contract(self._agent)
|
|
348
347
|
explicit_snapshot_answer = has_explicit_answer_field(self._agent)
|
|
349
348
|
final_result_fields: dict[str, Any] = {}
|
|
350
349
|
|
|
@@ -365,7 +364,7 @@ class _LangGraphCanonicalStreamMixin:
|
|
|
365
364
|
run_stream = await self._agent.astream_events(stream_input, **stream_kwargs)
|
|
366
365
|
async for event in adapter.stream_run(run_stream, adapter_context):
|
|
367
366
|
updated_answer_fields.update(answer_update_fields(event))
|
|
368
|
-
if (
|
|
367
|
+
if (
|
|
369
368
|
explicit_snapshot_answer
|
|
370
369
|
and event.source.metadata.get("message_delivery") == "snapshot"
|
|
371
370
|
):
|
|
@@ -374,6 +373,14 @@ class _LangGraphCanonicalStreamMixin:
|
|
|
374
373
|
# output when no model/custom text was streamed. Keep their
|
|
375
374
|
# snapshots observable and let final_answer_events select it.
|
|
376
375
|
event = internal_model_event(event)
|
|
376
|
+
if (isinstance(event, ItemStarted)
|
|
377
|
+
and event.item_kind in {"message", "reasoning"}
|
|
378
|
+
and event.source.metadata.get(
|
|
379
|
+
"conversation_visibility", event.source.metadata.get("visibility")
|
|
380
|
+
) in {"internal", "hidden"}):
|
|
381
|
+
# Explicitly private model calls cannot own the public
|
|
382
|
+
# final answer or suppress the graph's fallback answer.
|
|
383
|
+
event = event.model_copy(update={"phase": "commentary"})
|
|
377
384
|
if isinstance(event, RunInterrupted) or (
|
|
378
385
|
isinstance(event, RunProgress)
|
|
379
386
|
and authority is not None
|