agentengine-sdk-python 0.7.0__py3-none-any.whl → 0.8.1__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.1.dist-info}/METADATA +52 -20
- agentengine_sdk_python-0.8.1.dist-info/RECORD +644 -0
- {agentengine_sdk_python-0.7.0.dist-info → agentengine_sdk_python-0.8.1.dist-info}/WHEEL +1 -1
- ksadk/a2a/__init__.py +180 -11
- ksadk/a2a/bootstrap.py +332 -0
- ksadk/a2a/card.py +15 -0
- ksadk/a2a/context_store.py +203 -0
- ksadk/a2a/control_plane.py +1056 -0
- ksadk/a2a/credential.py +99 -0
- ksadk/a2a/event_adapter.py +149 -0
- ksadk/a2a/executor.py +361 -137
- 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 +112 -0
- ksadk/a2a/server.py +102 -62
- ksadk/a2a/service_env.py +33 -0
- ksadk/a2a/space_client.py +1122 -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/a2a_card.py +101 -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 +872 -0
- ksadk/agui/config.py +92 -0
- ksadk/agui/routes.py +47 -0
- ksadk/api/client.py +238 -204
- ksadk/api/environment.py +27 -0
- ksadk/builders/__init__.py +2 -0
- ksadk/builders/base.py +16 -14
- ksadk/builders/code_builder.py +375 -270
- ksadk/builders/container_builder.py +240 -200
- ksadk/builders/framework_requirements.py +31 -12
- ksadk/builders/ks3_uploader.py +60 -29
- ksadk/builders/managed_runtime_builder.py +173 -0
- ksadk/builders/mcp_builder.py +91 -92
- ksadk/builders/requirements_utils.py +1 -5
- ksadk/cli/__init__.py +97 -171
- ksadk/cli/cmd_a2a.py +255 -84
- 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 +507 -740
- ksadk/cli/cmd_dashboard.py +120 -45
- ksadk/cli/cmd_deploy.py +135 -59
- ksadk/cli/cmd_destroy.py +44 -14
- ksadk/cli/cmd_eval.py +386 -0
- ksadk/cli/cmd_files.py +63 -24
- ksadk/cli/cmd_hermes.py +313 -135
- ksadk/cli/cmd_invoke.py +184 -122
- ksadk/cli/cmd_launch.py +76 -28
- ksadk/cli/cmd_mcp.py +98 -64
- ksadk/cli/cmd_model.py +14 -5
- ksadk/cli/cmd_openclaw.py +564 -268
- ksadk/cli/cmd_replay.py +71 -0
- ksadk/cli/cmd_run.py +58 -73
- ksadk/cli/cmd_status.py +80 -31
- ksadk/cli/cmd_studio.py +110 -0
- ksadk/cli/cmd_version.py +20 -13
- ksadk/cli/cmd_web.py +95 -18
- ksadk/cli/deploy_utils.py +20 -20
- ksadk/cli/dry_run.py +7 -4
- ksadk/cli/env_options.py +83 -0
- ksadk/cli/error_utils.py +37 -12
- ksadk/cli/global_options.py +4 -3
- ksadk/cli/local_runtime.py +1 -2
- ksadk/cli/model_catalog.py +6 -2
- ksadk/cli/network_options.py +41 -19
- ksadk/cli/resource_common.py +6 -2
- ksadk/cli/runtime_bootstrap.py +51 -0
- ksadk/cli/storage.py +0 -1
- ksadk/cli/ui.py +11 -3
- ksadk/cli/workflow_common.py +52 -18
- ksadk/codex/__init__.py +12 -0
- ksadk/codex/client.py +1042 -0
- ksadk/codex/phase.py +143 -0
- ksadk/codex/runtime.py +940 -0
- ksadk/common/aicp_env.py +0 -1
- ksadk/common/auth.py +2 -2
- ksadk/common/constants.py +1 -3
- ksadk/common/kop_client.py +232 -0
- 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 -14
- ksadk/configs/env_registry.py +661 -116
- ksadk/configs/global_config.py +3 -2
- ksadk/configs/settings.py +133 -209
- ksadk/conversations/__init__.py +85 -92
- 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 +660 -0
- ksadk/conversations/runtime_invocation.py +395 -0
- ksadk/conversations/runtime_metadata.py +475 -0
- ksadk/conversations/runtime_observability.py +367 -0
- ksadk/conversations/runtime_payloads.py +272 -0
- ksadk/conversations/runtime_persistence.py +440 -0
- ksadk/conversations/runtime_preparation.py +426 -0
- ksadk/conversations/runtime_resume.py +836 -0
- ksadk/conversations/runtime_stream_events.py +902 -0
- ksadk/conversations/runtime_streaming.py +700 -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/managed_runtime.py +33 -0
- ksadk/deployment/manager.py +85 -71
- ksadk/deployment/providers/serverless.py +379 -210
- 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/evaluation/__init__.py +84 -0
- ksadk/evaluation/a2a_adapter.py +444 -0
- ksadk/evaluation/adapters.py +54 -0
- ksadk/evaluation/contracts.py +409 -0
- ksadk/evaluation/evalset.py +351 -0
- ksadk/evaluation/evaluators.py +461 -0
- ksadk/evaluation/executor.py +118 -0
- ksadk/evaluation/storage.py +68 -0
- ksadk/evaluation/target.py +73 -0
- ksadk/events/__init__.py +25 -0
- ksadk/events/parser.py +191 -0
- ksadk/events/replay.py +37 -0
- ksadk/events/runtime_event.py +273 -0
- ksadk/events/store.py +317 -0
- ksadk/harness/__init__.py +35 -0
- ksadk/harness/app.py +269 -0
- ksadk/harness/config.py +181 -0
- ksadk/harness/reasoner.py +105 -0
- ksadk/harness/runtime.py +364 -0
- ksadk/harness/sandbox.py +141 -0
- ksadk/harness/tools.py +222 -0
- ksadk/hermes_terminal.py +28 -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 +38 -33
- ksadk/managed_a2a_card.py +160 -0
- ksadk/managed_runtime.py +195 -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 +36 -36
- ksadk/memory/adk/long_term_memory.py +34 -37
- 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 +16 -6
- ksadk/memory/tool.py +4 -0
- 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 +66 -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 +201 -0
- ksadk/model_proxy/protocol_proxy.py +22 -0
- ksadk/model_proxy/server.py +443 -0
- ksadk/model_proxy/transform.py +735 -0
- ksadk/openclaw_gateway.py +29 -14
- ksadk/runners/adk_runner.py +354 -146
- ksadk/runners/base_runner.py +71 -29
- ksadk/runners/deepagents_runner.py +0 -1
- ksadk/runners/factory.py +18 -5
- ksadk/runners/langchain_runner.py +29 -742
- ksadk/runners/langgraph_runner.py +417 -97
- ksadk/runners/patch_langchain.py +16 -16
- ksadk/runners/remote_runner.py +134 -33
- ksadk/runners/usage_accumulator.py +1 -0
- ksadk/runners/utils/__init__.py +0 -10
- ksadk/runners/utils/loader.py +23 -7
- ksadk/runtime/__init__.py +67 -0
- ksadk/runtime/adapter.py +412 -0
- ksadk/runtime/conversation_execution.py +553 -0
- ksadk/runtime/executor.py +251 -0
- ksadk/runtime/factory.py +156 -0
- ksadk/runtime/framework_adapters.py +118 -0
- ksadk/runtime/launch.py +48 -0
- ksadk/runtime/preprocessing.py +131 -0
- ksadk/runtime/runner_adapter.py +1032 -0
- ksadk/runtime/runner_loading.py +36 -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/__init__.py +39 -4
- ksadk/server/api_models.py +15 -5
- ksadk/server/app.py +24 -3928
- ksadk/server/composition.py +47 -0
- ksadk/server/factory.py +622 -0
- ksadk/server/routes/__init__.py +1 -0
- ksadk/server/routes/checkpoint_resolution.py +116 -0
- ksadk/server/routes/common.py +682 -0
- ksadk/server/routes/control.py +331 -0
- ksadk/server/routes/dependencies.py +98 -0
- ksadk/server/routes/misc.py +425 -0
- ksadk/server/routes/models.py +451 -0
- ksadk/server/routes/openai_compat.py +229 -0
- ksadk/server/routes/projection.py +848 -0
- ksadk/server/routes/routers.py +52 -0
- ksadk/server/routes/run.py +519 -0
- ksadk/server/routes/sessions.py +644 -0
- ksadk/server/routes/streaming.py +265 -0
- ksadk/server/routes/workspace.py +414 -0
- ksadk/server/static/assets/{ArtifactsPanel-D-SSn2ee.js → ArtifactsPanel-CakCqxEN.js} +1 -1
- ksadk/server/static/assets/CodeBlock-CynLknyO.js +9 -0
- ksadk/server/static/assets/MathMessageMarkdown-3sQdOysS.js +8 -0
- ksadk/server/static/assets/MermaidBlock-NERD_ef7.js +303 -0
- ksadk/server/static/assets/NativeTerminalPanel-CiHWf82q.js +1 -0
- ksadk/server/static/assets/{arc-BA13sHc9.js → arc-DrgjcKhl.js} +1 -1
- ksadk/server/static/assets/architecture-7EHR7CIX-CpZLRCcY.js +1 -0
- ksadk/server/static/assets/{architectureDiagram-3BPJPVTR-DzJzgVoL.js → architectureDiagram-3BPJPVTR-BXoVRbQ6.js} +1 -1
- ksadk/server/static/assets/{blockDiagram-GPEHLZMM-UTdVcZhn.js → blockDiagram-GPEHLZMM-BnaB3Ywv.js} +1 -1
- ksadk/server/static/assets/{c4Diagram-AAUBKEIU-Dix0GD4m.js → c4Diagram-AAUBKEIU-Dw4weZcp.js} +1 -1
- ksadk/server/static/assets/channel-Dt3rQTFI.js +1 -0
- ksadk/server/static/assets/{chunk-2J33WTMH-C2JxuZ42.js → chunk-2J33WTMH-ChjpLK7j.js} +1 -1
- ksadk/server/static/assets/{chunk-4BX2VUAB-Be57QPgD.js → chunk-4BX2VUAB-B9drTgOW.js} +1 -1
- ksadk/server/static/assets/{chunk-55IACEB6-WjSuy4nv.js → chunk-55IACEB6-CK4ROATy.js} +1 -1
- ksadk/server/static/assets/{chunk-727SXJPM-BOovP-b5.js → chunk-727SXJPM-B9KtTTgw.js} +1 -1
- ksadk/server/static/assets/{chunk-AQP2D5EJ-DOmZNmWj.js → chunk-AQP2D5EJ-1O1mki3m.js} +1 -1
- ksadk/server/static/assets/{chunk-FMBD7UC4-DzwlodkU.js → chunk-FMBD7UC4-B_fH2YuH.js} +1 -1
- ksadk/server/static/assets/{chunk-ND2GUHAM-DMqAikEU.js → chunk-ND2GUHAM-D6rFLaVV.js} +1 -1
- ksadk/server/static/assets/chunk-QZHKN3VN-iXEZtKQc.js +1 -0
- ksadk/server/static/assets/classDiagram-4FO5ZUOK-DIveV17Q.js +1 -0
- ksadk/server/static/assets/classDiagram-v2-Q7XG4LA2-DIveV17Q.js +1 -0
- ksadk/server/static/assets/{cose-bilkent-S5V4N54A-Zhy2GBnP.js → cose-bilkent-S5V4N54A-ChNs_Mdk.js} +1 -1
- ksadk/server/static/assets/{dagre-BM42HDAG-CbKrtIUz.js → dagre-BM42HDAG-D0QXg_MQ.js} +1 -1
- ksadk/server/static/assets/{diagram-2AECGRRQ-BRApgQRK.js → diagram-2AECGRRQ-DBDDKwBQ.js} +1 -1
- ksadk/server/static/assets/{diagram-5GNKFQAL-D0xbnDiK.js → diagram-5GNKFQAL-BkwDOxmO.js} +1 -1
- ksadk/server/static/assets/{diagram-KO2AKTUF-CVugVI9L.js → diagram-KO2AKTUF-Bv8waYvY.js} +1 -1
- ksadk/server/static/assets/{diagram-LMA3HP47-DozUGgee.js → diagram-LMA3HP47-e1VECDdu.js} +1 -1
- ksadk/server/static/assets/{diagram-OG6HWLK6-ZOYsKlru.js → diagram-OG6HWLK6-Ds9adfRl.js} +1 -1
- ksadk/server/static/assets/{dist-DpKtt4Bo.js → dist-4N2NMVYg.js} +1 -1
- ksadk/server/static/assets/{dist-CkEKJFtk.js → dist-B-jNR6Vn.js} +1 -1
- ksadk/server/static/assets/{dist-D57wnGWd.js → dist-B5J2uhNk.js} +1 -1
- ksadk/server/static/assets/{dist-8_SfK1IP.js → dist-B5oS1zcj.js} +1 -1
- ksadk/server/static/assets/{dist-DMezvBGJ.js → dist-BB3-OwTQ.js} +1 -1
- ksadk/server/static/assets/{dist-2hInLS_J.js → dist-BIlKoW0k.js} +1 -1
- ksadk/server/static/assets/{dist-BrCcQ47T.js → dist-BjOdlDjj.js} +1 -1
- ksadk/server/static/assets/{dist-BmlMPsCc.js → dist-C1sz5Eo3.js} +1 -1
- ksadk/server/static/assets/{dist-B0NP_Z0z.js → dist-CWV4lDr1.js} +1 -1
- ksadk/server/static/assets/{dist-D-xOD048.js → dist-CmZHzlwZ.js} +1 -1
- ksadk/server/static/assets/{dist-DL_NKc_z.js → dist-D6MpCZtz.js} +1 -1
- ksadk/server/static/assets/{dist-DyOkZmze.js → dist-DJN_6Y39.js} +1 -1
- ksadk/server/static/assets/{dist-DmFaq_Iy.js → dist-DQU9EWw-.js} +1 -1
- ksadk/server/static/assets/{dist-gX6GOLKq.js → dist-DWKByxWV.js} +1 -1
- ksadk/server/static/assets/{dist-DyWsb78Q.js → dist-Dli7qW-B.js} +1 -1
- ksadk/server/static/assets/{dist-BIJVDMuB.js → dist-DsHPdk3W.js} +1 -1
- ksadk/server/static/assets/{dist-Dp0k7bWI.js → dist-X4TnqwOK.js} +1 -1
- ksadk/server/static/assets/{dist-8EEyGgDx.js → dist-_pHPTyZ-.js} +1 -1
- ksadk/server/static/assets/{dist-CPBtqRTW.js → dist-fhOuWds5.js} +1 -1
- ksadk/server/static/assets/{dist-D-JMdWPQ.js → dist-gLnrGsoU.js} +1 -1
- ksadk/server/static/assets/{dist-BssVmjIo.js → dist-j6Dxmf_j.js} +1 -1
- ksadk/server/static/assets/{dist-C3HIIaN5.js → dist-o2OVmKvt.js} +1 -1
- ksadk/server/static/assets/{erDiagram-TEJ5UH35-Bk-9bgE5.js → erDiagram-TEJ5UH35-BPItFKH6.js} +1 -1
- ksadk/server/static/assets/eventmodeling-FCH6USID-DYFSxbqr.js +1 -0
- ksadk/server/static/assets/{flowDiagram-I6XJVG4X-Dn9kZVuZ.js → flowDiagram-I6XJVG4X-BbYB9w5Y.js} +1 -1
- ksadk/server/static/assets/{ganttDiagram-6RSMTGT7-BGxXlJqm.js → ganttDiagram-6RSMTGT7-TQXa0KXv.js} +1 -1
- ksadk/server/static/assets/gitGraph-WXDBUCRP-DyNYp6BN.js +1 -0
- ksadk/server/static/assets/{gitGraphDiagram-PVQCEYII-C7Q0X-wi.js → gitGraphDiagram-PVQCEYII-bKblCnpa.js} +1 -1
- ksadk/server/static/assets/index-R52pJJvg.js +177 -0
- ksadk/server/static/assets/index-jJr3_955.css +2 -0
- ksadk/server/static/assets/info-J43DQDTF-WUx7qTde.js +1 -0
- ksadk/server/static/assets/{infoDiagram-5YYISTIA-BO_CSqq5.js → infoDiagram-5YYISTIA-BGVT7J_i.js} +1 -1
- ksadk/server/static/assets/{ishikawaDiagram-YF4QCWOH-eYLPLd46.js → ishikawaDiagram-YF4QCWOH-K0OOfVna.js} +1 -1
- ksadk/server/static/assets/{journeyDiagram-JHISSGLW-De9geSb0.js → journeyDiagram-JHISSGLW-8LeOJaZp.js} +1 -1
- ksadk/server/static/assets/{kanban-definition-UN3LZRKU-Cs80kQto.js → kanban-definition-UN3LZRKU-C6uCgZrW.js} +1 -1
- ksadk/server/static/assets/{katex-DSrCFD8n.js → katex-CYWseY5E.js} +1 -1
- ksadk/server/static/assets/{linear-CN9sbKTF.js → linear-hdBcYzM8.js} +1 -1
- ksadk/server/static/assets/{mermaid-parser.core-DlgSBU8l.js → mermaid-parser.core-BWrDjSZM.js} +2 -2
- ksadk/server/static/assets/{mindmap-definition-RKZ34NQL-9afz7Oug.js → mindmap-definition-RKZ34NQL-Bjy_2v4_.js} +1 -1
- ksadk/server/static/assets/packet-YPE3B663-BN13y_xl.js +1 -0
- ksadk/server/static/assets/pie-LRSECV5Y-ftSLXhhc.js +1 -0
- ksadk/server/static/assets/{pieDiagram-4H26LBE5-DPv_VstN.js → pieDiagram-4H26LBE5-GmmqNiVH.js} +1 -1
- ksadk/server/static/assets/{quadrantDiagram-W4KKPZXB-o77wZ1XK.js → quadrantDiagram-W4KKPZXB-BmkRbwCg.js} +1 -1
- ksadk/server/static/assets/radar-GUYGQ44K-jaICkIeO.js +1 -0
- ksadk/server/static/assets/{requirementDiagram-4Y6WPE33-BYVw81VC.js → requirementDiagram-4Y6WPE33-DSWFqL7c.js} +1 -1
- ksadk/server/static/assets/{sankeyDiagram-5OEKKPKP-B7nZFMKT.js → sankeyDiagram-5OEKKPKP-l6iXmU65.js} +1 -1
- ksadk/server/static/assets/{sequenceDiagram-3UESZ5HK-BGRRrFw5.js → sequenceDiagram-3UESZ5HK-Cq6UBeQB.js} +1 -1
- ksadk/server/static/assets/{stateDiagram-AJRCARHV-BUfHCoPs.js → stateDiagram-AJRCARHV-qzTQpg3Y.js} +1 -1
- ksadk/server/static/assets/stateDiagram-v2-BHNVJYJU-BYCoYGAN.js +1 -0
- ksadk/server/static/assets/{timeline-definition-PNZ67QCA-FbCTGrf9.js → timeline-definition-PNZ67QCA-DEz24vV0.js} +1 -1
- ksadk/server/static/assets/treeView-BLDUP644-Cpib_vlz.js +1 -0
- ksadk/server/static/assets/treemap-LRROVOQU-DQxfmVHK.js +1 -0
- ksadk/server/static/assets/{vennDiagram-CIIHVFJN-DWgwtPsJ.js → vennDiagram-CIIHVFJN-CMCixki2.js} +1 -1
- ksadk/server/static/assets/wardley-L42UT6IY-BQYHnnkU.js +1 -0
- ksadk/server/static/assets/{wardleyDiagram-YWT4CUSO-2x8G-tTM.js → wardleyDiagram-YWT4CUSO-CVzB8F9K.js} +1 -1
- ksadk/server/static/assets/{xychartDiagram-2RQKCTM6-Drma3AYl.js → xychartDiagram-2RQKCTM6-BFBqBLc1.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 +47 -16
- ksadk/skills/tool_defs.py +15 -10
- ksadk/studio/__init__.py +5 -0
- ksadk/studio/agent_avatar_assets.py +120 -0
- ksadk/studio/agent_lifecycle.py +51 -0
- ksadk/studio/api.py +1046 -0
- ksadk/studio/api_catalog_routes.py +324 -0
- ksadk/studio/api_contracts.py +177 -0
- ksadk/studio/api_helpers.py +132 -0
- ksadk/studio/authoring.py +524 -0
- ksadk/studio/authoring_coordinator.py +285 -0
- ksadk/studio/builder.py +320 -0
- ksadk/studio/capabilities.py +351 -0
- ksadk/studio/cloud.py +278 -0
- ksadk/studio/codex_agent_service.py +583 -0
- ksadk/studio/codex_builder.py +324 -0
- ksadk/studio/codex_manifest.py +278 -0
- ksadk/studio/codex_run.py +352 -0
- ksadk/studio/compiler.py +189 -0
- ksadk/studio/contracts.py +644 -0
- ksadk/studio/errors.py +47 -0
- ksadk/studio/evaluation.py +192 -0
- ksadk/studio/event_store.py +284 -0
- ksadk/studio/framework_run.py +114 -0
- ksadk/studio/identifiers.py +33 -0
- ksadk/studio/mcp_runtime.py +229 -0
- ksadk/studio/model_client.py +543 -0
- ksadk/studio/model_profile_service.py +214 -0
- ksadk/studio/operations.py +243 -0
- ksadk/studio/otel_trace.py +754 -0
- ksadk/studio/pagination.py +182 -0
- ksadk/studio/python_tool_inspection.py +183 -0
- ksadk/studio/repository.py +306 -0
- ksadk/studio/resource_catalog.py +1217 -0
- ksadk/studio/run_service.py +707 -0
- ksadk/studio/runtime_catalog.py +74 -0
- ksadk/studio/runtime_source.py +339 -0
- ksadk/studio/service.py +1141 -0
- ksadk/studio/shared_web.py +994 -0
- ksadk/studio/skill_discovery.py +628 -0
- ksadk/studio/static/assets/PrismRenderer-IYN-ffww.js +3 -0
- ksadk/studio/static/assets/index-CaEN0eTR.css +1 -0
- ksadk/studio/static/assets/index-DI2eY_NH.js +252 -0
- ksadk/studio/static/assets/react-vendor-BNmTiJ-I.js +9 -0
- ksadk/studio/static/assets/rolldown-runtime-hePW80VL.js +1 -0
- ksadk/studio/static/index.html +15 -0
- ksadk/studio/templates.py +630 -0
- ksadk/studio/validator.py +246 -0
- ksadk/studio/workspace.py +137 -0
- ksadk/terminal_exec_policy.py +3 -4
- ksadk/tools/gateway.py +101 -15
- ksadk/tools/result_budget.py +12 -4
- ksadk/toolsets/__init__.py +161 -37
- ksadk/toolsets/a2a.py +426 -0
- 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/__init__.py +19 -21
- ksadk/tracing/exporters/inmemory_exporter.py +62 -51
- ksadk/tracing/setup.py +135 -506
- ksadk/tracing/span_utils.py +0 -41
- 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/memory_backend/registry.py +56 -56
- ksadk_runtime_common/schemas/runtime_event_v1.json +95 -0
- ksadk_runtime_common/workspace_files/router.py +8 -2
- agentengine_sdk_python-0.7.0.dist-info/RECORD +0 -482
- ksadk/a2a/card_builder.py +0 -64
- ksadk/a2a/client.py +0 -309
- ksadk/runners/utils/langfuse.py +0 -230
- 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
- ksadk/tracing/exporters/langfuse_exporter.py +0 -445
- {agentengine_sdk_python-0.7.0.dist-info → agentengine_sdk_python-0.8.1.dist-info}/entry_points.txt +0 -0
- {agentengine_sdk_python-0.7.0.dist-info → agentengine_sdk_python-0.8.1.dist-info}/licenses/LICENSE +0 -0
- {agentengine_sdk_python-0.7.0.dist-info → agentengine_sdk_python-0.8.1.dist-info}/top_level.txt +0 -0
ksadk/runners/adk_runner.py
CHANGED
|
@@ -10,20 +10,20 @@ import base64
|
|
|
10
10
|
import inspect
|
|
11
11
|
import logging
|
|
12
12
|
import os
|
|
13
|
-
import sys
|
|
14
13
|
from dataclasses import dataclass
|
|
15
14
|
from importlib.metadata import PackageNotFoundError
|
|
16
15
|
from importlib.metadata import version as _pkg_version
|
|
17
16
|
from pathlib import Path
|
|
18
|
-
from typing import Any, AsyncIterator, Dict, Mapping, Optional
|
|
17
|
+
from typing import Any, AsyncIterator, Dict, Mapping, Optional, cast
|
|
19
18
|
|
|
20
|
-
from google.genai import types
|
|
21
19
|
from opentelemetry import trace
|
|
22
20
|
|
|
21
|
+
from ksadk.compat.adk_compat import genai_types as types
|
|
23
22
|
from ksadk.conversations.attachments import classify_attachment_kind, read_attachment_uri_bytes
|
|
24
23
|
from ksadk.conversations.model_context import supports_native_image_input
|
|
25
24
|
from ksadk.runners.base_runner import BaseRunner
|
|
26
25
|
from ksadk.runners.usage_accumulator import accumulate_usage
|
|
26
|
+
from ksadk.runners.utils import load_agent_module
|
|
27
27
|
from ksadk.sessions.continuity import ADKSessionAdapter
|
|
28
28
|
|
|
29
29
|
logger = logging.getLogger(__name__)
|
|
@@ -31,22 +31,36 @@ logger = logging.getLogger(__name__)
|
|
|
31
31
|
tracer = trace.get_tracer(__name__)
|
|
32
32
|
|
|
33
33
|
|
|
34
|
+
def _part_metadata_flag(part: Any, key: str) -> bool:
|
|
35
|
+
"""读取 A2A→GenAI Part 保留下来的扩展 metadata 标记。"""
|
|
36
|
+
metadata = getattr(part, "part_metadata", None)
|
|
37
|
+
if isinstance(metadata, Mapping):
|
|
38
|
+
return bool(metadata.get(key))
|
|
39
|
+
getter = getattr(metadata, "get", None)
|
|
40
|
+
if callable(getter):
|
|
41
|
+
try:
|
|
42
|
+
return bool(getter(key))
|
|
43
|
+
except (KeyError, TypeError, ValueError):
|
|
44
|
+
return False
|
|
45
|
+
return False
|
|
46
|
+
|
|
47
|
+
|
|
34
48
|
class ADKRunner(BaseRunner):
|
|
35
49
|
"""ADK 框架运行时"""
|
|
36
50
|
|
|
37
51
|
def __init__(self, detection_result: Any, project_dir: str):
|
|
38
52
|
super().__init__(detection_result, project_dir)
|
|
39
|
-
self._runner = None
|
|
40
|
-
self._session_service = None
|
|
53
|
+
self._runner: Any = None
|
|
54
|
+
self._session_service: Any = None
|
|
41
55
|
# Map external session_ids (e.g. from run_interactive or web) to ADK internal session IDs
|
|
42
56
|
self._session_map: Dict[str, str] = {}
|
|
43
57
|
# Fallback default session
|
|
44
58
|
self._default_session_id: Optional[str] = None
|
|
45
59
|
# Memory integration
|
|
46
|
-
self._short_term_memory = None
|
|
47
|
-
self._long_term_memory = None
|
|
60
|
+
self._short_term_memory: Any = None
|
|
61
|
+
self._long_term_memory: Any = None
|
|
48
62
|
# Knowledge base integration
|
|
49
|
-
self._knowledge_base = None
|
|
63
|
+
self._knowledge_base: Any = None
|
|
50
64
|
# Keep runtime toolsets alive for the lifetime of the runner.
|
|
51
65
|
self._runtime_toolsets: list[Any] = []
|
|
52
66
|
# ADK resumability state
|
|
@@ -55,7 +69,7 @@ class ADKRunner(BaseRunner):
|
|
|
55
69
|
# P1.1 sub-issue: guard invocation_map read-modify-write so concurrent
|
|
56
70
|
# invocations on the same session don't lose each other's mappings.
|
|
57
71
|
self._invocation_map_lock = asyncio.Lock()
|
|
58
|
-
self._module = None
|
|
72
|
+
self._module: Any = None
|
|
59
73
|
self._adk_resume_min_version = os.environ.get(
|
|
60
74
|
"GOOGLE_ADK_RESUME_MIN_VERSION", "1.16.0"
|
|
61
75
|
).strip()
|
|
@@ -98,7 +112,9 @@ class ADKRunner(BaseRunner):
|
|
|
98
112
|
import inspect as _inspect
|
|
99
113
|
import json as _stdlib_json
|
|
100
114
|
|
|
101
|
-
|
|
115
|
+
from ksadk.compat.adk_compat import lite_llm_module
|
|
116
|
+
|
|
117
|
+
adk_lite_llm = lite_llm_module()
|
|
102
118
|
|
|
103
119
|
_original_fn = adk_lite_llm._message_to_generate_content_response
|
|
104
120
|
if getattr(_original_fn, "__ksadk_json_patch__", False):
|
|
@@ -106,9 +122,7 @@ class ADKRunner(BaseRunner):
|
|
|
106
122
|
# Determine which kwargs the original function actually accepts,
|
|
107
123
|
# so the patch is compatible across ADK versions that may have
|
|
108
124
|
# added or removed `model_version` / `thought_parts`.
|
|
109
|
-
_orig_params = set(
|
|
110
|
-
_inspect.signature(_original_fn).parameters.keys()
|
|
111
|
-
)
|
|
125
|
+
_orig_params = set(_inspect.signature(_original_fn).parameters.keys())
|
|
112
126
|
|
|
113
127
|
def _patched_message_to_generate_content_response(
|
|
114
128
|
message, *, is_partial=False, model_version=None, thought_parts=None
|
|
@@ -129,8 +143,8 @@ class ADKRunner(BaseRunner):
|
|
|
129
143
|
"ADKRunner: caught JSONDecodeError in args parsing, "
|
|
130
144
|
"returning empty response"
|
|
131
145
|
)
|
|
132
|
-
from
|
|
133
|
-
from
|
|
146
|
+
from ksadk.compat.adk_compat import LlmResponse
|
|
147
|
+
from ksadk.compat.adk_compat import genai_types as _genai_types
|
|
134
148
|
|
|
135
149
|
return LlmResponse(
|
|
136
150
|
content=_genai_types.Content(role="model", parts=[]),
|
|
@@ -149,15 +163,11 @@ class ADKRunner(BaseRunner):
|
|
|
149
163
|
for i, part in enumerate(result.content.parts):
|
|
150
164
|
if part.function_call and part.function_call.args is None:
|
|
151
165
|
part.function_call.args = {}
|
|
152
|
-
if (
|
|
153
|
-
part.function_call
|
|
154
|
-
and not (part.function_call.name or "").strip()
|
|
155
|
-
):
|
|
166
|
+
if part.function_call and not (part.function_call.name or "").strip():
|
|
156
167
|
phantom_indices.add(i)
|
|
157
168
|
if phantom_indices:
|
|
158
169
|
result.content.parts = [
|
|
159
|
-
p for i, p in enumerate(result.content.parts)
|
|
160
|
-
if i not in phantom_indices
|
|
170
|
+
p for i, p in enumerate(result.content.parts) if i not in phantom_indices
|
|
161
171
|
]
|
|
162
172
|
return result
|
|
163
173
|
|
|
@@ -180,7 +190,6 @@ class ADKRunner(BaseRunner):
|
|
|
180
190
|
except Exception:
|
|
181
191
|
pass
|
|
182
192
|
|
|
183
|
-
|
|
184
193
|
def _apply_mcp_result_patch(self):
|
|
185
194
|
"""Patch ADK McpTool to convert CallToolResult to dict.
|
|
186
195
|
|
|
@@ -192,17 +201,17 @@ class ADKRunner(BaseRunner):
|
|
|
192
201
|
for the old version.
|
|
193
202
|
"""
|
|
194
203
|
try:
|
|
195
|
-
from
|
|
204
|
+
from ksadk.compat.adk_compat import McpTool
|
|
196
205
|
|
|
197
206
|
_original_run_async = McpTool._run_async_impl
|
|
198
207
|
if getattr(_original_run_async, "__ksadk_mcp_result_patch__", False):
|
|
199
208
|
return
|
|
200
209
|
|
|
201
|
-
async def _patched_run_async_impl(
|
|
202
|
-
self, *, args, tool_context, credential
|
|
203
|
-
):
|
|
210
|
+
async def _patched_run_async_impl(self, *, args, tool_context, credential):
|
|
204
211
|
response = await _original_run_async(
|
|
205
|
-
self,
|
|
212
|
+
self,
|
|
213
|
+
args=args,
|
|
214
|
+
tool_context=tool_context,
|
|
206
215
|
credential=credential,
|
|
207
216
|
)
|
|
208
217
|
# If response is a Pydantic model (e.g. CallToolResult),
|
|
@@ -224,7 +233,6 @@ class ADKRunner(BaseRunner):
|
|
|
224
233
|
except Exception as exc:
|
|
225
234
|
logger.debug("ADKRunner: MCP result patch failed: %s", exc)
|
|
226
235
|
|
|
227
|
-
|
|
228
236
|
def _init_short_term_memory(self):
|
|
229
237
|
"""从环境变量初始化短期记忆
|
|
230
238
|
|
|
@@ -268,8 +276,7 @@ class ADKRunner(BaseRunner):
|
|
|
268
276
|
def describe_checkpoint_capability(self) -> dict[str, Any]:
|
|
269
277
|
resumable = getattr(self, "_resumable", False)
|
|
270
278
|
stm_backend = (
|
|
271
|
-
getattr(self._short_term_memory, "backend", None)
|
|
272
|
-
if self._short_term_memory else None
|
|
279
|
+
getattr(self._short_term_memory, "backend", None) if self._short_term_memory else None
|
|
273
280
|
)
|
|
274
281
|
if resumable:
|
|
275
282
|
backend = "adk_invocation"
|
|
@@ -312,8 +319,7 @@ class ADKRunner(BaseRunner):
|
|
|
312
319
|
capabilities = super().get_runtime_capabilities()
|
|
313
320
|
resumable = getattr(self, "_resumable", False)
|
|
314
321
|
stm_backend = (
|
|
315
|
-
getattr(self._short_term_memory, "backend", None)
|
|
316
|
-
if self._short_term_memory else None
|
|
322
|
+
getattr(self._short_term_memory, "backend", None) if self._short_term_memory else None
|
|
317
323
|
)
|
|
318
324
|
is_durable = stm_backend is not None and stm_backend != "local"
|
|
319
325
|
if resumable:
|
|
@@ -352,9 +358,11 @@ class ADKRunner(BaseRunner):
|
|
|
352
358
|
"Supported": True,
|
|
353
359
|
"Type": "native_session" if has_native_session else "semantic_replay",
|
|
354
360
|
"Level": "semantic",
|
|
355
|
-
"Reason":
|
|
356
|
-
|
|
357
|
-
|
|
361
|
+
"Reason": (
|
|
362
|
+
"ADK native session can continue conversation context"
|
|
363
|
+
if has_native_session
|
|
364
|
+
else "conversation transcript can be replayed"
|
|
365
|
+
),
|
|
358
366
|
}
|
|
359
367
|
capabilities["ResumeRun"]["Reason"] = capabilities["Checkpoint"]["Reason"]
|
|
360
368
|
return capabilities
|
|
@@ -362,8 +370,8 @@ class ADKRunner(BaseRunner):
|
|
|
362
370
|
@dataclass
|
|
363
371
|
class _ResolvabilityResult:
|
|
364
372
|
enabled: bool
|
|
365
|
-
source: str
|
|
366
|
-
app: Any
|
|
373
|
+
source: str # "agent_module" | "env" | "auto_persistent_session" | "default"
|
|
374
|
+
app: Any # User module exported App object (if any)
|
|
367
375
|
|
|
368
376
|
def _resolve_resumability(self) -> "_ResolvabilityResult":
|
|
369
377
|
"""从环境变量或 agent 模块推断是否启用 ADK 可恢复性。"""
|
|
@@ -371,13 +379,15 @@ class ADKRunner(BaseRunner):
|
|
|
371
379
|
module = getattr(self, "_module", None)
|
|
372
380
|
if module is not None:
|
|
373
381
|
try:
|
|
374
|
-
from
|
|
382
|
+
from ksadk.compat.adk_compat import App
|
|
383
|
+
|
|
375
384
|
for attr_name in ("app", "application"):
|
|
376
385
|
candidate = getattr(module, attr_name, None)
|
|
377
386
|
if isinstance(candidate, App) and candidate.resumability_config:
|
|
378
387
|
if candidate.resumability_config.is_resumable:
|
|
379
388
|
return self._ResolvabilityResult(
|
|
380
|
-
enabled=True, source="agent_module", app=candidate
|
|
389
|
+
enabled=True, source="agent_module", app=candidate
|
|
390
|
+
)
|
|
381
391
|
except ImportError:
|
|
382
392
|
pass
|
|
383
393
|
|
|
@@ -388,12 +398,12 @@ class ADKRunner(BaseRunner):
|
|
|
388
398
|
|
|
389
399
|
# Priority 3: persistent session backend auto-enable
|
|
390
400
|
stm_backend = (
|
|
391
|
-
getattr(self._short_term_memory, "backend", None)
|
|
392
|
-
if self._short_term_memory else None
|
|
401
|
+
getattr(self._short_term_memory, "backend", None) if self._short_term_memory else None
|
|
393
402
|
)
|
|
394
403
|
if stm_backend and stm_backend != "local":
|
|
395
404
|
return self._ResolvabilityResult(
|
|
396
|
-
enabled=True, source="auto_persistent_session", app=None
|
|
405
|
+
enabled=True, source="auto_persistent_session", app=None
|
|
406
|
+
)
|
|
397
407
|
|
|
398
408
|
return self._ResolvabilityResult(enabled=False, source="default", app=None)
|
|
399
409
|
|
|
@@ -417,6 +427,7 @@ class ADKRunner(BaseRunner):
|
|
|
417
427
|
return False, "google-adk version unknown, cannot guarantee invocation_id support"
|
|
418
428
|
try:
|
|
419
429
|
from packaging.version import Version
|
|
430
|
+
|
|
420
431
|
if Version(adk_ver) < Version(self._adk_resume_min_version):
|
|
421
432
|
return (
|
|
422
433
|
False,
|
|
@@ -430,7 +441,7 @@ class ADKRunner(BaseRunner):
|
|
|
430
441
|
|
|
431
442
|
def _build_runner(self) -> None:
|
|
432
443
|
"""构造 ADK Runner,优先使用 App 对象以启用 ResumabilityConfig。"""
|
|
433
|
-
from
|
|
444
|
+
from ksadk.compat.adk_compat import Runner
|
|
434
445
|
|
|
435
446
|
resumable = self._resolve_resumability()
|
|
436
447
|
resumability_enabled = resumable.enabled
|
|
@@ -438,9 +449,7 @@ class ADKRunner(BaseRunner):
|
|
|
438
449
|
# 版本兼容性检查:低于最低版本时强制关闭恢复
|
|
439
450
|
resume_compatible, resume_reason = self._check_adk_resume_compatibility()
|
|
440
451
|
if not resume_compatible and resumable.enabled:
|
|
441
|
-
logger.warning(
|
|
442
|
-
"ADKRunner: resumability disabled — %s", resume_reason
|
|
443
|
-
)
|
|
452
|
+
logger.warning("ADKRunner: resumability disabled — %s", resume_reason)
|
|
444
453
|
resumable = self._ResolvabilityResult(enabled=False, source="version_check", app=None)
|
|
445
454
|
resumability_enabled = False
|
|
446
455
|
self._resume_disabled_reason = resume_reason
|
|
@@ -452,7 +461,8 @@ class ADKRunner(BaseRunner):
|
|
|
452
461
|
)
|
|
453
462
|
elif resumable.enabled:
|
|
454
463
|
try:
|
|
455
|
-
from
|
|
464
|
+
from ksadk.compat.adk_compat import App, ResumabilityConfig
|
|
465
|
+
|
|
456
466
|
app = App(
|
|
457
467
|
name=self._agent.name,
|
|
458
468
|
root_agent=self._agent,
|
|
@@ -491,7 +501,8 @@ class ADKRunner(BaseRunner):
|
|
|
491
501
|
if resumability_enabled:
|
|
492
502
|
stm_backend = (
|
|
493
503
|
getattr(self._short_term_memory, "backend", None)
|
|
494
|
-
if self._short_term_memory
|
|
504
|
+
if self._short_term_memory
|
|
505
|
+
else None
|
|
495
506
|
)
|
|
496
507
|
logger.info(
|
|
497
508
|
"ADKRunner: resumability enabled (source=%s, backend=%s)",
|
|
@@ -519,10 +530,7 @@ class ADKRunner(BaseRunner):
|
|
|
519
530
|
|
|
520
531
|
agent_name = self._agent.name if self._agent else "default"
|
|
521
532
|
ltm = LongTermMemory.from_env(app_name=agent_name)
|
|
522
|
-
logger.info(
|
|
523
|
-
f"LongTermMemory initialized: backend={backend}, "
|
|
524
|
-
f"app_name={agent_name}"
|
|
525
|
-
)
|
|
533
|
+
logger.info(f"LongTermMemory initialized: backend={backend}, " f"app_name={agent_name}")
|
|
526
534
|
return ltm
|
|
527
535
|
except Exception as e:
|
|
528
536
|
logger.warning(f"Failed to init LongTermMemory: {e}.")
|
|
@@ -546,8 +554,7 @@ class ADKRunner(BaseRunner):
|
|
|
546
554
|
|
|
547
555
|
kb = KnowledgeBaseClient.from_env()
|
|
548
556
|
logger.info(
|
|
549
|
-
f"KnowledgeBase initialized: dataset_id={kb.dataset_id}, "
|
|
550
|
-
f"region={kb.region}"
|
|
557
|
+
f"KnowledgeBase initialized: dataset_id={kb.dataset_id}, " f"region={kb.region}"
|
|
551
558
|
)
|
|
552
559
|
return kb
|
|
553
560
|
except ImportError:
|
|
@@ -582,7 +589,7 @@ class ADKRunner(BaseRunner):
|
|
|
582
589
|
def _inject_load_memory_tool(self):
|
|
583
590
|
"""自动注入 load_memory 工具到 Agent"""
|
|
584
591
|
try:
|
|
585
|
-
from
|
|
592
|
+
from ksadk.compat.adk_compat import load_memory
|
|
586
593
|
|
|
587
594
|
added = self._append_tools_by_name([load_memory])
|
|
588
595
|
if added:
|
|
@@ -810,7 +817,7 @@ class ADKRunner(BaseRunner):
|
|
|
810
817
|
|
|
811
818
|
@staticmethod
|
|
812
819
|
def _tool_name(tool: Any) -> str:
|
|
813
|
-
return getattr(tool, "name", None) or getattr(tool, "__name__", "")
|
|
820
|
+
return str(getattr(tool, "name", None) or getattr(tool, "__name__", ""))
|
|
814
821
|
|
|
815
822
|
def _append_tools_by_name(self, tools: list[Any]) -> list[str]:
|
|
816
823
|
if not hasattr(self._agent, "tools"):
|
|
@@ -821,9 +828,7 @@ class ADKRunner(BaseRunner):
|
|
|
821
828
|
self._agent.tools = []
|
|
822
829
|
|
|
823
830
|
existing_names = {
|
|
824
|
-
self._tool_name(tool)
|
|
825
|
-
for tool in self._agent.tools
|
|
826
|
-
if self._tool_name(tool)
|
|
831
|
+
self._tool_name(tool) for tool in self._agent.tools if self._tool_name(tool)
|
|
827
832
|
}
|
|
828
833
|
added_names: list[str] = []
|
|
829
834
|
for tool in tools:
|
|
@@ -845,9 +850,7 @@ class ADKRunner(BaseRunner):
|
|
|
845
850
|
self._agent.tools = []
|
|
846
851
|
|
|
847
852
|
existing_keys = {
|
|
848
|
-
getattr(tool, key_attr)
|
|
849
|
-
for tool in self._agent.tools
|
|
850
|
-
if getattr(tool, key_attr, None)
|
|
853
|
+
getattr(tool, key_attr) for tool in self._agent.tools if getattr(tool, key_attr, None)
|
|
851
854
|
}
|
|
852
855
|
added_keys: list[str] = []
|
|
853
856
|
for toolset in toolsets:
|
|
@@ -879,11 +882,13 @@ class ADKRunner(BaseRunner):
|
|
|
879
882
|
name = detail.get("input")
|
|
880
883
|
if location not in (("name",), ["name"]) or not isinstance(name, str):
|
|
881
884
|
continue
|
|
882
|
-
|
|
885
|
+
# adk 1.34 报 "...valid identifier";adk 2.x 报 "...valid Python identifier"。
|
|
886
|
+
# 放宽匹配以同时覆盖两种措辞,保证两版都给出 actionable hint。
|
|
887
|
+
msg_lower = message.lower()
|
|
888
|
+
if "identifier" not in msg_lower or "valid" not in msg_lower:
|
|
883
889
|
continue
|
|
884
890
|
safe_name = "".join(
|
|
885
|
-
char if char.isascii() and (char.isalnum() or char == "_") else "_"
|
|
886
|
-
for char in name
|
|
891
|
+
char if char.isascii() and (char.isalnum() or char == "_") else "_" for char in name
|
|
887
892
|
)
|
|
888
893
|
if not safe_name or safe_name[0].isdigit():
|
|
889
894
|
safe_name = f"agent_{safe_name}"
|
|
@@ -905,26 +910,12 @@ class ADKRunner(BaseRunner):
|
|
|
905
910
|
self._apply_json_patch()
|
|
906
911
|
self._apply_mcp_result_patch()
|
|
907
912
|
|
|
908
|
-
# 添加项目目录到 Python 路径
|
|
909
|
-
project_path = Path(self.project_dir).resolve()
|
|
910
|
-
if str(project_path) not in sys.path:
|
|
911
|
-
sys.path.insert(0, str(project_path))
|
|
912
|
-
|
|
913
|
-
# 确定模块名: 从 entry_point 获取
|
|
914
|
-
# (e.g. "smart_assistant_adk/agent.py" -> "smart_assistant_adk.agent")
|
|
915
|
-
entry_point = self.detection_result.entry_point
|
|
916
|
-
if entry_point.endswith(".py"):
|
|
917
|
-
module_name = entry_point[:-3] # 移除 .py 后缀
|
|
918
|
-
else:
|
|
919
|
-
module_name = entry_point
|
|
920
|
-
|
|
921
|
-
# 转换路径为模块路径 (e.g., "subdir/agent" -> "subdir.agent")
|
|
922
|
-
module_name = module_name.replace("/", ".").replace("\\", ".")
|
|
923
|
-
|
|
924
913
|
try:
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
914
|
+
self._agent, self._module = load_agent_module(
|
|
915
|
+
self.project_dir,
|
|
916
|
+
self.detection_result.entry_point,
|
|
917
|
+
self.detection_result.agent_variable,
|
|
918
|
+
)
|
|
928
919
|
|
|
929
920
|
# Inject safety instruction for DeepSeek/LLMs to prevent empty tool names
|
|
930
921
|
if hasattr(self._agent, "instruction"):
|
|
@@ -934,12 +925,8 @@ class ADKRunner(BaseRunner):
|
|
|
934
925
|
else:
|
|
935
926
|
self._agent.instruction = safety_prompt
|
|
936
927
|
|
|
937
|
-
except ImportError
|
|
938
|
-
raise
|
|
939
|
-
except AttributeError:
|
|
940
|
-
raise AttributeError(
|
|
941
|
-
f"模块 {module_name} 中未找到 {self.detection_result.agent_variable}"
|
|
942
|
-
)
|
|
928
|
+
except (ImportError, AttributeError):
|
|
929
|
+
raise
|
|
943
930
|
except Exception as exc:
|
|
944
931
|
name_error = self._invalid_agent_name_load_error(exc)
|
|
945
932
|
if name_error is not None:
|
|
@@ -960,7 +947,7 @@ class ADKRunner(BaseRunner):
|
|
|
960
947
|
self._inject_search_knowledge_tool()
|
|
961
948
|
|
|
962
949
|
# 初始化 SessionService
|
|
963
|
-
from
|
|
950
|
+
from ksadk.compat.adk_compat import InMemorySessionService
|
|
964
951
|
|
|
965
952
|
if self._short_term_memory:
|
|
966
953
|
self._session_service = self._short_term_memory.session_service
|
|
@@ -983,10 +970,7 @@ class ADKRunner(BaseRunner):
|
|
|
983
970
|
os.getenv("OPENAI_MODEL_NAME") or os.getenv("MODEL_NAME")
|
|
984
971
|
)
|
|
985
972
|
self._default_model_reference = self._discover_model_reference(self._agent)
|
|
986
|
-
self._active_model_name =
|
|
987
|
-
self._default_model_reference
|
|
988
|
-
or self._default_model_name
|
|
989
|
-
)
|
|
973
|
+
self._active_model_name = self._default_model_reference or self._default_model_name
|
|
990
974
|
|
|
991
975
|
def _discover_model_reference(self, agent: Any) -> Optional[str]:
|
|
992
976
|
visited: set[int] = set()
|
|
@@ -1058,18 +1042,14 @@ class ADKRunner(BaseRunner):
|
|
|
1058
1042
|
def prepare_for_request(self, model: str | None) -> None:
|
|
1059
1043
|
normalized = self.sync_process_model_env(model)
|
|
1060
1044
|
if normalized is None:
|
|
1061
|
-
default_model_name = (
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
)
|
|
1045
|
+
default_model_name = getattr(
|
|
1046
|
+
self, "_default_model_name", None
|
|
1047
|
+
) or self.normalize_requested_model(
|
|
1048
|
+
os.getenv("OPENAI_MODEL_NAME") or os.getenv("MODEL_NAME")
|
|
1066
1049
|
)
|
|
1067
1050
|
if default_model_name:
|
|
1068
1051
|
self.sync_process_model_env(default_model_name)
|
|
1069
|
-
target_reference = (
|
|
1070
|
-
getattr(self, "_default_model_reference", None)
|
|
1071
|
-
or default_model_name
|
|
1072
|
-
)
|
|
1052
|
+
target_reference = getattr(self, "_default_model_reference", None) or default_model_name
|
|
1073
1053
|
if target_reference and self._agent is not None:
|
|
1074
1054
|
current_reference = self._discover_model_reference(self._agent)
|
|
1075
1055
|
if current_reference != target_reference:
|
|
@@ -1095,14 +1075,13 @@ class ADKRunner(BaseRunner):
|
|
|
1095
1075
|
return
|
|
1096
1076
|
self._active_model_name = target_reference
|
|
1097
1077
|
|
|
1098
|
-
def _prepare_trace_metadata(self, session_id: str):
|
|
1078
|
+
def _prepare_trace_metadata(self, session_id: Optional[str]):
|
|
1099
1079
|
"""准备 Trace 元数据 (Tags, UserID, etc.)"""
|
|
1100
1080
|
from ksadk.tracing.span_utils import prepare_trace_metadata
|
|
1101
|
-
return prepare_trace_metadata(
|
|
1102
|
-
detection_result=getattr(self, "detection_result", None)
|
|
1103
|
-
)
|
|
1104
1081
|
|
|
1105
|
-
|
|
1082
|
+
return prepare_trace_metadata(detection_result=getattr(self, "detection_result", None))
|
|
1083
|
+
|
|
1084
|
+
async def _ensure_session(self, external_session_id: Optional[str] = None) -> str:
|
|
1106
1085
|
"""Get or create ADK session ID based on external ID
|
|
1107
1086
|
|
|
1108
1087
|
When ShortTermMemory is configured, uses its create_session method
|
|
@@ -1121,11 +1100,13 @@ class ADKRunner(BaseRunner):
|
|
|
1121
1100
|
session_id=external_session_id,
|
|
1122
1101
|
)
|
|
1123
1102
|
else:
|
|
1103
|
+
if self._session_service is None:
|
|
1104
|
+
raise RuntimeError("ADK session service is not initialized")
|
|
1124
1105
|
session = await self._session_service.create_session(
|
|
1125
1106
|
app_name=self._agent.name, user_id="ksadk_user"
|
|
1126
1107
|
)
|
|
1127
1108
|
self._session_map[external_session_id] = session.id
|
|
1128
|
-
return session.id
|
|
1109
|
+
return str(session.id)
|
|
1129
1110
|
|
|
1130
1111
|
# Case 2: No external ID (use default singleton)
|
|
1131
1112
|
if self._default_session_id is None:
|
|
@@ -1135,11 +1116,13 @@ class ADKRunner(BaseRunner):
|
|
|
1135
1116
|
user_id="ksadk_user",
|
|
1136
1117
|
)
|
|
1137
1118
|
else:
|
|
1119
|
+
if self._session_service is None:
|
|
1120
|
+
raise RuntimeError("ADK session service is not initialized")
|
|
1138
1121
|
session = await self._session_service.create_session(
|
|
1139
1122
|
app_name=self._agent.name, user_id="ksadk_user"
|
|
1140
1123
|
)
|
|
1141
1124
|
self._default_session_id = session.id
|
|
1142
|
-
return self._default_session_id
|
|
1125
|
+
return str(self._default_session_id)
|
|
1143
1126
|
|
|
1144
1127
|
async def save_session_to_long_term_memory(
|
|
1145
1128
|
self, session_id: str, user_id: str = "ksadk_user"
|
|
@@ -1254,6 +1237,7 @@ class ADKRunner(BaseRunner):
|
|
|
1254
1237
|
"current_attachments",
|
|
1255
1238
|
"current_attachment_results",
|
|
1256
1239
|
"has_current_files",
|
|
1240
|
+
"metadata",
|
|
1257
1241
|
):
|
|
1258
1242
|
if key in input_data:
|
|
1259
1243
|
state_delta[key] = input_data.get(key)
|
|
@@ -1323,8 +1307,11 @@ class ADKRunner(BaseRunner):
|
|
|
1323
1307
|
usage_metadata.get("total_token_count") or (input_tokens + output_tokens)
|
|
1324
1308
|
)
|
|
1325
1309
|
if not (
|
|
1326
|
-
input_tokens
|
|
1327
|
-
or
|
|
1310
|
+
input_tokens
|
|
1311
|
+
or output_tokens
|
|
1312
|
+
or total_tokens
|
|
1313
|
+
or input_token_details
|
|
1314
|
+
or output_token_details
|
|
1328
1315
|
):
|
|
1329
1316
|
return {}
|
|
1330
1317
|
return {
|
|
@@ -1339,7 +1326,6 @@ class ADKRunner(BaseRunner):
|
|
|
1339
1326
|
def _extract_event_usage(cls, event: Any) -> dict[str, Any]:
|
|
1340
1327
|
return cls._normalize_usage_metadata(getattr(event, "usage_metadata", None))
|
|
1341
1328
|
|
|
1342
|
-
|
|
1343
1329
|
# --- ADK invocation_id & checkpoint helpers ---
|
|
1344
1330
|
|
|
1345
1331
|
async def _get_max_checkpoint_seq_for_run(
|
|
@@ -1380,9 +1366,9 @@ class ADKRunner(BaseRunner):
|
|
|
1380
1366
|
return max_seq
|
|
1381
1367
|
except Exception as exc:
|
|
1382
1368
|
logger.warning(
|
|
1383
|
-
"ADKRunner: failed to query max checkpoint_seq "
|
|
1384
|
-
|
|
1385
|
-
|
|
1369
|
+
"ADKRunner: failed to query max checkpoint_seq " "for run_id=%s: %s",
|
|
1370
|
+
run_id,
|
|
1371
|
+
exc,
|
|
1386
1372
|
)
|
|
1387
1373
|
return 0
|
|
1388
1374
|
|
|
@@ -1406,7 +1392,8 @@ class ADKRunner(BaseRunner):
|
|
|
1406
1392
|
captured_adk_invocation_id = ""
|
|
1407
1393
|
# 从已有 checkpoint 的最大 seq 继续,避免恢复模式下 ID 碰撞被去重丢弃
|
|
1408
1394
|
checkpoint_seq = await self._get_max_checkpoint_seq_for_run(
|
|
1409
|
-
session_id=session_id,
|
|
1395
|
+
session_id=session_id,
|
|
1396
|
+
run_id=effective_run_id,
|
|
1410
1397
|
)
|
|
1411
1398
|
async for event in events_async:
|
|
1412
1399
|
if not first_event_captured and hasattr(event, "invocation_id") and event.invocation_id:
|
|
@@ -1513,7 +1500,6 @@ class ADKRunner(BaseRunner):
|
|
|
1513
1500
|
except Exception:
|
|
1514
1501
|
return None
|
|
1515
1502
|
|
|
1516
|
-
|
|
1517
1503
|
def _is_resumable_boundary(self, event: Any) -> bool:
|
|
1518
1504
|
"""判断 ADK event 是否为可恢复边界。"""
|
|
1519
1505
|
# 工具调用请求
|
|
@@ -1527,6 +1513,83 @@ class ADKRunner(BaseRunner):
|
|
|
1527
1513
|
return True
|
|
1528
1514
|
return False
|
|
1529
1515
|
|
|
1516
|
+
def _extract_approval_signals(self, event: Any) -> list[dict[str, Any]]:
|
|
1517
|
+
"""从 ADK event 提取原生审批信号,翻译成统一 interrupt_info(供 runtime:4645 消费)。
|
|
1518
|
+
|
|
1519
|
+
覆盖 ADK 两套原生 HITL 机制,经 ``adk_compat`` 能力探测,兼容 1.34.x → 2.x:
|
|
1520
|
+
|
|
1521
|
+
1. **tool-confirmation**(``actions.requested_tool_confirmations``):工具执行前
|
|
1522
|
+
yes/no 审批,1.34+ 均有。→ ``kind="tool"``。
|
|
1523
|
+
2. **workflow HITL**(v2.0+):``event.interrupted=True`` + ``RequestInput`` 信号
|
|
1524
|
+
(message/payload/response_schema)。→ ``kind="input"``。
|
|
1525
|
+
|
|
1526
|
+
命中任一即返回 ``[{"approval_request_id","tool_name","args","kind","message"}, ...]``,
|
|
1527
|
+
否则返回 ``[]``。不引入对 v2.0 API 的硬依赖——字段缺失时跳过,不报错。
|
|
1528
|
+
"""
|
|
1529
|
+
signals: list[dict[str, Any]] = []
|
|
1530
|
+
actions = getattr(event, "actions", None)
|
|
1531
|
+
|
|
1532
|
+
# 1) tool-confirmation:requested_tool_confirmations(1.34+,经 getattr 容错)
|
|
1533
|
+
if actions is not None:
|
|
1534
|
+
confirmations = getattr(actions, "requested_tool_confirmations", None)
|
|
1535
|
+
if confirmations:
|
|
1536
|
+
for conf in confirmations:
|
|
1537
|
+
if conf is None:
|
|
1538
|
+
continue
|
|
1539
|
+
conf_id = str(
|
|
1540
|
+
getattr(conf, "id", "") or getattr(conf, "approval_request_id", "") or ""
|
|
1541
|
+
)
|
|
1542
|
+
if not conf_id:
|
|
1543
|
+
continue
|
|
1544
|
+
signals.append(
|
|
1545
|
+
{
|
|
1546
|
+
"approval_request_id": conf_id,
|
|
1547
|
+
"tool_name": str(
|
|
1548
|
+
getattr(conf, "tool_name", "")
|
|
1549
|
+
or getattr(conf, "name", "")
|
|
1550
|
+
or "tool"
|
|
1551
|
+
),
|
|
1552
|
+
"args": dict(getattr(conf, "args", None) or {}),
|
|
1553
|
+
"kind": "tool",
|
|
1554
|
+
"message": str(
|
|
1555
|
+
getattr(conf, "message", "") or getattr(conf, "hint", "") or ""
|
|
1556
|
+
),
|
|
1557
|
+
}
|
|
1558
|
+
)
|
|
1559
|
+
|
|
1560
|
+
# 2) workflow HITL(v2.0+):event.interrupted + RequestInput 信号
|
|
1561
|
+
# 仅当 adk_compat 探测到 v2.0+ 时检查,避免在 1.34 上访问不存在字段。
|
|
1562
|
+
try:
|
|
1563
|
+
from ksadk.compat.adk_compat import adk_version_at_least
|
|
1564
|
+
|
|
1565
|
+
if adk_version_at_least("2.0.0") and getattr(event, "interrupted", False):
|
|
1566
|
+
# RequestInput 信号可能挂在 actions 或 event 上(字段名跨小版本未冻结,
|
|
1567
|
+
# 用 getattr 容错,缺失即视为纯 interrupt 无 payload)。
|
|
1568
|
+
req_input = None
|
|
1569
|
+
if actions is not None:
|
|
1570
|
+
req_input = getattr(actions, "requested_input", None) or getattr(
|
|
1571
|
+
actions, "request_input", None
|
|
1572
|
+
)
|
|
1573
|
+
if req_input is None:
|
|
1574
|
+
req_input = getattr(event, "requested_input", None)
|
|
1575
|
+
interrupt_id = "adk-hitl-" + str(getattr(event, "invocation_id", "") or "unknown")
|
|
1576
|
+
signals.append(
|
|
1577
|
+
{
|
|
1578
|
+
"approval_request_id": interrupt_id,
|
|
1579
|
+
"tool_name": "RequestInput",
|
|
1580
|
+
"args": dict(getattr(req_input, "payload", None) or {}),
|
|
1581
|
+
"kind": "input",
|
|
1582
|
+
"message": str(
|
|
1583
|
+
getattr(req_input, "message", "") or "ADK workflow 请求人工输入"
|
|
1584
|
+
),
|
|
1585
|
+
}
|
|
1586
|
+
)
|
|
1587
|
+
except Exception:
|
|
1588
|
+
# 能力探测失败时不阻塞主流(审批 surface 是 best-effort,不降级为报错)。
|
|
1589
|
+
pass
|
|
1590
|
+
|
|
1591
|
+
return signals
|
|
1592
|
+
|
|
1530
1593
|
async def _maybe_write_checkpoint(
|
|
1531
1594
|
self,
|
|
1532
1595
|
*,
|
|
@@ -1573,9 +1636,10 @@ class ADKRunner(BaseRunner):
|
|
|
1573
1636
|
metadata=metadata,
|
|
1574
1637
|
)
|
|
1575
1638
|
logger.debug(
|
|
1576
|
-
"ADKRunner: wrote checkpoint adk-ckpt-%d at boundary "
|
|
1577
|
-
|
|
1578
|
-
|
|
1639
|
+
"ADKRunner: wrote checkpoint adk-ckpt-%d at boundary " "(session=%s, invocation_id=%s)",
|
|
1640
|
+
checkpoint_seq,
|
|
1641
|
+
session_id,
|
|
1642
|
+
adk_invocation_id,
|
|
1579
1643
|
)
|
|
1580
1644
|
|
|
1581
1645
|
def _extract_checkpoint_metadata(self, event: Any) -> dict[str, Any]:
|
|
@@ -1602,8 +1666,7 @@ class ADKRunner(BaseRunner):
|
|
|
1602
1666
|
|
|
1603
1667
|
# 是否可恢复
|
|
1604
1668
|
stm_backend = (
|
|
1605
|
-
getattr(self._short_term_memory, "backend", None)
|
|
1606
|
-
if self._short_term_memory else None
|
|
1669
|
+
getattr(self._short_term_memory, "backend", None) if self._short_term_memory else None
|
|
1607
1670
|
)
|
|
1608
1671
|
shared_across_pods = stm_backend == "database"
|
|
1609
1672
|
platform_resumable = self._resumable and shared_across_pods
|
|
@@ -1655,9 +1718,9 @@ class ADKRunner(BaseRunner):
|
|
|
1655
1718
|
)
|
|
1656
1719
|
if not adk_invocation_id:
|
|
1657
1720
|
logger.error(
|
|
1658
|
-
"Resume requested but ADK invocation_id not found for "
|
|
1659
|
-
|
|
1660
|
-
|
|
1721
|
+
"Resume requested but ADK invocation_id not found for " "session=%s ksadk_inv=%s",
|
|
1722
|
+
session_id,
|
|
1723
|
+
ksadk_invocation_id,
|
|
1661
1724
|
)
|
|
1662
1725
|
raise ValueError(
|
|
1663
1726
|
f"checkpoint_not_resumable: ADK invocation_id not found for "
|
|
@@ -1665,7 +1728,7 @@ class ADKRunner(BaseRunner):
|
|
|
1665
1728
|
f"The checkpoint data may have been lost or the invocation was "
|
|
1666
1729
|
f"never persisted."
|
|
1667
1730
|
)
|
|
1668
|
-
return adk_invocation_id
|
|
1731
|
+
return str(adk_invocation_id)
|
|
1669
1732
|
|
|
1670
1733
|
async def _prepare_run_events(
|
|
1671
1734
|
self,
|
|
@@ -1691,9 +1754,7 @@ class ADKRunner(BaseRunner):
|
|
|
1691
1754
|
else:
|
|
1692
1755
|
new_message = None
|
|
1693
1756
|
|
|
1694
|
-
ksadk_invocation_id = str(
|
|
1695
|
-
input_data.get("invocation_id") or input_data.get("run_id") or ""
|
|
1696
|
-
)
|
|
1757
|
+
ksadk_invocation_id = str(input_data.get("invocation_id") or input_data.get("run_id") or "")
|
|
1697
1758
|
|
|
1698
1759
|
checkpoint_run_id = (
|
|
1699
1760
|
str(input_data.get("run_id") or "").strip()
|
|
@@ -1725,6 +1786,8 @@ class ADKRunner(BaseRunner):
|
|
|
1725
1786
|
run_kwargs["new_message"] = new_message
|
|
1726
1787
|
run_kwargs["state_delta"] = self._build_state_delta(input_data) or None
|
|
1727
1788
|
|
|
1789
|
+
if self._runner is None:
|
|
1790
|
+
raise RuntimeError("ADK runner is not initialized")
|
|
1728
1791
|
events_async = self._runner.run_async(**run_kwargs)
|
|
1729
1792
|
|
|
1730
1793
|
if ksadk_invocation_id and self._resumable:
|
|
@@ -1740,7 +1803,7 @@ class ADKRunner(BaseRunner):
|
|
|
1740
1803
|
session_id=session_id,
|
|
1741
1804
|
ksadk_invocation_id=ksadk_invocation_id,
|
|
1742
1805
|
)
|
|
1743
|
-
return wrapped_async
|
|
1806
|
+
return cast(AsyncIterator[Any], wrapped_async)
|
|
1744
1807
|
|
|
1745
1808
|
async def invoke(self, input_data: Dict[str, Any]) -> Dict[str, Any]:
|
|
1746
1809
|
"""调用 ADK Agent"""
|
|
@@ -1764,9 +1827,7 @@ class ADKRunner(BaseRunner):
|
|
|
1764
1827
|
# Set input.value for Langfuse top-level input display
|
|
1765
1828
|
span.set_attribute("input.value", user_input)
|
|
1766
1829
|
truncated_input = (
|
|
1767
|
-
user_input[:200]
|
|
1768
|
-
if isinstance(user_input, str)
|
|
1769
|
-
else str(user_input)[:200]
|
|
1830
|
+
user_input[:200] if isinstance(user_input, str) else str(user_input)[:200]
|
|
1770
1831
|
)
|
|
1771
1832
|
span.set_attribute("user.input", truncated_input)
|
|
1772
1833
|
|
|
@@ -1819,7 +1880,7 @@ class ADKRunner(BaseRunner):
|
|
|
1819
1880
|
# final_response may hold only intermediate fragments.
|
|
1820
1881
|
last_event_text = ""
|
|
1821
1882
|
if last_event is not None and hasattr(last_event, "content") and last_event.content:
|
|
1822
|
-
for part in
|
|
1883
|
+
for part in last_event.content.parts or []:
|
|
1823
1884
|
is_thought = getattr(part, "thought", False)
|
|
1824
1885
|
if hasattr(part, "text") and part.text and not is_thought:
|
|
1825
1886
|
last_event_text += part.text
|
|
@@ -1835,7 +1896,10 @@ class ADKRunner(BaseRunner):
|
|
|
1835
1896
|
# Set output.value for Langfuse top-level output display
|
|
1836
1897
|
span.set_attribute("output.value", final_response[:5000] if final_response else "")
|
|
1837
1898
|
span.set_attribute("agent.output", final_response[:500] if final_response else "")
|
|
1838
|
-
result
|
|
1899
|
+
result: dict[str, Any] = {
|
|
1900
|
+
"output": final_response,
|
|
1901
|
+
"events": events_list,
|
|
1902
|
+
}
|
|
1839
1903
|
if usage:
|
|
1840
1904
|
result["usage"] = usage
|
|
1841
1905
|
# last_usage = 最后一次 LLM 调用快照(input_tokens = 当前上下文窗口占用)
|
|
@@ -1847,7 +1911,7 @@ class ADKRunner(BaseRunner):
|
|
|
1847
1911
|
|
|
1848
1912
|
使用 StreamingMode.SSE 启用真正的流式 token 输出
|
|
1849
1913
|
"""
|
|
1850
|
-
from
|
|
1914
|
+
from ksadk.compat.adk_compat import RunConfig, StreamingMode
|
|
1851
1915
|
|
|
1852
1916
|
# 判断是否为恢复调用 — 提前判断以避免将 resume_input dict 当作 string 处理
|
|
1853
1917
|
is_resume = bool(input_data.get("checkpoint_resume"))
|
|
@@ -1868,9 +1932,7 @@ class ADKRunner(BaseRunner):
|
|
|
1868
1932
|
# Set input.value for Langfuse top-level input display
|
|
1869
1933
|
span.set_attribute("input.value", user_input)
|
|
1870
1934
|
truncated_input = (
|
|
1871
|
-
user_input[:200]
|
|
1872
|
-
if isinstance(user_input, str)
|
|
1873
|
-
else str(user_input)[:200]
|
|
1935
|
+
user_input[:200] if isinstance(user_input, str) else str(user_input)[:200]
|
|
1874
1936
|
)
|
|
1875
1937
|
span.set_attribute("user.input", truncated_input)
|
|
1876
1938
|
|
|
@@ -1899,6 +1961,13 @@ class ADKRunner(BaseRunner):
|
|
|
1899
1961
|
accumulated_text = ""
|
|
1900
1962
|
usage: dict[str, Any] = {}
|
|
1901
1963
|
last_usage: dict[str, Any] = {}
|
|
1964
|
+
# handoff/sub-agent(如 RemoteA2aAgent)回复事件 partial=None,不进上面
|
|
1965
|
+
# partial 分支;且远端 agent 经 A2A 流式返回时,ADK 会产出多个"累积快照"
|
|
1966
|
+
# 事件(后一个含前一个内容)。按 author 记录已输出快照,只补发增量去重。
|
|
1967
|
+
sub_agent_snapshots: dict[str, str] = {}
|
|
1968
|
+
sub_agent_thought_snapshots: dict[str, str] = {}
|
|
1969
|
+
sub_agent_last_output_kind: dict[str, str] = {}
|
|
1970
|
+
top_agent_name = getattr(self._agent, "name", None)
|
|
1902
1971
|
|
|
1903
1972
|
async for event in wrapped_async:
|
|
1904
1973
|
event_usage = self._extract_event_usage(event)
|
|
@@ -1908,15 +1977,137 @@ class ADKRunner(BaseRunner):
|
|
|
1908
1977
|
# Only yield text delta if event is partial to avoid duplication of final summary
|
|
1909
1978
|
if hasattr(event, "content") and event.content and getattr(event, "partial", False):
|
|
1910
1979
|
if hasattr(event.content, "parts"):
|
|
1980
|
+
author = getattr(event, "author", None)
|
|
1981
|
+
is_sub_agent = bool(author and top_agent_name and author != top_agent_name)
|
|
1982
|
+
author_key = str(author)
|
|
1911
1983
|
for part in event.content.parts:
|
|
1912
1984
|
if hasattr(part, "text") and part.text:
|
|
1913
1985
|
is_thought = getattr(part, "thought", False)
|
|
1914
|
-
|
|
1986
|
+
replace_snapshot = bool(
|
|
1987
|
+
is_sub_agent
|
|
1988
|
+
and _part_metadata_flag(part, "ksadk_output_snapshot")
|
|
1989
|
+
)
|
|
1990
|
+
output_delta = part.text
|
|
1991
|
+
# 思考内容只作为 thinking delta 流出,不计入最终输出,
|
|
1992
|
+
# 否则最终回复会把思考过程再重复一遍(与 invoke() 语义对齐)。
|
|
1993
|
+
if is_thought and is_sub_agent:
|
|
1994
|
+
if sub_agent_last_output_kind.get(author_key) == "text":
|
|
1995
|
+
# 正文之后的 thought 是一个新的 reasoning segment。
|
|
1996
|
+
sub_agent_thought_snapshots[author_key] = ""
|
|
1997
|
+
previous_thought = sub_agent_thought_snapshots.get(
|
|
1998
|
+
author_key, ""
|
|
1999
|
+
)
|
|
2000
|
+
if part.text.startswith(previous_thought):
|
|
2001
|
+
output_delta = part.text[len(previous_thought) :]
|
|
2002
|
+
sub_agent_thought_snapshots[author_key] = part.text
|
|
2003
|
+
else:
|
|
2004
|
+
sub_agent_thought_snapshots[author_key] = (
|
|
2005
|
+
previous_thought + part.text
|
|
2006
|
+
)
|
|
2007
|
+
elif not is_thought:
|
|
2008
|
+
accumulated_text = (
|
|
2009
|
+
part.text
|
|
2010
|
+
if replace_snapshot
|
|
2011
|
+
else accumulated_text + part.text
|
|
2012
|
+
)
|
|
2013
|
+
# sub-agent(RemoteA2aAgent)增量也累积进快照,供后续
|
|
2014
|
+
# completed 全文消息(同一份结果)在 handoff 分支去重。
|
|
2015
|
+
if is_sub_agent:
|
|
2016
|
+
sub_agent_snapshots[author_key] = (
|
|
2017
|
+
part.text
|
|
2018
|
+
if replace_snapshot
|
|
2019
|
+
else sub_agent_snapshots.get(author_key, "") + part.text
|
|
2020
|
+
)
|
|
1915
2021
|
# 标记思考内容,前端可以选择是否展示
|
|
1916
|
-
|
|
1917
|
-
|
|
1918
|
-
|
|
1919
|
-
|
|
2022
|
+
if output_delta:
|
|
2023
|
+
output_chunk: dict[str, Any] = {
|
|
2024
|
+
"delta": output_delta,
|
|
2025
|
+
"type": "thinking" if is_thought else "text",
|
|
2026
|
+
}
|
|
2027
|
+
if replace_snapshot and not is_thought:
|
|
2028
|
+
output_chunk["replace"] = True
|
|
2029
|
+
yield output_chunk
|
|
2030
|
+
if is_sub_agent:
|
|
2031
|
+
sub_agent_last_output_kind[author_key] = (
|
|
2032
|
+
"thinking" if is_thought else "text"
|
|
2033
|
+
)
|
|
2034
|
+
# handoff/sub-agent 回复:partial 为 None/False,上面分支跳过,这里补上。
|
|
2035
|
+
elif hasattr(event, "content") and event.content:
|
|
2036
|
+
author = getattr(event, "author", None)
|
|
2037
|
+
if (
|
|
2038
|
+
author
|
|
2039
|
+
and top_agent_name
|
|
2040
|
+
and author != top_agent_name
|
|
2041
|
+
and hasattr(event.content, "parts")
|
|
2042
|
+
):
|
|
2043
|
+
author_key = str(author)
|
|
2044
|
+
for part in event.content.parts:
|
|
2045
|
+
if (
|
|
2046
|
+
hasattr(part, "text")
|
|
2047
|
+
and part.text
|
|
2048
|
+
and getattr(part, "thought", False)
|
|
2049
|
+
):
|
|
2050
|
+
# A2A's terminal artifact is converted by ADK to
|
|
2051
|
+
# partial=False. Once that sub-agent has already
|
|
2052
|
+
# emitted response text, a trailing thought here is
|
|
2053
|
+
# a terminal snapshot/replacement (not a new
|
|
2054
|
+
# interleaved reasoning step). Showing it makes
|
|
2055
|
+
# the UI appear to end at "thinking" and hides the
|
|
2056
|
+
# just-emitted final response.
|
|
2057
|
+
if sub_agent_last_output_kind.get(author_key) == "text":
|
|
2058
|
+
continue
|
|
2059
|
+
# RemoteA2aAgent 将 last_chunk=True 映射成
|
|
2060
|
+
# partial=False;这可能是一个此前 partial thought
|
|
2061
|
+
# 的终态快照。只补发新增内容,避免正文之后再显示一遍
|
|
2062
|
+
# 相同的思考块;若此前没有 partial thought,仍完整透传。
|
|
2063
|
+
previous_thought = sub_agent_thought_snapshots.get(
|
|
2064
|
+
author_key, ""
|
|
2065
|
+
)
|
|
2066
|
+
if part.text.startswith(previous_thought):
|
|
2067
|
+
thought_delta = part.text[len(previous_thought) :]
|
|
2068
|
+
sub_agent_thought_snapshots[author_key] = part.text
|
|
2069
|
+
elif previous_thought.startswith(part.text):
|
|
2070
|
+
thought_delta = ""
|
|
2071
|
+
else:
|
|
2072
|
+
thought_delta = part.text
|
|
2073
|
+
sub_agent_thought_snapshots[author_key] = (
|
|
2074
|
+
previous_thought + part.text
|
|
2075
|
+
)
|
|
2076
|
+
if thought_delta:
|
|
2077
|
+
yield {"delta": thought_delta, "type": "thinking"}
|
|
2078
|
+
snapshot = ""
|
|
2079
|
+
replace_snapshot = False
|
|
2080
|
+
for part in event.content.parts:
|
|
2081
|
+
if hasattr(part, "text") and part.text and not getattr(
|
|
2082
|
+
part, "thought", False
|
|
2083
|
+
):
|
|
2084
|
+
snapshot += part.text
|
|
2085
|
+
replace_snapshot = replace_snapshot or _part_metadata_flag(
|
|
2086
|
+
part,
|
|
2087
|
+
"ksadk_output_snapshot",
|
|
2088
|
+
)
|
|
2089
|
+
if snapshot:
|
|
2090
|
+
prev = sub_agent_snapshots.get(author_key, "")
|
|
2091
|
+
if replace_snapshot:
|
|
2092
|
+
delta = snapshot
|
|
2093
|
+
sub_agent_snapshots[author_key] = snapshot
|
|
2094
|
+
accumulated_text = snapshot
|
|
2095
|
+
elif snapshot.startswith(prev):
|
|
2096
|
+
# 累计快照(如 completed 全文):只补发超出已累积的部分;
|
|
2097
|
+
# 若增量已发全,delta 为空,避免 completed 再渲染一遍。
|
|
2098
|
+
delta = snapshot[len(prev) :]
|
|
2099
|
+
sub_agent_snapshots[author_key] = snapshot
|
|
2100
|
+
else:
|
|
2101
|
+
# final 增量(小块):追加进累积,不覆盖。
|
|
2102
|
+
delta = snapshot
|
|
2103
|
+
sub_agent_snapshots[author_key] = prev + snapshot
|
|
2104
|
+
if delta:
|
|
2105
|
+
if not replace_snapshot:
|
|
2106
|
+
accumulated_text += delta
|
|
2107
|
+
output_chunk = {"delta": delta, "type": "text"}
|
|
2108
|
+
if replace_snapshot:
|
|
2109
|
+
output_chunk["replace"] = True
|
|
2110
|
+
yield output_chunk
|
|
1920
2111
|
|
|
1921
2112
|
# 处理工具调用事件 — ADK 通过 event.content.parts[].function_call
|
|
1922
2113
|
# 发出工具调用(即 event.get_function_calls()),而非
|
|
@@ -1935,6 +2126,7 @@ class ADKRunner(BaseRunner):
|
|
|
1935
2126
|
if not isinstance(fc_args, dict):
|
|
1936
2127
|
try:
|
|
1937
2128
|
import json as _json
|
|
2129
|
+
|
|
1938
2130
|
fc_args = _json.loads(fc_args) if isinstance(fc_args, str) else {}
|
|
1939
2131
|
except Exception:
|
|
1940
2132
|
fc_args = {}
|
|
@@ -1958,6 +2150,21 @@ class ADKRunner(BaseRunner):
|
|
|
1958
2150
|
"tool_args": getattr(tool_call, "input", {}),
|
|
1959
2151
|
}
|
|
1960
2152
|
|
|
2153
|
+
# ADK 原生审批 surface(tool-confirmation + v2.0 workflow HITL):
|
|
2154
|
+
# 翻译成统一 interrupt chunk,经 runtime:4645 既有 approval_request 通道
|
|
2155
|
+
# 消费 → 审批卡。能力探测兼容 1.34.x→2.x,缺字段则跳过。
|
|
2156
|
+
emitted_approval_ids: set[str] = set()
|
|
2157
|
+
for signal in self._extract_approval_signals(event):
|
|
2158
|
+
aid = signal.get("approval_request_id", "")
|
|
2159
|
+
if not aid or aid in emitted_approval_ids:
|
|
2160
|
+
continue
|
|
2161
|
+
emitted_approval_ids.add(aid)
|
|
2162
|
+
yield {
|
|
2163
|
+
"type": "interrupt",
|
|
2164
|
+
"interrupt_info": signal,
|
|
2165
|
+
"session_id": session_id,
|
|
2166
|
+
}
|
|
2167
|
+
|
|
1961
2168
|
# 处理工具返回结果 — ADK 通过 event.content.parts[].function_response
|
|
1962
2169
|
# 发出工具执行结果。当工具执行完毕后 ADK 会产生一个包含
|
|
1963
2170
|
# function_response 的事件,此处将其转为 tool_result 语义事件,
|
|
@@ -1971,6 +2178,7 @@ class ADKRunner(BaseRunner):
|
|
|
1971
2178
|
if not isinstance(fr_output, dict):
|
|
1972
2179
|
try:
|
|
1973
2180
|
import json as _json2
|
|
2181
|
+
|
|
1974
2182
|
if isinstance(fr_output, str):
|
|
1975
2183
|
fr_output = _json2.loads(fr_output)
|
|
1976
2184
|
else:
|