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/conversations/projector.py
CHANGED
|
@@ -36,6 +36,7 @@ from ksadk.events.content import (
|
|
|
36
36
|
ToolResultContent,
|
|
37
37
|
)
|
|
38
38
|
from ksadk.events.usage import usage_mode
|
|
39
|
+
from ksadk.harness.service_presentation import engine_presentation, engine_view_hash
|
|
39
40
|
from ksadk.kernel.contracts import SessionEventEnvelope
|
|
40
41
|
|
|
41
42
|
_INTERACTION_EVENT_TYPES = frozenset(
|
|
@@ -334,6 +335,11 @@ def project_conversation_item(
|
|
|
334
335
|
if isinstance(event, (RunCompleted, RunFailed, RunCanceled, RunInterrupted)):
|
|
335
336
|
payload.update(_run_outcome_payload(event.source.metadata))
|
|
336
337
|
payload.update(public_item_presentation(event, kind))
|
|
338
|
+
engine_view = event.source.metadata.get("harness_service_presentation")
|
|
339
|
+
if event.source.framework == "ksadk" and isinstance(engine_view, dict):
|
|
340
|
+
presentation = engine_presentation(engine_view_hash(engine_view), engine_view.get("event"))
|
|
341
|
+
if presentation:
|
|
342
|
+
payload["harnessView"] = presentation
|
|
337
343
|
if kind == "tool_call" and event.source.metadata.get("engine_kind") == "native":
|
|
338
344
|
# Native public results contain a sealed execution status, not arbitrary
|
|
339
345
|
# business output. An approval receipt is nonterminal even in old logs
|
|
@@ -42,6 +42,7 @@ from ksadk.conversations.semantic_summary import (
|
|
|
42
42
|
summarize_compaction,
|
|
43
43
|
)
|
|
44
44
|
from ksadk.sessions import SessionEvent, resolve_session_service
|
|
45
|
+
from ksadk.sessions.model_history import read_model_history
|
|
45
46
|
|
|
46
47
|
logger = logging.getLogger(__name__)
|
|
47
48
|
|
|
@@ -213,6 +214,7 @@ async def preview_auto_compaction(
|
|
|
213
214
|
model_metadata: Mapping[str, Any] | None = None,
|
|
214
215
|
session_service_provider: Callable[[], Any] | None = None,
|
|
215
216
|
prompt_integration_mode: str = "",
|
|
217
|
+
compaction_owner: str = "",
|
|
216
218
|
) -> CompactionPlan:
|
|
217
219
|
"""在真正写入 turn 之前预估是否会触发自动压缩。
|
|
218
220
|
|
|
@@ -276,13 +278,14 @@ async def preview_auto_compaction(
|
|
|
276
278
|
attachments=effective_attachments,
|
|
277
279
|
attachment_results=effective_attachment_results,
|
|
278
280
|
)
|
|
279
|
-
events = await service
|
|
281
|
+
events = await read_model_history(service, session_id)
|
|
280
282
|
return _plan_compaction(
|
|
281
283
|
events,
|
|
282
284
|
model=model,
|
|
283
285
|
model_metadata=resolved_model_metadata,
|
|
284
286
|
pending_events=[pending_event],
|
|
285
287
|
prompt_integration_mode=prompt_integration_mode,
|
|
288
|
+
compaction_owner=compaction_owner,
|
|
286
289
|
)
|
|
287
290
|
|
|
288
291
|
|
|
@@ -370,6 +373,7 @@ async def compact_conversation_history(
|
|
|
370
373
|
session_service_provider: Callable[[], Any] | None = None,
|
|
371
374
|
prompt_integration_mode: str = "",
|
|
372
375
|
compaction_owner: str = "",
|
|
376
|
+
preloaded_events: list[SessionEvent] | None = None,
|
|
373
377
|
) -> SessionEvent | None:
|
|
374
378
|
"""把旧轮次折叠为 checkpoint。
|
|
375
379
|
|
|
@@ -380,7 +384,7 @@ async def compact_conversation_history(
|
|
|
380
384
|
"""
|
|
381
385
|
provider = session_service_provider or resolve_session_service
|
|
382
386
|
service = provider()
|
|
383
|
-
events = await service
|
|
387
|
+
events = preloaded_events if preloaded_events is not None else await read_model_history(service, session_id)
|
|
384
388
|
header_reader = getattr(service, "get_session_header", None) or getattr(
|
|
385
389
|
service, "get_session_metadata", None) or service.get_session
|
|
386
390
|
session = await header_reader(session_id)
|
|
@@ -505,6 +505,10 @@ def _build_runner_request_payload(
|
|
|
505
505
|
# (for example, its conversation approval profile) without leaking
|
|
506
506
|
# caller public metadata into the agent payload.
|
|
507
507
|
payload["request_metadata"] = dict(prepared.request_metadata)
|
|
508
|
+
uses_model_context = getattr(runner, "uses_ksadk_model_context", None)
|
|
509
|
+
if (prepared.langgraph_model_context is not None and callable(uses_model_context)
|
|
510
|
+
and uses_model_context() and prepared.resume_input is None):
|
|
511
|
+
payload["langgraph_model_context"] = dict(prepared.langgraph_model_context)
|
|
508
512
|
# PR E:hosted pipeline 接管(最高优先级)。当 build_run_input 产出 assembled_input 时,
|
|
509
513
|
# 用组装好的 system/input/history 直接覆盖 payload——它已含 compiled_prompt + working_state
|
|
510
514
|
# + planner 决策后的有序 messages。此分支满足后不再走 PR B/D2(避免双重注入)。
|
|
@@ -285,7 +285,11 @@ async def invoke_conversation_once(
|
|
|
285
285
|
)
|
|
286
286
|
raise
|
|
287
287
|
except Exception as exc:
|
|
288
|
-
if
|
|
288
|
+
if (
|
|
289
|
+
attempt == 0
|
|
290
|
+
and _is_prompt_too_long_error(exc)
|
|
291
|
+
and not getattr(exc, "ksadk_model_boundary_failure", False)
|
|
292
|
+
):
|
|
289
293
|
_baseline_ptl = True
|
|
290
294
|
_baseline_attempts = attempt + 1
|
|
291
295
|
try:
|
|
@@ -93,16 +93,15 @@ async def _update_session_metadata_after_assistant_turn(
|
|
|
93
93
|
model: str | None,
|
|
94
94
|
) -> None:
|
|
95
95
|
summary = _truncate_text(strip_reasoning_markup(assistant_text), SESSION_SUMMARY_MAX_CHARS)
|
|
96
|
-
if summary:
|
|
97
|
-
await service.update_session_metadata(session_id, summary=summary)
|
|
98
|
-
|
|
99
|
-
session = await service.get_session(session_id)
|
|
100
|
-
if not session:
|
|
96
|
+
if not summary:
|
|
101
97
|
return
|
|
98
|
+
# The update returns the session metadata. Reloading a full session here
|
|
99
|
+
# would replay its transcript before the caller can close the stream.
|
|
100
|
+
session = await service.update_session_metadata(session_id, summary=summary)
|
|
102
101
|
if (session.title_source or "").strip() != "fallback_first_prompt":
|
|
103
102
|
return
|
|
104
103
|
first_prompt = str(session.first_prompt or "").strip()
|
|
105
|
-
if not first_prompt
|
|
104
|
+
if not first_prompt:
|
|
106
105
|
return
|
|
107
106
|
|
|
108
107
|
next_title = build_heuristic_title(first_prompt=first_prompt, assistant_text=summary)
|
|
@@ -156,7 +155,7 @@ async def _refine_session_title_in_background(
|
|
|
156
155
|
|
|
157
156
|
if not title or is_low_quality_title(title, first_prompt=first_prompt):
|
|
158
157
|
return
|
|
159
|
-
session = await service.
|
|
158
|
+
session = await service.get_session_metadata(session_id)
|
|
160
159
|
if not session:
|
|
161
160
|
return
|
|
162
161
|
if title == (session.title or "").strip():
|
|
@@ -442,6 +442,7 @@ def _set_conversation_span_attributes(
|
|
|
442
442
|
span.set_attribute("langfuse.trace.name", runner_name)
|
|
443
443
|
span.set_attribute("langfuse.session.id", session_id)
|
|
444
444
|
span.set_attribute("session.id", session_id)
|
|
445
|
+
span.set_attribute("gen_ai.conversation.id", session_id)
|
|
445
446
|
span.set_attribute("langfuse.user.id", user_id)
|
|
446
447
|
span.set_attribute("user.id", user_id)
|
|
447
448
|
if model:
|
|
@@ -94,6 +94,9 @@ class PreparedConversationTurn:
|
|
|
94
94
|
flush_before_compaction: bool = True
|
|
95
95
|
provider_ref: str = "local-default"
|
|
96
96
|
session_context: dict[str, Any] = field(default_factory=dict)
|
|
97
|
+
# Internal new-turn context consumed by the shared LangGraphRunner.
|
|
98
|
+
# Native graph state and model nodes do not need an SDK-specific schema.
|
|
99
|
+
langgraph_model_context: dict[str, Any] | None = None
|
|
97
100
|
|
|
98
101
|
|
|
99
102
|
@dataclass
|
|
@@ -273,8 +276,9 @@ def build_chat_completions_payload(
|
|
|
273
276
|
model: Optional[str],
|
|
274
277
|
session_id: str,
|
|
275
278
|
metadata: Mapping[str, Any] | None = None,
|
|
279
|
+
usage: Mapping[str, Any] | None = None,
|
|
276
280
|
) -> dict[str, Any]:
|
|
277
|
-
usage = _chat_usage_payload(_usage_from_metadata(metadata))
|
|
281
|
+
usage = _chat_usage_payload(usage or _usage_from_metadata(metadata))
|
|
278
282
|
payload = {
|
|
279
283
|
"id": f"chatcmpl-{uuid.uuid4()}",
|
|
280
284
|
"object": "chat.completion",
|
|
@@ -22,6 +22,7 @@ from ksadk.conversations.runtime_constants import (
|
|
|
22
22
|
from ksadk.conversations.runtime_observability import _extract_deferred_tool_names
|
|
23
23
|
from ksadk.runtime_context import TRUSTED_IDENTITY_METADATA_KEY, PlatformIdentityContext
|
|
24
24
|
from ksadk.sessions import Session, SessionEvent, resolve_session_service
|
|
25
|
+
from ksadk.sessions.base import SessionEventQuery
|
|
25
26
|
from ksadk.sessions.agent_identity import session_agent_ids
|
|
26
27
|
from ksadk.sessions.invocation_identity import (
|
|
27
28
|
bind_or_validate_session_identity,
|
|
@@ -185,7 +186,27 @@ async def _find_latest_session_event(
|
|
|
185
186
|
service: Any,
|
|
186
187
|
session_id: str,
|
|
187
188
|
predicate: Callable[[SessionEvent], bool],
|
|
189
|
+
*,
|
|
190
|
+
invocation_id: str | None = None,
|
|
191
|
+
event_type: str | None = None,
|
|
188
192
|
) -> SessionEvent | None:
|
|
193
|
+
if invocation_id and event_type and callable(getattr(service, "query_events", None)):
|
|
194
|
+
before = None
|
|
195
|
+
try:
|
|
196
|
+
while True:
|
|
197
|
+
page = await service.query_events(SessionEventQuery(
|
|
198
|
+
session_ids=[session_id], invocation_id=invocation_id,
|
|
199
|
+
event_types=[event_type], before_seq_id=before,
|
|
200
|
+
order_by_seq=True, limit=EVENT_SCAN_PAGE_SIZE,
|
|
201
|
+
))
|
|
202
|
+
for event in reversed(page):
|
|
203
|
+
if predicate(event):
|
|
204
|
+
return event
|
|
205
|
+
if len(page) < EVENT_SCAN_PAGE_SIZE:
|
|
206
|
+
return None
|
|
207
|
+
before = min(event.seq_id for event in page)
|
|
208
|
+
except NotImplementedError:
|
|
209
|
+
pass
|
|
189
210
|
total = await service.count_events(session_id)
|
|
190
211
|
offset = 0
|
|
191
212
|
while offset < total:
|
|
@@ -238,6 +259,8 @@ async def append_run_status_event(
|
|
|
238
259
|
)
|
|
239
260
|
== status
|
|
240
261
|
),
|
|
262
|
+
invocation_id=invocation_id,
|
|
263
|
+
event_type="run_status",
|
|
241
264
|
)
|
|
242
265
|
if existing is not None:
|
|
243
266
|
return existing
|
|
@@ -2,6 +2,7 @@ from __future__ import annotations
|
|
|
2
2
|
|
|
3
3
|
import logging
|
|
4
4
|
import os
|
|
5
|
+
import uuid
|
|
5
6
|
from typing import Any, Callable, Dict, Mapping, Optional, Sequence
|
|
6
7
|
|
|
7
8
|
from ksadk.context_engine.shadow_plan import (
|
|
@@ -79,10 +80,60 @@ from ksadk.model_policy import model_policy_options_for_model
|
|
|
79
80
|
from ksadk.runtime_context import TRUSTED_IDENTITY_METADATA_KEY, PlatformIdentityContext
|
|
80
81
|
from ksadk.session_context import split_session_context
|
|
81
82
|
from ksadk.sessions import SessionEvent, resolve_session_service
|
|
83
|
+
from ksadk.sessions.model_history import read_model_history
|
|
82
84
|
|
|
83
85
|
logger = logging.getLogger(__name__)
|
|
84
86
|
|
|
85
87
|
|
|
88
|
+
def _langgraph_model_context(
|
|
89
|
+
events: list[SessionEvent], request_history: list[dict[str, str]], invocation_id: str
|
|
90
|
+
) -> dict[str, Any]:
|
|
91
|
+
# Compaction runs after persisting the current input. Its summary can share
|
|
92
|
+
# this invocation_id, but the current user/tool/answer events are not history.
|
|
93
|
+
previous = [
|
|
94
|
+
event
|
|
95
|
+
for event in events
|
|
96
|
+
if event.invocation_id != invocation_id
|
|
97
|
+
or canonical_event_type(event.event_type) == "context_checkpoint"
|
|
98
|
+
]
|
|
99
|
+
history = build_history_from_events(previous)
|
|
100
|
+
checkpoints = [
|
|
101
|
+
event
|
|
102
|
+
for event in previous
|
|
103
|
+
if canonical_event_type(event.event_type) == "context_checkpoint"
|
|
104
|
+
]
|
|
105
|
+
seeded = any(
|
|
106
|
+
(event.metadata or {}).get("context_source") == "request_history" for event in previous
|
|
107
|
+
)
|
|
108
|
+
if not checkpoints and not seeded:
|
|
109
|
+
history = _merge_request_history_with_session_history(request_history, history)
|
|
110
|
+
# Once a summary covers a prefix, client replay must not resurrect it.
|
|
111
|
+
boundary = max(
|
|
112
|
+
(int((event.metadata or {}).get("compacted_until_seq_id") or 0) for event in checkpoints),
|
|
113
|
+
default=0,
|
|
114
|
+
)
|
|
115
|
+
turns: dict[str, list[SessionEvent]] = {}
|
|
116
|
+
for event in previous:
|
|
117
|
+
if (
|
|
118
|
+
event.seq_id > boundary
|
|
119
|
+
and event.invocation_id
|
|
120
|
+
and canonical_event_type(event.event_type) != "context_checkpoint"
|
|
121
|
+
):
|
|
122
|
+
turns.setdefault(event.invocation_id, []).append(event)
|
|
123
|
+
return {
|
|
124
|
+
"version": 1,
|
|
125
|
+
"invocation_id": invocation_id,
|
|
126
|
+
"history": history,
|
|
127
|
+
"compacted_until_seq_id": boundary,
|
|
128
|
+
"uncompacted": not checkpoints,
|
|
129
|
+
"turns": [
|
|
130
|
+
{"invocation_id": turn, "history": build_history_from_events(items)}
|
|
131
|
+
for turn, items in turns.items()
|
|
132
|
+
if any(canonical_event_type(event.event_type) == "user_message" for event in items)
|
|
133
|
+
],
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
|
|
86
137
|
async def build_run_input(
|
|
87
138
|
*,
|
|
88
139
|
agent_id: str,
|
|
@@ -141,6 +192,10 @@ async def build_run_input(
|
|
|
141
192
|
resolved_user_id = session.user_id
|
|
142
193
|
resolved_session_id = session.id
|
|
143
194
|
resolved_invocation_id = str(invocation_id or new_run_id(resolved_session_id))
|
|
195
|
+
uses_model_context = getattr(runner, "uses_ksadk_model_context", None)
|
|
196
|
+
integrated_model_context = (
|
|
197
|
+
callable(uses_model_context) and uses_model_context()
|
|
198
|
+
) or (runner is None and runtime_type in {"langgraph", "langchain"})
|
|
144
199
|
resolved_model_metadata = await _resolve_runtime_model_metadata(
|
|
145
200
|
model,
|
|
146
201
|
model_metadata=model_metadata,
|
|
@@ -203,7 +258,7 @@ async def build_run_input(
|
|
|
203
258
|
run_mode=caller_run_mode,
|
|
204
259
|
run_trigger=RUN_TRIGGER_CHECKPOINT_RESUME,
|
|
205
260
|
)
|
|
206
|
-
event_history = await service
|
|
261
|
+
event_history = await read_model_history(service, resolved_session_id)
|
|
207
262
|
history = build_history_from_events(event_history)
|
|
208
263
|
responses_history = project_responses_history(event_history)
|
|
209
264
|
return PreparedConversationTurn(
|
|
@@ -399,7 +454,7 @@ async def build_run_input(
|
|
|
399
454
|
"_ksadk_gateway_approval_resume": True,
|
|
400
455
|
}
|
|
401
456
|
del existing_events
|
|
402
|
-
event_history = await service
|
|
457
|
+
event_history = await read_model_history(service, resolved_session_id)
|
|
403
458
|
history = build_history_from_events(event_history)
|
|
404
459
|
responses_history = project_responses_history(event_history)
|
|
405
460
|
return PreparedConversationTurn(
|
|
@@ -475,7 +530,8 @@ async def build_run_input(
|
|
|
475
530
|
|
|
476
531
|
if normalized_instructions:
|
|
477
532
|
event_metadata["instructions"] = normalized_instructions
|
|
478
|
-
|
|
533
|
+
previous_events = await read_model_history(service, resolved_session_id)
|
|
534
|
+
deferred_tool_names = _latest_deferred_tool_names(previous_events)
|
|
479
535
|
if deferred_tool_names and "deferred_tool_names" not in normalized_request_metadata:
|
|
480
536
|
normalized_request_metadata["deferred_tool_names"] = deferred_tool_names
|
|
481
537
|
if normalized_custom_metadata:
|
|
@@ -483,6 +539,26 @@ async def build_run_input(
|
|
|
483
539
|
if normalized_request_metadata:
|
|
484
540
|
event_metadata["runtime_metadata"] = normalized_request_metadata
|
|
485
541
|
|
|
542
|
+
if integrated_model_context and not build_history_from_events(previous_events):
|
|
543
|
+
# A new session may arrive with caller-provided history. Seed it once so
|
|
544
|
+
# later current-only requests and compaction share the same source.
|
|
545
|
+
seed_turn = 0
|
|
546
|
+
for index, item in enumerate(build_request_history(normalized_messages[:-1])):
|
|
547
|
+
if item["role"] == "user":
|
|
548
|
+
seed_turn += 1
|
|
549
|
+
await append_conversation_event(
|
|
550
|
+
session_id=resolved_session_id,
|
|
551
|
+
author="user" if item["role"] == "user" else agent_id,
|
|
552
|
+
role=item["role"],
|
|
553
|
+
text=item["content"],
|
|
554
|
+
invocation_id=f"{resolved_invocation_id}:history:{seed_turn}",
|
|
555
|
+
event_id=str(
|
|
556
|
+
uuid.uuid5(uuid.NAMESPACE_URL, f"ksadk:{resolved_session_id}:history:{index}")
|
|
557
|
+
),
|
|
558
|
+
metadata={"context_source": "request_history"},
|
|
559
|
+
session_service_provider=provider,
|
|
560
|
+
)
|
|
561
|
+
|
|
486
562
|
await append_conversation_event(
|
|
487
563
|
session_id=resolved_session_id,
|
|
488
564
|
author="user",
|
|
@@ -517,9 +593,17 @@ async def build_run_input(
|
|
|
517
593
|
if runner is not None
|
|
518
594
|
else capabilities_for_runtime_type(runtime_type)
|
|
519
595
|
)
|
|
596
|
+
# The history prefix consists of committed, immutable events. Read only
|
|
597
|
+
# its suffix after persisting the input and after committing a summary.
|
|
598
|
+
history_cursor = max((event.seq_id for event in previous_events), default=0)
|
|
599
|
+
event_history = previous_events + await read_model_history(
|
|
600
|
+
service, resolved_session_id, after_seq_id=history_cursor,
|
|
601
|
+
)
|
|
602
|
+
history_cursor = max((event.seq_id for event in event_history), default=0)
|
|
520
603
|
checkpoint = await _compact_conversation_history_with_governance(
|
|
521
604
|
governance_state,
|
|
522
605
|
session_id=resolved_session_id,
|
|
606
|
+
preloaded_events=event_history,
|
|
523
607
|
author=agent_id,
|
|
524
608
|
invocation_id=resolved_invocation_id,
|
|
525
609
|
model=model,
|
|
@@ -529,7 +613,7 @@ async def build_run_input(
|
|
|
529
613
|
prompt_integration_mode=prompt_integration_mode,
|
|
530
614
|
compaction_owner=_caps.compaction_owner,
|
|
531
615
|
)
|
|
532
|
-
event_history
|
|
616
|
+
event_history.extend(await read_model_history(service, resolved_session_id, after_seq_id=history_cursor))
|
|
533
617
|
history = build_history_from_events(event_history)
|
|
534
618
|
responses_history = project_responses_history(event_history)
|
|
535
619
|
request_history = build_request_history(normalized_messages[:-1])
|
|
@@ -556,6 +640,12 @@ async def build_run_input(
|
|
|
556
640
|
[event for event in event_history if event.invocation_id != resolved_invocation_id]
|
|
557
641
|
),
|
|
558
642
|
)
|
|
643
|
+
model_context = (
|
|
644
|
+
_langgraph_model_context(event_history, request_history, resolved_invocation_id)
|
|
645
|
+
if integrated_model_context else None
|
|
646
|
+
)
|
|
647
|
+
if model_context is not None:
|
|
648
|
+
hosted_history = model_context["history"]
|
|
559
649
|
# PR D2:取最新 checkpoint 的 WorkingState(仅 ksadk_hosted 路径重注入)。
|
|
560
650
|
# 非 ksadk_hosted → working_state=None(零注入,Runner 输入与旧逻辑一致)。
|
|
561
651
|
# PTL retry 后 _refresh_history 也会重读 events,但此处 build_run_input 首次构建时取一次即可;
|
|
@@ -566,6 +656,7 @@ async def build_run_input(
|
|
|
566
656
|
|
|
567
657
|
prepared = PreparedConversationTurn(
|
|
568
658
|
session_context=session_context.to_payload(),
|
|
659
|
+
langgraph_model_context=model_context,
|
|
569
660
|
session_id=resolved_session_id,
|
|
570
661
|
invocation_id=resolved_invocation_id,
|
|
571
662
|
user_id=resolved_user_id,
|
|
@@ -747,6 +838,13 @@ async def _maybe_fill_hosted_pipeline(
|
|
|
747
838
|
"estimated_tokens": result.assembled.estimated_tokens,
|
|
748
839
|
"warnings": list(result.assembled.warnings),
|
|
749
840
|
}
|
|
841
|
+
if prepared.langgraph_model_context is not None:
|
|
842
|
+
from ksadk.context_engine.hosted_pipeline import assembled_to_payload
|
|
843
|
+
|
|
844
|
+
selected = assembled_to_payload(result.assembled)["history"]
|
|
845
|
+
if selected != prepared.langgraph_model_context["history"]:
|
|
846
|
+
prepared.langgraph_model_context["uncompacted"] = False
|
|
847
|
+
prepared.langgraph_model_context["history"] = selected
|
|
750
848
|
|
|
751
849
|
|
|
752
850
|
def _latest_checkpoint_working_state(events: Sequence[SessionEvent]) -> dict[str, Any] | None:
|
|
@@ -772,7 +870,7 @@ async def _refresh_history(
|
|
|
772
870
|
"""在 compaction 后刷新 prepared turn 的 history 视图。"""
|
|
773
871
|
provider = session_service_provider or resolve_session_service
|
|
774
872
|
service = provider()
|
|
775
|
-
event_history = await service
|
|
873
|
+
event_history = await read_model_history(service, prepared.session_id)
|
|
776
874
|
prepared.history = _merge_request_history_with_session_history(
|
|
777
875
|
prepared.request_history,
|
|
778
876
|
build_history_from_events(event_history),
|
|
@@ -781,4 +879,29 @@ async def _refresh_history(
|
|
|
781
879
|
prepared.request_responses_history,
|
|
782
880
|
project_responses_history(event_history),
|
|
783
881
|
)
|
|
882
|
+
if prepared.langgraph_model_context is not None:
|
|
883
|
+
prepared.langgraph_model_context = _langgraph_model_context(
|
|
884
|
+
event_history, prepared.request_history, prepared.invocation_id
|
|
885
|
+
)
|
|
886
|
+
if prepared.assembled_input is not None:
|
|
887
|
+
# PTL retries must not reuse the pre-compaction planner selection.
|
|
888
|
+
budget = (prepared.context_plan or {}).get("budget") or {}
|
|
889
|
+
await _maybe_fill_hosted_pipeline(
|
|
890
|
+
prepared,
|
|
891
|
+
compiled_prompt=prepared.compiled_prompt,
|
|
892
|
+
user_input=prepared.user_input,
|
|
893
|
+
history=prepared.langgraph_model_context["history"],
|
|
894
|
+
working_state=prepared.working_state,
|
|
895
|
+
model_metadata=prepared.model_metadata,
|
|
896
|
+
prompt_integration_mode=prepared.prompt_integration_mode,
|
|
897
|
+
context_engine_rollout="enabled",
|
|
898
|
+
memory_recall_enabled=prepared.memory_recall_enabled,
|
|
899
|
+
runtime_type="langgraph",
|
|
900
|
+
session_id=prepared.session_id,
|
|
901
|
+
invocation_id=prepared.invocation_id,
|
|
902
|
+
user_id=prepared.user_id,
|
|
903
|
+
agent_id=prepared.agent_id,
|
|
904
|
+
agent_max_input_tokens=budget.get("max_input_tokens"),
|
|
905
|
+
agent_reserve_output_tokens=budget.get("reserved_output_tokens"),
|
|
906
|
+
)
|
|
784
907
|
return prepared
|
ksadk/detection/mcp_detector.py
CHANGED
|
@@ -35,15 +35,36 @@ class MCPDetectionResult:
|
|
|
35
35
|
|
|
36
36
|
|
|
37
37
|
class MCPDetector:
|
|
38
|
-
"""MCP 检测器 - 检测 FastMCP 项目"""
|
|
39
|
-
|
|
40
|
-
#
|
|
38
|
+
"""MCP 检测器 - 检测 FastMCP / MCPServer 项目"""
|
|
39
|
+
|
|
40
|
+
# Server 类导入特征。
|
|
41
|
+
#
|
|
42
|
+
# ## 为什么要认三套
|
|
43
|
+
#
|
|
44
|
+
# `mcp` 2.3.0 把 `FastMCP` 改名成 `MCPServer` 并挪了路径,
|
|
45
|
+
# **同时删除** `mcp.server.fastmcp`。反过来,mcp 1.x 没有新路径。
|
|
46
|
+
#
|
|
47
|
+
# 只认一套的后果(2026-11-18 实测):迁移到 mcp 2.x 后
|
|
48
|
+
# `_find_mcp_file()` 返回 `None` → `is_mcp=False` → `ksadk mcp build`
|
|
49
|
+
# 直接报「未检测到 FastMCP 项目」,**构建彻底失败**。
|
|
50
|
+
#
|
|
51
|
+
# 顺序:新的在前(用户装的通常是新版),旧的兜底。
|
|
41
52
|
FASTMCP_PATTERNS = [
|
|
53
|
+
# mcp >= 2.3
|
|
54
|
+
"from mcp.server.mcpserver import",
|
|
55
|
+
"import mcp.server.mcpserver",
|
|
56
|
+
# mcp 2.0 ~ 2.2 的内部路径
|
|
57
|
+
"from mcp.server.mcpserver.server import",
|
|
58
|
+
# mcp 1.x(兼独立 fastmcp 包)
|
|
59
|
+
"from mcp.server.fastmcp import",
|
|
42
60
|
"from fastmcp import FastMCP",
|
|
43
61
|
"from fastmcp import",
|
|
44
62
|
"import fastmcp",
|
|
45
63
|
]
|
|
46
64
|
|
|
65
|
+
# 实例化时的类名(`_find_mcp_variable` 用它定位变量名)
|
|
66
|
+
SERVER_CLASS_NAMES = ("MCPServer", "FastMCP")
|
|
67
|
+
|
|
47
68
|
MCP_DECORATORS = [
|
|
48
69
|
"@mcp.tool",
|
|
49
70
|
"@mcp.resource",
|
|
@@ -110,7 +131,7 @@ class MCPDetector:
|
|
|
110
131
|
# 常见的 MCP 入口文件名
|
|
111
132
|
entry_files = ["server.py", "mcp_server.py", "main.py", "__init__.py"]
|
|
112
133
|
|
|
113
|
-
#
|
|
134
|
+
# 首先在根目录查找(根目录文件不会误判,不需要跳过)
|
|
114
135
|
for entry in entry_files:
|
|
115
136
|
file_path = self.project_dir / entry
|
|
116
137
|
if file_path.exists() and self._is_mcp_file(file_path):
|
|
@@ -119,7 +140,7 @@ class MCPDetector:
|
|
|
119
140
|
# 在子包中查找
|
|
120
141
|
for item in self.project_dir.iterdir():
|
|
121
142
|
if item.is_dir() and (item / "__init__.py").exists():
|
|
122
|
-
if
|
|
143
|
+
if self._should_skip(item):
|
|
123
144
|
continue
|
|
124
145
|
|
|
125
146
|
for entry in entry_files:
|
|
@@ -134,19 +155,55 @@ class MCPDetector:
|
|
|
134
155
|
|
|
135
156
|
# 扫描所有 .py 文件
|
|
136
157
|
for py_file in self.project_dir.rglob("*.py"):
|
|
137
|
-
|
|
138
|
-
if (
|
|
139
|
-
"__pycache__" in path_str
|
|
140
|
-
or "/.agentengine/" in path_str
|
|
141
|
-
or "/.venv/" in path_str
|
|
142
|
-
or "/venv/" in path_str
|
|
143
|
-
):
|
|
158
|
+
if self._should_skip(py_file):
|
|
144
159
|
continue
|
|
145
160
|
if self._is_mcp_file(py_file):
|
|
146
161
|
return py_file
|
|
147
162
|
|
|
148
163
|
return None
|
|
149
164
|
|
|
165
|
+
# 已知非源码目录:入口探测必须跳过它们。
|
|
166
|
+
NON_SOURCE_DIRS = frozenset(
|
|
167
|
+
{
|
|
168
|
+
"tests",
|
|
169
|
+
"test",
|
|
170
|
+
"testing",
|
|
171
|
+
"__pycache__",
|
|
172
|
+
"node_modules",
|
|
173
|
+
"venv",
|
|
174
|
+
"env",
|
|
175
|
+
}
|
|
176
|
+
)
|
|
177
|
+
|
|
178
|
+
def _should_skip(self, path: Path) -> bool:
|
|
179
|
+
"""判断路径是否应被入口探测跳过。
|
|
180
|
+
|
|
181
|
+
## 为什么必须跳过 `tests/`
|
|
182
|
+
|
|
183
|
+
单元测试里经常 `from fastmcp import FastMCP`(为了构造 Server 断言工具面)。
|
|
184
|
+
而 `_is_mcp_file()` 只看这一行导入,于是测试文件会被当成生产入口。
|
|
185
|
+
|
|
186
|
+
实测(ezone-mcp):一个 4310 文件的项目,`rglob("*.py")` 先命中
|
|
187
|
+
`tests/test_agent_surface.py`,生成的 entrypoint 变成
|
|
188
|
+
`from tests.test_agent_surface import mcp` —— **打包能过,运行必崩**
|
|
189
|
+
(模块级没有 `mcp`,且 tests 不在运行路径里)。
|
|
190
|
+
|
|
191
|
+
## 为什么还要跳过点目录
|
|
192
|
+
|
|
193
|
+
`.venv/` / `.agentengine/` / `.worktrees/` / `.git/` / `.tox/` 里可能是
|
|
194
|
+
**完整仓库副本或已安装依赖**。扫描它们既慢(几千个文件),
|
|
195
|
+
又必然把三方包里的 FastMCP 示例当成入口。
|
|
196
|
+
|
|
197
|
+
判断只看**父目录**(`parts[:-1]`)——文件名本身不参与,
|
|
198
|
+
所以 `test_server.py` 这种根目录文件仍会被根目录扫描命中。
|
|
199
|
+
"""
|
|
200
|
+
try:
|
|
201
|
+
parts = path.relative_to(self.project_dir).parts
|
|
202
|
+
except ValueError:
|
|
203
|
+
# 不在项目目录内(理论上不会发生),保守地不跳过
|
|
204
|
+
return False
|
|
205
|
+
return any(part.startswith(".") or part in self.NON_SOURCE_DIRS for part in parts[:-1])
|
|
206
|
+
|
|
150
207
|
def _is_mcp_file(self, file_path: Path) -> bool:
|
|
151
208
|
"""检查文件是否包含 FastMCP 代码"""
|
|
152
209
|
try:
|
|
@@ -212,17 +269,18 @@ class MCPDetector:
|
|
|
212
269
|
)
|
|
213
270
|
|
|
214
271
|
def _find_mcp_variable(self, tree: ast.AST, content: str) -> str:
|
|
215
|
-
"""查找
|
|
216
|
-
# 查找 xxx = FastMCP(...) 模式
|
|
272
|
+
"""查找 server 实例的变量名(`xxx = MCPServer(...)` / `xxx = MCPServer(...)`)。"""
|
|
217
273
|
for node in ast.walk(tree):
|
|
218
|
-
if isinstance(node, ast.Assign):
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
274
|
+
if not isinstance(node, ast.Assign):
|
|
275
|
+
continue
|
|
276
|
+
if not isinstance(node.value, ast.Call):
|
|
277
|
+
continue
|
|
278
|
+
func = node.value.func
|
|
279
|
+
# 兼容 `MCPServer(...)` 与 `fastmcp.MCPServer(...)` 两种写法
|
|
280
|
+
name = func.id if isinstance(func, ast.Name) else getattr(func, "attr", None)
|
|
281
|
+
if name in self.SERVER_CLASS_NAMES:
|
|
282
|
+
if node.targets and isinstance(node.targets[0], ast.Name):
|
|
283
|
+
return node.targets[0].id
|
|
226
284
|
|
|
227
285
|
# 默认返回 mcp
|
|
228
286
|
return "mcp"
|
|
@@ -8,6 +8,7 @@ from typing import Any
|
|
|
8
8
|
|
|
9
9
|
from langchain_core.messages import AIMessage, HumanMessage, SystemMessage, ToolMessage
|
|
10
10
|
from langgraph.stream import AsyncGraphRunStream
|
|
11
|
+
from langgraph.types import Command
|
|
11
12
|
|
|
12
13
|
from ksadk.events.adapters._langgraph_custom import CustomOutputMapper
|
|
13
14
|
from ksadk.events.adapters._langgraph_model_tasks import NativeModelTasks
|
|
@@ -93,6 +94,50 @@ _TOOL_DELTA_TYPES = frozenset(
|
|
|
93
94
|
)
|
|
94
95
|
|
|
95
96
|
|
|
97
|
+
def _tool_output(output: Any, call_id: str) -> Any:
|
|
98
|
+
"""Project a Command's tool reply without exposing graph state or routing data."""
|
|
99
|
+
if isinstance(output, Command):
|
|
100
|
+
items = [output]
|
|
101
|
+
elif isinstance(output, (list, tuple)) and any(
|
|
102
|
+
isinstance(item, (Command, ToolMessage)) for item in output
|
|
103
|
+
):
|
|
104
|
+
items = output
|
|
105
|
+
else:
|
|
106
|
+
return output
|
|
107
|
+
|
|
108
|
+
for item in items:
|
|
109
|
+
if isinstance(item, Command):
|
|
110
|
+
update = item.update
|
|
111
|
+
messages = update.get("messages") if isinstance(update, Mapping) else update
|
|
112
|
+
else:
|
|
113
|
+
messages = item
|
|
114
|
+
reply = _command_reply(messages, call_id)
|
|
115
|
+
if reply is not None:
|
|
116
|
+
return reply
|
|
117
|
+
# Routing and parent-graph Commands can finish without a user-facing reply.
|
|
118
|
+
return None
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+
def _command_reply(messages: Any, call_id: str) -> ToolMessage | None:
|
|
122
|
+
# LangGraph accepts message lists and (channel, value) updates. Traverse
|
|
123
|
+
# only the messages channel. Other state can be sensitive or non-JSON.
|
|
124
|
+
candidates = messages if isinstance(messages, (list, tuple)) else (messages,)
|
|
125
|
+
for candidate in candidates:
|
|
126
|
+
if isinstance(candidate, ToolMessage) and candidate.tool_call_id == call_id:
|
|
127
|
+
return candidate
|
|
128
|
+
if (
|
|
129
|
+
isinstance(candidate, Mapping)
|
|
130
|
+
and candidate.get("tool_call_id") == call_id
|
|
131
|
+
and candidate.get("role", candidate.get("type")) == "tool"
|
|
132
|
+
):
|
|
133
|
+
return ToolMessage.model_validate(candidate)
|
|
134
|
+
if isinstance(candidate, tuple) and len(candidate) == 2 and candidate[0] == "messages":
|
|
135
|
+
reply = _command_reply(candidate[1], call_id)
|
|
136
|
+
if reply is not None:
|
|
137
|
+
return reply
|
|
138
|
+
return None
|
|
139
|
+
|
|
140
|
+
|
|
96
141
|
class LangGraphEventAdapter:
|
|
97
142
|
"""Consume the lossless raw log exposed by ``AsyncGraphRunStream``."""
|
|
98
143
|
|
|
@@ -415,6 +460,9 @@ class LangGraphEventAdapter:
|
|
|
415
460
|
f"LangGraph tool call {call_id!r} started twice",
|
|
416
461
|
)
|
|
417
462
|
name = _required_string(payload.get("tool_name"), "tools tool_name")
|
|
463
|
+
source = source.model_copy(update={"metadata": {
|
|
464
|
+
**source.metadata, "tool_name": name,
|
|
465
|
+
}})
|
|
418
466
|
occurrence = self._tool_occurrences.get(state_key, 0)
|
|
419
467
|
self._tool_occurrences[state_key] = occurrence + 1
|
|
420
468
|
item_id = (
|
|
@@ -459,6 +507,10 @@ class LangGraphEventAdapter:
|
|
|
459
507
|
"tools tool_call_id",
|
|
460
508
|
f"LangGraph tool call {call_id!r} mutated before tool-started",
|
|
461
509
|
)
|
|
510
|
+
# Finish frames need not repeat the name; retain this execution's name.
|
|
511
|
+
source = source.model_copy(update={"metadata": {
|
|
512
|
+
**source.metadata, "tool_name": state.name,
|
|
513
|
+
}})
|
|
462
514
|
envelope = lambda event_type, part_id: env( # noqa: E731
|
|
463
515
|
frame.scope_id, frame.parent_scope_id, state.item_id, event_type, part_id, source
|
|
464
516
|
)
|
|
@@ -480,7 +532,7 @@ class LangGraphEventAdapter:
|
|
|
480
532
|
if native_type == "tool-finished":
|
|
481
533
|
if self._tool_outcomes is not None:
|
|
482
534
|
self._tool_outcomes.consume(frame.namespace, call_id, native_type)
|
|
483
|
-
output = payload.get("output")
|
|
535
|
+
output = _tool_output(payload.get("output"), call_id)
|
|
484
536
|
result_value = output.content if isinstance(output, ToolMessage) else output
|
|
485
537
|
is_error = isinstance(output, ToolMessage) and output.status == "error"
|
|
486
538
|
result = ToolResultContent(
|