agentengine-sdk-python 0.6.2__py3-none-any.whl → 0.6.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.6.9.dist-info/METADATA +179 -0
- agentengine_sdk_python-0.6.9.dist-info/RECORD +487 -0
- {agentengine_sdk_python-0.6.2.dist-info → agentengine_sdk_python-0.6.9.dist-info}/WHEEL +1 -1
- agentengine_sdk_python-0.6.9.dist-info/entry_points.txt +3 -0
- agentengine_sdk_python-0.6.9.dist-info/licenses/LICENSE +175 -0
- agentengine_sdk_python-0.6.9.dist-info/top_level.txt +2 -0
- ksadk/__init__.py +13 -0
- ksadk/__main__.py +4 -0
- ksadk/a2a/__init__.py +15 -0
- ksadk/a2a/card_builder.py +64 -0
- ksadk/a2a/client.py +309 -0
- ksadk/a2a/executor.py +201 -0
- ksadk/a2a/server.py +79 -0
- ksadk/agents/__init__.py +20 -0
- ksadk/agents/base.py +370 -0
- ksadk/agents/context.py +38 -0
- ksadk/agents/event.py +35 -0
- ksadk/agents/loop_agent.py +71 -0
- ksadk/agents/parallel_agent.py +109 -0
- ksadk/agents/runner_adapter.py +24 -0
- ksadk/agents/sequential_agent.py +34 -0
- ksadk/api/__init__.py +3 -0
- ksadk/api/client.py +2227 -0
- ksadk/builders/__init__.py +20 -0
- ksadk/builders/base.py +66 -0
- ksadk/builders/code_builder.py +1990 -0
- ksadk/builders/container_builder.py +786 -0
- ksadk/builders/framework_requirements.py +59 -0
- ksadk/builders/ks3_uploader.py +389 -0
- ksadk/builders/mcp_builder.py +476 -0
- ksadk/builders/requirements_utils.py +75 -0
- ksadk/cli/__init__.py +531 -0
- ksadk/cli/__main__.py +4 -0
- ksadk/cli/agent_ref.py +204 -0
- ksadk/cli/cmd_a2a.py +167 -0
- ksadk/cli/cmd_agent.py +201 -0
- ksadk/cli/cmd_build.py +270 -0
- ksadk/cli/cmd_completion.py +304 -0
- ksadk/cli/cmd_config.py +758 -0
- ksadk/cli/cmd_create.py +2277 -0
- ksadk/cli/cmd_dashboard.py +900 -0
- ksadk/cli/cmd_deploy.py +704 -0
- ksadk/cli/cmd_destroy.py +345 -0
- ksadk/cli/cmd_files.py +1227 -0
- ksadk/cli/cmd_hermes.py +1259 -0
- ksadk/cli/cmd_invoke.py +1336 -0
- ksadk/cli/cmd_launch.py +564 -0
- ksadk/cli/cmd_mcp.py +1174 -0
- ksadk/cli/cmd_model.py +302 -0
- ksadk/cli/cmd_openclaw.py +3918 -0
- ksadk/cli/cmd_run.py +232 -0
- ksadk/cli/cmd_status.py +588 -0
- ksadk/cli/cmd_version.py +522 -0
- ksadk/cli/cmd_web.py +288 -0
- ksadk/cli/deploy_utils.py +87 -0
- ksadk/cli/dry_run.py +214 -0
- ksadk/cli/env_options.py +82 -0
- ksadk/cli/error_utils.py +525 -0
- ksadk/cli/global_options.py +31 -0
- ksadk/cli/local_runtime.py +97 -0
- ksadk/cli/model_catalog.py +136 -0
- ksadk/cli/network_options.py +410 -0
- ksadk/cli/resource_common.py +621 -0
- ksadk/cli/storage.py +84 -0
- ksadk/cli/ui.py +431 -0
- ksadk/cli/workflow_common.py +552 -0
- ksadk/common/__init__.py +14 -0
- ksadk/common/aicp_env.py +128 -0
- ksadk/common/auth.py +190 -0
- ksadk/common/constants.py +84 -0
- ksadk/common/llm_utils.py +61 -0
- ksadk/configs/__init__.py +61 -0
- ksadk/configs/env_registry.py +342 -0
- ksadk/configs/global_config.py +200 -0
- ksadk/configs/settings.py +706 -0
- ksadk/conversations/__init__.py +95 -0
- ksadk/conversations/attachment_storage.py +379 -0
- ksadk/conversations/attachments.py +774 -0
- ksadk/conversations/compaction_pipeline.py +387 -0
- ksadk/conversations/compaction_prompt.py +128 -0
- ksadk/conversations/context.py +303 -0
- ksadk/conversations/model_context.py +360 -0
- ksadk/conversations/model_options.py +136 -0
- ksadk/conversations/normalize.py +446 -0
- ksadk/conversations/reasoning_markup.py +91 -0
- ksadk/conversations/run_kinds.py +61 -0
- ksadk/conversations/run_status.py +53 -0
- ksadk/conversations/runtime.py +5208 -0
- ksadk/conversations/semantic_summary.py +359 -0
- ksadk/conversations/session_title.py +254 -0
- ksadk/deployment/__init__.py +83 -0
- ksadk/deployment/agent_access.py +226 -0
- ksadk/deployment/base.py +229 -0
- ksadk/deployment/manager.py +332 -0
- ksadk/deployment/providers/__init__.py +10 -0
- ksadk/deployment/providers/serverless.py +1105 -0
- ksadk/deployment/registry.py +120 -0
- ksadk/deployment/state.py +78 -0
- ksadk/deployment/ui_config.py +21 -0
- ksadk/detection/__init__.py +7 -0
- ksadk/detection/detector.py +431 -0
- ksadk/detection/mcp_detector.py +250 -0
- ksadk/hermes_terminal.py +467 -0
- ksadk/identity/__init__.py +17 -0
- ksadk/identity/resolver.py +385 -0
- ksadk/knowledge_base/__init__.py +62 -0
- ksadk/knowledge_base/adk_tool.py +47 -0
- ksadk/knowledge_base/client.py +297 -0
- ksadk/knowledge_base/langchain_tool.py +55 -0
- ksadk/knowledge_base/service.py +66 -0
- ksadk/knowledge_base/tool.py +50 -0
- ksadk/markdown.py +169 -0
- ksadk/mcp_runtime/__init__.py +231 -0
- ksadk/memory/__init__.py +57 -0
- ksadk/memory/adk/__init__.py +51 -0
- ksadk/memory/adk/backends/__init__.py +5 -0
- ksadk/memory/adk/backends/base_ltm_backend.py +52 -0
- ksadk/memory/adk/backends/http_ltm_backend.py +183 -0
- ksadk/memory/adk/backends/inmemory_ltm_backend.py +96 -0
- ksadk/memory/adk/backends/sdk_ltm_backend.py +456 -0
- ksadk/memory/adk/long_term_memory.py +273 -0
- ksadk/memory/adk/short_term_memory.py +289 -0
- ksadk/memory/adk_tool.py +31 -0
- ksadk/memory/backends/__init__.py +6 -0
- ksadk/memory/backends/base.py +103 -0
- ksadk/memory/backends/memory.py +112 -0
- ksadk/memory/backends/redis.py +146 -0
- ksadk/memory/langchain_tool.py +39 -0
- ksadk/memory/ltm_backend_factory.py +24 -0
- ksadk/memory/manager.py +215 -0
- ksadk/memory/service.py +172 -0
- ksadk/memory/tool.py +96 -0
- ksadk/model_policy.py +223 -0
- ksadk/openclaw_gateway.py +378 -0
- ksadk/runners/__init__.py +8 -0
- ksadk/runners/adk_runner.py +1135 -0
- ksadk/runners/base_runner.py +305 -0
- ksadk/runners/deepagents_runner.py +13 -0
- ksadk/runners/factory.py +73 -0
- ksadk/runners/langchain_runner.py +539 -0
- ksadk/runners/langgraph_runner.py +852 -0
- ksadk/runners/patch_langchain.py +187 -0
- ksadk/runners/remote_runner.py +667 -0
- ksadk/runners/usage_accumulator.py +38 -0
- ksadk/runners/utils/__init__.py +19 -0
- ksadk/runners/utils/langfuse.py +230 -0
- ksadk/runners/utils/loader.py +62 -0
- ksadk/runtime_context.py +166 -0
- ksadk/runtime_state.py +25 -0
- ksadk/sandbox/__init__.py +28 -0
- ksadk/sandbox/backends/__init__.py +9 -0
- ksadk/sandbox/backends/e2b.py +154 -0
- ksadk/sandbox/backends/local_process.py +131 -0
- ksadk/sandbox/base.py +101 -0
- ksadk/sandbox/factory.py +53 -0
- ksadk/sandbox/registry.py +187 -0
- ksadk/server/__init__.py +7 -0
- ksadk/server/api_models.py +73 -0
- ksadk/server/app.py +3789 -0
- ksadk/server/static/assets/ArtifactsPanel-C0meuOdi.js +1 -0
- ksadk/server/static/assets/CodeBlock-BbI4HPtJ.js +9 -0
- ksadk/server/static/assets/KaTeX_AMS-Regular-BQhdFMY1.woff2 +0 -0
- ksadk/server/static/assets/KaTeX_AMS-Regular-DMm9YOAa.woff +0 -0
- ksadk/server/static/assets/KaTeX_AMS-Regular-DRggAlZN.ttf +0 -0
- ksadk/server/static/assets/KaTeX_Caligraphic-Bold-ATXxdsX0.ttf +0 -0
- ksadk/server/static/assets/KaTeX_Caligraphic-Bold-BEiXGLvX.woff +0 -0
- ksadk/server/static/assets/KaTeX_Caligraphic-Bold-Dq_IR9rO.woff2 +0 -0
- ksadk/server/static/assets/KaTeX_Caligraphic-Regular-CTRA-rTL.woff +0 -0
- ksadk/server/static/assets/KaTeX_Caligraphic-Regular-Di6jR-x-.woff2 +0 -0
- ksadk/server/static/assets/KaTeX_Caligraphic-Regular-wX97UBjC.ttf +0 -0
- ksadk/server/static/assets/KaTeX_Fraktur-Bold-BdnERNNW.ttf +0 -0
- ksadk/server/static/assets/KaTeX_Fraktur-Bold-BsDP51OF.woff +0 -0
- ksadk/server/static/assets/KaTeX_Fraktur-Bold-CL6g_b3V.woff2 +0 -0
- ksadk/server/static/assets/KaTeX_Fraktur-Regular-CB_wures.ttf +0 -0
- ksadk/server/static/assets/KaTeX_Fraktur-Regular-CTYiF6lA.woff2 +0 -0
- ksadk/server/static/assets/KaTeX_Fraktur-Regular-Dxdc4cR9.woff +0 -0
- ksadk/server/static/assets/KaTeX_Main-Bold-Cx986IdX.woff2 +0 -0
- ksadk/server/static/assets/KaTeX_Main-Bold-Jm3AIy58.woff +0 -0
- ksadk/server/static/assets/KaTeX_Main-Bold-waoOVXN0.ttf +0 -0
- ksadk/server/static/assets/KaTeX_Main-BoldItalic-DxDJ3AOS.woff2 +0 -0
- ksadk/server/static/assets/KaTeX_Main-BoldItalic-DzxPMmG6.ttf +0 -0
- ksadk/server/static/assets/KaTeX_Main-BoldItalic-SpSLRI95.woff +0 -0
- ksadk/server/static/assets/KaTeX_Main-Italic-3WenGoN9.ttf +0 -0
- ksadk/server/static/assets/KaTeX_Main-Italic-BMLOBm91.woff +0 -0
- ksadk/server/static/assets/KaTeX_Main-Italic-NWA7e6Wa.woff2 +0 -0
- ksadk/server/static/assets/KaTeX_Main-Regular-B22Nviop.woff2 +0 -0
- ksadk/server/static/assets/KaTeX_Main-Regular-Dr94JaBh.woff +0 -0
- ksadk/server/static/assets/KaTeX_Main-Regular-ypZvNtVU.ttf +0 -0
- ksadk/server/static/assets/KaTeX_Math-BoldItalic-B3XSjfu4.ttf +0 -0
- ksadk/server/static/assets/KaTeX_Math-BoldItalic-CZnvNsCZ.woff2 +0 -0
- ksadk/server/static/assets/KaTeX_Math-BoldItalic-iY-2wyZ7.woff +0 -0
- ksadk/server/static/assets/KaTeX_Math-Italic-DA0__PXp.woff +0 -0
- ksadk/server/static/assets/KaTeX_Math-Italic-flOr_0UB.ttf +0 -0
- ksadk/server/static/assets/KaTeX_Math-Italic-t53AETM-.woff2 +0 -0
- ksadk/server/static/assets/KaTeX_SansSerif-Bold-CFMepnvq.ttf +0 -0
- ksadk/server/static/assets/KaTeX_SansSerif-Bold-D1sUS0GD.woff2 +0 -0
- ksadk/server/static/assets/KaTeX_SansSerif-Bold-DbIhKOiC.woff +0 -0
- ksadk/server/static/assets/KaTeX_SansSerif-Italic-C3H0VqGB.woff2 +0 -0
- ksadk/server/static/assets/KaTeX_SansSerif-Italic-DN2j7dab.woff +0 -0
- ksadk/server/static/assets/KaTeX_SansSerif-Italic-YYjJ1zSn.ttf +0 -0
- ksadk/server/static/assets/KaTeX_SansSerif-Regular-BNo7hRIc.ttf +0 -0
- ksadk/server/static/assets/KaTeX_SansSerif-Regular-CS6fqUqJ.woff +0 -0
- ksadk/server/static/assets/KaTeX_SansSerif-Regular-DDBCnlJ7.woff2 +0 -0
- ksadk/server/static/assets/KaTeX_Script-Regular-C5JkGWo-.ttf +0 -0
- ksadk/server/static/assets/KaTeX_Script-Regular-D3wIWfF6.woff2 +0 -0
- ksadk/server/static/assets/KaTeX_Script-Regular-D5yQViql.woff +0 -0
- ksadk/server/static/assets/KaTeX_Size1-Regular-C195tn64.woff +0 -0
- ksadk/server/static/assets/KaTeX_Size1-Regular-Dbsnue_I.ttf +0 -0
- ksadk/server/static/assets/KaTeX_Size1-Regular-mCD8mA8B.woff2 +0 -0
- ksadk/server/static/assets/KaTeX_Size2-Regular-B7gKUWhC.ttf +0 -0
- ksadk/server/static/assets/KaTeX_Size2-Regular-Dy4dx90m.woff2 +0 -0
- ksadk/server/static/assets/KaTeX_Size2-Regular-oD1tc_U0.woff +0 -0
- ksadk/server/static/assets/KaTeX_Size3-Regular-CTq5MqoE.woff +0 -0
- ksadk/server/static/assets/KaTeX_Size3-Regular-DgpXs0kz.ttf +0 -0
- ksadk/server/static/assets/KaTeX_Size4-Regular-BF-4gkZK.woff +0 -0
- ksadk/server/static/assets/KaTeX_Size4-Regular-DWFBv043.ttf +0 -0
- ksadk/server/static/assets/KaTeX_Size4-Regular-Dl5lxZxV.woff2 +0 -0
- ksadk/server/static/assets/KaTeX_Typewriter-Regular-C0xS9mPB.woff +0 -0
- ksadk/server/static/assets/KaTeX_Typewriter-Regular-CO6r4hn1.woff2 +0 -0
- ksadk/server/static/assets/KaTeX_Typewriter-Regular-D3Ib7_Hf.ttf +0 -0
- ksadk/server/static/assets/MathMessageMarkdown-DMLQYoLp.js +8 -0
- ksadk/server/static/assets/MathMessageMarkdown-DeYh8QPr.css +1 -0
- ksadk/server/static/assets/MermaidBlock-DCR8WZ17.js +303 -0
- ksadk/server/static/assets/NativeTerminalPanel-CHOd7Rch.css +1 -0
- ksadk/server/static/assets/NativeTerminalPanel-CKUvWhUz.js +1 -0
- ksadk/server/static/assets/addon-fit-DthTIhi3.js +1 -0
- ksadk/server/static/assets/apl-CnwPGSsG.js +1 -0
- ksadk/server/static/assets/arc-bj2rZnP5.js +1 -0
- ksadk/server/static/assets/architecture-7EHR7CIX-Cr6Xz1_c.js +1 -0
- ksadk/server/static/assets/architectureDiagram-3BPJPVTR-2u1ltDIj.js +36 -0
- ksadk/server/static/assets/asciiarmor-qTkVPQu6.js +1 -0
- ksadk/server/static/assets/asn1-Dr8qZg38.js +1 -0
- ksadk/server/static/assets/asterisk-Bja0s6e1.js +1 -0
- ksadk/server/static/assets/blockDiagram-GPEHLZMM-D6fvdK20.js +132 -0
- ksadk/server/static/assets/brainfuck-D5EjA2JK.js +1 -0
- ksadk/server/static/assets/c4Diagram-AAUBKEIU-BK82L5n5.js +10 -0
- ksadk/server/static/assets/channel-BSSOwFIb.js +1 -0
- ksadk/server/static/assets/chunk-2J33WTMH-DLVdkeyQ.js +1 -0
- ksadk/server/static/assets/chunk-4BX2VUAB-BbwsYcbW.js +1 -0
- ksadk/server/static/assets/chunk-55IACEB6-DOairxzw.js +1 -0
- ksadk/server/static/assets/chunk-727SXJPM-hCO487gs.js +206 -0
- ksadk/server/static/assets/chunk-AQP2D5EJ-XU8vDOuG.js +231 -0
- ksadk/server/static/assets/chunk-FMBD7UC4-PrapyfMu.js +15 -0
- ksadk/server/static/assets/chunk-ND2GUHAM-CboKhTZ3.js +1 -0
- ksadk/server/static/assets/chunk-QZHKN3VN-XXpdiwUL.js +1 -0
- ksadk/server/static/assets/classDiagram-4FO5ZUOK-C5HvGiyK.js +1 -0
- ksadk/server/static/assets/classDiagram-v2-Q7XG4LA2-C5HvGiyK.js +1 -0
- ksadk/server/static/assets/clike-DHH8Ad3s.js +1 -0
- ksadk/server/static/assets/clojure-BflJGmDX.js +1 -0
- ksadk/server/static/assets/cmake-CyVbuzPu.js +1 -0
- ksadk/server/static/assets/cobol-B_OZ4V-R.js +1 -0
- ksadk/server/static/assets/coffeescript-B2pKbFk8.js +1 -0
- ksadk/server/static/assets/commonlisp-CcllspGY.js +1 -0
- ksadk/server/static/assets/cose-bilkent-S5V4N54A-_N8bJ-EU.js +1 -0
- ksadk/server/static/assets/crystal-M5-qzICs.js +1 -0
- ksadk/server/static/assets/css-CYpP4FRV.js +1 -0
- ksadk/server/static/assets/cypher-p9eYesGn.js +1 -0
- ksadk/server/static/assets/cytoscape.esm-DelgaX4f.js +321 -0
- ksadk/server/static/assets/d-BhMjBjQP.js +1 -0
- ksadk/server/static/assets/dagre-BM42HDAG-FoDlo5J2.js +4 -0
- ksadk/server/static/assets/dagre-Bx709z4p.js +1 -0
- ksadk/server/static/assets/defaultLocale-C8Fc0cco.js +1 -0
- ksadk/server/static/assets/diagram-2AECGRRQ-BBp6ebBw.js +43 -0
- ksadk/server/static/assets/diagram-5GNKFQAL-CqOvG1PR.js +10 -0
- ksadk/server/static/assets/diagram-KO2AKTUF-O9T3t6ba.js +3 -0
- ksadk/server/static/assets/diagram-LMA3HP47-CGG8ekBO.js +24 -0
- ksadk/server/static/assets/diagram-OG6HWLK6-4BmH1EEg.js +24 -0
- ksadk/server/static/assets/diff-ChtP43wD.js +1 -0
- ksadk/server/static/assets/dist-6kSZvCZh.js +1 -0
- ksadk/server/static/assets/dist-B67uF2uK.js +1 -0
- ksadk/server/static/assets/dist-BMKM66B4.js +1 -0
- ksadk/server/static/assets/dist-BVzcWa6D.js +1 -0
- ksadk/server/static/assets/dist-Bk1l05Ni.js +1 -0
- ksadk/server/static/assets/dist-BkJjNih3.js +1 -0
- ksadk/server/static/assets/dist-BmuTWcm7.js +9 -0
- ksadk/server/static/assets/dist-C2DKRFVK.js +1 -0
- ksadk/server/static/assets/dist-CWiTDN_V.js +6 -0
- ksadk/server/static/assets/dist-CZ6C3x8B.js +23 -0
- ksadk/server/static/assets/dist-CiZHB6ZW.js +1 -0
- ksadk/server/static/assets/dist-Cp1_jKwf.js +1 -0
- ksadk/server/static/assets/dist-Cwhk4lwI.js +2 -0
- ksadk/server/static/assets/dist-D5JGcxBx.js +11 -0
- ksadk/server/static/assets/dist-D99wf6_X.js +1 -0
- ksadk/server/static/assets/dist-DCpZrjaK.js +1 -0
- ksadk/server/static/assets/dist-DI-oVAXw.js +1 -0
- ksadk/server/static/assets/dist-DLMjL01k.js +1 -0
- ksadk/server/static/assets/dist-DLeM1OCK.js +1 -0
- ksadk/server/static/assets/dist-DM0rEQPk.js +1 -0
- ksadk/server/static/assets/dist-DbaH3p5h.js +1 -0
- ksadk/server/static/assets/dist-S4klkK5W.js +1 -0
- ksadk/server/static/assets/dockerfile-BLkNEvjs.js +1 -0
- ksadk/server/static/assets/dtd-DTF72YNO.js +1 -0
- ksadk/server/static/assets/dylan-C6jEEEk-.js +1 -0
- ksadk/server/static/assets/ebnf-D4c0_ac3.js +1 -0
- ksadk/server/static/assets/ecl-BSZaIHnp.js +1 -0
- ksadk/server/static/assets/eiffel-BEjRio4Q.js +1 -0
- ksadk/server/static/assets/elm-Cshzl8qu.js +1 -0
- ksadk/server/static/assets/erDiagram-TEJ5UH35-oJhaci7S.js +85 -0
- ksadk/server/static/assets/erlang-DaB2Rkuy.js +1 -0
- ksadk/server/static/assets/eventmodeling-FCH6USID-CIgwHJLL.js +1 -0
- ksadk/server/static/assets/factor-D7LVTn2l.js +1 -0
- ksadk/server/static/assets/fcl-ClOhbFR7.js +1 -0
- ksadk/server/static/assets/flowDiagram-I6XJVG4X-DtTmUan-.js +162 -0
- ksadk/server/static/assets/forth-Cezjo90N.js +1 -0
- ksadk/server/static/assets/fortran-Bt6PBEDR.js +1 -0
- ksadk/server/static/assets/ganttDiagram-6RSMTGT7-BSsb_eij.js +292 -0
- ksadk/server/static/assets/gas-BHEdbvp9.js +1 -0
- ksadk/server/static/assets/gherkin-oBAE_ms0.js +1 -0
- ksadk/server/static/assets/gitGraph-WXDBUCRP-BVAJ7uo0.js +1 -0
- ksadk/server/static/assets/gitGraphDiagram-PVQCEYII-BR5s6Pws.js +106 -0
- ksadk/server/static/assets/graphlib-B8gBHxth.js +1 -0
- ksadk/server/static/assets/groovy-BC3IOsC8.js +1 -0
- ksadk/server/static/assets/haskell-BRsoo5mP.js +1 -0
- ksadk/server/static/assets/haxe-DIz0ZZqd.js +1 -0
- ksadk/server/static/assets/http-CLVgA2GD.js +1 -0
- ksadk/server/static/assets/idl-BUZw3wgd.js +1 -0
- ksadk/server/static/assets/index-BH7-pC0B.js +165 -0
- ksadk/server/static/assets/index-DAURbCsP.css +1 -0
- ksadk/server/static/assets/info-J43DQDTF-MT80V4ge.js +1 -0
- ksadk/server/static/assets/infoDiagram-5YYISTIA-DYPc5cvh.js +2 -0
- ksadk/server/static/assets/init-D6jRqBbL.js +1 -0
- ksadk/server/static/assets/ishikawaDiagram-YF4QCWOH-MoBdALDg.js +70 -0
- ksadk/server/static/assets/javascript-9Tg8ixDm.js +1 -0
- ksadk/server/static/assets/journeyDiagram-JHISSGLW-DgLiQT8l.js +139 -0
- ksadk/server/static/assets/julia-CQfgDRfP.js +1 -0
- ksadk/server/static/assets/kanban-definition-UN3LZRKU-CsFx112F.js +89 -0
- ksadk/server/static/assets/katex-DRsiwpM2.js +265 -0
- ksadk/server/static/assets/linear-TNRQ5Orv.js +1 -0
- ksadk/server/static/assets/livescript-BXxG0Yva.js +1 -0
- ksadk/server/static/assets/lua-CiA1ziua.js +1 -0
- ksadk/server/static/assets/mathematica-u8YMmbU0.js +1 -0
- ksadk/server/static/assets/mbox-BEMVcqjs.js +1 -0
- ksadk/server/static/assets/mermaid-parser.core-D2eMVOgo.js +161 -0
- ksadk/server/static/assets/mindmap-definition-RKZ34NQL-BtByYFhL.js +96 -0
- ksadk/server/static/assets/mirc-C9zpzAZU.js +1 -0
- ksadk/server/static/assets/mllike-B45xgp2S.js +1 -0
- ksadk/server/static/assets/modelica-CqHI_q-D.js +1 -0
- ksadk/server/static/assets/mscgen-qgSLujhx.js +1 -0
- ksadk/server/static/assets/mumps-CW_TBmxz.js +1 -0
- ksadk/server/static/assets/nginx-BMaDbqW3.js +1 -0
- ksadk/server/static/assets/nsis-AQ_alPln.js +1 -0
- ksadk/server/static/assets/ntriples-d28e9m0E.js +1 -0
- ksadk/server/static/assets/octave-D2Q8cUp1.js +1 -0
- ksadk/server/static/assets/ordinal-hYBb2elL.js +1 -0
- ksadk/server/static/assets/oz-BwTct_5T.js +1 -0
- ksadk/server/static/assets/packet-YPE3B663-BLKhbXZB.js +1 -0
- ksadk/server/static/assets/pascal-Dp_KdFgX.js +1 -0
- ksadk/server/static/assets/perl-CdEHsPfU.js +1 -0
- ksadk/server/static/assets/pie-LRSECV5Y-DFOikjSY.js +1 -0
- ksadk/server/static/assets/pieDiagram-4H26LBE5-DPnuCB8c.js +30 -0
- ksadk/server/static/assets/pig-AF4Hwhju.js +1 -0
- ksadk/server/static/assets/powershell-CzG71I4L.js +1 -0
- ksadk/server/static/assets/properties-C357ku5U.js +1 -0
- ksadk/server/static/assets/protobuf-D1ij_kNL.js +1 -0
- ksadk/server/static/assets/pug-Bugr-47h.js +1 -0
- ksadk/server/static/assets/puppet-B4hC2X4m.js +1 -0
- ksadk/server/static/assets/python-BqYw9LYJ.js +1 -0
- ksadk/server/static/assets/q-B9NhS7L_.js +1 -0
- ksadk/server/static/assets/quadrantDiagram-W4KKPZXB-miFpCPv4.js +7 -0
- ksadk/server/static/assets/r-DADKenSm.js +1 -0
- ksadk/server/static/assets/radar-GUYGQ44K-095b1Ikw.js +1 -0
- ksadk/server/static/assets/requirementDiagram-4Y6WPE33-mjB_yYkW.js +84 -0
- ksadk/server/static/assets/rpm-gpDK5sbt.js +1 -0
- ksadk/server/static/assets/ruby-DsYpTuWg.js +1 -0
- ksadk/server/static/assets/sankeyDiagram-5OEKKPKP-D7hSlZZZ.js +40 -0
- ksadk/server/static/assets/sas-C2OyD2Y6.js +1 -0
- ksadk/server/static/assets/scheme-CyDdOh7e.js +1 -0
- ksadk/server/static/assets/sequenceDiagram-3UESZ5HK-D9Cx6hC3.js +162 -0
- ksadk/server/static/assets/shell-Du5Qg9im.js +1 -0
- ksadk/server/static/assets/sieve-BAxa3IjF.js +1 -0
- ksadk/server/static/assets/simple-mode-DRpGK0lJ.js +1 -0
- ksadk/server/static/assets/smalltalk-BLp5-jwC.js +1 -0
- ksadk/server/static/assets/solr-BBopId9w.js +1 -0
- ksadk/server/static/assets/sparql-Dz-mlCAC.js +1 -0
- ksadk/server/static/assets/spreadsheet-CTIncYxj.js +1 -0
- ksadk/server/static/assets/sql-DcCJ9jop.js +1 -0
- ksadk/server/static/assets/stateDiagram-AJRCARHV-D_zrg47o.js +1 -0
- ksadk/server/static/assets/stateDiagram-v2-BHNVJYJU-J9kCb0nC.js +1 -0
- ksadk/server/static/assets/stex-sDrdk2BW.js +1 -0
- ksadk/server/static/assets/stylus-DLLZ8dgm.js +1 -0
- ksadk/server/static/assets/swift-DKB6_1j6.js +1 -0
- ksadk/server/static/assets/tcl-BGfruO1u.js +1 -0
- ksadk/server/static/assets/textile-DWBqthVk.js +1 -0
- ksadk/server/static/assets/tiddlywiki-VlUiK86J.js +1 -0
- ksadk/server/static/assets/tiki-CxVlf5KZ.js +1 -0
- ksadk/server/static/assets/timeline-definition-PNZ67QCA-CwSec0Wa.js +120 -0
- ksadk/server/static/assets/toml-LvoKBwCs.js +1 -0
- ksadk/server/static/assets/treeView-BLDUP644-yinfJEY6.js +1 -0
- ksadk/server/static/assets/treemap-LRROVOQU-DosUqN1Q.js +1 -0
- ksadk/server/static/assets/troff-C2dAgh7P.js +1 -0
- ksadk/server/static/assets/ttcn-BePYh-hG.js +1 -0
- ksadk/server/static/assets/ttcn-cfg-CY0aot7Q.js +1 -0
- ksadk/server/static/assets/turtle-BDLWE2cD.js +1 -0
- ksadk/server/static/assets/vb-BthdM_4N.js +1 -0
- ksadk/server/static/assets/vbscript-D9f6rSsU.js +1 -0
- ksadk/server/static/assets/velocity-CqftRsjg.js +1 -0
- ksadk/server/static/assets/vennDiagram-CIIHVFJN-agCVobiF.js +34 -0
- ksadk/server/static/assets/verilog-D-x6ne0Z.js +1 -0
- ksadk/server/static/assets/vhdl-CMrOq2q1.js +1 -0
- ksadk/server/static/assets/wardley-L42UT6IY-Bvp7-5uH.js +1 -0
- ksadk/server/static/assets/wardleyDiagram-YWT4CUSO-TmrlhWNt.js +78 -0
- ksadk/server/static/assets/webidl-D5jiJvOU.js +1 -0
- ksadk/server/static/assets/xquery-fj_R-kMw.js +1 -0
- ksadk/server/static/assets/xterm-DooSxjI5.js +36 -0
- ksadk/server/static/assets/xychartDiagram-2RQKCTM6-DV71V-ah.js +7 -0
- ksadk/server/static/assets/yacas-CXXgtw0p.js +1 -0
- ksadk/server/static/assets/z80-CL1naaMV.js +1 -0
- ksadk/server/static/favicon.svg +1 -0
- ksadk/server/static/icons.svg +24 -0
- ksadk/server/static/index.html +14 -0
- ksadk/server/terminal_sessions.py +551 -0
- ksadk/sessions/__init__.py +283 -0
- ksadk/sessions/base.py +354 -0
- ksadk/sessions/continuity.py +313 -0
- ksadk/sessions/errors.py +7 -0
- ksadk/sessions/in_memory.py +273 -0
- ksadk/sessions/local_service.py +949 -0
- ksadk/sessions/postgres_service.py +838 -0
- ksadk/sessions/sqlite_service.py +13 -0
- ksadk/skills/__init__.py +9 -0
- ksadk/skills/loader.py +46 -0
- ksadk/skills/models.py +120 -0
- ksadk/skills/package_store.py +104 -0
- ksadk/skills/runtime/__init__.py +17 -0
- ksadk/skills/runtime/agent.py +183 -0
- ksadk/skills/runtime/artifacts.py +39 -0
- ksadk/skills/runtime/backends/__init__.py +1 -0
- ksadk/skills/runtime/backends/disabled.py +8 -0
- ksadk/skills/runtime/backends/e2b.py +168 -0
- ksadk/skills/runtime/backends/local.py +95 -0
- ksadk/skills/runtime/base.py +103 -0
- ksadk/skills/runtime/executor.py +219 -0
- ksadk/skills/runtime/factory.py +37 -0
- ksadk/skills/runtime/loader.py +131 -0
- ksadk/skills/runtime/registry.py +150 -0
- ksadk/skills/runtime/request.py +67 -0
- ksadk/skills/service_client.py +239 -0
- ksadk/skills/service_env.py +58 -0
- ksadk/skills/tool_defs.py +221 -0
- ksadk/terminal_client.py +69 -0
- ksadk/terminal_exec_policy.py +229 -0
- ksadk/tools/__init__.py +17 -0
- ksadk/tools/gateway.py +230 -0
- ksadk/tools/result_budget.py +154 -0
- ksadk/toolsets/__init__.py +852 -0
- ksadk/toolsets/_langchain.py +11 -0
- ksadk/toolsets/platform.py +93 -0
- ksadk/toolsets/sandbox.py +310 -0
- ksadk/toolsets/skills.py +217 -0
- ksadk/toolsets/web.py +266 -0
- ksadk/toolsets/workspace.py +878 -0
- ksadk/toolsets/workspace_state.py +44 -0
- ksadk/tracing/__init__.py +37 -0
- ksadk/tracing/exporters/__init__.py +1 -0
- ksadk/tracing/exporters/inmemory_exporter.py +116 -0
- ksadk/tracing/exporters/langfuse_exporter.py +445 -0
- ksadk/tracing/setup.py +829 -0
- ksadk/tracing/span_utils.py +114 -0
- ksadk/tui/__init__.py +12 -0
- ksadk/tui/app.py +400 -0
- ksadk/tui/clipboard.py +100 -0
- ksadk/tui/widgets/__init__.py +22 -0
- ksadk/tui/widgets/assistant.py +89 -0
- ksadk/tui/widgets/base.py +54 -0
- ksadk/tui/widgets/chat_input.py +246 -0
- ksadk/tui/widgets/history.py +156 -0
- ksadk/tui/widgets/system.py +87 -0
- ksadk/tui/widgets/thinking.py +110 -0
- ksadk/tui/widgets/tool_call.py +161 -0
- ksadk/tui/widgets/user.py +37 -0
- ksadk/ui_config.py +168 -0
- ksadk/version.py +4 -0
- ksadk_runtime_common/__init__.py +20 -0
- ksadk_runtime_common/memory_backend/__init__.py +29 -0
- ksadk_runtime_common/memory_backend/manifest.py +79 -0
- ksadk_runtime_common/memory_backend/providers/__init__.py +6 -0
- ksadk_runtime_common/memory_backend/providers/lancedb.py +151 -0
- ksadk_runtime_common/memory_backend/providers/mem0.py +74 -0
- ksadk_runtime_common/memory_backend/registry.py +56 -0
- ksadk_runtime_common/memory_backend/render.py +71 -0
- ksadk_runtime_common/schemas/memory_backend_manifest.schema.json +148 -0
- ksadk_runtime_common/workspace_files/__init__.py +29 -0
- ksadk_runtime_common/workspace_files/bootstrap.py +56 -0
- ksadk_runtime_common/workspace_files/constants.py +9 -0
- ksadk_runtime_common/workspace_files/path_utils.py +71 -0
- ksadk_runtime_common/workspace_files/preview.py +96 -0
- ksadk_runtime_common/workspace_files/router.py +254 -0
- agentengine_sdk_python-0.6.2.dist-info/METADATA +0 -46
- agentengine_sdk_python-0.6.2.dist-info/RECORD +0 -4
- agentengine_sdk_python-0.6.2.dist-info/top_level.txt +0 -1
|
@@ -0,0 +1,539 @@
|
|
|
1
|
+
"""LangChain runner with session continuity aware input preparation."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import inspect
|
|
6
|
+
import logging
|
|
7
|
+
import os
|
|
8
|
+
import uuid
|
|
9
|
+
from typing import Any, AsyncIterator, Dict, Optional
|
|
10
|
+
|
|
11
|
+
from ksadk.runners.base_runner import BaseRunner
|
|
12
|
+
from ksadk.runners.utils import (
|
|
13
|
+
get_langfuse_callbacks,
|
|
14
|
+
get_langfuse_metadata,
|
|
15
|
+
load_agent_module,
|
|
16
|
+
prepare_trace_metadata,
|
|
17
|
+
)
|
|
18
|
+
from ksadk.sessions.continuity import LangChainSessionAdapter
|
|
19
|
+
|
|
20
|
+
logger = logging.getLogger(__name__)
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
class LangChainRunner(BaseRunner):
|
|
24
|
+
"""LangChain framework runner."""
|
|
25
|
+
|
|
26
|
+
def load_agent(self) -> None:
|
|
27
|
+
self._load_agent(force_reload=False)
|
|
28
|
+
|
|
29
|
+
def _load_agent(self, *, force_reload: bool) -> None:
|
|
30
|
+
self._agent, self._module = load_agent_module(
|
|
31
|
+
self.project_dir,
|
|
32
|
+
self.detection_result.entry_point,
|
|
33
|
+
self.detection_result.agent_variable,
|
|
34
|
+
force_reload=force_reload,
|
|
35
|
+
)
|
|
36
|
+
self._loaded_model_name = self.normalize_requested_model(
|
|
37
|
+
os.getenv("OPENAI_MODEL_NAME") or os.getenv("MODEL_NAME")
|
|
38
|
+
)
|
|
39
|
+
|
|
40
|
+
def prepare_for_request(self, model: Optional[str]) -> None:
|
|
41
|
+
normalized = self.sync_process_model_env(model)
|
|
42
|
+
if normalized is None or self._agent is None:
|
|
43
|
+
return
|
|
44
|
+
if normalized == getattr(self, "_loaded_model_name", None):
|
|
45
|
+
return
|
|
46
|
+
self._load_agent(force_reload=True)
|
|
47
|
+
|
|
48
|
+
def get_session_adapter(self):
|
|
49
|
+
return LangChainSessionAdapter()
|
|
50
|
+
|
|
51
|
+
def _get_config(self, session_id: Optional[str] = None) -> Optional[dict[str, Any]]:
|
|
52
|
+
config: dict[str, Any] = {}
|
|
53
|
+
|
|
54
|
+
langfuse_callbacks = get_langfuse_callbacks()
|
|
55
|
+
if langfuse_callbacks:
|
|
56
|
+
config["callbacks"] = langfuse_callbacks
|
|
57
|
+
|
|
58
|
+
metadata = get_langfuse_metadata(session_id)
|
|
59
|
+
user_id, tags, _, _ = prepare_trace_metadata(session_id)
|
|
60
|
+
if user_id:
|
|
61
|
+
metadata["langfuse_user_id"] = user_id
|
|
62
|
+
if tags:
|
|
63
|
+
metadata["langfuse_tags"] = tags
|
|
64
|
+
config["metadata"] = metadata
|
|
65
|
+
|
|
66
|
+
return config or None
|
|
67
|
+
|
|
68
|
+
async def invoke(self, input_data: Dict[str, Any]) -> Dict[str, Any]:
|
|
69
|
+
session_id = input_data.get("session_id") or str(uuid.uuid4())[:8]
|
|
70
|
+
path = self._resolve_request_path()
|
|
71
|
+
config = self._get_config(session_id)
|
|
72
|
+
native_context = self.build_native_context(input_data.get("platform_context"))
|
|
73
|
+
|
|
74
|
+
if path == "standard_hook":
|
|
75
|
+
payload = self._prepare_with_standard_hook(input_data, session_id)
|
|
76
|
+
result = await self._invoke_agent(payload, config=config, context=native_context)
|
|
77
|
+
elif path == "runnable_with_message_history":
|
|
78
|
+
result = await self._invoke_with_message_history(
|
|
79
|
+
input_data,
|
|
80
|
+
session_id,
|
|
81
|
+
config=config,
|
|
82
|
+
context=native_context,
|
|
83
|
+
)
|
|
84
|
+
else:
|
|
85
|
+
payload = self._prepare_with_replay(input_data)
|
|
86
|
+
result = await self._invoke_agent(payload, config=config, context=native_context)
|
|
87
|
+
|
|
88
|
+
output = {"output": self._extract_output(result)}
|
|
89
|
+
usage = self._extract_usage(result)
|
|
90
|
+
if usage:
|
|
91
|
+
output["usage"] = usage
|
|
92
|
+
last_usage = self._extract_last_usage(result)
|
|
93
|
+
if last_usage:
|
|
94
|
+
output.setdefault("metadata", {})["last_usage"] = last_usage
|
|
95
|
+
return output
|
|
96
|
+
|
|
97
|
+
async def stream(self, input_data: Dict[str, Any]) -> AsyncIterator[Dict[str, Any]]:
|
|
98
|
+
session_id = input_data.get("session_id") or str(uuid.uuid4())[:8]
|
|
99
|
+
path = self._resolve_request_path()
|
|
100
|
+
config = self._get_config(session_id)
|
|
101
|
+
native_context = self.build_native_context(input_data.get("platform_context"))
|
|
102
|
+
|
|
103
|
+
if path == "standard_hook":
|
|
104
|
+
payload = self._prepare_with_standard_hook(input_data, session_id)
|
|
105
|
+
elif path == "runnable_with_message_history":
|
|
106
|
+
payload = {"input": self._prepare_message_history_input(input_data)}
|
|
107
|
+
config = self._with_session_config(config, session_id)
|
|
108
|
+
else:
|
|
109
|
+
payload = self._prepare_with_replay(input_data)
|
|
110
|
+
|
|
111
|
+
accumulated_text = ""
|
|
112
|
+
last_chunk: Any = None
|
|
113
|
+
|
|
114
|
+
try:
|
|
115
|
+
if hasattr(self._agent, "astream"):
|
|
116
|
+
kwargs = self._build_optional_call_kwargs(
|
|
117
|
+
self._agent.astream,
|
|
118
|
+
config=config,
|
|
119
|
+
context=native_context,
|
|
120
|
+
)
|
|
121
|
+
async for chunk in self._agent.astream(payload, **kwargs):
|
|
122
|
+
last_chunk = chunk
|
|
123
|
+
delta, chunk_type = self._extract_chunk(chunk)
|
|
124
|
+
if delta:
|
|
125
|
+
accumulated_text += delta
|
|
126
|
+
yield {"delta": delta, "type": chunk_type}
|
|
127
|
+
elif hasattr(self._agent, "stream"):
|
|
128
|
+
kwargs = self._build_optional_call_kwargs(
|
|
129
|
+
self._agent.stream,
|
|
130
|
+
config=config,
|
|
131
|
+
context=native_context,
|
|
132
|
+
)
|
|
133
|
+
for chunk in self._agent.stream(payload, **kwargs):
|
|
134
|
+
last_chunk = chunk
|
|
135
|
+
delta, chunk_type = self._extract_chunk(chunk)
|
|
136
|
+
if delta:
|
|
137
|
+
accumulated_text += delta
|
|
138
|
+
yield {"delta": delta, "type": chunk_type}
|
|
139
|
+
except Exception as exc:
|
|
140
|
+
print(f"\n⚠️ 流式调用失败: {exc},回退到同步模式")
|
|
141
|
+
|
|
142
|
+
if not accumulated_text:
|
|
143
|
+
result = await self.invoke(input_data)
|
|
144
|
+
final_chunk = {"output": result.get("output", ""), "type": "final"}
|
|
145
|
+
usage = self._extract_usage(result)
|
|
146
|
+
if usage:
|
|
147
|
+
final_chunk["usage"] = usage
|
|
148
|
+
last_usage = self._extract_last_usage(result)
|
|
149
|
+
if last_usage:
|
|
150
|
+
final_chunk.setdefault("metadata", {})["last_usage"] = last_usage
|
|
151
|
+
yield final_chunk
|
|
152
|
+
return
|
|
153
|
+
|
|
154
|
+
final_chunk = {"output": accumulated_text, "type": "final"}
|
|
155
|
+
usage = self._extract_usage(last_chunk)
|
|
156
|
+
if usage:
|
|
157
|
+
final_chunk["usage"] = usage
|
|
158
|
+
last_usage = self._extract_last_usage(last_chunk)
|
|
159
|
+
if last_usage:
|
|
160
|
+
final_chunk.setdefault("metadata", {})["last_usage"] = last_usage
|
|
161
|
+
yield final_chunk
|
|
162
|
+
|
|
163
|
+
def _resolve_request_path(self) -> str:
|
|
164
|
+
module = getattr(self, "_module", None)
|
|
165
|
+
if callable(getattr(module, "ksadk_prepare_input", None)):
|
|
166
|
+
return "standard_hook"
|
|
167
|
+
if self._is_runnable_with_message_history():
|
|
168
|
+
return "runnable_with_message_history"
|
|
169
|
+
return "replay"
|
|
170
|
+
|
|
171
|
+
def _prepare_with_standard_hook(self, input_data: Dict[str, Any], session_id: str) -> dict[str, Any]:
|
|
172
|
+
module = getattr(self, "_module", None)
|
|
173
|
+
prepare_input = getattr(module, "ksadk_prepare_input", None)
|
|
174
|
+
if not callable(prepare_input):
|
|
175
|
+
return {"input": input_data.get("input", "")}
|
|
176
|
+
|
|
177
|
+
payload = {"input": input_data.get("input", "")}
|
|
178
|
+
session_context = {
|
|
179
|
+
"session_id": session_id,
|
|
180
|
+
"history": list(input_data.get("history") or []),
|
|
181
|
+
"input_parts": list(input_data.get("input_parts") or []),
|
|
182
|
+
"attachments": list(input_data.get("attachments") or []),
|
|
183
|
+
"attachment_results": list(input_data.get("attachment_results") or []),
|
|
184
|
+
"instructions": input_data.get("instructions"),
|
|
185
|
+
"platform_context": input_data.get("platform_context"),
|
|
186
|
+
"kb_context": input_data.get("kb_context"),
|
|
187
|
+
"memory_context": input_data.get("memory_context"),
|
|
188
|
+
}
|
|
189
|
+
builtin_context = self._ksadk_builtin_tool_context()
|
|
190
|
+
if builtin_context:
|
|
191
|
+
session_context.update(builtin_context)
|
|
192
|
+
prepared = prepare_input(payload, session_context)
|
|
193
|
+
return prepared if isinstance(prepared, dict) else payload
|
|
194
|
+
|
|
195
|
+
@staticmethod
|
|
196
|
+
def _ksadk_builtin_tool_context() -> dict[str, Any]:
|
|
197
|
+
try:
|
|
198
|
+
from ksadk.toolsets import builtin_tool_descriptors_for_runtime, builtin_tools_mode, builtin_tools_profile
|
|
199
|
+
|
|
200
|
+
mode = builtin_tools_mode(default="off")
|
|
201
|
+
descriptors = builtin_tool_descriptors_for_runtime(mode=mode)
|
|
202
|
+
if not descriptors:
|
|
203
|
+
return {}
|
|
204
|
+
return {
|
|
205
|
+
"ksadk_tools": descriptors,
|
|
206
|
+
"ksadk_builtin_tools_mode": mode,
|
|
207
|
+
"ksadk_builtin_tools_profile": builtin_tools_profile("default"),
|
|
208
|
+
"deferred_direct_injection_supported": False,
|
|
209
|
+
}
|
|
210
|
+
except Exception as exc:
|
|
211
|
+
logger.warning("Failed to prepare ksadk built-in tool descriptors: %s", exc)
|
|
212
|
+
return {}
|
|
213
|
+
|
|
214
|
+
def _prepare_with_replay(self, input_data: Dict[str, Any]) -> dict[str, Any]:
|
|
215
|
+
user_input = str(input_data.get("input", "") or "")
|
|
216
|
+
history = list(input_data.get("history") or [])
|
|
217
|
+
ambient_text = self._ambient_context_text(input_data)
|
|
218
|
+
instructions = str(input_data.get("instructions") or "").strip()
|
|
219
|
+
if not history and not ambient_text and not instructions:
|
|
220
|
+
return {"input": user_input}
|
|
221
|
+
return {
|
|
222
|
+
"input": self._format_replay_prompt(
|
|
223
|
+
user_input,
|
|
224
|
+
history,
|
|
225
|
+
ambient_text=ambient_text,
|
|
226
|
+
instructions=instructions,
|
|
227
|
+
)
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
@staticmethod
|
|
231
|
+
def _ambient_context_text(input_data: Dict[str, Any]) -> str:
|
|
232
|
+
sections: list[str] = []
|
|
233
|
+
kb_context = input_data.get("kb_context") or {}
|
|
234
|
+
kb_text = str(kb_context.get("formatted_text") or "").strip() if isinstance(kb_context, dict) else ""
|
|
235
|
+
if kb_text:
|
|
236
|
+
sections.append(f"Knowledge base context:\n{kb_text}")
|
|
237
|
+
|
|
238
|
+
memory_context = input_data.get("memory_context") or {}
|
|
239
|
+
memory_text = (
|
|
240
|
+
str(memory_context.get("formatted_text") or "").strip()
|
|
241
|
+
if isinstance(memory_context, dict)
|
|
242
|
+
else ""
|
|
243
|
+
)
|
|
244
|
+
if memory_text:
|
|
245
|
+
sections.append(f"Long-term memory context:\n{memory_text}")
|
|
246
|
+
|
|
247
|
+
return "\n\n".join(section for section in sections if section)
|
|
248
|
+
|
|
249
|
+
def _prepare_message_history_input(self, input_data: Dict[str, Any]) -> str:
|
|
250
|
+
user_input = str(input_data.get("input", "") or "")
|
|
251
|
+
context_text = self._request_context_text(input_data)
|
|
252
|
+
if not context_text:
|
|
253
|
+
return user_input
|
|
254
|
+
current_input = user_input.strip() or "[empty message]"
|
|
255
|
+
return f"{context_text}\n\nCurrent user input:\n{current_input}"
|
|
256
|
+
|
|
257
|
+
def _request_context_text(self, input_data: Dict[str, Any]) -> str:
|
|
258
|
+
ambient_text = self._ambient_context_text(input_data)
|
|
259
|
+
instructions = str(input_data.get("instructions") or "").strip()
|
|
260
|
+
return "\n\n".join(section for section in (instructions, ambient_text) if section)
|
|
261
|
+
|
|
262
|
+
def _format_replay_prompt(
|
|
263
|
+
self,
|
|
264
|
+
user_input: str,
|
|
265
|
+
history: list[dict[str, Any]],
|
|
266
|
+
*,
|
|
267
|
+
ambient_text: str = "",
|
|
268
|
+
instructions: str = "",
|
|
269
|
+
) -> str:
|
|
270
|
+
lines: list[str] = []
|
|
271
|
+
if instructions:
|
|
272
|
+
lines.append(instructions)
|
|
273
|
+
if ambient_text:
|
|
274
|
+
lines.append(ambient_text)
|
|
275
|
+
if history:
|
|
276
|
+
lines.append("Conversation history:")
|
|
277
|
+
normalized_history: list[tuple[str, str]] = []
|
|
278
|
+
for item in history:
|
|
279
|
+
role = self._normalize_history_role(item.get("role"))
|
|
280
|
+
content = str(item.get("content", "") or "").strip()
|
|
281
|
+
if not role or not content:
|
|
282
|
+
continue
|
|
283
|
+
normalized_history.append((role, content))
|
|
284
|
+
lines.append(f"{role}: {content}")
|
|
285
|
+
|
|
286
|
+
if user_input.strip():
|
|
287
|
+
if not normalized_history or normalized_history[-1] != ("user", user_input.strip()):
|
|
288
|
+
lines.append(f"user: {user_input.strip()}")
|
|
289
|
+
elif ambient_text and not history:
|
|
290
|
+
lines.append("Current user input:\n[empty message]")
|
|
291
|
+
|
|
292
|
+
return "\n".join(lines)
|
|
293
|
+
|
|
294
|
+
@staticmethod
|
|
295
|
+
def _normalize_history_role(role: Any) -> str:
|
|
296
|
+
normalized = str(role or "").strip().lower()
|
|
297
|
+
if normalized in {"assistant", "model"}:
|
|
298
|
+
return "assistant"
|
|
299
|
+
if normalized == "user":
|
|
300
|
+
return "user"
|
|
301
|
+
return normalized
|
|
302
|
+
|
|
303
|
+
@staticmethod
|
|
304
|
+
def _with_session_config(
|
|
305
|
+
config: Optional[dict[str, Any]],
|
|
306
|
+
session_id: str,
|
|
307
|
+
) -> dict[str, Any]:
|
|
308
|
+
merged = dict(config or {})
|
|
309
|
+
configurable = dict(merged.get("configurable") or {})
|
|
310
|
+
configurable["session_id"] = session_id
|
|
311
|
+
merged["configurable"] = configurable
|
|
312
|
+
return merged
|
|
313
|
+
|
|
314
|
+
async def _invoke_agent(
|
|
315
|
+
self,
|
|
316
|
+
payload: Any,
|
|
317
|
+
*,
|
|
318
|
+
config: Optional[dict[str, Any]],
|
|
319
|
+
context: Optional[dict[str, Any]],
|
|
320
|
+
) -> Any:
|
|
321
|
+
if hasattr(self._agent, "ainvoke"):
|
|
322
|
+
kwargs = self._build_optional_call_kwargs(
|
|
323
|
+
self._agent.ainvoke,
|
|
324
|
+
config=config,
|
|
325
|
+
context=context,
|
|
326
|
+
)
|
|
327
|
+
return await self._agent.ainvoke(payload, **kwargs)
|
|
328
|
+
if hasattr(self._agent, "invoke"):
|
|
329
|
+
kwargs = self._build_optional_call_kwargs(
|
|
330
|
+
self._agent.invoke,
|
|
331
|
+
config=config,
|
|
332
|
+
context=context,
|
|
333
|
+
)
|
|
334
|
+
return self._agent.invoke(payload, **kwargs)
|
|
335
|
+
if callable(self._agent):
|
|
336
|
+
return self._agent(payload)
|
|
337
|
+
raise TypeError("Agent 不支持 invoke 调用")
|
|
338
|
+
|
|
339
|
+
def _is_runnable_with_message_history(self) -> bool:
|
|
340
|
+
try:
|
|
341
|
+
from langchain_core.runnables.history import RunnableWithMessageHistory
|
|
342
|
+
|
|
343
|
+
return isinstance(self._agent, RunnableWithMessageHistory)
|
|
344
|
+
except Exception:
|
|
345
|
+
return False
|
|
346
|
+
|
|
347
|
+
async def _invoke_with_message_history(
|
|
348
|
+
self,
|
|
349
|
+
input_data: Dict[str, Any],
|
|
350
|
+
session_id: str,
|
|
351
|
+
*,
|
|
352
|
+
config: Optional[dict[str, Any]],
|
|
353
|
+
context: Optional[dict[str, Any]],
|
|
354
|
+
) -> Any:
|
|
355
|
+
context_text = self._request_context_text(input_data)
|
|
356
|
+
payload = {"input": self._prepare_message_history_input(input_data)}
|
|
357
|
+
session_config = self._with_session_config(config, session_id)
|
|
358
|
+
wrapped_runnable = self._extract_wrapped_history_runnable()
|
|
359
|
+
message_history = self._get_message_history_store(session_id)
|
|
360
|
+
|
|
361
|
+
if context_text and wrapped_runnable is not None and message_history is not None:
|
|
362
|
+
return await self._invoke_wrapped_history_with_ambient_context(
|
|
363
|
+
input_data=input_data,
|
|
364
|
+
wrapped_runnable=wrapped_runnable,
|
|
365
|
+
message_history=message_history,
|
|
366
|
+
session_config=session_config,
|
|
367
|
+
context=context,
|
|
368
|
+
ambient_text=context_text,
|
|
369
|
+
)
|
|
370
|
+
|
|
371
|
+
try:
|
|
372
|
+
return await self._invoke_agent(payload, config=session_config, context=context)
|
|
373
|
+
except Exception:
|
|
374
|
+
if wrapped_runnable is None or message_history is None:
|
|
375
|
+
raise
|
|
376
|
+
return await self._invoke_wrapped_history_with_ambient_context(
|
|
377
|
+
input_data=input_data,
|
|
378
|
+
wrapped_runnable=wrapped_runnable,
|
|
379
|
+
message_history=message_history,
|
|
380
|
+
session_config=session_config,
|
|
381
|
+
context=context,
|
|
382
|
+
ambient_text=context_text,
|
|
383
|
+
)
|
|
384
|
+
|
|
385
|
+
async def _invoke_wrapped_runnable(
|
|
386
|
+
self,
|
|
387
|
+
runnable: Any,
|
|
388
|
+
payload: Any,
|
|
389
|
+
config: Optional[dict[str, Any]],
|
|
390
|
+
context: Optional[dict[str, Any]],
|
|
391
|
+
) -> Any:
|
|
392
|
+
if hasattr(runnable, "ainvoke"):
|
|
393
|
+
kwargs = self._build_optional_call_kwargs(
|
|
394
|
+
runnable.ainvoke,
|
|
395
|
+
config=config,
|
|
396
|
+
context=context,
|
|
397
|
+
)
|
|
398
|
+
return await runnable.ainvoke(payload, **kwargs)
|
|
399
|
+
if hasattr(runnable, "invoke"):
|
|
400
|
+
kwargs = self._build_optional_call_kwargs(
|
|
401
|
+
runnable.invoke,
|
|
402
|
+
config=config,
|
|
403
|
+
context=context,
|
|
404
|
+
)
|
|
405
|
+
return runnable.invoke(payload, **kwargs)
|
|
406
|
+
raise TypeError("Wrapped runnable does not support invoke")
|
|
407
|
+
|
|
408
|
+
async def _invoke_wrapped_history_with_ambient_context(
|
|
409
|
+
self,
|
|
410
|
+
*,
|
|
411
|
+
input_data: Dict[str, Any],
|
|
412
|
+
wrapped_runnable: Any,
|
|
413
|
+
message_history: Any,
|
|
414
|
+
session_config: Optional[dict[str, Any]],
|
|
415
|
+
context: Optional[dict[str, Any]],
|
|
416
|
+
ambient_text: str,
|
|
417
|
+
) -> Any:
|
|
418
|
+
from langchain_core.messages import AIMessage, HumanMessage, SystemMessage
|
|
419
|
+
|
|
420
|
+
user_input = str(input_data.get("input", "") or "")
|
|
421
|
+
prompt_messages = list(getattr(message_history, "messages", []))
|
|
422
|
+
if ambient_text:
|
|
423
|
+
prompt_messages = [SystemMessage(content=ambient_text), *prompt_messages]
|
|
424
|
+
prompt_messages.append(HumanMessage(content=user_input or "[empty message]"))
|
|
425
|
+
result = await self._invoke_wrapped_runnable(
|
|
426
|
+
wrapped_runnable,
|
|
427
|
+
{"input": prompt_messages},
|
|
428
|
+
session_config,
|
|
429
|
+
context,
|
|
430
|
+
)
|
|
431
|
+
output_text = self._extract_output(result)
|
|
432
|
+
await self._append_message_history(
|
|
433
|
+
message_history,
|
|
434
|
+
[
|
|
435
|
+
HumanMessage(content=user_input or "[empty message]"),
|
|
436
|
+
AIMessage(content=output_text),
|
|
437
|
+
],
|
|
438
|
+
)
|
|
439
|
+
return result
|
|
440
|
+
|
|
441
|
+
def _extract_wrapped_history_runnable(self) -> Any | None:
|
|
442
|
+
runnable_lambda = self._get_nested_attr(
|
|
443
|
+
self._agent,
|
|
444
|
+
("bound", "bound", "last", "bound"),
|
|
445
|
+
)
|
|
446
|
+
if runnable_lambda is None:
|
|
447
|
+
logger.debug(
|
|
448
|
+
"Unable to inspect RunnableWithMessageHistory wrapper: "
|
|
449
|
+
"missing bound.bound.last.bound"
|
|
450
|
+
)
|
|
451
|
+
return None
|
|
452
|
+
|
|
453
|
+
func = getattr(runnable_lambda, "func", None)
|
|
454
|
+
if func is None:
|
|
455
|
+
logger.debug(
|
|
456
|
+
"Unable to inspect RunnableWithMessageHistory wrapper: missing lambda func"
|
|
457
|
+
)
|
|
458
|
+
return None
|
|
459
|
+
|
|
460
|
+
try:
|
|
461
|
+
closure = inspect.getclosurevars(func).nonlocals
|
|
462
|
+
except Exception as exc:
|
|
463
|
+
logger.debug(
|
|
464
|
+
"Unable to inspect RunnableWithMessageHistory wrapper: %s",
|
|
465
|
+
exc,
|
|
466
|
+
)
|
|
467
|
+
return None
|
|
468
|
+
return closure.get("runnable_async") or closure.get("runnable_sync")
|
|
469
|
+
|
|
470
|
+
@staticmethod
|
|
471
|
+
def _get_nested_attr(obj: Any, path: tuple[str, ...]) -> Any | None:
|
|
472
|
+
current = obj
|
|
473
|
+
for name in path:
|
|
474
|
+
current = getattr(current, name, None)
|
|
475
|
+
if current is None:
|
|
476
|
+
return None
|
|
477
|
+
return current
|
|
478
|
+
|
|
479
|
+
def _get_message_history_store(self, session_id: str) -> Any | None:
|
|
480
|
+
get_session_history = getattr(self._agent, "get_session_history", None)
|
|
481
|
+
if not callable(get_session_history):
|
|
482
|
+
return None
|
|
483
|
+
return get_session_history(session_id)
|
|
484
|
+
|
|
485
|
+
async def _append_message_history(self, history_store: Any, messages: list[Any]) -> None:
|
|
486
|
+
if hasattr(history_store, "aadd_messages"):
|
|
487
|
+
await history_store.aadd_messages(messages)
|
|
488
|
+
return
|
|
489
|
+
if hasattr(history_store, "add_messages"):
|
|
490
|
+
history_store.add_messages(messages)
|
|
491
|
+
return
|
|
492
|
+
for message in messages:
|
|
493
|
+
role = getattr(message, "type", "")
|
|
494
|
+
content = getattr(message, "content", "")
|
|
495
|
+
if role == "human" and hasattr(history_store, "add_user_message"):
|
|
496
|
+
history_store.add_user_message(content)
|
|
497
|
+
elif role == "ai" and hasattr(history_store, "add_ai_message"):
|
|
498
|
+
history_store.add_ai_message(content)
|
|
499
|
+
|
|
500
|
+
@staticmethod
|
|
501
|
+
def _extract_output(result: Any) -> str:
|
|
502
|
+
if isinstance(result, dict):
|
|
503
|
+
if "output" in result:
|
|
504
|
+
return result["output"]
|
|
505
|
+
if "text" in result:
|
|
506
|
+
return result["text"]
|
|
507
|
+
messages = result.get("messages")
|
|
508
|
+
if isinstance(messages, list) and messages:
|
|
509
|
+
last = messages[-1]
|
|
510
|
+
if isinstance(last, dict):
|
|
511
|
+
return str(last.get("content", str(last)))
|
|
512
|
+
content = getattr(last, "content", None)
|
|
513
|
+
if content is not None:
|
|
514
|
+
return str(content)
|
|
515
|
+
return str(result)
|
|
516
|
+
content = getattr(result, "content", None)
|
|
517
|
+
if content is not None:
|
|
518
|
+
return str(content)
|
|
519
|
+
return str(result)
|
|
520
|
+
|
|
521
|
+
def _extract_chunk(self, chunk: Any) -> tuple[Optional[str], Optional[str]]:
|
|
522
|
+
if isinstance(chunk, dict):
|
|
523
|
+
if "output" in chunk:
|
|
524
|
+
return chunk["output"], "text"
|
|
525
|
+
if "text" in chunk:
|
|
526
|
+
return chunk["text"], "text"
|
|
527
|
+
return None, None
|
|
528
|
+
|
|
529
|
+
reasoning = None
|
|
530
|
+
if hasattr(chunk, "reasoning_content") and chunk.reasoning_content:
|
|
531
|
+
reasoning = chunk.reasoning_content
|
|
532
|
+
elif hasattr(chunk, "additional_kwargs"):
|
|
533
|
+
reasoning = chunk.additional_kwargs.get("reasoning_content")
|
|
534
|
+
|
|
535
|
+
if reasoning:
|
|
536
|
+
return reasoning, "thinking"
|
|
537
|
+
|
|
538
|
+
content = chunk.content if hasattr(chunk, "content") else str(chunk)
|
|
539
|
+
return content if content else None, "text"
|