agentengine-sdk-python 0.8.7__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.7.dist-info → agentengine_sdk_python-0.8.9.dist-info}/METADATA +22 -20
- {agentengine_sdk_python-0.8.7.dist-info → agentengine_sdk_python-0.8.9.dist-info}/RECORD +259 -221
- ksadk/__init__.py +2 -1
- ksadk/_build_provenance.json +1 -1
- ksadk/_mcp_compat.py +305 -0
- ksadk/agent.py +29 -0
- ksadk/agui/_agent_kernel.py +176 -142
- ksadk/agui/agent.py +75 -6
- ksadk/agui/hosted.py +343 -0
- ksadk/agui/request_identity.py +11 -0
- ksadk/agui/routes.py +77 -2
- ksadk/builders/code_builder.py +30 -23
- ksadk/builders/container_builder.py +5 -5
- ksadk/builders/framework_requirements.py +1 -1
- ksadk/builders/mcp_builder.py +142 -0
- ksadk/builders/project_imports.py +66 -0
- ksadk/cli/cmd_mcp.py +1 -1
- ksadk/cli/cmd_run.py +6 -4
- ksadk/cli/cmd_web.py +12 -0
- ksadk/cli/runtime_bootstrap.py +4 -1
- ksadk/cli/runtime_logging.py +30 -0
- ksadk/common/cloud_headers.py +33 -6
- ksadk/compat/adk_compat.py +2 -0
- ksadk/compat/adk_stream.py +35 -0
- ksadk/configs/env_registry.py +31 -0
- ksadk/context_engine/capabilities.py +13 -9
- ksadk/conversations/context.py +5 -0
- ksadk/conversations/message_projection.py +28 -19
- ksadk/conversations/projector.py +6 -0
- 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_observability.py +1 -0
- ksadk/conversations/runtime_payloads.py +5 -1
- ksadk/conversations/runtime_persistence.py +23 -0
- ksadk/conversations/runtime_preparation.py +128 -5
- ksadk/detection/mcp_detector.py +80 -22
- ksadk/events/adapters/langgraph.py +53 -1
- ksadk/harness/__init__.py +3 -0
- ksadk/harness/service_presentation.py +44 -0
- ksadk/harness/service_runtime.py +1038 -0
- ksadk/interaction/providers/harness.py +9 -4
- ksadk/kernel/control.py +16 -22
- ksadk/kernel/history_projection.py +191 -58
- ksadk/kernel/ingress.py +50 -26
- 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.py +2 -2
- ksadk/kernel/worker_controls.py +11 -1
- ksadk/kernel/worker_identity.py +15 -8
- ksadk/knowledge_base/client.py +10 -3
- ksadk/mcp_runtime/oauth/_agent.py +77 -9
- ksadk/mcp_runtime/oauth/kernel.py +5 -0
- ksadk/mcp_runtime/oauth/langgraph.py +47 -15
- ksadk/mcp_runtime/oauth/local/broker.py +41 -9
- ksadk/mcp_runtime/oauth/local/protocol.py +3 -11
- ksadk/mcp_runtime/oauth/local/transport.py +9 -2
- ksadk/mcp_runtime/oauth/tools.py +46 -8
- ksadk/mcp_runtime/oauth/transport.py +19 -2
- ksadk/memory/adk/backends/sdk_ltm_backend.py +21 -12
- ksadk/memory/scope_ids.py +49 -0
- ksadk/plugins/providers/harness.py +65 -28
- ksadk/plugins/providers/harness_service.py +198 -0
- ksadk/plugins/providers/harness_service_context.py +175 -0
- ksadk/plugins/providers/harness_service_hooks.py +168 -0
- ksadk/plugins/providers/harness_service_memory.py +479 -0
- ksadk/plugins/providers/platform_resources.py +2 -2
- ksadk/resource_runtime/contracts.py +39 -1
- ksadk/resource_runtime/langgraph.py +7 -3
- ksadk/resource_runtime/managed_projection.py +8 -6
- ksadk/resource_runtime/mcp_server.py +3 -3
- ksadk/resource_runtime/worker.py +27 -5
- ksadk/runners/_adk_canonical_stream.py +53 -24
- ksadk/runners/_adk_tunnel_history.py +96 -0
- ksadk/runners/_langgraph_answer_contract.py +1 -7
- ksadk/runners/_langgraph_canonical_stream.py +29 -6
- ksadk/runners/_langgraph_context.py +265 -0
- ksadk/runners/_langgraph_factory.py +79 -0
- ksadk/runners/_langgraph_model_budget.py +397 -0
- ksadk/runners/_langgraph_runner_streams.py +13 -6
- ksadk/runners/_session_identity.py +8 -3
- ksadk/runners/adk_runner.py +104 -36
- ksadk/runners/langgraph_runner.py +145 -29
- ksadk/runners/usage_accumulator.py +40 -0
- ksadk/runtime/conversation_execution.py +26 -4
- ksadk/runtime/factory.py +17 -5
- ksadk/runtime/framework_adapters.py +10 -0
- ksadk/runtime/langgraph_checkpoint_view.py +28 -7
- ksadk/runtime/launch.py +2 -0
- ksadk/server/factory.py +58 -1
- ksadk/server/routes/common.py +2 -0
- ksadk/server/routes/control.py +24 -8
- ksadk/server/routes/harness_service_view.py +38 -0
- 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/routes/ui_bootstrap.py +16 -2
- 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/skills/mcp_server/server.py +239 -217
- ksadk/studio/contracts.py +8 -0
- ksadk/studio/mcp_runtime.py +23 -8
- ksadk/studio/native_mcp_disclosure.py +8 -6
- ksadk/studio/native_mcp_tool_port.py +3 -1
- ksadk/studio/native_memory_context.py +10 -8
- ksadk/studio/native_product.py +3 -4
- ksadk/studio/plugin_composition.py +8 -1
- ksadk/studio/plugin_native_activation.py +4 -2
- ksadk/studio/plugin_runtime.py +9 -0
- ksadk/studio/service.py +2 -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/tracing/setup.py +53 -3
- ksadk/tunnel/__init__.py +37 -0
- ksadk/tunnel/connector.py +384 -0
- ksadk/tunnel/discovery.py +107 -0
- ksadk/tunnel/failure.py +168 -0
- ksadk/tunnel/http_tools.py +100 -0
- ksadk/tunnel/langgraph.py +125 -0
- ksadk/tunnel/middleware.py +28 -0
- ksadk/tunnel/peers.py +872 -0
- ksadk/tunnel/protocol.py +97 -0
- ksadk/tunnel/registry.py +306 -0
- ksadk/tunnel/runtime.py +147 -0
- ksadk/tunnel/server.py +201 -0
- ksadk/tunnel/services.py +366 -0
- ksadk/tunnel/toolset.py +78 -0
- ksadk/version.py +1 -1
- ksadk_runtime_common/memory_backend/providers/mem0.py +20 -0
- 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.7.dist-info → agentengine_sdk_python-0.8.9.dist-info}/WHEEL +0 -0
- {agentengine_sdk_python-0.8.7.dist-info → agentengine_sdk_python-0.8.9.dist-info}/entry_points.txt +0 -0
- {agentengine_sdk_python-0.8.7.dist-info → agentengine_sdk_python-0.8.9.dist-info}/licenses/LICENSE +0 -0
- {agentengine_sdk_python-0.8.7.dist-info → agentengine_sdk_python-0.8.9.dist-info}/top_level.txt +0 -0
ksadk/kernel/postgres_store.py
CHANGED
|
@@ -108,6 +108,7 @@ class PostgresKernelEventLog:
|
|
|
108
108
|
workspace_id: str = "default",
|
|
109
109
|
) -> None:
|
|
110
110
|
self._pool = pool
|
|
111
|
+
self._history_insert_fields = None
|
|
111
112
|
self._namespace = namespace.strip() or "default"
|
|
112
113
|
self._tenant_id = tenant_id.strip() or "default"
|
|
113
114
|
self._workspace_id = workspace_id.strip() or "default"
|
|
@@ -149,15 +150,22 @@ class PostgresKernelEventLog:
|
|
|
149
150
|
)
|
|
150
151
|
seq = int(next_seq or 1)
|
|
151
152
|
packed.bind_seq_id(seq) # 把物理 seq 绑定回 runtime/session envelope 内容
|
|
153
|
+
# Standalone ingress may connect to a previous Session schema during rollout.
|
|
154
|
+
# Decide once per writer; legacy INSERTs keep working until its next restart.
|
|
155
|
+
if self._history_insert_fields is None:
|
|
156
|
+
from ksadk.sessions._postgres_schema import history_item_insert_fields
|
|
157
|
+
|
|
158
|
+
self._history_insert_fields = await history_item_insert_fields(connection)
|
|
159
|
+
history_column, history_value = self._history_insert_fields
|
|
152
160
|
inserted = await connection.fetchrow(
|
|
153
161
|
f"""
|
|
154
162
|
INSERT INTO {KSADK_PG_EVENTS_TABLE} (
|
|
155
163
|
namespace, tenant_id, workspace_id, id, session_id, author,
|
|
156
164
|
event_type, content_json, timestamp, state_delta_json,
|
|
157
|
-
seq_id, invocation_id, metadata_json
|
|
165
|
+
seq_id, invocation_id, metadata_json{history_column}
|
|
158
166
|
) VALUES (
|
|
159
167
|
$1, $2, $3, $4, $5, $6, $7, $8::jsonb, $9,
|
|
160
|
-
'{{}}'::jsonb, $10, $11, $12::jsonb
|
|
168
|
+
'{{}}'::jsonb, $10, $11, $12::jsonb{history_value}
|
|
161
169
|
)
|
|
162
170
|
ON CONFLICT (namespace, id) DO NOTHING
|
|
163
171
|
RETURNING seq_id, timestamp
|
|
@@ -337,6 +345,7 @@ class PostgresKernelEventLog:
|
|
|
337
345
|
COALESCE(octet_length(metadata_json::text),0) + 1024 AS bytes
|
|
338
346
|
FROM {KSADK_PG_EVENTS_TABLE}
|
|
339
347
|
WHERE namespace=$1 AND session_id=$2 AND seq_id>$3
|
|
348
|
+
AND metadata_json @> '{{"ksadk_session_event_envelope": true}}'::jsonb
|
|
340
349
|
ORDER BY seq_id LIMIT $4
|
|
341
350
|
), measured AS (
|
|
342
351
|
SELECT *,ROW_NUMBER() OVER (ORDER BY seq_id) AS position,
|
|
@@ -763,6 +772,28 @@ class PostgresAgentKernelStore(PostgresInteractionStoreMixin, PostgresExecutionG
|
|
|
763
772
|
)
|
|
764
773
|
return self._row_to_message(row)
|
|
765
774
|
|
|
775
|
+
async def history_input_chunks(
|
|
776
|
+
self, accepted: dict[str, str], *, tenant_id: str, agent_instance_id: str,
|
|
777
|
+
session_id: str, offset: int, limit: int,
|
|
778
|
+
) -> dict[str, tuple[str, int | None]]:
|
|
779
|
+
"""Read only the caller-visible content from verified enqueue commands."""
|
|
780
|
+
async with self._connection() as connection:
|
|
781
|
+
rows = await connection.fetch("""
|
|
782
|
+
SELECT message_id::text AS id,
|
|
783
|
+
substring((payload->'payload'->'content')::text FROM $7::integer FOR $8::integer) AS part
|
|
784
|
+
FROM kernel_inbox
|
|
785
|
+
JOIN unnest($1::uuid[], $2::text[]) AS accepted(id, cmd)
|
|
786
|
+
ON message_id=accepted.id AND payload->>'command_id'=accepted.cmd
|
|
787
|
+
WHERE tenant_id=$3 AND agent_instance_id=$4 AND session_id=$5
|
|
788
|
+
AND payload->>'command_type'='enqueue' AND payload->>'tenant_id'=$6
|
|
789
|
+
AND payload->>'agent_instance_id'=$4 AND payload->>'session_id'=$5
|
|
790
|
+
""", list(accepted), list(accepted.values()), self.tenant_id, agent_instance_id,
|
|
791
|
+
session_id, tenant_id, offset + 1, limit + 1)
|
|
792
|
+
return {
|
|
793
|
+
row["id"]: (row["part"][:limit], offset + limit if len(row["part"]) > limit else None)
|
|
794
|
+
for row in rows if row["part"] is not None
|
|
795
|
+
}
|
|
796
|
+
|
|
766
797
|
async def load_messages_for_history(
|
|
767
798
|
self, message_ids: list[str], *, tenant_id: str, agent_instance_id: str,
|
|
768
799
|
session_id: str,
|
|
@@ -1141,6 +1172,16 @@ class PostgresAgentKernelStore(PostgresInteractionStoreMixin, PostgresExecutionG
|
|
|
1141
1172
|
)
|
|
1142
1173
|
)
|
|
1143
1174
|
|
|
1175
|
+
async def has_claimed_work(self, agent_instance_id: str, session_id: str) -> bool:
|
|
1176
|
+
"""Observe a Worker claim before its Run reaches the active query."""
|
|
1177
|
+
async with self._connection() as connection:
|
|
1178
|
+
return bool(await connection.fetchval(
|
|
1179
|
+
"SELECT EXISTS(SELECT 1 FROM kernel_inbox WHERE agent_instance_id=$1"
|
|
1180
|
+
" AND tenant_id=$2 AND (session_namespace=$3 OR session_namespace IS NULL)"
|
|
1181
|
+
" AND session_id=$4 AND status='claimed')",
|
|
1182
|
+
agent_instance_id, self.tenant_id, self._events._namespace, session_id,
|
|
1183
|
+
))
|
|
1184
|
+
|
|
1144
1185
|
async def find_active_run(
|
|
1145
1186
|
self, agent_instance_id: str, session_id: str | None = None
|
|
1146
1187
|
) -> RunRecord | None:
|
|
@@ -1509,6 +1550,42 @@ class PostgresAgentKernelStore(PostgresInteractionStoreMixin, PostgresExecutionG
|
|
|
1509
1550
|
metadata=json.loads(row["metadata"]),
|
|
1510
1551
|
)
|
|
1511
1552
|
|
|
1553
|
+
async def history_input_command_ids(
|
|
1554
|
+
self, run_ids: list[str], *, agent_instance_id: str, session_id: str,
|
|
1555
|
+
) -> dict[str, str]:
|
|
1556
|
+
"""Return only the stable command identity, without loading run metadata blobs."""
|
|
1557
|
+
async with self._connection() as connection:
|
|
1558
|
+
rows = await connection.fetch("""
|
|
1559
|
+
SELECT run_id, metadata->>'command_id' AS cmd FROM kernel_runs
|
|
1560
|
+
WHERE run_id=ANY($1::text[]) AND tenant_id=$2
|
|
1561
|
+
AND agent_instance_id=$3 AND session_id=$4
|
|
1562
|
+
AND length(metadata->>'command_id') BETWEEN 1 AND 128
|
|
1563
|
+
""", run_ids, self.tenant_id, agent_instance_id, session_id)
|
|
1564
|
+
return {row["run_id"]: row["cmd"] for row in rows}
|
|
1565
|
+
|
|
1566
|
+
async def history_input_start_seq(
|
|
1567
|
+
self, command_id: str, *, agent_instance_id: str, session_id: str,
|
|
1568
|
+
after_seq_id: int, before_seq_id: int,
|
|
1569
|
+
) -> int | None:
|
|
1570
|
+
"""Locate the durable acceptance in its Session sequence space."""
|
|
1571
|
+
async with self._connection() as connection:
|
|
1572
|
+
return await connection.fetchval(f"""
|
|
1573
|
+
SELECT e.seq_id
|
|
1574
|
+
FROM kernel_inbox AS i
|
|
1575
|
+
JOIN {KSADK_PG_EVENTS_TABLE} AS e
|
|
1576
|
+
ON e.namespace=$1 AND e.session_id=i.session_id AND e.seq_id=i.accepted_seq
|
|
1577
|
+
WHERE i.tenant_id=$2 AND i.agent_instance_id=$3 AND i.session_id=$4
|
|
1578
|
+
AND i.session_namespace=$1 AND i.payload->>'command_id'=$5
|
|
1579
|
+
AND i.accepted_seq>$6 AND i.accepted_seq<$7
|
|
1580
|
+
AND e.event_type='control.command_accepted'
|
|
1581
|
+
AND e.content_json#>>'{{session_event,family}}'='control'
|
|
1582
|
+
AND e.content_json#>>'{{session_event,payload,command_id}}'=$5
|
|
1583
|
+
AND e.content_json#>>'{{session_event,payload,message_id}}'=i.message_id::text
|
|
1584
|
+
AND e.content_json#>>'{{session_event,payload,command_type}}'='enqueue'
|
|
1585
|
+
ORDER BY e.seq_id DESC LIMIT 1
|
|
1586
|
+
""", self._events._namespace, self.tenant_id, agent_instance_id, session_id,
|
|
1587
|
+
command_id, after_seq_id, before_seq_id)
|
|
1588
|
+
|
|
1512
1589
|
async def load_runs_for_history(
|
|
1513
1590
|
self, run_ids: list[str], *, tenant_id: str, agent_instance_id: str,
|
|
1514
1591
|
session_id: str,
|
|
@@ -1671,6 +1748,8 @@ class PostgresFencedSessionEventStore:
|
|
|
1671
1748
|
走 event log 自开事务。
|
|
1672
1749
|
"""
|
|
1673
1750
|
|
|
1751
|
+
subscription_cursor_chain = True
|
|
1752
|
+
|
|
1674
1753
|
def __init__(self, store: "PostgresAgentKernelStore") -> None:
|
|
1675
1754
|
self._store = store
|
|
1676
1755
|
self._log = store._events
|
|
@@ -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.py
CHANGED
|
@@ -614,7 +614,7 @@ class AgentKernelWorker(WorkerInteractionMixin, WorkerControlMixin):
|
|
|
614
614
|
}
|
|
615
615
|
if approval_mode in approval_overrides:
|
|
616
616
|
request_config["approval_mode"] = approval_overrides[approval_mode]
|
|
617
|
-
effective_user_id, invocation_identity = await prepare_worker_identity(
|
|
617
|
+
effective_user_id, invocation_identity, session_agent_id = await prepare_worker_identity(
|
|
618
618
|
command=command,
|
|
619
619
|
defaults=defaults,
|
|
620
620
|
session_service=self._session_service,
|
|
@@ -644,7 +644,7 @@ class AgentKernelWorker(WorkerInteractionMixin, WorkerControlMixin):
|
|
|
644
644
|
input=command.payload.get("content"),
|
|
645
645
|
user_id=effective_user_id,
|
|
646
646
|
session_id=command.session_id,
|
|
647
|
-
agent_id=
|
|
647
|
+
agent_id=session_agent_id,
|
|
648
648
|
model=selected_model,
|
|
649
649
|
config=request_config,
|
|
650
650
|
# durable run_id 优先传给 adapter;adapter 不认时以
|
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,
|
ksadk/kernel/worker_identity.py
CHANGED
|
@@ -15,9 +15,10 @@ async def prepare_worker_identity(
|
|
|
15
15
|
command: AgentControlCommand,
|
|
16
16
|
defaults: Mapping[str, object],
|
|
17
17
|
session_service: object | None,
|
|
18
|
-
) -> tuple[str, Mapping[str, Any] | None]:
|
|
19
|
-
"""Resolve
|
|
18
|
+
) -> tuple[str, Mapping[str, Any] | None, str]:
|
|
19
|
+
"""Resolve storage user, admitted identity and Agent from one owner snapshot."""
|
|
20
20
|
|
|
21
|
+
fallback_agent_id = str(defaults.get("agent_id") or command.agent_instance_id)
|
|
21
22
|
invocation_identity = command.payload.get("invocation_identity")
|
|
22
23
|
effective_user_id = str(command.tenant_id or "agent-kernel")
|
|
23
24
|
if command.payload.get("teams_context_ref") is not None:
|
|
@@ -34,11 +35,12 @@ async def prepare_worker_identity(
|
|
|
34
35
|
raise ValueError("prepared Teams session owner is unavailable")
|
|
35
36
|
return existing.user_id, (
|
|
36
37
|
invocation_identity if isinstance(invocation_identity, Mapping) else None
|
|
37
|
-
)
|
|
38
|
+
), fallback_agent_id
|
|
38
39
|
if not isinstance(invocation_identity, Mapping):
|
|
39
40
|
existing = (
|
|
40
41
|
await session_service.get_session_metadata(command.session_id)
|
|
41
|
-
if session_service is not None
|
|
42
|
+
if session_service is not None
|
|
43
|
+
else None
|
|
42
44
|
)
|
|
43
45
|
if existing is not None:
|
|
44
46
|
# Kernel ingress has authorized this exact session/instance. Tenant
|
|
@@ -47,10 +49,10 @@ async def prepare_worker_identity(
|
|
|
47
49
|
agent_id = str(defaults.get("agent_id") or command.agent_instance_id)
|
|
48
50
|
if existing.agent_id != agent_id or not existing.user_id:
|
|
49
51
|
raise ValueError("prepared session Agent differs from the Kernel Build")
|
|
50
|
-
return existing.user_id, None
|
|
51
|
-
return effective_user_id, None
|
|
52
|
+
return existing.user_id, None, fallback_agent_id
|
|
53
|
+
return effective_user_id, None, fallback_agent_id
|
|
52
54
|
if session_service is None:
|
|
53
|
-
return identity_native_user_id(invocation_identity), invocation_identity
|
|
55
|
+
return identity_native_user_id(invocation_identity), invocation_identity, fallback_agent_id
|
|
54
56
|
|
|
55
57
|
# Hosted runtimes have two stable identifiers: the platform deployment
|
|
56
58
|
# instance (used by the Kernel command) and the public AgentId used by
|
|
@@ -71,4 +73,9 @@ async def prepare_worker_identity(
|
|
|
71
73
|
invocation_identity=invocation_identity,
|
|
72
74
|
allow_agent_alias=True,
|
|
73
75
|
)
|
|
74
|
-
|
|
76
|
+
# Use the same owner snapshot we just authorized; do not look up the
|
|
77
|
+
# session again after a concurrent deletion/recreation could replace it.
|
|
78
|
+
resolved_agent_id = (
|
|
79
|
+
canonical_session.agent_id if command.source.kind == "agui" else fallback_agent_id
|
|
80
|
+
)
|
|
81
|
+
return canonical_session.user_id, invocation_identity, resolved_agent_id
|
ksadk/knowledge_base/client.py
CHANGED
|
@@ -44,7 +44,11 @@ from typing import Any, List, Optional
|
|
|
44
44
|
from pydantic import BaseModel, ConfigDict, Field, field_validator
|
|
45
45
|
|
|
46
46
|
from ksadk.common.aicp_env import resolve_aicp_connection
|
|
47
|
-
from ksadk.common.cloud_headers import
|
|
47
|
+
from ksadk.common.cloud_headers import (
|
|
48
|
+
build_component_headers,
|
|
49
|
+
resolve_component_env,
|
|
50
|
+
resolve_traffic_source,
|
|
51
|
+
)
|
|
48
52
|
|
|
49
53
|
logger = logging.getLogger(__name__)
|
|
50
54
|
|
|
@@ -94,6 +98,7 @@ class KnowledgeBaseClient(BaseModel):
|
|
|
94
98
|
secret_key: str = ""
|
|
95
99
|
session_token: str = ""
|
|
96
100
|
traffic_source: str = Field(default_factory=resolve_traffic_source)
|
|
101
|
+
component_env: str = Field(default_factory=resolve_component_env)
|
|
97
102
|
region: str = "cn-beijing-6"
|
|
98
103
|
endpoint: str = "aicp.api.ksyun.com"
|
|
99
104
|
scheme: str = "https"
|
|
@@ -198,8 +203,10 @@ class KnowledgeBaseClient(BaseModel):
|
|
|
198
203
|
class ObservedAicpClient(aicp_module.AicpClient):
|
|
199
204
|
def call(self, action, params, options=None):
|
|
200
205
|
options = dict(options or {})
|
|
201
|
-
options["CustomHeaders"] =
|
|
202
|
-
options.get("CustomHeaders"),
|
|
206
|
+
options["CustomHeaders"] = build_component_headers(
|
|
207
|
+
options.get("CustomHeaders"),
|
|
208
|
+
traffic_source=owner.traffic_source,
|
|
209
|
+
component_env=owner.component_env,
|
|
203
210
|
)
|
|
204
211
|
return super().call(action, params, options)
|
|
205
212
|
|
|
@@ -22,6 +22,8 @@ If an operation is rejected, stop that operation. Never claim success for a fail
|
|
|
22
22
|
|
|
23
23
|
class _State(McpOAuthState):
|
|
24
24
|
mcp_call_count: int
|
|
25
|
+
mcp_tunnel_catalog: list[dict]
|
|
26
|
+
mcp_tunnel_unknown: bool
|
|
25
27
|
|
|
26
28
|
|
|
27
29
|
class _Agent:
|
|
@@ -34,6 +36,7 @@ class _Agent:
|
|
|
34
36
|
if not isinstance(prompt, str):
|
|
35
37
|
raise ValueError("system_prompt must be a string")
|
|
36
38
|
self.model, self.prompt, self.limit = model, prompt, limit
|
|
39
|
+
self.tunnel_tools = None
|
|
37
40
|
self.tools = {}
|
|
38
41
|
for tool in tools:
|
|
39
42
|
if not isinstance(tool, BaseTool) or tool.name in self.tools:
|
|
@@ -43,13 +46,21 @@ class _Agent:
|
|
|
43
46
|
raise ValueError("MCP connection tool name collision")
|
|
44
47
|
|
|
45
48
|
def begin(self, state):
|
|
46
|
-
|
|
49
|
+
update = {**self.oauth.reset(state), "mcp_call_count": 0}
|
|
50
|
+
if self.tunnel_tools is not None:
|
|
51
|
+
update.update(mcp_tunnel_catalog=[], mcp_tunnel_unknown=False)
|
|
52
|
+
return update
|
|
47
53
|
|
|
48
54
|
async def chat(self, state, config: RunnableConfig):
|
|
49
55
|
oauth_tools = self.oauth.model_tools(state)
|
|
50
|
-
|
|
56
|
+
tunnel_catalog = await self.tunnel_tools.discover() if self.tunnel_tools is not None else []
|
|
57
|
+
tunnel_tools = (
|
|
58
|
+
self.tunnel_tools.model_tools(tunnel_catalog) if self.tunnel_tools is not None else []
|
|
59
|
+
)
|
|
60
|
+
names = [*self.tools, *(t["function"]["name"] for t in [*oauth_tools, *tunnel_tools])]
|
|
61
|
+
if len(names) != len(set(names)):
|
|
51
62
|
raise BrokerError("MCP_TOOL_NAME_COLLISION")
|
|
52
|
-
definitions: list[Any] = [*self.tools.values(), *oauth_tools]
|
|
63
|
+
definitions: list[Any] = [*self.tools.values(), *oauth_tools, *tunnel_tools]
|
|
53
64
|
runnable = self.model.bind_tools(definitions) if definitions else self.model
|
|
54
65
|
response = await runnable.ainvoke(
|
|
55
66
|
[SystemMessage(content=self.prompt + "\n\n" + _GUIDANCE), *state["messages"]],
|
|
@@ -70,7 +81,10 @@ class _Agent:
|
|
|
70
81
|
}
|
|
71
82
|
if any(not value for value in ids) or len(set(ids)) != len(ids) or set(ids) & prior_ids:
|
|
72
83
|
raise BrokerError("MCP_MODEL_TOOL_CALL_ID_INVALID")
|
|
73
|
-
|
|
84
|
+
update = {"messages": [response]}
|
|
85
|
+
if self.tunnel_tools is not None:
|
|
86
|
+
update["mcp_tunnel_catalog"] = tunnel_catalog
|
|
87
|
+
return update
|
|
74
88
|
|
|
75
89
|
async def execute(self, state, config: RunnableConfig):
|
|
76
90
|
call = _pending(state)
|
|
@@ -81,6 +95,32 @@ class _Agent:
|
|
|
81
95
|
# Preserve the caller's existing LangChain tool implementation.
|
|
82
96
|
update["messages"] = [await self.tools[call["name"]].ainvoke(call, config=config)]
|
|
83
97
|
return update
|
|
98
|
+
selected = next(
|
|
99
|
+
(
|
|
100
|
+
entry
|
|
101
|
+
for entry in state.get("mcp_tunnel_catalog", [])
|
|
102
|
+
if entry["name"] == call["name"]
|
|
103
|
+
),
|
|
104
|
+
None,
|
|
105
|
+
)
|
|
106
|
+
if self.tunnel_tools is not None and selected is not None:
|
|
107
|
+
from ksadk.tunnel.protocol import TunnelError
|
|
108
|
+
|
|
109
|
+
try:
|
|
110
|
+
# Use the same callback path as ordinary tools for the runtime timeline.
|
|
111
|
+
(tool,) = await self.tunnel_tools.get_tools([selected])
|
|
112
|
+
update["messages"] = [await tool.ainvoke(call, config=config)]
|
|
113
|
+
except TunnelError as exc:
|
|
114
|
+
update["messages"] = [
|
|
115
|
+
_reply(
|
|
116
|
+
call, {"error": exc.code, "indeterminate": exc.indeterminate}, error=True
|
|
117
|
+
)
|
|
118
|
+
]
|
|
119
|
+
if exc.indeterminate:
|
|
120
|
+
# Do not let a model turn an unknown result into an
|
|
121
|
+
# automatic second attempt of a potentially completed call.
|
|
122
|
+
update.update(mcp_stop=True, mcp_tunnel_unknown=True)
|
|
123
|
+
return update
|
|
84
124
|
if self.oauth.owns(call, state):
|
|
85
125
|
return {**update, **await self.oauth.execute(state, config)}
|
|
86
126
|
update["messages"] = [_reply(call, {"error": "MCP_TOOL_UNAVAILABLE"}, error=True)]
|
|
@@ -98,9 +138,13 @@ class _Agent:
|
|
|
98
138
|
@staticmethod
|
|
99
139
|
def finish(state):
|
|
100
140
|
message = (
|
|
101
|
-
"
|
|
102
|
-
if state.get("
|
|
103
|
-
else
|
|
141
|
+
"工具调用结果未知,已停止本次操作。请先查询业务状态,再决定是否重新执行。"
|
|
142
|
+
if state.get("mcp_tunnel_unknown")
|
|
143
|
+
else (
|
|
144
|
+
"已按你的决定停止本次操作。"
|
|
145
|
+
if state.get("mcp_stop")
|
|
146
|
+
else "已达到本次工具调用上限,请缩小任务范围后重试。"
|
|
147
|
+
)
|
|
104
148
|
)
|
|
105
149
|
messages, working = [], dict(state)
|
|
106
150
|
while call := _pending(working):
|
|
@@ -130,6 +174,11 @@ def build_agent(
|
|
|
130
174
|
max_tool_calls,
|
|
131
175
|
execution_policies,
|
|
132
176
|
)
|
|
177
|
+
return _compile_agent(agent, checkpointer=checkpointer)
|
|
178
|
+
|
|
179
|
+
|
|
180
|
+
def _compile_agent(agent, *, checkpointer, template=None):
|
|
181
|
+
"""Rebuild SDK nodes around an isolated agent; preserve graph-owned storage."""
|
|
133
182
|
graph = StateGraph(_State)
|
|
134
183
|
graph.add_node("begin", agent.begin)
|
|
135
184
|
graph.add_node("chat", agent.chat)
|
|
@@ -140,8 +189,27 @@ def build_agent(
|
|
|
140
189
|
graph.add_conditional_edges("chat", agent.after_chat)
|
|
141
190
|
graph.add_conditional_edges("tools", agent.after_tool)
|
|
142
191
|
graph.add_edge("finish", END)
|
|
143
|
-
|
|
144
|
-
|
|
192
|
+
compile_options = {}
|
|
193
|
+
if template is not None:
|
|
194
|
+
compile_options = {
|
|
195
|
+
"store": template.store,
|
|
196
|
+
"cache": template.cache,
|
|
197
|
+
"interrupt_before": template.interrupt_before_nodes,
|
|
198
|
+
"interrupt_after": template.interrupt_after_nodes,
|
|
199
|
+
"debug": template.debug,
|
|
200
|
+
"name": template.name,
|
|
201
|
+
}
|
|
202
|
+
compiled = graph.compile(checkpointer=checkpointer, **compile_options).with_config(
|
|
203
|
+
{"recursion_limit": 2 * agent.limit + 8, **dict(getattr(template, "config", None) or {})}
|
|
145
204
|
)
|
|
146
205
|
graph._ksadk_mcp_agent = agent
|
|
147
206
|
return compiled
|
|
207
|
+
|
|
208
|
+
|
|
209
|
+
def bind_tunnel_graph(graph, tunnel_tools, *, checkpointer):
|
|
210
|
+
"""Copy SDK graph behavior, never mutate the imported graph's closures."""
|
|
211
|
+
from copy import copy
|
|
212
|
+
|
|
213
|
+
agent = copy(graph.builder._ksadk_mcp_agent)
|
|
214
|
+
agent.tunnel_tools = tunnel_tools
|
|
215
|
+
return _compile_agent(agent, checkpointer=checkpointer, template=graph)
|
|
@@ -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"]
|
|
@@ -8,6 +8,8 @@ from .client import BrokerError, MCPToolOutcomeUnknown
|
|
|
8
8
|
|
|
9
9
|
SCHEMA = "mcp.authorization/v1"
|
|
10
10
|
MARKER = "x-ksadk-mcp-authorization"
|
|
11
|
+
|
|
12
|
+
from ksadk._mcp_compat import tool_input_schema # noqa: E402
|
|
11
13
|
_declaration = ContextVar("mcp_oauth_declaration", default=None)
|
|
12
14
|
_extension = ContextVar("mcp_oauth_extension", default=None)
|
|
13
15
|
|
|
@@ -92,13 +94,14 @@ def classify_mcp_error(error):
|
|
|
92
94
|
if isinstance(error, BrokerError):
|
|
93
95
|
return error.code
|
|
94
96
|
import httpx
|
|
97
|
+
from ksadk._mcp_compat import httpx_module
|
|
95
98
|
|
|
96
99
|
children = getattr(error, "exceptions", ())
|
|
97
100
|
for child in children:
|
|
98
101
|
code = classify_mcp_error(child)
|
|
99
102
|
if code != "CONNECTION_FAILED":
|
|
100
103
|
return code
|
|
101
|
-
if isinstance(error, httpx.HTTPStatusError):
|
|
104
|
+
if isinstance(error, (httpx.HTTPStatusError, httpx_module().HTTPStatusError)):
|
|
102
105
|
challenge = error.response.headers.get("WWW-Authenticate", "")
|
|
103
106
|
if error.response.status_code == 403:
|
|
104
107
|
return (
|
|
@@ -114,18 +117,43 @@ def classify_mcp_error(error):
|
|
|
114
117
|
@asynccontextmanager
|
|
115
118
|
async def connect(credential):
|
|
116
119
|
from mcp import ClientSession
|
|
117
|
-
from mcp.client.streamable_http import streamablehttp_client
|
|
118
120
|
|
|
121
|
+
from ksadk._mcp_compat import streamable_http
|
|
119
122
|
from .transport import http_client_factory
|
|
120
123
|
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
124
|
+
authorization_error = None
|
|
125
|
+
|
|
126
|
+
async def remember_authorization_error(response):
|
|
127
|
+
nonlocal authorization_error
|
|
128
|
+
# MCP 2 replaces non-JSON-RPC HTTP errors with a generic MCPError.
|
|
129
|
+
# Retain only the safe authorization category, never the token/body/URL.
|
|
130
|
+
# A background GET/DELETE denial is not proof a business POST declined.
|
|
131
|
+
if response.request.method != "POST":
|
|
132
|
+
return
|
|
133
|
+
if response.status_code == 401:
|
|
134
|
+
authorization_error = "REAUTHORIZATION_REQUIRED"
|
|
135
|
+
elif response.status_code == 403:
|
|
136
|
+
authorization_error = (
|
|
137
|
+
"INSUFFICIENT_SCOPE"
|
|
138
|
+
if "insufficient_scope" in response.headers.get("WWW-Authenticate", "")
|
|
139
|
+
else "BUSINESS_PERMISSION_DENIED"
|
|
140
|
+
)
|
|
141
|
+
|
|
142
|
+
async with http_client_factory(credential)(
|
|
143
|
+
headers={"Authorization": "Bearer " + credential["access_token"]}, timeout=30,
|
|
144
|
+
) as http_client:
|
|
145
|
+
http_client.event_hooks["response"].append(remember_authorization_error)
|
|
146
|
+
try:
|
|
147
|
+
async with streamable_http(
|
|
148
|
+
credential["resource"], http_client=http_client,
|
|
149
|
+
) as (read, write):
|
|
150
|
+
async with ClientSession(read, write) as session:
|
|
151
|
+
await session.initialize()
|
|
152
|
+
yield session
|
|
153
|
+
except Exception:
|
|
154
|
+
if authorization_error is not None:
|
|
155
|
+
raise BrokerError(authorization_error) from None
|
|
156
|
+
raise
|
|
129
157
|
|
|
130
158
|
|
|
131
159
|
async def prepare_connection(client, wait_id):
|
|
@@ -202,17 +230,21 @@ async def _authorized_credential(
|
|
|
202
230
|
|
|
203
231
|
async def _catalog(session, credential):
|
|
204
232
|
"""Read all catalog pages and apply the immutable connection filter."""
|
|
233
|
+
from ksadk._mcp_compat import list_tools_page
|
|
234
|
+
|
|
205
235
|
allowed = credential.get("allowed_tools", [])
|
|
206
236
|
tools, cursors = {}, set()
|
|
207
237
|
cursor = None
|
|
208
238
|
while True:
|
|
209
|
-
|
|
239
|
+
# mcp 2.x 的 `list_tools` 不接受 `cursor` 关键字(改成
|
|
240
|
+
# `params=PaginatedRequestParams(cursor=...)`),用兼容层统一。
|
|
241
|
+
page = await list_tools_page(session, cursor)
|
|
210
242
|
for tool in page.tools:
|
|
211
243
|
if not allowed or tool.name in allowed:
|
|
212
244
|
if tool.name in tools:
|
|
213
245
|
raise BrokerError("MCP_TOOL_CATALOG_INVALID")
|
|
214
246
|
tools[tool.name] = tool
|
|
215
|
-
cursor = page
|
|
247
|
+
cursor = getattr(page, 'next_cursor', None) or getattr(page, 'nextCursor', None)
|
|
216
248
|
if not cursor:
|
|
217
249
|
return tools
|
|
218
250
|
if cursor in cursors or len(cursors) >= 100:
|
|
@@ -275,7 +307,7 @@ async def list_mcp_tools(config_id: str, *, request_key: str):
|
|
|
275
307
|
{
|
|
276
308
|
"name": tool.name,
|
|
277
309
|
"description": tool.description or "",
|
|
278
|
-
"inputSchema": tool
|
|
310
|
+
"inputSchema": tool_input_schema(tool),
|
|
279
311
|
}
|
|
280
312
|
for tool in tools.values()
|
|
281
313
|
]
|
|
@@ -318,12 +350,12 @@ async def call_mcp_tool(
|
|
|
318
350
|
):
|
|
319
351
|
if tool not in catalog:
|
|
320
352
|
raise BrokerError("MCP_TOOL_UNAVAILABLE")
|
|
321
|
-
validate_input_schema(catalog[tool]
|
|
353
|
+
validate_input_schema(tool_input_schema(catalog[tool]), arguments)
|
|
322
354
|
call_digest = digest([credential["config_ref"], tool, arguments])
|
|
323
355
|
result = await extension.claim_dispatch(run_id, request_key, call_digest)
|
|
324
356
|
if result is None:
|
|
325
357
|
dispatched = True
|
|
326
|
-
result = (await session.call_tool(tool, arguments)).model_dump(mode="json")
|
|
358
|
+
result = (await session.call_tool(tool, arguments)).model_dump(mode="json", by_alias=True)
|
|
327
359
|
await extension.finish_dispatch(run_id, request_key, call_digest, result)
|
|
328
360
|
except BrokerError as exc:
|
|
329
361
|
if not dispatched:
|