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/builders/mcp_builder.py
CHANGED
|
@@ -6,9 +6,13 @@ MCP Builders - FastMCP 代码打包 / 容器构建
|
|
|
6
6
|
- Container 模式: 复用现有 Docker 登录/推送逻辑,但检测/打包走 FastMCP 专属链路
|
|
7
7
|
"""
|
|
8
8
|
|
|
9
|
+
import json
|
|
9
10
|
import os
|
|
10
11
|
import shutil
|
|
11
12
|
import subprocess
|
|
13
|
+
import sys
|
|
14
|
+
import tempfile
|
|
15
|
+
from dataclasses import replace
|
|
12
16
|
from pathlib import Path
|
|
13
17
|
from typing import List, Optional
|
|
14
18
|
|
|
@@ -73,6 +77,8 @@ class MCPCodeBuilder(CodeBuilder):
|
|
|
73
77
|
self._save_input_fingerprint(zip_path, detection_result)
|
|
74
78
|
zip_size = zip_path.stat().st_size / (1024 * 1024)
|
|
75
79
|
click.secho(f"\n✅ 使用已有构建: {zip_path.name} ({zip_size:.2f} MB)", fg="green")
|
|
80
|
+
# 缓存命中也要探一次——AST 结果可能不准,而工具列表要进平台元数据
|
|
81
|
+
detection_result = self._resolve_tools(detection_result)
|
|
76
82
|
return BuildResult(
|
|
77
83
|
success=True,
|
|
78
84
|
artifact_path=zip_path,
|
|
@@ -99,6 +105,9 @@ class MCPCodeBuilder(CodeBuilder):
|
|
|
99
105
|
if not self._install_dependencies(requirements_path):
|
|
100
106
|
return BuildResult(success=False, error_message="依赖安装失败")
|
|
101
107
|
|
|
108
|
+
# 依赖装完后用**运行时真值**覆盖 AST 猜测(工厂函数注册的工具 AST 扫不到)
|
|
109
|
+
detection_result = self._resolve_tools(detection_result)
|
|
110
|
+
|
|
102
111
|
# Step 3: 打包
|
|
103
112
|
click.echo("\n📦 Step 3/3: 打包 zip...")
|
|
104
113
|
self._package_mcp_zip(zip_path, detection_result)
|
|
@@ -120,6 +129,139 @@ class MCPCodeBuilder(CodeBuilder):
|
|
|
120
129
|
},
|
|
121
130
|
)
|
|
122
131
|
|
|
132
|
+
# 工具探测超时(秒)。导入项目 + 加载 catalog 通常 <5s,60s 足够宽松。
|
|
133
|
+
TOOL_PROBE_TIMEOUT = 60.0
|
|
134
|
+
|
|
135
|
+
def _find_probe_python(self) -> Path | None:
|
|
136
|
+
"""找一个**能 import 项目依赖**的 Python 解释器。
|
|
137
|
+
|
|
138
|
+
## 为什么不能直接用 `sys.executable`
|
|
139
|
+
|
|
140
|
+
构建机上的 ksadk 环境**未必装了项目依赖**,而且版本可能不兼容。
|
|
141
|
+
实测(2026-11-18):ksadk venv 的 fastmcp 版本过旧,import 项目直接报
|
|
142
|
+
`No module named 'fastmcp.server.transforms'`。
|
|
143
|
+
|
|
144
|
+
## 为什么不能用 `deps_dir`
|
|
145
|
+
|
|
146
|
+
`_install_dependencies()` 装的是**目标平台**的 wheel(Linux manylinux),
|
|
147
|
+
在 macOS 构建机上 import 不了。所以只能找**开发者本地环境**。
|
|
148
|
+
|
|
149
|
+
优先级:`<project>/.venv` → `venv` → `env` → `sys.executable`(最后兜底)。
|
|
150
|
+
"""
|
|
151
|
+
for name in (".venv", "venv", "env"):
|
|
152
|
+
candidate = self.project_dir / name / "bin" / "python"
|
|
153
|
+
if candidate.is_file():
|
|
154
|
+
return candidate
|
|
155
|
+
# Windows
|
|
156
|
+
win = self.project_dir / name / "Scripts" / "python.exe"
|
|
157
|
+
if win.is_file():
|
|
158
|
+
return win
|
|
159
|
+
return Path(sys.executable) if sys.executable else None
|
|
160
|
+
|
|
161
|
+
def _probe_tools_runtime(self, detection_result: MCPDetectionResult) -> list[str] | None:
|
|
162
|
+
"""**真调** `list_tools()` 拿工具列表,而不是 AST 猜。
|
|
163
|
+
|
|
164
|
+
## 为什么需要
|
|
165
|
+
|
|
166
|
+
`MCPDetector._extract_tools()` 用 AST 扫入口文件的 `@mcp.tool` 装饰器。
|
|
167
|
+
但只要项目用**工厂函数**注册工具就扫不到:
|
|
168
|
+
|
|
169
|
+
```python
|
|
170
|
+
# mcp_server.py
|
|
171
|
+
from ezone_mcp.server import create_server
|
|
172
|
+
mcp = create_server() # ← 没有装饰器,AST 返回 []
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
后果(2026-11-18 云端实测):`build-metadata.json` 的 `tools` 恒为 `[]`,
|
|
176
|
+
平台「工具」tab 空白,`ksadk mcp status` 显示 `tools: []`。
|
|
177
|
+
|
|
178
|
+
**`list_tools()` 是事实,AST 是猜测。**
|
|
179
|
+
|
|
180
|
+
## 实现
|
|
181
|
+
|
|
182
|
+
起一个**子进程**(避免污染构建进程的 import 缓存),把结果写进临时文件
|
|
183
|
+
(避免 stdout 被日志污染),任何失败都返回 `None` 让调用方回退 AST。
|
|
184
|
+
|
|
185
|
+
Returns:
|
|
186
|
+
工具名列表;探测失败返回 ``None``。
|
|
187
|
+
"""
|
|
188
|
+
python = self._find_probe_python()
|
|
189
|
+
if python is None:
|
|
190
|
+
return None
|
|
191
|
+
|
|
192
|
+
module = detection_result.entry_point.replace("/", ".").replace("\\", ".")
|
|
193
|
+
if module.endswith(".py"):
|
|
194
|
+
module = module[:-3]
|
|
195
|
+
variable = detection_result.mcp_variable or "mcp"
|
|
196
|
+
|
|
197
|
+
with tempfile.TemporaryDirectory(prefix="ksadk-probe-") as tmp:
|
|
198
|
+
out_file = Path(tmp) / "tools.json"
|
|
199
|
+
# 工具枚举 API 在 fastmcp 各大版本间**变过名字**:
|
|
200
|
+
# - fastmcp 4.x / mcp 2.x : `await mcp.list_tools() -> list[Tool]`
|
|
201
|
+
# - fastmcp 2.x : `await mcp.get_tools() -> dict[str, Tool]`
|
|
202
|
+
# 统一在子进程里试两条,任一成功即可。
|
|
203
|
+
script = (
|
|
204
|
+
"import asyncio, json, sys\n"
|
|
205
|
+
"out, root, module, variable = sys.argv[1:5]\n"
|
|
206
|
+
"sys.path.insert(0, root)\n"
|
|
207
|
+
"import importlib\n"
|
|
208
|
+
f"mcp = getattr(importlib.import_module(module), variable)\n"
|
|
209
|
+
"def _names():\n"
|
|
210
|
+
" lister = getattr(mcp, 'list_tools', None)\n"
|
|
211
|
+
" if lister is not None:\n"
|
|
212
|
+
" return [getattr(t, 'name', None) for t in asyncio.run(lister())]\n"
|
|
213
|
+
" getter = getattr(mcp, 'get_tools', None)\n"
|
|
214
|
+
" if getter is None:\n"
|
|
215
|
+
" raise AttributeError('MCP 实例既没有 list_tools 也没有 get_tools')\n"
|
|
216
|
+
" found = asyncio.run(getter())\n"
|
|
217
|
+
" return list(found) if isinstance(found, dict) else [getattr(t, 'name', None) for t in found]\n"
|
|
218
|
+
"json.dump([n for n in _names() if n], open(out, 'w', encoding='utf-8'))\n"
|
|
219
|
+
)
|
|
220
|
+
env = {**os.environ, "PYTHONPATH": str(self.project_dir)}
|
|
221
|
+
try:
|
|
222
|
+
completed = subprocess.run(
|
|
223
|
+
[str(python), "-c", script, str(out_file), str(self.project_dir),
|
|
224
|
+
module, variable],
|
|
225
|
+
cwd=str(self.project_dir),
|
|
226
|
+
capture_output=True,
|
|
227
|
+
text=True,
|
|
228
|
+
timeout=self.TOOL_PROBE_TIMEOUT,
|
|
229
|
+
env=env,
|
|
230
|
+
check=False,
|
|
231
|
+
)
|
|
232
|
+
except (OSError, subprocess.SubprocessError) as exc:
|
|
233
|
+
click.secho(f" ⚠️ 工具探测失败({type(exc).__name__}),回退 AST 结果", fg="yellow")
|
|
234
|
+
return None
|
|
235
|
+
|
|
236
|
+
if completed.returncode != 0 or not out_file.is_file():
|
|
237
|
+
detail = (completed.stderr or "").strip().splitlines()
|
|
238
|
+
hint = detail[-1] if detail else f"exit={completed.returncode}"
|
|
239
|
+
click.secho(f" ⚠️ 工具探测失败({hint}),回退 AST 结果", fg="yellow")
|
|
240
|
+
return None
|
|
241
|
+
|
|
242
|
+
try:
|
|
243
|
+
tools = json.loads(out_file.read_text(encoding="utf-8"))
|
|
244
|
+
except (OSError, json.JSONDecodeError):
|
|
245
|
+
return None
|
|
246
|
+
|
|
247
|
+
if not isinstance(tools, list):
|
|
248
|
+
return None
|
|
249
|
+
return [str(name) for name in tools]
|
|
250
|
+
|
|
251
|
+
def _resolve_tools(self, detection_result: MCPDetectionResult) -> MCPDetectionResult:
|
|
252
|
+
"""用运行时真值覆盖 AST 结果(探测失败则原样返回)。"""
|
|
253
|
+
probed = self._probe_tools_runtime(detection_result)
|
|
254
|
+
if probed is None:
|
|
255
|
+
return detection_result
|
|
256
|
+
if probed == list(detection_result.tools):
|
|
257
|
+
return detection_result
|
|
258
|
+
click.echo(
|
|
259
|
+
f" 工具: 运行时探测到 {len(probed)} 个"
|
|
260
|
+
+ (f"(AST 只扫到 {len(detection_result.tools)} 个)" if detection_result.tools else
|
|
261
|
+
"(AST 扫不到动态注册的工具)")
|
|
262
|
+
)
|
|
263
|
+
return replace(detection_result, tools=probed)
|
|
264
|
+
|
|
123
265
|
def _prepare_mcp_requirements(self, detection_result: MCPDetectionResult) -> Path:
|
|
124
266
|
"""准备 MCP 依赖"""
|
|
125
267
|
base_deps = self._get_mcp_base_requirements()
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
"""Detect optional runtime dependencies without importing user code."""
|
|
2
|
+
|
|
3
|
+
import ast
|
|
4
|
+
from pathlib import Path
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
def _parse(path: Path) -> ast.Module | None:
|
|
8
|
+
try:
|
|
9
|
+
return ast.parse(path.read_text(encoding="utf-8-sig"), filename=str(path))
|
|
10
|
+
except (OSError, SyntaxError, UnicodeDecodeError):
|
|
11
|
+
return None
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
def imports_any(path: Path, module_names: set[str]) -> bool:
|
|
15
|
+
tree = _parse(path)
|
|
16
|
+
if tree is None:
|
|
17
|
+
return False
|
|
18
|
+
for node in ast.walk(tree):
|
|
19
|
+
if isinstance(node, ast.Import):
|
|
20
|
+
names = [alias.name for alias in node.names]
|
|
21
|
+
elif isinstance(node, ast.ImportFrom) and node.module:
|
|
22
|
+
names = [node.module, *(f"{node.module}.{alias.name}" for alias in node.names)]
|
|
23
|
+
else:
|
|
24
|
+
continue
|
|
25
|
+
if any(n == target or n.startswith(target + ".") for n in names for target in module_names):
|
|
26
|
+
return True
|
|
27
|
+
return False
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
def uses_tunnel(path: Path) -> bool:
|
|
31
|
+
tree = _parse(path)
|
|
32
|
+
if tree is None:
|
|
33
|
+
return False
|
|
34
|
+
|
|
35
|
+
factories = set()
|
|
36
|
+
for node in ast.walk(tree):
|
|
37
|
+
if isinstance(node, ast.Import):
|
|
38
|
+
names = [(a.name, a.asname or a.name) for a in node.names]
|
|
39
|
+
elif isinstance(node, ast.ImportFrom) and node.module and not node.level:
|
|
40
|
+
names = [(f"{node.module}.{a.name}", a.asname or a.name) for a in node.names]
|
|
41
|
+
else:
|
|
42
|
+
continue
|
|
43
|
+
for name, local in names:
|
|
44
|
+
if name == "ksadk.tunnel" or name.startswith("ksadk.tunnel."):
|
|
45
|
+
return True
|
|
46
|
+
if name in {"ksadk.Agent", "ksadk.agent.Agent"}:
|
|
47
|
+
factories.add(local)
|
|
48
|
+
elif name in {"ksadk", "ksadk.agent"}:
|
|
49
|
+
factories.add(f"{local}.Agent")
|
|
50
|
+
if name == "ksadk":
|
|
51
|
+
factories.add(f"{local}.agent.Agent")
|
|
52
|
+
|
|
53
|
+
if not factories:
|
|
54
|
+
return False
|
|
55
|
+
for node in ast.walk(tree):
|
|
56
|
+
if not isinstance(node, ast.Call) or not isinstance(node.func, (ast.Name, ast.Attribute)):
|
|
57
|
+
continue
|
|
58
|
+
if ast.unparse(node.func) not in factories:
|
|
59
|
+
continue
|
|
60
|
+
for kw in node.keywords:
|
|
61
|
+
if kw.arg is None: # **options may enable the tunnel at runtime.
|
|
62
|
+
return True
|
|
63
|
+
if kw.arg == "enable_tunnel":
|
|
64
|
+
if not isinstance(kw.value, ast.Constant) or kw.value.value is not False:
|
|
65
|
+
return True
|
|
66
|
+
return False
|
ksadk/cli/cmd_mcp.py
CHANGED
ksadk/cli/cmd_run.py
CHANGED
|
@@ -91,6 +91,10 @@ def run(
|
|
|
91
91
|
|
|
92
92
|
setup_environment(agent_path)
|
|
93
93
|
|
|
94
|
+
from ksadk.cli.runtime_logging import configure_runtime_logging
|
|
95
|
+
|
|
96
|
+
configure_runtime_logging()
|
|
97
|
+
|
|
94
98
|
# 1. 检测框架类型
|
|
95
99
|
detector = FrameworkDetector(str(agent_path))
|
|
96
100
|
result = detector.detect()
|
|
@@ -181,10 +185,8 @@ def _run_custom(
|
|
|
181
185
|
"""Run one detected project through the canonical RuntimeAdapter composition."""
|
|
182
186
|
|
|
183
187
|
# 初始化 Tracing
|
|
184
|
-
if not no_trace:
|
|
188
|
+
if not no_trace and os.getenv("OTEL_SDK_DISABLED", "").strip().lower() != "true":
|
|
185
189
|
try:
|
|
186
|
-
import os
|
|
187
|
-
|
|
188
190
|
from ksadk.tracing import setup_tracing
|
|
189
191
|
|
|
190
192
|
has_otlp = bool(
|
|
@@ -212,7 +214,7 @@ def _run_custom(
|
|
|
212
214
|
raise SystemExit(2)
|
|
213
215
|
|
|
214
216
|
try:
|
|
215
|
-
runtime_app = create_runtime_web_app(result, agent_path)
|
|
217
|
+
runtime_app = create_runtime_web_app(result, agent_path, auto_tracing=not no_trace)
|
|
216
218
|
except Exception as e:
|
|
217
219
|
print_exception("RuntimeAdapter 初始化失败", e)
|
|
218
220
|
raise SystemExit(1)
|
ksadk/cli/cmd_web.py
CHANGED
|
@@ -251,6 +251,18 @@ def web(agent_dir: str, port: int, host: str, model: str, no_open: bool):
|
|
|
251
251
|
|
|
252
252
|
setup_environment(agent_path)
|
|
253
253
|
|
|
254
|
+
from ksadk.cli.runtime_logging import configure_runtime_logging
|
|
255
|
+
|
|
256
|
+
configure_runtime_logging()
|
|
257
|
+
|
|
258
|
+
# 托管 Code 包直接启动 web,必须在加载 Agent 前初始化采集与上报。
|
|
259
|
+
try:
|
|
260
|
+
from ksadk.tracing import setup_tracing
|
|
261
|
+
|
|
262
|
+
setup_tracing()
|
|
263
|
+
except Exception as e:
|
|
264
|
+
print_warn(f"Tracing 初始化失败: {e}")
|
|
265
|
+
|
|
254
266
|
# 检测框架
|
|
255
267
|
detector = FrameworkDetector(str(agent_path))
|
|
256
268
|
result = detector.detect()
|
ksadk/cli/runtime_bootstrap.py
CHANGED
|
@@ -33,7 +33,9 @@ def _managed_a2a_card() -> Any:
|
|
|
33
33
|
return build_managed_a2a_card_if_configured()
|
|
34
34
|
|
|
35
35
|
|
|
36
|
-
def create_runtime_web_app(
|
|
36
|
+
def create_runtime_web_app(
|
|
37
|
+
detection: Any, agent_path: Path, *, auto_tracing: bool = True,
|
|
38
|
+
) -> FastAPI:
|
|
37
39
|
"""Compose one detected project around the canonical RuntimeExecutor."""
|
|
38
40
|
|
|
39
41
|
config = dict(getattr(detection, "raw_config", None) or {})
|
|
@@ -88,6 +90,7 @@ def create_runtime_web_app(detection: Any, agent_path: Path) -> FastAPI:
|
|
|
88
90
|
a2a=managed_a2a,
|
|
89
91
|
a2a_runtime_adapter=adapter,
|
|
90
92
|
local_mcp_oauth=not managed_runtime,
|
|
93
|
+
auto_tracing=auto_tracing,
|
|
91
94
|
),
|
|
92
95
|
configure_runtime_app,
|
|
93
96
|
)
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"""Defaults for CLI-hosted business logs, without claiming the root handler."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import logging
|
|
6
|
+
import os
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
class _RuntimeFallback(logging.StreamHandler):
|
|
10
|
+
"""Used by logging only when no logger in the propagation chain has a handler."""
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
def configure_runtime_logging() -> None:
|
|
14
|
+
root = logging.getLogger()
|
|
15
|
+
# Leave configured applications alone, including a custom/disabled lastResort.
|
|
16
|
+
# Keeping root.handlers empty lets an agent's later basicConfig take ownership.
|
|
17
|
+
if root.handlers or logging.lastResort is not logging._defaultLastResort:
|
|
18
|
+
return
|
|
19
|
+
value = os.getenv("LOG_LEVEL", "").strip().upper() or "INFO"
|
|
20
|
+
level = logging.getLevelNamesMapping().get(value)
|
|
21
|
+
invalid = level is None
|
|
22
|
+
if invalid:
|
|
23
|
+
level = logging.INFO
|
|
24
|
+
handler = _RuntimeFallback()
|
|
25
|
+
handler.setFormatter(logging.Formatter("%(asctime)s %(levelname)s %(name)s: %(message)s"))
|
|
26
|
+
logging.lastResort = handler
|
|
27
|
+
if root.level == logging.WARNING:
|
|
28
|
+
root.setLevel(level)
|
|
29
|
+
if invalid:
|
|
30
|
+
logging.getLogger(__name__).warning("Invalid LOG_LEVEL; using INFO")
|
ksadk/common/cloud_headers.py
CHANGED
|
@@ -7,6 +7,7 @@ from collections.abc import Mapping
|
|
|
7
7
|
|
|
8
8
|
DEFAULT_TRAFFIC_SOURCE = "agentkit"
|
|
9
9
|
TRAFFIC_SOURCE_HEADER = "X-Traffic-Source"
|
|
10
|
+
COMPONENT_ENV_VAR = "KSADK_COMPONENT_ENV"
|
|
10
11
|
|
|
11
12
|
|
|
12
13
|
def resolve_traffic_source(value: str | None = None) -> str:
|
|
@@ -19,18 +20,44 @@ def resolve_traffic_source(value: str | None = None) -> str:
|
|
|
19
20
|
return value.strip() or DEFAULT_TRAFFIC_SOURCE
|
|
20
21
|
|
|
21
22
|
|
|
23
|
+
def resolve_component_env() -> str:
|
|
24
|
+
"""Resolve KSADK_COMPONENT_ENV for knowledge and memory routing."""
|
|
25
|
+
return str(os.getenv(COMPONENT_ENV_VAR, "") or "").strip()
|
|
26
|
+
|
|
27
|
+
|
|
22
28
|
def build_cloud_headers(
|
|
23
29
|
headers: Mapping[str, str] | None = None, *, traffic_source: str | None = None
|
|
24
30
|
) -> dict[str, str]:
|
|
25
|
-
"""Copy headers and set
|
|
31
|
+
"""Copy headers and set canonical source attribution before request signing.
|
|
26
32
|
|
|
27
33
|
Source attribution is owned by KSADK_TRAFFIC_SOURCE (or an explicit worker
|
|
28
34
|
snapshot), including when a caller supplies differently cased extra headers.
|
|
29
35
|
"""
|
|
30
|
-
result = {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
if
|
|
34
|
-
|
|
36
|
+
result: dict[str, str] = {}
|
|
37
|
+
for name, value in (headers or {}).items():
|
|
38
|
+
lower = name.lower()
|
|
39
|
+
if lower == TRAFFIC_SOURCE_HEADER.lower():
|
|
40
|
+
continue
|
|
41
|
+
result[name] = value
|
|
42
|
+
|
|
35
43
|
result[TRAFFIC_SOURCE_HEADER] = resolve_traffic_source(traffic_source)
|
|
44
|
+
|
|
45
|
+
return result
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
def build_component_headers(
|
|
49
|
+
headers: Mapping[str, str] | None = None,
|
|
50
|
+
*,
|
|
51
|
+
component_env: str,
|
|
52
|
+
traffic_source: str | None = None,
|
|
53
|
+
) -> dict[str, str]:
|
|
54
|
+
"""Add the preproduction route only for knowledge and memory clients."""
|
|
55
|
+
result = build_cloud_headers(headers, traffic_source=traffic_source)
|
|
56
|
+
if component_env.strip().lower() == "pre":
|
|
57
|
+
result = {
|
|
58
|
+
name: value
|
|
59
|
+
for name, value in result.items()
|
|
60
|
+
if name.lower() != "x-ksc-custom-source"
|
|
61
|
+
}
|
|
62
|
+
result["X-KSC-CUSTOM-SOURCE"] = "pre"
|
|
36
63
|
return result
|
ksadk/compat/adk_compat.py
CHANGED
|
@@ -81,6 +81,8 @@ _LAZY_SYMBOLS: dict[str, str] = {
|
|
|
81
81
|
"ListSessionsResponse": "google.adk.sessions.base_session_service",
|
|
82
82
|
# tools
|
|
83
83
|
"FunctionTool": "google.adk.tools",
|
|
84
|
+
"BaseTool": "google.adk.tools.base_tool",
|
|
85
|
+
"BaseToolset": "google.adk.tools.base_toolset",
|
|
84
86
|
"load_memory": "google.adk.tools",
|
|
85
87
|
"McpTool": "google.adk.tools.mcp_tool.mcp_tool",
|
|
86
88
|
"McpToolset": "google.adk.tools.mcp_tool.mcp_toolset",
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"""Compatibility with LiteLLM function calls whose type is empty."""
|
|
2
|
+
|
|
3
|
+
from functools import wraps
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
def normalize_tool_call_types(message):
|
|
7
|
+
calls = (
|
|
8
|
+
message.get("tool_calls")
|
|
9
|
+
if isinstance(message, dict)
|
|
10
|
+
else getattr(message, "tool_calls", None)
|
|
11
|
+
)
|
|
12
|
+
for call in calls or ():
|
|
13
|
+
if isinstance(call, dict):
|
|
14
|
+
if call.get("type") in (None, "") and call.get("function") is not None:
|
|
15
|
+
call["type"] = "function"
|
|
16
|
+
elif (
|
|
17
|
+
getattr(call, "type", None) in (None, "")
|
|
18
|
+
and getattr(call, "function", None) is not None
|
|
19
|
+
):
|
|
20
|
+
call.type = "function"
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
def normalize_tool_delta_types(module):
|
|
24
|
+
convert = getattr(module, "_model_response_to_chunk", None)
|
|
25
|
+
if convert is None or getattr(convert, "_ksadk_tool_delta_types", False):
|
|
26
|
+
return
|
|
27
|
+
|
|
28
|
+
@wraps(convert)
|
|
29
|
+
def convert_stream_chunk(response, *args, **kwargs):
|
|
30
|
+
for choice in response.get("choices") or ():
|
|
31
|
+
normalize_tool_call_types(choice.get("delta") or choice.get("message"))
|
|
32
|
+
yield from convert(response, *args, **kwargs)
|
|
33
|
+
|
|
34
|
+
convert_stream_chunk._ksadk_tool_delta_types = True
|
|
35
|
+
module._model_response_to_chunk = convert_stream_chunk
|
ksadk/configs/env_registry.py
CHANGED
|
@@ -6,6 +6,18 @@ from ksadk.configs.env_registry_studio import STUDIO_ENV_VAR_REGISTRY_ITEMS
|
|
|
6
6
|
from ksadk.configs.env_var_spec import EnvVarSpec
|
|
7
7
|
|
|
8
8
|
_ENV_VAR_REGISTRY_ITEMS: tuple[EnvVarSpec, ...] = (
|
|
9
|
+
EnvVarSpec(
|
|
10
|
+
"KSADK_COMPONENT_ENV",
|
|
11
|
+
"cloud",
|
|
12
|
+
"Opt-in knowledge and Memory component routing; pre adds X-KSC-CUSTOM-SOURCE before signing.",
|
|
13
|
+
"",
|
|
14
|
+
),
|
|
15
|
+
EnvVarSpec("KSADK_CHAT_PREFERRED_TRANSPORT", "agui", "Preferred available chat transport: ag-ui or responses; existing endpoints remain available."),
|
|
16
|
+
EnvVarSpec("KSADK_HARNESS_SERVICE_URL", "harness", "Opt-in external Harness service base URL."),
|
|
17
|
+
EnvVarSpec("KSADK_HARNESS_SERVICE_TOKEN", "harness", "External Harness service access credential.", sensitive=True),
|
|
18
|
+
EnvVarSpec("KSADK_HARNESS_SERVICE_WORKSPACE", "harness", "Existing absolute local workspace mount for the Harness service adapter."),
|
|
19
|
+
EnvVarSpec("KSADK_HARNESS_SERVICE_CA_FILE", "harness", "CA file used to verify the Harness service TLS certificate."),
|
|
20
|
+
EnvVarSpec("KSADK_HARNESS_SERVICE_DURABLE_APPROVALS", "harness", "Enable the external service durable approval contract only when supported.", "0"),
|
|
9
21
|
EnvVarSpec(
|
|
10
22
|
"KSADK_TRAFFIC_SOURCE",
|
|
11
23
|
"cloud",
|
|
@@ -483,6 +495,25 @@ _ENV_VAR_REGISTRY_ITEMS: tuple[EnvVarSpec, ...] = (
|
|
|
483
495
|
EnvVarSpec(
|
|
484
496
|
"KSADK_MCP_SERVERS", "mcp_runtime", "JSON array of MCP server configs.", sensitive=True
|
|
485
497
|
),
|
|
498
|
+
EnvVarSpec(
|
|
499
|
+
"KSADK_TUNNEL_PEER_SECRET",
|
|
500
|
+
"mcp_runtime",
|
|
501
|
+
"Optional peer HMAC secret override, at least 32 bytes; otherwise derived from "
|
|
502
|
+
"the declared tunnel token and runtime ID.",
|
|
503
|
+
sensitive=True,
|
|
504
|
+
),
|
|
505
|
+
EnvVarSpec(
|
|
506
|
+
"KSADK_TUNNEL_PEER_SERVICE",
|
|
507
|
+
"mcp_runtime",
|
|
508
|
+
"Headless service for tunnel peer discovery; defaults to the runtime ID plus -headless.",
|
|
509
|
+
),
|
|
510
|
+
EnvVarSpec(
|
|
511
|
+
"KSADK_TUNNEL_PEER_PORT",
|
|
512
|
+
"mcp_runtime",
|
|
513
|
+
"Internal peer WebSocket listener port.",
|
|
514
|
+
"8092",
|
|
515
|
+
),
|
|
516
|
+
EnvVarSpec("KSADK_TUNNEL_TOKEN", "mcp_runtime", "Required application token for tool tunnel registration.", sensitive=True),
|
|
486
517
|
EnvVarSpec(
|
|
487
518
|
"KSADK_MCP_OAUTH_PROJECTION",
|
|
488
519
|
"configs",
|
|
@@ -304,14 +304,19 @@ def _durable_checkpoint_active(runner: Any) -> bool:
|
|
|
304
304
|
def _downgrade_compaction_owner_for_checkpoint_hook(
|
|
305
305
|
runner: Any, caps: ContextCapabilities
|
|
306
306
|
) -> ContextCapabilities:
|
|
307
|
-
"""
|
|
307
|
+
"""Standard message graphs receive SDK context at the Runner boundary.
|
|
308
308
|
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
``context_checkpoint`` 事件,对模型输入零贡献——继续声明 ``compaction_owner="ksadk"``
|
|
312
|
-
会让 compaction 门控在每个双阈值触发点白耗一次摘要 LLM 调用。降级后
|
|
313
|
-
``_plan_compaction`` 落 ``none`` 带,不产生 LLM 调用。其余字段不变。
|
|
309
|
+
Graphs with explicit framework summarization retain framework ownership.
|
|
310
|
+
Nonstandard state/hooks retain the existing capability contract.
|
|
314
311
|
"""
|
|
312
|
+
uses_model_context = getattr(runner, "uses_ksadk_model_context", None)
|
|
313
|
+
if callable(uses_model_context):
|
|
314
|
+
if uses_model_context():
|
|
315
|
+
return replace(caps, compaction_owner="ksadk")
|
|
316
|
+
from ksadk.runners._langgraph_context import framework_summary
|
|
317
|
+
|
|
318
|
+
if framework_summary(getattr(runner, "_agent", None)):
|
|
319
|
+
return replace(caps, compaction_owner="framework")
|
|
315
320
|
if caps.compaction_owner != "ksadk":
|
|
316
321
|
return caps
|
|
317
322
|
if not _prepare_state_hook_exported(runner) or not _durable_checkpoint_active(runner):
|
|
@@ -327,9 +332,8 @@ def capabilities_for_runner(runner: Any | None) -> ContextCapabilities:
|
|
|
327
332
|
``describe_context_capabilities``
|
|
328
333
|
走 ``_capabilities_for_detection_type``,故本函数对 BaseRunner 子类不会递归。已被 compaction
|
|
329
334
|
门控(``runtime_preparation`` proactive compaction)与 shadow plan / conformance 测试消费。
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
``_downgrade_compaction_owner_for_checkpoint_hook``)。
|
|
335
|
+
标准消息图由共用 Runner 接入 SDK 压缩;显式框架摘要保留 framework ownership。
|
|
336
|
+
非标准图继续使用原有 checkpoint + hook 降级规则。
|
|
333
337
|
"""
|
|
334
338
|
if runner is None:
|
|
335
339
|
return DEFAULT_CONTEXT_CAPABILITIES()
|
ksadk/conversations/context.py
CHANGED
|
@@ -22,6 +22,7 @@ CANONICAL_EVENT_TYPES = {
|
|
|
22
22
|
"approval_request",
|
|
23
23
|
"approval_response",
|
|
24
24
|
"attachment_ref",
|
|
25
|
+
"progress",
|
|
25
26
|
"reasoning",
|
|
26
27
|
"run_status",
|
|
27
28
|
"run_checkpoint",
|
|
@@ -87,6 +88,10 @@ def extract_event_text(event: SessionEvent) -> str:
|
|
|
87
88
|
这里优先取 `agent_input`,因为它通常比展示给 UI 的 display text 更接近
|
|
88
89
|
真实 prompt;如果没有,再退回到 parts/text。
|
|
89
90
|
"""
|
|
91
|
+
# Legacy progress rows can carry model-authored text for history replay.
|
|
92
|
+
# They contribute no model input, including when building a compaction prompt.
|
|
93
|
+
if str(event.event_type or "").strip().lower() == "progress":
|
|
94
|
+
return ""
|
|
90
95
|
metadata = event.metadata or {}
|
|
91
96
|
if metadata.get("agent_input"):
|
|
92
97
|
return sanitize_event_text_for_context(metadata["agent_input"])
|
|
@@ -269,7 +269,7 @@ def _project_tool_events(
|
|
|
269
269
|
approval_responses: Mapping[str, Mapping[str, Any]],
|
|
270
270
|
) -> list[dict[str, Any]]:
|
|
271
271
|
projected: list[dict[str, Any]] = []
|
|
272
|
-
pending_calls: list[dict[str, Any]] = []
|
|
272
|
+
pending_calls: list[tuple[str, Any, dict[str, Any]]] = []
|
|
273
273
|
pending_by_key: dict[str, dict[str, Any]] = {}
|
|
274
274
|
seen_result_receipts: set[str] = set()
|
|
275
275
|
|
|
@@ -288,7 +288,7 @@ def _project_tool_events(
|
|
|
288
288
|
continue
|
|
289
289
|
entry = _tool_event_from_call(event, metadata)
|
|
290
290
|
projected.append(entry)
|
|
291
|
-
pending_calls.append(entry)
|
|
291
|
+
pending_calls.append((pair_key, metadata.get("run_id"), entry))
|
|
292
292
|
if pair_key:
|
|
293
293
|
pending_by_key[pair_key] = entry
|
|
294
294
|
continue
|
|
@@ -308,19 +308,22 @@ def _project_tool_events(
|
|
|
308
308
|
pair_key = _tool_pair_key(metadata)
|
|
309
309
|
match = pending_by_key.get(pair_key) if pair_key else None
|
|
310
310
|
if match is None or match["Status"] != "running":
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
)
|
|
317
|
-
|
|
318
|
-
|
|
311
|
+
# Old runtimes sometimes only recorded a tool name. Use it when
|
|
312
|
+
# the remaining association is unambiguous, never across known IDs.
|
|
313
|
+
candidates = [
|
|
314
|
+
item for key, run_id, item in pending_calls
|
|
315
|
+
if item["Name"] == name and item["Status"] == "running"
|
|
316
|
+
and not (pair_key.startswith("call:") and key.startswith("call:"))
|
|
317
|
+
and not (run_id and metadata.get("run_id") and run_id != metadata["run_id"])
|
|
318
|
+
]
|
|
319
|
+
match = candidates[0] if len(candidates) == 1 else None
|
|
319
320
|
if match is None:
|
|
320
321
|
entry = _tool_event_from_call(event, metadata)
|
|
321
322
|
projected.append(entry)
|
|
322
323
|
else:
|
|
323
324
|
entry = match
|
|
325
|
+
if result_call_id := _explicit_tool_call_id(metadata):
|
|
326
|
+
entry["ToolCallId"] = result_call_id
|
|
324
327
|
output = metadata.get("tool_output", _event_text(event))
|
|
325
328
|
entry["Status"] = (
|
|
326
329
|
"failed" if metadata.get("tool_is_error") is True
|
|
@@ -335,13 +338,16 @@ def _project_tool_events(
|
|
|
335
338
|
return projected
|
|
336
339
|
|
|
337
340
|
|
|
341
|
+
def _explicit_tool_call_id(metadata: Mapping[str, Any]) -> Any:
|
|
342
|
+
receipt = metadata.get("tool_receipt")
|
|
343
|
+
return (metadata.get("call_id") or metadata.get("tool_call_id")
|
|
344
|
+
or (receipt.get("tool_call_id") if isinstance(receipt, Mapping) else None))
|
|
345
|
+
|
|
346
|
+
|
|
338
347
|
def _tool_pair_key(metadata: Mapping[str, Any]) -> str:
|
|
339
|
-
call_id = metadata
|
|
348
|
+
call_id = _explicit_tool_call_id(metadata)
|
|
340
349
|
if call_id:
|
|
341
350
|
return f"call:{call_id}"
|
|
342
|
-
tool_receipt = metadata.get("tool_receipt")
|
|
343
|
-
if isinstance(tool_receipt, Mapping) and tool_receipt.get("tool_call_id"):
|
|
344
|
-
return f"call:{tool_receipt['tool_call_id']}"
|
|
345
351
|
run_id = metadata.get("run_id")
|
|
346
352
|
if run_id:
|
|
347
353
|
return f"run:{run_id}:{metadata.get('tool_name') or 'tool'}"
|
|
@@ -349,10 +355,7 @@ def _tool_pair_key(metadata: Mapping[str, Any]) -> str:
|
|
|
349
355
|
|
|
350
356
|
|
|
351
357
|
def _tool_event_from_call(event: Mapping[str, Any], metadata: Mapping[str, Any]) -> dict[str, Any]:
|
|
352
|
-
|
|
353
|
-
call_id = metadata.get("call_id") or metadata.get("run_id")
|
|
354
|
-
if not call_id and isinstance(tool_receipt, Mapping):
|
|
355
|
-
call_id = tool_receipt.get("tool_call_id")
|
|
358
|
+
call_id = _explicit_tool_call_id(metadata) or metadata.get("run_id")
|
|
356
359
|
return {
|
|
357
360
|
"SeqId": event.get("SeqId"),
|
|
358
361
|
"Type": "tool_call",
|
|
@@ -696,12 +699,18 @@ def _normalize_canonical_event(
|
|
|
696
699
|
part = parts[0] if isinstance(parts, list) and parts else {}
|
|
697
700
|
call_id = part.get("call_id", "")
|
|
698
701
|
result = part.get("result", "")
|
|
702
|
+
name = normalized_metadata.get("tool_name")
|
|
703
|
+
if not name and isinstance(source_metadata, Mapping):
|
|
704
|
+
name = source_metadata.get("tool_name")
|
|
705
|
+
name = name if isinstance(name, str) else ""
|
|
699
706
|
normalized["EventType"] = "tool_result"
|
|
700
|
-
normalized["Content"] = {"call_id": call_id, "name":
|
|
707
|
+
normalized["Content"] = {"call_id": call_id, "name": name, "result": result}
|
|
701
708
|
normalized_metadata.update({
|
|
702
709
|
"call_id": call_id, "tool_output": result,
|
|
703
710
|
"tool_is_error": part.get("is_error") is True,
|
|
704
711
|
})
|
|
712
|
+
if name:
|
|
713
|
+
normalized_metadata["tool_name"] = name
|
|
705
714
|
elif item_kind == "data" and source.get("protocol") == "a2ui":
|
|
706
715
|
source_metadata = source.get("metadata")
|
|
707
716
|
if (
|