agentengine-sdk-python 0.7.0__py3-none-any.whl → 0.8.0__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.7.0.dist-info → agentengine_sdk_python-0.8.0.dist-info}/METADATA +36 -20
- agentengine_sdk_python-0.8.0.dist-info/RECORD +578 -0
- ksadk/a2a/__init__.py +178 -11
- ksadk/a2a/bootstrap.py +334 -0
- ksadk/a2a/card.py +120 -0
- ksadk/a2a/context_store.py +203 -0
- ksadk/a2a/control_plane.py +818 -0
- ksadk/a2a/credential.py +99 -0
- ksadk/a2a/event_adapter.py +149 -0
- ksadk/a2a/executor.py +406 -89
- ksadk/a2a/external_transport.py +516 -0
- ksadk/a2a/identity.py +304 -0
- ksadk/a2a/ids.py +22 -0
- ksadk/a2a/langgraph.py +285 -0
- ksadk/a2a/resume_store.py +201 -0
- ksadk/a2a/routes.py +105 -0
- ksadk/a2a/server.py +107 -60
- ksadk/a2a/space_client.py +1101 -0
- ksadk/a2a/task_adapter.py +423 -0
- ksadk/a2a/task_event_dispatcher.py +167 -0
- ksadk/a2a/task_event_outbox.py +326 -0
- ksadk/a2a/task_store.py +206 -0
- ksadk/a2ui/__init__.py +27 -0
- ksadk/a2ui/core.py +186 -0
- ksadk/a2ui/models.py +166 -0
- ksadk/a2ui/renderer.py +198 -0
- ksadk/agui/__init__.py +9 -0
- ksadk/agui/a2ui_projection.py +92 -0
- ksadk/agui/agent.py +857 -0
- ksadk/agui/config.py +86 -0
- ksadk/agui/routes.py +55 -0
- ksadk/api/client.py +233 -191
- ksadk/builders/__init__.py +2 -0
- ksadk/builders/base.py +16 -14
- ksadk/builders/code_builder.py +318 -236
- ksadk/builders/container_builder.py +187 -167
- ksadk/builders/framework_requirements.py +29 -11
- ksadk/builders/ks3_uploader.py +58 -27
- ksadk/builders/managed_runtime_builder.py +145 -0
- ksadk/builders/mcp_builder.py +91 -92
- ksadk/builders/requirements_utils.py +1 -5
- ksadk/cli/__init__.py +89 -171
- ksadk/cli/cmd_a2a.py +254 -70
- ksadk/cli/cmd_agent.py +19 -5
- ksadk/cli/cmd_build.py +158 -29
- ksadk/cli/cmd_completion.py +47 -35
- ksadk/cli/cmd_config.py +267 -198
- ksadk/cli/cmd_create.py +500 -720
- ksadk/cli/cmd_dashboard.py +120 -45
- ksadk/cli/cmd_deploy.py +117 -58
- ksadk/cli/cmd_destroy.py +44 -14
- ksadk/cli/cmd_files.py +63 -24
- ksadk/cli/cmd_hermes.py +168 -89
- ksadk/cli/cmd_invoke.py +184 -122
- ksadk/cli/cmd_launch.py +64 -28
- ksadk/cli/cmd_mcp.py +98 -64
- ksadk/cli/cmd_model.py +14 -5
- ksadk/cli/cmd_openclaw.py +483 -227
- ksadk/cli/cmd_replay.py +71 -0
- ksadk/cli/cmd_run.py +33 -10
- ksadk/cli/cmd_status.py +80 -31
- ksadk/cli/cmd_version.py +20 -13
- ksadk/cli/cmd_web.py +89 -13
- ksadk/cli/deploy_utils.py +20 -20
- ksadk/cli/dry_run.py +5 -3
- ksadk/cli/error_utils.py +37 -12
- ksadk/cli/global_options.py +1 -2
- ksadk/cli/local_runtime.py +1 -2
- ksadk/cli/model_catalog.py +6 -2
- ksadk/cli/network_options.py +34 -14
- ksadk/cli/resource_common.py +6 -2
- ksadk/cli/storage.py +0 -1
- ksadk/cli/ui.py +5 -3
- ksadk/cli/workflow_common.py +51 -17
- ksadk/codex/__init__.py +12 -0
- ksadk/codex/client.py +408 -0
- ksadk/codex/phase.py +143 -0
- ksadk/codex/runtime.py +449 -0
- ksadk/common/aicp_env.py +0 -1
- ksadk/common/auth.py +2 -2
- ksadk/common/constants.py +1 -3
- ksadk/common/llm_utils.py +17 -13
- ksadk/compat/__init__.py +5 -0
- ksadk/compat/adk_compat.py +200 -0
- ksadk/compat/copilotkit_a2ui.py +330 -0
- ksadk/configs/__init__.py +12 -12
- ksadk/configs/env_registry.py +500 -100
- ksadk/configs/global_config.py +2 -1
- ksadk/configs/settings.py +151 -124
- ksadk/conversations/__init__.py +7 -5
- ksadk/conversations/attachment_storage.py +16 -11
- ksadk/conversations/attachments.py +44 -36
- ksadk/conversations/compaction_pipeline.py +12 -12
- ksadk/conversations/compaction_prompt.py +9 -5
- ksadk/conversations/context.py +221 -6
- ksadk/conversations/message_projection.py +438 -51
- ksadk/conversations/model_context.py +12 -6
- ksadk/conversations/model_options.py +0 -1
- ksadk/conversations/normalize.py +20 -16
- ksadk/conversations/reasoning_markup.py +1 -1
- ksadk/conversations/runtime.py +339 -5255
- ksadk/conversations/runtime_compaction.py +333 -0
- ksadk/conversations/runtime_constants.py +27 -0
- ksadk/conversations/runtime_governance.py +185 -0
- ksadk/conversations/runtime_input.py +652 -0
- ksadk/conversations/runtime_invocation.py +395 -0
- ksadk/conversations/runtime_metadata.py +475 -0
- ksadk/conversations/runtime_observability.py +355 -0
- ksadk/conversations/runtime_payloads.py +272 -0
- ksadk/conversations/runtime_persistence.py +440 -0
- ksadk/conversations/runtime_preparation.py +418 -0
- ksadk/conversations/runtime_resume.py +816 -0
- ksadk/conversations/runtime_stream_events.py +902 -0
- ksadk/conversations/runtime_streaming.py +547 -0
- ksadk/conversations/semantic_summary.py +17 -5
- ksadk/conversations/session_title.py +6 -3
- ksadk/deployment/__init__.py +15 -16
- ksadk/deployment/agent_access.py +12 -23
- ksadk/deployment/base.py +51 -38
- ksadk/deployment/manager.py +63 -65
- ksadk/deployment/providers/serverless.py +309 -202
- ksadk/deployment/registry.py +38 -32
- ksadk/deployment/state.py +11 -11
- ksadk/deployment/ui_config.py +1 -1
- ksadk/detection/__init__.py +1 -1
- ksadk/detection/detector.py +146 -83
- ksadk/detection/mcp_detector.py +9 -6
- ksadk/events/__init__.py +25 -0
- ksadk/events/parser.py +191 -0
- ksadk/events/replay.py +37 -0
- ksadk/events/runtime_event.py +264 -0
- ksadk/events/store.py +317 -0
- ksadk/harness/__init__.py +34 -0
- ksadk/harness/app.py +278 -0
- ksadk/harness/config.py +181 -0
- ksadk/harness/reasoner.py +105 -0
- ksadk/harness/runner.py +211 -0
- ksadk/harness/sandbox.py +141 -0
- ksadk/harness/tools.py +222 -0
- ksadk/hermes_terminal.py +23 -12
- ksadk/identity/resolver.py +15 -9
- ksadk/ids.py +32 -0
- ksadk/knowledge_base/adk_tool.py +1 -1
- ksadk/knowledge_base/client.py +23 -29
- ksadk/managed_runtime.py +188 -0
- ksadk/markdown.py +5 -2
- ksadk/mcp_runtime/__init__.py +9 -6
- ksadk/memory/__init__.py +1 -1
- ksadk/memory/adk/__init__.py +2 -0
- ksadk/memory/adk/backends/base_ltm_backend.py +2 -6
- ksadk/memory/adk/backends/http_ltm_backend.py +13 -21
- ksadk/memory/adk/backends/inmemory_ltm_backend.py +7 -13
- ksadk/memory/adk/backends/sdk_ltm_backend.py +26 -33
- ksadk/memory/adk/long_term_memory.py +31 -35
- ksadk/memory/adk/resilient_session_service.py +4 -5
- ksadk/memory/adk/short_term_memory.py +12 -21
- ksadk/memory/adk_tool.py +3 -2
- ksadk/memory/backends/base.py +19 -19
- ksadk/memory/backends/memory.py +24 -25
- ksadk/memory/backends/redis.py +31 -30
- ksadk/memory/langchain_tool.py +2 -1
- ksadk/memory/manager.py +52 -47
- ksadk/memory/service.py +10 -8
- ksadk/model_policy.py +15 -7
- ksadk/model_proxy/__init__.py +51 -0
- ksadk/model_proxy/bootstrap.py +80 -0
- ksadk/model_proxy/cache.py +165 -0
- ksadk/model_proxy/config.py +45 -0
- ksadk/model_proxy/demo_webui.py +115 -0
- ksadk/model_proxy/detect.py +145 -0
- ksadk/model_proxy/gate.py +68 -0
- ksadk/model_proxy/namespace.py +173 -0
- ksadk/model_proxy/protocol_proxy.py +22 -0
- ksadk/model_proxy/server.py +300 -0
- ksadk/model_proxy/transform.py +691 -0
- ksadk/openclaw_gateway.py +29 -14
- ksadk/runners/adk_runner.py +345 -120
- ksadk/runners/base_runner.py +46 -29
- ksadk/runners/codex_runner.py +132 -0
- ksadk/runners/deepagents_runner.py +0 -1
- ksadk/runners/factory.py +17 -5
- ksadk/runners/langchain_runner.py +29 -742
- ksadk/runners/langgraph_runner.py +352 -90
- ksadk/runners/patch_langchain.py +16 -16
- ksadk/runners/remote_runner.py +134 -33
- ksadk/runners/usage_accumulator.py +1 -0
- ksadk/runners/utils/langfuse.py +3 -3
- ksadk/runners/utils/loader.py +7 -7
- ksadk/runtime/__init__.py +41 -0
- ksadk/runtime/adapter.py +345 -0
- ksadk/runtime/framework_adapters.py +124 -0
- ksadk/runtime/preprocessing.py +118 -0
- ksadk/runtime/runner_adapter.py +873 -0
- ksadk/runtime_context.py +18 -3
- ksadk/runtime_state.py +0 -1
- ksadk/sandbox/__init__.py +4 -1
- ksadk/sandbox/backends/__init__.py +4 -1
- ksadk/sandbox/backends/e2b.py +13 -5
- ksadk/sandbox/backends/local_process.py +11 -3
- ksadk/sandbox/base.py +10 -15
- ksadk/sandbox/factory.py +14 -4
- ksadk/sandbox/registry.py +57 -6
- ksadk/server/api_models.py +15 -5
- ksadk/server/app.py +455 -3885
- ksadk/server/composition.py +21 -0
- ksadk/server/factory.py +624 -0
- ksadk/server/routes/__init__.py +1 -0
- ksadk/server/routes/checkpoint_resolution.py +116 -0
- ksadk/server/routes/common.py +713 -0
- ksadk/server/routes/control.py +327 -0
- ksadk/server/routes/dependencies.py +98 -0
- ksadk/server/routes/misc.py +448 -0
- ksadk/server/routes/models.py +443 -0
- ksadk/server/routes/openai_compat.py +207 -0
- ksadk/server/routes/projection.py +795 -0
- ksadk/server/routes/routers.py +52 -0
- ksadk/server/routes/run.py +726 -0
- ksadk/server/routes/sessions.py +649 -0
- ksadk/server/routes/streaming.py +223 -0
- ksadk/server/routes/workspace.py +381 -0
- ksadk/server/static/assets/{ArtifactsPanel-D-SSn2ee.js → ArtifactsPanel-Cjnqt-8W.js} +1 -1
- ksadk/server/static/assets/CodeBlock-BqyqZfuB.js +9 -0
- ksadk/server/static/assets/MathMessageMarkdown-BpH7jiFM.js +8 -0
- ksadk/server/static/assets/MermaidBlock-DWuxETaJ.js +303 -0
- ksadk/server/static/assets/NativeTerminalPanel-MDTopWMO.js +1 -0
- ksadk/server/static/assets/{arc-BA13sHc9.js → arc-CFKwSk_B.js} +1 -1
- ksadk/server/static/assets/architecture-7EHR7CIX-CynqOWjZ.js +1 -0
- ksadk/server/static/assets/{architectureDiagram-3BPJPVTR-DzJzgVoL.js → architectureDiagram-3BPJPVTR-Dej8jX8c.js} +1 -1
- ksadk/server/static/assets/{blockDiagram-GPEHLZMM-UTdVcZhn.js → blockDiagram-GPEHLZMM-1F64jqvy.js} +1 -1
- ksadk/server/static/assets/{c4Diagram-AAUBKEIU-Dix0GD4m.js → c4Diagram-AAUBKEIU-9q7AUAKb.js} +1 -1
- ksadk/server/static/assets/channel-iUGv2N24.js +1 -0
- ksadk/server/static/assets/{chunk-2J33WTMH-C2JxuZ42.js → chunk-2J33WTMH-6qgwJm7Q.js} +1 -1
- ksadk/server/static/assets/{chunk-4BX2VUAB-Be57QPgD.js → chunk-4BX2VUAB-CsWIQRhc.js} +1 -1
- ksadk/server/static/assets/{chunk-55IACEB6-WjSuy4nv.js → chunk-55IACEB6-BK8paA20.js} +1 -1
- ksadk/server/static/assets/{chunk-727SXJPM-BOovP-b5.js → chunk-727SXJPM-B-JEhy7h.js} +1 -1
- ksadk/server/static/assets/{chunk-AQP2D5EJ-DOmZNmWj.js → chunk-AQP2D5EJ-DYBvMHAa.js} +1 -1
- ksadk/server/static/assets/{chunk-FMBD7UC4-DzwlodkU.js → chunk-FMBD7UC4-BGhvzDYt.js} +1 -1
- ksadk/server/static/assets/{chunk-ND2GUHAM-DMqAikEU.js → chunk-ND2GUHAM-D98vPd-E.js} +1 -1
- ksadk/server/static/assets/chunk-QZHKN3VN-YQIEXeF6.js +1 -0
- ksadk/server/static/assets/classDiagram-4FO5ZUOK-CDAUuoXK.js +1 -0
- ksadk/server/static/assets/classDiagram-v2-Q7XG4LA2-CDAUuoXK.js +1 -0
- ksadk/server/static/assets/{cose-bilkent-S5V4N54A-Zhy2GBnP.js → cose-bilkent-S5V4N54A-CX3yotHq.js} +1 -1
- ksadk/server/static/assets/{dagre-BM42HDAG-CbKrtIUz.js → dagre-BM42HDAG-C7TguAWo.js} +1 -1
- ksadk/server/static/assets/{diagram-2AECGRRQ-BRApgQRK.js → diagram-2AECGRRQ-Dd17_kws.js} +1 -1
- ksadk/server/static/assets/{diagram-5GNKFQAL-D0xbnDiK.js → diagram-5GNKFQAL-DVIClIil.js} +1 -1
- ksadk/server/static/assets/{diagram-KO2AKTUF-CVugVI9L.js → diagram-KO2AKTUF-Df_3gYQa.js} +1 -1
- ksadk/server/static/assets/{diagram-LMA3HP47-DozUGgee.js → diagram-LMA3HP47-BhLk6ZtA.js} +1 -1
- ksadk/server/static/assets/{diagram-OG6HWLK6-ZOYsKlru.js → diagram-OG6HWLK6-D4GNGvuu.js} +1 -1
- ksadk/server/static/assets/{dist-DmFaq_Iy.js → dist-6CVKuTAe.js} +1 -1
- ksadk/server/static/assets/{dist-8EEyGgDx.js → dist-BUHRxvDG.js} +1 -1
- ksadk/server/static/assets/{dist-B0NP_Z0z.js → dist-BZ9n9AjO.js} +1 -1
- ksadk/server/static/assets/{dist-DMezvBGJ.js → dist-BibcG1V9.js} +1 -1
- ksadk/server/static/assets/{dist-C3HIIaN5.js → dist-Bs-jQcRX.js} +1 -1
- ksadk/server/static/assets/{dist-BrCcQ47T.js → dist-C2xjE7cO.js} +1 -1
- ksadk/server/static/assets/{dist-Dp0k7bWI.js → dist-C7-3jInC.js} +1 -1
- ksadk/server/static/assets/{dist-D-xOD048.js → dist-C99THtIA.js} +1 -1
- ksadk/server/static/assets/{dist-CkEKJFtk.js → dist-CGcp2ex8.js} +1 -1
- ksadk/server/static/assets/{dist-DyOkZmze.js → dist-CVQRZjPu.js} +1 -1
- ksadk/server/static/assets/{dist-BssVmjIo.js → dist-Cf23NY4L.js} +1 -1
- ksadk/server/static/assets/{dist-BIJVDMuB.js → dist-CgF3fj15.js} +1 -1
- ksadk/server/static/assets/{dist-2hInLS_J.js → dist-Cwt7koer.js} +1 -1
- ksadk/server/static/assets/{dist-DyWsb78Q.js → dist-D82mtD2s.js} +1 -1
- ksadk/server/static/assets/{dist-D-JMdWPQ.js → dist-DF06ORQo.js} +1 -1
- ksadk/server/static/assets/{dist-BmlMPsCc.js → dist-DHn6nBzr.js} +1 -1
- ksadk/server/static/assets/{dist-gX6GOLKq.js → dist-Djgl2wVZ.js} +1 -1
- ksadk/server/static/assets/{dist-DpKtt4Bo.js → dist-DlzCRy0S.js} +1 -1
- ksadk/server/static/assets/{dist-8_SfK1IP.js → dist-DqNnNFrw.js} +1 -1
- ksadk/server/static/assets/{dist-D57wnGWd.js → dist-DyvYLMW9.js} +1 -1
- ksadk/server/static/assets/{dist-CPBtqRTW.js → dist-eoW6tZXA.js} +1 -1
- ksadk/server/static/assets/{dist-DL_NKc_z.js → dist-ivOya1LD.js} +1 -1
- ksadk/server/static/assets/{erDiagram-TEJ5UH35-Bk-9bgE5.js → erDiagram-TEJ5UH35-CnfRcY2M.js} +1 -1
- ksadk/server/static/assets/eventmodeling-FCH6USID-ChYO-ijM.js +1 -0
- ksadk/server/static/assets/{flowDiagram-I6XJVG4X-Dn9kZVuZ.js → flowDiagram-I6XJVG4X-DGaJjGNJ.js} +1 -1
- ksadk/server/static/assets/{ganttDiagram-6RSMTGT7-BGxXlJqm.js → ganttDiagram-6RSMTGT7-DpCoB2g9.js} +1 -1
- ksadk/server/static/assets/gitGraph-WXDBUCRP-BN_0Fk-j.js +1 -0
- ksadk/server/static/assets/{gitGraphDiagram-PVQCEYII-C7Q0X-wi.js → gitGraphDiagram-PVQCEYII-9IKVFBVT.js} +1 -1
- ksadk/server/static/assets/index-QSwCHuB8.js +177 -0
- ksadk/server/static/assets/index-jOPmTOZH.css +2 -0
- ksadk/server/static/assets/info-J43DQDTF-Cp6o3vId.js +1 -0
- ksadk/server/static/assets/{infoDiagram-5YYISTIA-BO_CSqq5.js → infoDiagram-5YYISTIA-CYIIsb8y.js} +1 -1
- ksadk/server/static/assets/{ishikawaDiagram-YF4QCWOH-eYLPLd46.js → ishikawaDiagram-YF4QCWOH-DLOHGvWw.js} +1 -1
- ksadk/server/static/assets/{journeyDiagram-JHISSGLW-De9geSb0.js → journeyDiagram-JHISSGLW-BIzKeejT.js} +1 -1
- ksadk/server/static/assets/{kanban-definition-UN3LZRKU-Cs80kQto.js → kanban-definition-UN3LZRKU-BWHoFSw2.js} +1 -1
- ksadk/server/static/assets/{katex-DSrCFD8n.js → katex-DATssjp1.js} +1 -1
- ksadk/server/static/assets/{linear-CN9sbKTF.js → linear-CvMBw9cA.js} +1 -1
- ksadk/server/static/assets/{mermaid-parser.core-DlgSBU8l.js → mermaid-parser.core-mGAcEwcq.js} +2 -2
- ksadk/server/static/assets/{mindmap-definition-RKZ34NQL-9afz7Oug.js → mindmap-definition-RKZ34NQL-CSAQxEAe.js} +1 -1
- ksadk/server/static/assets/packet-YPE3B663-wQzct3cT.js +1 -0
- ksadk/server/static/assets/pie-LRSECV5Y-BgTQiv-9.js +1 -0
- ksadk/server/static/assets/{pieDiagram-4H26LBE5-DPv_VstN.js → pieDiagram-4H26LBE5-By-ra07M.js} +1 -1
- ksadk/server/static/assets/{quadrantDiagram-W4KKPZXB-o77wZ1XK.js → quadrantDiagram-W4KKPZXB-CxIR4JXI.js} +1 -1
- ksadk/server/static/assets/radar-GUYGQ44K-BIq5fXsn.js +1 -0
- ksadk/server/static/assets/{requirementDiagram-4Y6WPE33-BYVw81VC.js → requirementDiagram-4Y6WPE33-DpW90iu3.js} +1 -1
- ksadk/server/static/assets/{sankeyDiagram-5OEKKPKP-B7nZFMKT.js → sankeyDiagram-5OEKKPKP-DpGa6EAV.js} +1 -1
- ksadk/server/static/assets/{sequenceDiagram-3UESZ5HK-BGRRrFw5.js → sequenceDiagram-3UESZ5HK-NTKNGGe5.js} +1 -1
- ksadk/server/static/assets/{stateDiagram-AJRCARHV-BUfHCoPs.js → stateDiagram-AJRCARHV-DGpd9yFG.js} +1 -1
- ksadk/server/static/assets/stateDiagram-v2-BHNVJYJU-B3o579IQ.js +1 -0
- ksadk/server/static/assets/{timeline-definition-PNZ67QCA-FbCTGrf9.js → timeline-definition-PNZ67QCA-jqoYs3jQ.js} +1 -1
- ksadk/server/static/assets/treeView-BLDUP644-Dqi-E0EM.js +1 -0
- ksadk/server/static/assets/treemap-LRROVOQU-ClQP9CJ9.js +1 -0
- ksadk/server/static/assets/{vennDiagram-CIIHVFJN-DWgwtPsJ.js → vennDiagram-CIIHVFJN-l3Z7-wbP.js} +1 -1
- ksadk/server/static/assets/wardley-L42UT6IY-8XLvnNIs.js +1 -0
- ksadk/server/static/assets/{wardleyDiagram-YWT4CUSO-2x8G-tTM.js → wardleyDiagram-YWT4CUSO-BR54GPmr.js} +1 -1
- ksadk/server/static/assets/{xychartDiagram-2RQKCTM6-Drma3AYl.js → xychartDiagram-2RQKCTM6-SkiH8GsK.js} +1 -1
- ksadk/server/static/index.html +2 -2
- ksadk/server/terminal_sessions.py +111 -58
- ksadk/sessions/__init__.py +69 -19
- ksadk/sessions/base.py +31 -11
- ksadk/sessions/continuity.py +2 -3
- ksadk/sessions/in_memory.py +46 -2
- ksadk/sessions/local_service.py +148 -17
- ksadk/sessions/postgres_service.py +143 -25
- ksadk/sessions/resilient.py +36 -8
- ksadk/skills/models.py +17 -5
- ksadk/skills/package_store.py +5 -2
- ksadk/skills/runtime/agent.py +20 -5
- ksadk/skills/runtime/artifacts.py +1 -5
- ksadk/skills/runtime/backends/e2b.py +10 -4
- ksadk/skills/runtime/backends/local.py +15 -3
- ksadk/skills/runtime/base.py +1 -2
- ksadk/skills/runtime/executor.py +10 -3
- ksadk/skills/runtime/factory.py +4 -2
- ksadk/skills/runtime/loader.py +1 -2
- ksadk/skills/runtime/registry.py +15 -10
- ksadk/skills/runtime/request.py +3 -1
- ksadk/skills/service_client.py +38 -17
- ksadk/skills/tool_defs.py +15 -10
- ksadk/terminal_exec_policy.py +3 -4
- ksadk/tools/gateway.py +92 -15
- ksadk/tools/result_budget.py +12 -4
- ksadk/toolsets/__init__.py +134 -36
- ksadk/toolsets/platform.py +21 -5
- ksadk/toolsets/sandbox.py +82 -16
- ksadk/toolsets/skills.py +200 -39
- ksadk/toolsets/web.py +123 -26
- ksadk/toolsets/workspace.py +212 -101
- ksadk/tracing/exporters/inmemory_exporter.py +62 -51
- ksadk/tracing/exporters/langfuse_exporter.py +91 -76
- ksadk/tracing/setup.py +69 -53
- ksadk/tracing/span_utils.py +5 -2
- ksadk/tui/loop.py +78 -30
- ksadk/tui/stream_render.py +1 -0
- ksadk/ui_config.py +5 -3
- ksadk/version.py +1 -1
- ksadk_runtime_common/schemas/runtime_event_v1.json +95 -0
- agentengine_sdk_python-0.7.0.dist-info/RECORD +0 -482
- ksadk/server/static/assets/CodeBlock-P16VOLYi.js +0 -9
- ksadk/server/static/assets/MathMessageMarkdown-CdGiQWHR.js +0 -8
- ksadk/server/static/assets/MermaidBlock-IOcal8cm.js +0 -303
- ksadk/server/static/assets/NativeTerminalPanel-DGSDWsei.js +0 -1
- ksadk/server/static/assets/architecture-7EHR7CIX-BvUlsA6l.js +0 -1
- ksadk/server/static/assets/channel-CTuydARX.js +0 -1
- ksadk/server/static/assets/chunk-QZHKN3VN-BnCydivS.js +0 -1
- ksadk/server/static/assets/classDiagram-4FO5ZUOK-BNHg45Be.js +0 -1
- ksadk/server/static/assets/classDiagram-v2-Q7XG4LA2-BNHg45Be.js +0 -1
- ksadk/server/static/assets/eventmodeling-FCH6USID-DsAgWnlf.js +0 -1
- ksadk/server/static/assets/gitGraph-WXDBUCRP-BIao9Yjg.js +0 -1
- ksadk/server/static/assets/index-C00Lwg3L.js +0 -165
- ksadk/server/static/assets/index-DAURbCsP.css +0 -1
- ksadk/server/static/assets/info-J43DQDTF-CyipqGxU.js +0 -1
- ksadk/server/static/assets/packet-YPE3B663-CGkyRxlg.js +0 -1
- ksadk/server/static/assets/pie-LRSECV5Y-M0uWAf4n.js +0 -1
- ksadk/server/static/assets/radar-GUYGQ44K-Bdbm24-x.js +0 -1
- ksadk/server/static/assets/stateDiagram-v2-BHNVJYJU-8xBN_gLM.js +0 -1
- ksadk/server/static/assets/treeView-BLDUP644-npMo0ak1.js +0 -1
- ksadk/server/static/assets/treemap-LRROVOQU-CHdzrrdo.js +0 -1
- ksadk/server/static/assets/wardley-L42UT6IY-BEQz7wyy.js +0 -1
- {agentengine_sdk_python-0.7.0.dist-info → agentengine_sdk_python-0.8.0.dist-info}/WHEEL +0 -0
- {agentengine_sdk_python-0.7.0.dist-info → agentengine_sdk_python-0.8.0.dist-info}/entry_points.txt +0 -0
- {agentengine_sdk_python-0.7.0.dist-info → agentengine_sdk_python-0.8.0.dist-info}/licenses/LICENSE +0 -0
- {agentengine_sdk_python-0.7.0.dist-info → agentengine_sdk_python-0.8.0.dist-info}/top_level.txt +0 -0
ksadk/harness/tools.py
ADDED
|
@@ -0,0 +1,222 @@
|
|
|
1
|
+
"""Tool catalog for one Harness runner."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import json
|
|
6
|
+
import uuid
|
|
7
|
+
from dataclasses import dataclass
|
|
8
|
+
from typing import Any, Awaitable, Callable
|
|
9
|
+
|
|
10
|
+
from ksadk.compat.adk_compat import Agent, InMemorySessionService, InvocationContext, ToolContext
|
|
11
|
+
from ksadk.harness.config import McpToolSpec
|
|
12
|
+
from ksadk.harness.sandbox import HarnessSandboxExecutor
|
|
13
|
+
from ksadk.mcp_runtime import MCPServerConfig, build_mcp_toolset
|
|
14
|
+
|
|
15
|
+
ToolHandler = Callable[[dict[str, Any], str | None], Awaitable[Any]]
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
@dataclass(frozen=True)
|
|
19
|
+
class HarnessTool:
|
|
20
|
+
name: str
|
|
21
|
+
description: str
|
|
22
|
+
parameters: dict[str, Any]
|
|
23
|
+
handler: ToolHandler
|
|
24
|
+
source: str
|
|
25
|
+
|
|
26
|
+
@property
|
|
27
|
+
def openai_schema(self) -> dict[str, Any]:
|
|
28
|
+
return {
|
|
29
|
+
"type": "function",
|
|
30
|
+
"function": {
|
|
31
|
+
"name": self.name,
|
|
32
|
+
"description": self.description,
|
|
33
|
+
"parameters": self.parameters,
|
|
34
|
+
},
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
async def call(self, arguments: dict[str, Any], *, call_id: str | None = None) -> Any:
|
|
38
|
+
return await self.handler(arguments, call_id)
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
def sandbox_tools(sandbox: HarnessSandboxExecutor) -> list[HarnessTool]:
|
|
42
|
+
async def _read_file(arguments: dict[str, Any], call_id: str | None) -> Any:
|
|
43
|
+
del call_id
|
|
44
|
+
return await sandbox.read_file(str(arguments.get("path") or ""))
|
|
45
|
+
|
|
46
|
+
async def _run_command(arguments: dict[str, Any], call_id: str | None) -> Any:
|
|
47
|
+
del call_id
|
|
48
|
+
return await sandbox.run_command(str(arguments.get("command") or ""))
|
|
49
|
+
|
|
50
|
+
return [
|
|
51
|
+
HarnessTool(
|
|
52
|
+
name="sandbox_read_file",
|
|
53
|
+
description="Read one UTF-8 file inside the Harness workspace.",
|
|
54
|
+
parameters={
|
|
55
|
+
"type": "object",
|
|
56
|
+
"properties": {"path": {"type": "string"}},
|
|
57
|
+
"required": ["path"],
|
|
58
|
+
"additionalProperties": False,
|
|
59
|
+
},
|
|
60
|
+
handler=_read_file,
|
|
61
|
+
source="sandbox",
|
|
62
|
+
),
|
|
63
|
+
HarnessTool(
|
|
64
|
+
name="sandbox_run_command",
|
|
65
|
+
description=(
|
|
66
|
+
"Run an allowlisted read-only command inside the Harness workspace. "
|
|
67
|
+
"Writes, network access, and dangerous process actions are denied."
|
|
68
|
+
),
|
|
69
|
+
parameters={
|
|
70
|
+
"type": "object",
|
|
71
|
+
"properties": {"command": {"type": "string"}},
|
|
72
|
+
"required": ["command"],
|
|
73
|
+
"additionalProperties": False,
|
|
74
|
+
},
|
|
75
|
+
handler=_run_command,
|
|
76
|
+
source="sandbox",
|
|
77
|
+
),
|
|
78
|
+
]
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
async def load_mcp_tools(spec: McpToolSpec) -> tuple[Any, list[HarnessTool]]:
|
|
82
|
+
config = MCPServerConfig(
|
|
83
|
+
name=spec.name,
|
|
84
|
+
url=spec.url,
|
|
85
|
+
api_key=spec.api_key,
|
|
86
|
+
tool_filter=spec.tool_filter,
|
|
87
|
+
tool_name_prefix=spec.tool_name_prefix,
|
|
88
|
+
)
|
|
89
|
+
toolset = build_mcp_toolset(config)
|
|
90
|
+
try:
|
|
91
|
+
native_tools = await toolset.get_tools_with_prefix()
|
|
92
|
+
except Exception as exc:
|
|
93
|
+
await toolset.close()
|
|
94
|
+
raise RuntimeError(
|
|
95
|
+
f"Harness MCP server {spec.name!r} at {spec.url!r} failed to start: {exc}"
|
|
96
|
+
) from exc
|
|
97
|
+
|
|
98
|
+
available_names = {str(tool.name) for tool in native_tools}
|
|
99
|
+
expected_names = {
|
|
100
|
+
f"{spec.tool_name_prefix}_{name}" if spec.tool_name_prefix else name
|
|
101
|
+
for name in spec.tool_filter
|
|
102
|
+
}
|
|
103
|
+
missing_names = sorted(expected_names - available_names)
|
|
104
|
+
if missing_names:
|
|
105
|
+
await toolset.close()
|
|
106
|
+
raise RuntimeError(
|
|
107
|
+
f"Harness MCP server {spec.name!r} at {spec.url!r} did not expose configured "
|
|
108
|
+
f"tool(s): {missing_names}"
|
|
109
|
+
)
|
|
110
|
+
if not native_tools:
|
|
111
|
+
await toolset.close()
|
|
112
|
+
raise RuntimeError(
|
|
113
|
+
f"Harness MCP server {spec.name!r} at {spec.url!r} exposed no callable tools"
|
|
114
|
+
)
|
|
115
|
+
|
|
116
|
+
tools: list[HarnessTool] = []
|
|
117
|
+
for native_tool in native_tools:
|
|
118
|
+
# ADK's declaration builder is private and changed across 1.x/2.x.
|
|
119
|
+
# MCP exposes the original public tool schema, which is stable across
|
|
120
|
+
# the supported versions.
|
|
121
|
+
raw_tool = getattr(native_tool, "raw_mcp_tool", None)
|
|
122
|
+
parameters = getattr(raw_tool, "inputSchema", None)
|
|
123
|
+
if parameters is None:
|
|
124
|
+
parameters = getattr(raw_tool, "input_schema", None)
|
|
125
|
+
if parameters is None:
|
|
126
|
+
parameters = getattr(native_tool, "input_schema", None)
|
|
127
|
+
if not isinstance(parameters, dict):
|
|
128
|
+
parameters = {"type": "object", "properties": {}}
|
|
129
|
+
parameters = _normalize_json_schema(parameters)
|
|
130
|
+
|
|
131
|
+
async def _call(
|
|
132
|
+
arguments: dict[str, Any],
|
|
133
|
+
call_id: str | None,
|
|
134
|
+
*,
|
|
135
|
+
_native_tool=native_tool,
|
|
136
|
+
_tool_name=str(native_tool.name),
|
|
137
|
+
) -> Any:
|
|
138
|
+
try:
|
|
139
|
+
context = await _new_tool_context(call_id or _tool_name)
|
|
140
|
+
result = await _native_tool.run_async(args=arguments, tool_context=context)
|
|
141
|
+
return _normalize_tool_result(result, context)
|
|
142
|
+
except Exception as exc:
|
|
143
|
+
raise RuntimeError(
|
|
144
|
+
f"Harness MCP tool {_tool_name!r} on server {spec.name!r} failed: {exc}"
|
|
145
|
+
) from exc
|
|
146
|
+
|
|
147
|
+
tools.append(
|
|
148
|
+
HarnessTool(
|
|
149
|
+
name=str(native_tool.name),
|
|
150
|
+
description=str(getattr(native_tool, "description", None) or "MCP tool"),
|
|
151
|
+
parameters=parameters,
|
|
152
|
+
handler=_call,
|
|
153
|
+
source=f"mcp:{spec.name}",
|
|
154
|
+
)
|
|
155
|
+
)
|
|
156
|
+
return toolset, tools
|
|
157
|
+
|
|
158
|
+
|
|
159
|
+
async def _new_tool_context(tool_name: str) -> Any:
|
|
160
|
+
"""Build a real ADK ToolContext for a standalone MCP invocation."""
|
|
161
|
+
service = InMemorySessionService()
|
|
162
|
+
session = await service.create_session(
|
|
163
|
+
app_name="ksadk-harness",
|
|
164
|
+
user_id="harness",
|
|
165
|
+
session_id=f"tool-{uuid.uuid4().hex}",
|
|
166
|
+
)
|
|
167
|
+
invocation = InvocationContext(
|
|
168
|
+
session_service=service,
|
|
169
|
+
invocation_id=f"harness-tool-{tool_name}",
|
|
170
|
+
# ADK 1.34 requires an agent while 2.x makes it optional. Supplying a
|
|
171
|
+
# minimal public Agent keeps the same ToolContext construction on both.
|
|
172
|
+
agent=Agent(name="harness_tool", model="gemini-2.0-flash"),
|
|
173
|
+
session=session,
|
|
174
|
+
)
|
|
175
|
+
return ToolContext(invocation_context=invocation, function_call_id=tool_name)
|
|
176
|
+
|
|
177
|
+
|
|
178
|
+
def _normalize_tool_result(result: Any, context: Any) -> Any:
|
|
179
|
+
"""Keep MCP failures structured so the reasoner can produce a final answer."""
|
|
180
|
+
confirmations = getattr(context.actions, "requested_tool_confirmations", {})
|
|
181
|
+
if confirmations:
|
|
182
|
+
error = result.get("error") if isinstance(result, dict) else None
|
|
183
|
+
return {
|
|
184
|
+
"ok": False,
|
|
185
|
+
"confirmation_required": True,
|
|
186
|
+
"confirmation_ids": sorted(str(item) for item in confirmations),
|
|
187
|
+
"error": str(error or "tool confirmation is required"),
|
|
188
|
+
}
|
|
189
|
+
if isinstance(result, dict) and result.get("error") is not None:
|
|
190
|
+
return {"ok": False, "error": str(result["error"])}
|
|
191
|
+
return result
|
|
192
|
+
|
|
193
|
+
|
|
194
|
+
def tool_result_text(result: Any) -> str:
|
|
195
|
+
if isinstance(result, str):
|
|
196
|
+
return result
|
|
197
|
+
if isinstance(result, dict):
|
|
198
|
+
content = result.get("content")
|
|
199
|
+
if isinstance(content, list):
|
|
200
|
+
texts = [
|
|
201
|
+
str(item.get("text"))
|
|
202
|
+
for item in content
|
|
203
|
+
if isinstance(item, dict) and item.get("text") is not None
|
|
204
|
+
]
|
|
205
|
+
if texts:
|
|
206
|
+
return "\n".join(texts)
|
|
207
|
+
return json.dumps(result, ensure_ascii=False, default=str)
|
|
208
|
+
|
|
209
|
+
|
|
210
|
+
def _normalize_json_schema(value: Any) -> Any:
|
|
211
|
+
if isinstance(value, dict):
|
|
212
|
+
normalized = {key: _normalize_json_schema(item) for key, item in value.items()}
|
|
213
|
+
schema_type = normalized.get("type")
|
|
214
|
+
if isinstance(schema_type, str):
|
|
215
|
+
normalized["type"] = schema_type.lower()
|
|
216
|
+
return normalized
|
|
217
|
+
if isinstance(value, list):
|
|
218
|
+
return [_normalize_json_schema(item) for item in value]
|
|
219
|
+
return value
|
|
220
|
+
|
|
221
|
+
|
|
222
|
+
__all__ = ["HarnessTool", "load_mcp_tools", "sandbox_tools", "tool_result_text"]
|
ksadk/hermes_terminal.py
CHANGED
|
@@ -5,6 +5,7 @@ from __future__ import annotations
|
|
|
5
5
|
import asyncio
|
|
6
6
|
import contextlib
|
|
7
7
|
import ctypes
|
|
8
|
+
import importlib
|
|
8
9
|
import io
|
|
9
10
|
import json
|
|
10
11
|
import os
|
|
@@ -123,7 +124,9 @@ def validate_terminal_exec_argv(argv: Iterable[str]) -> list[str]:
|
|
|
123
124
|
return validate_exec_argv_with_policy(argv, policy=GENERIC_TERMINAL_EXEC_POLICY)
|
|
124
125
|
|
|
125
126
|
|
|
126
|
-
def build_terminal_exec_validator(
|
|
127
|
+
def build_terminal_exec_validator(
|
|
128
|
+
policy: TerminalExecPolicy,
|
|
129
|
+
) -> Callable[[Iterable[str]], list[str]]:
|
|
127
130
|
def _validator(argv: Iterable[str]) -> list[str]:
|
|
128
131
|
return validate_exec_argv_with_policy(argv, policy=policy)
|
|
129
132
|
|
|
@@ -190,30 +193,34 @@ def _raw_terminal(stdin: Any):
|
|
|
190
193
|
|
|
191
194
|
|
|
192
195
|
@contextlib.contextmanager
|
|
193
|
-
def _windows_raw_terminal(
|
|
196
|
+
def _windows_raw_terminal(
|
|
197
|
+
stdin: Any, *, kernel32: Any | None = None, msvcrt_module: Any | None = None
|
|
198
|
+
):
|
|
194
199
|
if not hasattr(stdin, "fileno") or not hasattr(stdin, "isatty") or not stdin.isatty():
|
|
195
200
|
yield
|
|
196
201
|
return
|
|
197
202
|
|
|
203
|
+
resolved_kernel32: Any = kernel32
|
|
204
|
+
resolved_msvcrt: Any = msvcrt_module
|
|
198
205
|
try:
|
|
199
|
-
if
|
|
200
|
-
|
|
201
|
-
if
|
|
202
|
-
|
|
206
|
+
if resolved_kernel32 is None:
|
|
207
|
+
resolved_kernel32 = getattr(ctypes, "windll").kernel32
|
|
208
|
+
if resolved_msvcrt is None:
|
|
209
|
+
resolved_msvcrt = importlib.import_module("msvcrt")
|
|
203
210
|
except Exception:
|
|
204
211
|
yield
|
|
205
212
|
return
|
|
206
213
|
|
|
207
214
|
try:
|
|
208
215
|
fd = stdin.fileno()
|
|
209
|
-
handle =
|
|
216
|
+
handle = resolved_msvcrt.get_osfhandle(fd)
|
|
210
217
|
except Exception:
|
|
211
218
|
yield
|
|
212
219
|
return
|
|
213
220
|
|
|
214
221
|
original_mode = wintypes.DWORD()
|
|
215
222
|
try:
|
|
216
|
-
if not
|
|
223
|
+
if not resolved_kernel32.GetConsoleMode(handle, ctypes.byref(original_mode)):
|
|
217
224
|
yield
|
|
218
225
|
return
|
|
219
226
|
except Exception:
|
|
@@ -233,7 +240,7 @@ def _windows_raw_terminal(stdin: Any, *, kernel32: Any | None = None, msvcrt_mod
|
|
|
233
240
|
)
|
|
234
241
|
|
|
235
242
|
try:
|
|
236
|
-
if not
|
|
243
|
+
if not resolved_kernel32.SetConsoleMode(handle, raw_mode):
|
|
237
244
|
yield
|
|
238
245
|
return
|
|
239
246
|
except Exception:
|
|
@@ -244,14 +251,18 @@ def _windows_raw_terminal(stdin: Any, *, kernel32: Any | None = None, msvcrt_mod
|
|
|
244
251
|
yield
|
|
245
252
|
finally:
|
|
246
253
|
with contextlib.suppress(Exception):
|
|
247
|
-
|
|
254
|
+
resolved_kernel32.SetConsoleMode(handle, int(original_mode.value))
|
|
248
255
|
|
|
249
256
|
|
|
250
|
-
async def _connect_websocket(
|
|
257
|
+
async def _connect_websocket(
|
|
258
|
+
ws_url: str, headers: dict[str, str], ssl_context: ssl.SSLContext | None
|
|
259
|
+
):
|
|
251
260
|
try:
|
|
252
261
|
import websockets
|
|
253
262
|
except ImportError as e:
|
|
254
|
-
raise RuntimeError(
|
|
263
|
+
raise RuntimeError(
|
|
264
|
+
"missing dependency websockets, please install ksadk with websocket support"
|
|
265
|
+
) from e
|
|
255
266
|
|
|
256
267
|
kwargs: dict[str, Any] = {"subprotocols": [TERMINAL_SUBPROTOCOL]}
|
|
257
268
|
if ssl_context is not None:
|
ksadk/identity/resolver.py
CHANGED
|
@@ -31,11 +31,11 @@ _KRN_ACCOUNT_RE = re.compile(r"krn:ksc:iam::([^:]+):user/")
|
|
|
31
31
|
class ResolvedIdentity:
|
|
32
32
|
"""AK/SK 反查到的身份信息。"""
|
|
33
33
|
|
|
34
|
-
user_uuid: Optional[str]
|
|
34
|
+
user_uuid: Optional[str] # 子账号 UserId(X-Ksc-User-uuid 值);主账号 AK 时 None
|
|
35
35
|
main_account_id: Optional[str] # 从 Krn 提取的主账号 ID
|
|
36
|
-
user_name: Optional[str]
|
|
37
|
-
krn: Optional[str]
|
|
38
|
-
ak_fingerprint: str
|
|
36
|
+
user_name: Optional[str] # 子账号 UserName(调试用)
|
|
37
|
+
krn: Optional[str] # 原始 Krn(调试用)
|
|
38
|
+
ak_fingerprint: str # sha256(AK)[:16],缓存 key
|
|
39
39
|
|
|
40
40
|
|
|
41
41
|
# ---------------------------------------------------------------------------
|
|
@@ -107,14 +107,20 @@ def _should_retry_intranet(error: Exception | None) -> bool:
|
|
|
107
107
|
def _import_iam_sdk():
|
|
108
108
|
"""惰性导入 ksyun IAM SDK,失败返回 None。"""
|
|
109
109
|
try:
|
|
110
|
-
from ksyun.client.iam.v20151101.client import
|
|
111
|
-
|
|
110
|
+
from ksyun.client.iam.v20151101.client import ( # type: ignore[import-untyped]
|
|
111
|
+
IamClient,
|
|
112
|
+
)
|
|
113
|
+
from ksyun.client.iam.v20151101.models import ( # type: ignore[import-untyped]
|
|
112
114
|
GetUserRequest,
|
|
113
115
|
ListAllUserAccessKeysRequest,
|
|
114
116
|
)
|
|
115
|
-
from ksyun.common.credential import Credential
|
|
116
|
-
from ksyun.common.profile.client_profile import
|
|
117
|
-
|
|
117
|
+
from ksyun.common.credential import Credential # type: ignore[import-untyped]
|
|
118
|
+
from ksyun.common.profile.client_profile import ( # type: ignore[import-untyped]
|
|
119
|
+
ClientProfile,
|
|
120
|
+
)
|
|
121
|
+
from ksyun.common.profile.http_profile import ( # type: ignore[import-untyped]
|
|
122
|
+
HttpProfile,
|
|
123
|
+
)
|
|
118
124
|
except Exception as exc:
|
|
119
125
|
logger.warning("导入 ksyun IAM SDK 失败: %s", exc)
|
|
120
126
|
return None
|
ksadk/ids.py
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"""统一 id 铸造规范。
|
|
2
|
+
|
|
3
|
+
历史上 session / run(invocation) id 各层格式混杂:
|
|
4
|
+
|
|
5
|
+
- agentengine-server hosted 会话: ``sess-<16 hex>``(conversation_service)
|
|
6
|
+
- ksadk 本地 session: 裸 ``<16 hex>``(sessions/base.generate_id)
|
|
7
|
+
- ksadk 后台 run: ``inv_<32 hex>``(server/app RunAgent)
|
|
8
|
+
- ksadk conversation turn: 裸 ``uuid4``(conversations/runtime)
|
|
9
|
+
- research-ui run_agent 模式: ``run_<session段>``(由 session id 推导)
|
|
10
|
+
|
|
11
|
+
新代码统一走这里:
|
|
12
|
+
|
|
13
|
+
- session id: ``sess-<16 hex>``,与 agentengine-server 对齐。
|
|
14
|
+
- run/invocation id: ``run_<32 hex>``,每次 run 唯一且固定长度。
|
|
15
|
+
|
|
16
|
+
id 均为不透明字符串,仅在铸造时保证格式,消费方不做结构解析。
|
|
17
|
+
"""
|
|
18
|
+
|
|
19
|
+
from __future__ import annotations
|
|
20
|
+
|
|
21
|
+
import uuid
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
def new_session_id() -> str:
|
|
25
|
+
"""铸造 session id:``sess-<16 hex>``。"""
|
|
26
|
+
return f"sess-{uuid.uuid4().hex[:16]}"
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
def new_run_id(session_id: str | None = None) -> str:
|
|
30
|
+
"""铸造固定长度 opaque run/invocation id:``run_<32 hex>``。"""
|
|
31
|
+
del session_id
|
|
32
|
+
return f"run_{uuid.uuid4().hex}"
|
ksadk/knowledge_base/adk_tool.py
CHANGED
ksadk/knowledge_base/client.py
CHANGED
|
@@ -101,9 +101,13 @@ class KnowledgeBaseClient(BaseModel):
|
|
|
101
101
|
return self._aicp_client
|
|
102
102
|
|
|
103
103
|
try:
|
|
104
|
-
from ksyun.common import credential
|
|
105
|
-
from ksyun.common.profile.client_profile import
|
|
106
|
-
|
|
104
|
+
from ksyun.common import credential # type: ignore[import-untyped]
|
|
105
|
+
from ksyun.common.profile.client_profile import ( # type: ignore[import-untyped]
|
|
106
|
+
ClientProfile,
|
|
107
|
+
)
|
|
108
|
+
from ksyun.common.profile.http_profile import ( # type: ignore[import-untyped]
|
|
109
|
+
HttpProfile,
|
|
110
|
+
)
|
|
107
111
|
except ImportError:
|
|
108
112
|
raise ImportError(
|
|
109
113
|
"kingsoftcloud-sdk-python is required for knowledge base. "
|
|
@@ -140,9 +144,7 @@ class KnowledgeBaseClient(BaseModel):
|
|
|
140
144
|
client_profile = ClientProfile()
|
|
141
145
|
client_profile.httpProfile = http_profile
|
|
142
146
|
|
|
143
|
-
self._aicp_client = aicp_module.AicpClient(
|
|
144
|
-
cred, self.region, profile=client_profile
|
|
145
|
-
)
|
|
147
|
+
self._aicp_client = aicp_module.AicpClient(cred, self.region, profile=client_profile)
|
|
146
148
|
|
|
147
149
|
# 强制覆写 API 版本为 RetrieveKnowledge 所需的 2025-11-14
|
|
148
150
|
# SDK 的 _apiVersion 由导入的模块版本决定,可能不匹配
|
|
@@ -159,19 +161,20 @@ class KnowledgeBaseClient(BaseModel):
|
|
|
159
161
|
"""构建 RetrieveKnowledge 请求参数 (JSON 嵌套格式)"""
|
|
160
162
|
effective_top_k = top_k if top_k is not None else self.top_k
|
|
161
163
|
|
|
162
|
-
|
|
164
|
+
retrieval_model: dict[str, Any] = {
|
|
165
|
+
"SearchMethod": self.search_method,
|
|
166
|
+
"TopK": effective_top_k,
|
|
167
|
+
"RerankingEnable": self.reranking_enable,
|
|
168
|
+
}
|
|
169
|
+
params: dict[str, Any] = {
|
|
163
170
|
"DatasetId": self.dataset_id,
|
|
164
171
|
"Query": query,
|
|
165
|
-
"RetrievalModel":
|
|
166
|
-
"SearchMethod": self.search_method,
|
|
167
|
-
"TopK": effective_top_k,
|
|
168
|
-
"RerankingEnable": self.reranking_enable,
|
|
169
|
-
},
|
|
172
|
+
"RetrievalModel": retrieval_model,
|
|
170
173
|
}
|
|
171
174
|
|
|
172
175
|
if self.score_threshold_enabled:
|
|
173
|
-
|
|
174
|
-
|
|
176
|
+
retrieval_model["ScoreThresholdEnabled"] = True
|
|
177
|
+
retrieval_model["ScoreThreshold"] = self.score_threshold
|
|
175
178
|
|
|
176
179
|
return params
|
|
177
180
|
|
|
@@ -205,9 +208,7 @@ class KnowledgeBaseClient(BaseModel):
|
|
|
205
208
|
|
|
206
209
|
return results
|
|
207
210
|
|
|
208
|
-
def search(
|
|
209
|
-
self, query: str, top_k: Optional[int] = None
|
|
210
|
-
) -> List[KnowledgeBaseResult]:
|
|
211
|
+
def search(self, query: str, top_k: Optional[int] = None) -> List[KnowledgeBaseResult]:
|
|
211
212
|
"""检索知识库
|
|
212
213
|
|
|
213
214
|
Args:
|
|
@@ -221,18 +222,14 @@ class KnowledgeBaseClient(BaseModel):
|
|
|
221
222
|
params = self._build_params(query, top_k)
|
|
222
223
|
|
|
223
224
|
logger.info(
|
|
224
|
-
f"Searching knowledge base: dataset_id={self.dataset_id}, "
|
|
225
|
-
f"query='{query[:50]}'"
|
|
225
|
+
f"Searching knowledge base: dataset_id={self.dataset_id}, " f"query='{query[:50]}'"
|
|
226
226
|
)
|
|
227
227
|
|
|
228
228
|
try:
|
|
229
|
-
response = client.call(
|
|
230
|
-
"RetrieveKnowledge", params, options={"IsPostJson": True}
|
|
231
|
-
)
|
|
229
|
+
response = client.call("RetrieveKnowledge", params, options={"IsPostJson": True})
|
|
232
230
|
results = self._parse_response(response)
|
|
233
231
|
logger.info(
|
|
234
|
-
f"Knowledge base returned {len(results)} results "
|
|
235
|
-
f"for query='{query[:50]}'"
|
|
232
|
+
f"Knowledge base returned {len(results)} results " f"for query='{query[:50]}'"
|
|
236
233
|
)
|
|
237
234
|
return results
|
|
238
235
|
except Exception as e:
|
|
@@ -252,8 +249,7 @@ class KnowledgeBaseClient(BaseModel):
|
|
|
252
249
|
dataset_id = os.environ.get("KSADK_KB_DATASET_ID", "")
|
|
253
250
|
if not dataset_id:
|
|
254
251
|
raise ValueError(
|
|
255
|
-
"KSADK_KB_DATASET_ID environment variable is required "
|
|
256
|
-
"to enable knowledge base."
|
|
252
|
+
"KSADK_KB_DATASET_ID environment variable is required " "to enable knowledge base."
|
|
257
253
|
)
|
|
258
254
|
|
|
259
255
|
access_key = (
|
|
@@ -283,9 +279,7 @@ class KnowledgeBaseClient(BaseModel):
|
|
|
283
279
|
endpoint=connection["endpoint"],
|
|
284
280
|
scheme=connection["scheme"],
|
|
285
281
|
top_k=int(os.environ.get("KSADK_KB_TOP_K", "5")),
|
|
286
|
-
search_method=os.environ.get(
|
|
287
|
-
"KSADK_KB_SEARCH_METHOD", "intelligence_search"
|
|
288
|
-
),
|
|
282
|
+
search_method=os.environ.get("KSADK_KB_SEARCH_METHOD", "intelligence_search"),
|
|
289
283
|
score_threshold=score_threshold,
|
|
290
284
|
score_threshold_enabled=score_threshold_enabled,
|
|
291
285
|
reranking_enable=reranking_enable,
|