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
|
@@ -0,0 +1,700 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import json
|
|
4
|
+
import time
|
|
5
|
+
import uuid
|
|
6
|
+
from typing import Any, AsyncIterator, Callable, Dict, Mapping, Optional, Sequence
|
|
7
|
+
|
|
8
|
+
from ksadk.conversations.run_kinds import (
|
|
9
|
+
RUN_MODE_FOREGROUND,
|
|
10
|
+
)
|
|
11
|
+
from ksadk.conversations.runtime_invocation import _response_sse
|
|
12
|
+
from ksadk.conversations.runtime_payloads import (
|
|
13
|
+
build_compaction_sse_event,
|
|
14
|
+
build_responses_payload,
|
|
15
|
+
)
|
|
16
|
+
from ksadk.conversations.runtime_stream_events import _iter_conversation_turn_events
|
|
17
|
+
from ksadk.runtime.conversation_execution import iter_runtime_conversation_semantic_events
|
|
18
|
+
from ksadk.runtime.executor import RuntimeExecutor, RuntimeStartPreparation
|
|
19
|
+
from ksadk.runtime.launch import RuntimeLaunchContext
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
async def stream_conversation_turn(
|
|
23
|
+
*,
|
|
24
|
+
runner: Any,
|
|
25
|
+
agent_id: str,
|
|
26
|
+
user_id: str,
|
|
27
|
+
session_id: Optional[str],
|
|
28
|
+
messages: Sequence[Dict[str, Any]],
|
|
29
|
+
model: Optional[str],
|
|
30
|
+
prepare_runner: Callable[[Any, Optional[str]], None],
|
|
31
|
+
model_metadata: Mapping[str, Any] | None = None,
|
|
32
|
+
model_options: Mapping[str, Any] | None = None,
|
|
33
|
+
state_delta: Optional[dict[str, Any]] = None,
|
|
34
|
+
instructions: Optional[str] = None,
|
|
35
|
+
request_metadata: Mapping[str, Any] | None = None,
|
|
36
|
+
custom_metadata: Mapping[str, Any] | None = None,
|
|
37
|
+
resume_input: Mapping[str, Any] | None = None,
|
|
38
|
+
account_id: str | None = None,
|
|
39
|
+
invocation_id: Optional[str] = None,
|
|
40
|
+
session_service_provider: Callable[[], Any] | None = None,
|
|
41
|
+
run_mode: str = RUN_MODE_FOREGROUND,
|
|
42
|
+
) -> AsyncIterator[str]:
|
|
43
|
+
"""Legacy ksadk response SSE stream used by hosted chat and chat-completions."""
|
|
44
|
+
events = _iter_conversation_turn_events(
|
|
45
|
+
runner=runner,
|
|
46
|
+
agent_id=agent_id,
|
|
47
|
+
user_id=user_id,
|
|
48
|
+
session_id=session_id,
|
|
49
|
+
messages=messages,
|
|
50
|
+
model=model,
|
|
51
|
+
prepare_runner=prepare_runner,
|
|
52
|
+
model_metadata=model_metadata,
|
|
53
|
+
model_options=model_options,
|
|
54
|
+
state_delta=state_delta,
|
|
55
|
+
instructions=instructions,
|
|
56
|
+
request_metadata=request_metadata,
|
|
57
|
+
custom_metadata=custom_metadata,
|
|
58
|
+
resume_input=resume_input,
|
|
59
|
+
account_id=account_id,
|
|
60
|
+
invocation_id=invocation_id,
|
|
61
|
+
session_service_provider=session_service_provider,
|
|
62
|
+
run_mode=run_mode,
|
|
63
|
+
)
|
|
64
|
+
async for chunk in _stream_conversation_semantic_events(
|
|
65
|
+
events=events,
|
|
66
|
+
model=model,
|
|
67
|
+
session_id=session_id,
|
|
68
|
+
):
|
|
69
|
+
yield chunk
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
async def stream_runtime_conversation_turn(
|
|
73
|
+
*,
|
|
74
|
+
executor: RuntimeExecutor,
|
|
75
|
+
launch_context: RuntimeLaunchContext,
|
|
76
|
+
agent_id: str,
|
|
77
|
+
user_id: str,
|
|
78
|
+
messages: Sequence[Dict[str, Any]],
|
|
79
|
+
session_id: Optional[str],
|
|
80
|
+
model: Optional[str],
|
|
81
|
+
model_metadata: Mapping[str, Any] | None = None,
|
|
82
|
+
model_options: Mapping[str, Any] | None = None,
|
|
83
|
+
state_delta: Optional[dict[str, Any]] = None,
|
|
84
|
+
instructions: Optional[str] = None,
|
|
85
|
+
request_metadata: Mapping[str, Any] | None = None,
|
|
86
|
+
custom_metadata: Mapping[str, Any] | None = None,
|
|
87
|
+
resume_input: Mapping[str, Any] | None = None,
|
|
88
|
+
account_id: str | None = None,
|
|
89
|
+
invocation_id: Optional[str] = None,
|
|
90
|
+
session_service_provider: Callable[[], Any] | None = None,
|
|
91
|
+
run_mode: str = RUN_MODE_FOREGROUND,
|
|
92
|
+
runtime_preparation: RuntimeStartPreparation | None = None,
|
|
93
|
+
) -> AsyncIterator[str]:
|
|
94
|
+
"""Legacy hosted-chat SSE driven by the canonical RuntimeExecutor."""
|
|
95
|
+
|
|
96
|
+
events = iter_runtime_conversation_semantic_events(
|
|
97
|
+
executor=executor,
|
|
98
|
+
launch_context=launch_context,
|
|
99
|
+
agent_id=agent_id,
|
|
100
|
+
user_id=user_id,
|
|
101
|
+
messages=messages,
|
|
102
|
+
session_id=session_id,
|
|
103
|
+
model=model,
|
|
104
|
+
model_metadata=model_metadata,
|
|
105
|
+
model_options=model_options,
|
|
106
|
+
state_delta=state_delta,
|
|
107
|
+
instructions=instructions,
|
|
108
|
+
request_metadata=request_metadata,
|
|
109
|
+
custom_metadata=custom_metadata,
|
|
110
|
+
resume_input=resume_input,
|
|
111
|
+
account_id=account_id,
|
|
112
|
+
invocation_id=invocation_id,
|
|
113
|
+
session_service_provider=session_service_provider,
|
|
114
|
+
run_mode=run_mode,
|
|
115
|
+
runtime_preparation=runtime_preparation,
|
|
116
|
+
)
|
|
117
|
+
async for chunk in _stream_conversation_semantic_events(
|
|
118
|
+
events=events,
|
|
119
|
+
model=model,
|
|
120
|
+
session_id=session_id,
|
|
121
|
+
):
|
|
122
|
+
yield chunk
|
|
123
|
+
|
|
124
|
+
|
|
125
|
+
async def _stream_conversation_semantic_events(
|
|
126
|
+
*,
|
|
127
|
+
events: AsyncIterator[dict[str, Any]],
|
|
128
|
+
model: Optional[str],
|
|
129
|
+
session_id: Optional[str],
|
|
130
|
+
) -> AsyncIterator[str]:
|
|
131
|
+
async for event in events:
|
|
132
|
+
event_type = event.get("type")
|
|
133
|
+
if event_type == "compaction":
|
|
134
|
+
yield build_compaction_sse_event(
|
|
135
|
+
phase=str(event.get("phase") or "start"),
|
|
136
|
+
trigger=str(event.get("trigger") or "auto"),
|
|
137
|
+
compacted_until_seq_id=event.get("compacted_until_seq_id"),
|
|
138
|
+
total_chars=event.get("total_chars"),
|
|
139
|
+
total_estimated_tokens=event.get("total_estimated_tokens"),
|
|
140
|
+
group_count=event.get("group_count"),
|
|
141
|
+
threshold_percentage=event.get("threshold_percentage"),
|
|
142
|
+
)
|
|
143
|
+
elif event_type == "thinking":
|
|
144
|
+
yield _response_sse("response.reasoning.delta", {"delta": event.get("delta", "")})
|
|
145
|
+
elif event_type == "text":
|
|
146
|
+
text_payload: dict[str, Any] = {"delta": event.get("delta", "")}
|
|
147
|
+
if event.get("replace"):
|
|
148
|
+
text_payload["replace"] = True
|
|
149
|
+
yield _response_sse("response.output_text.delta", text_payload)
|
|
150
|
+
elif event_type == "tool_call":
|
|
151
|
+
yield _response_sse(
|
|
152
|
+
"response.tool_call",
|
|
153
|
+
{
|
|
154
|
+
"name": event.get("name"),
|
|
155
|
+
"args": event.get("args", {}),
|
|
156
|
+
"run_id": event.get("run_id"),
|
|
157
|
+
"stage": event.get("stage"),
|
|
158
|
+
"event_kind": event.get("event_kind"),
|
|
159
|
+
"display_title": event.get("display_title"),
|
|
160
|
+
"display_summary": event.get("display_summary"),
|
|
161
|
+
},
|
|
162
|
+
)
|
|
163
|
+
elif event_type == "tool_result":
|
|
164
|
+
yield _response_sse(
|
|
165
|
+
"response.tool_result",
|
|
166
|
+
{
|
|
167
|
+
"name": event.get("name"),
|
|
168
|
+
"output": event.get("output", ""),
|
|
169
|
+
"run_id": event.get("run_id"),
|
|
170
|
+
},
|
|
171
|
+
)
|
|
172
|
+
elif event_type in {"stage_tool_call", "stage_tool_result"}:
|
|
173
|
+
yield _response_sse(
|
|
174
|
+
f"response.ksadk.{event_type}",
|
|
175
|
+
{
|
|
176
|
+
"type": event_type,
|
|
177
|
+
"name": event.get("name"),
|
|
178
|
+
"args": event.get("args", {}),
|
|
179
|
+
"output": event.get("output", ""),
|
|
180
|
+
"run_id": event.get("run_id"),
|
|
181
|
+
"stage": event.get("stage"),
|
|
182
|
+
"event_kind": event.get("event_kind"),
|
|
183
|
+
"display_title": event.get("display_title"),
|
|
184
|
+
"display_summary": event.get("display_summary"),
|
|
185
|
+
},
|
|
186
|
+
)
|
|
187
|
+
elif event_type == "interrupt":
|
|
188
|
+
yield _response_sse(
|
|
189
|
+
"response.approval_request", {"interrupt_info": event.get("interrupt_info")}
|
|
190
|
+
)
|
|
191
|
+
elif event_type == "error":
|
|
192
|
+
yield _response_sse(
|
|
193
|
+
"response.error", {"message": event.get("message") or "Agent 运行失败"}
|
|
194
|
+
)
|
|
195
|
+
elif event_type == "cancelled":
|
|
196
|
+
yield _response_sse("response.cancelled", {"status": "cancelled"})
|
|
197
|
+
elif event_type == "completed":
|
|
198
|
+
final_payload = build_responses_payload(
|
|
199
|
+
output_text=str(event.get("output_text") or ""),
|
|
200
|
+
model=event.get("model") or model,
|
|
201
|
+
session_id=str(event.get("session_id") or session_id or ""),
|
|
202
|
+
metadata=(
|
|
203
|
+
event.get("metadata") if isinstance(event.get("metadata"), Mapping) else None
|
|
204
|
+
),
|
|
205
|
+
usage=event.get("usage") if isinstance(event.get("usage"), Mapping) else None,
|
|
206
|
+
)
|
|
207
|
+
yield _response_sse("response.completed", final_payload)
|
|
208
|
+
|
|
209
|
+
|
|
210
|
+
async def stream_responses_conversation_turn(
|
|
211
|
+
*,
|
|
212
|
+
runner: Any,
|
|
213
|
+
agent_id: str,
|
|
214
|
+
user_id: str,
|
|
215
|
+
session_id: Optional[str],
|
|
216
|
+
messages: Sequence[Dict[str, Any]],
|
|
217
|
+
model: Optional[str],
|
|
218
|
+
prepare_runner: Callable[[Any, Optional[str]], None],
|
|
219
|
+
model_metadata: Mapping[str, Any] | None = None,
|
|
220
|
+
model_options: Mapping[str, Any] | None = None,
|
|
221
|
+
state_delta: Optional[dict[str, Any]] = None,
|
|
222
|
+
instructions: Optional[str] = None,
|
|
223
|
+
request_metadata: Mapping[str, Any] | None = None,
|
|
224
|
+
custom_metadata: Mapping[str, Any] | None = None,
|
|
225
|
+
include_agentengine_metadata: bool = False,
|
|
226
|
+
resume_input: Mapping[str, Any] | None = None,
|
|
227
|
+
account_id: str | None = None,
|
|
228
|
+
invocation_id: Optional[str] = None,
|
|
229
|
+
session_service_provider: Callable[[], Any] | None = None,
|
|
230
|
+
run_mode: str = RUN_MODE_FOREGROUND,
|
|
231
|
+
) -> AsyncIterator[str]:
|
|
232
|
+
"""OpenAI Responses-style SSE stream."""
|
|
233
|
+
response_id = f"resp_{uuid.uuid4().hex}"
|
|
234
|
+
events = _iter_conversation_turn_events(
|
|
235
|
+
runner=runner,
|
|
236
|
+
agent_id=agent_id,
|
|
237
|
+
user_id=user_id,
|
|
238
|
+
session_id=session_id,
|
|
239
|
+
messages=messages,
|
|
240
|
+
model=model,
|
|
241
|
+
prepare_runner=prepare_runner,
|
|
242
|
+
model_metadata=model_metadata,
|
|
243
|
+
model_options=model_options,
|
|
244
|
+
state_delta=state_delta,
|
|
245
|
+
instructions=instructions,
|
|
246
|
+
request_metadata=request_metadata,
|
|
247
|
+
custom_metadata=custom_metadata,
|
|
248
|
+
resume_input=resume_input,
|
|
249
|
+
response_id=response_id,
|
|
250
|
+
account_id=account_id,
|
|
251
|
+
invocation_id=invocation_id,
|
|
252
|
+
session_service_provider=session_service_provider,
|
|
253
|
+
run_mode=run_mode,
|
|
254
|
+
)
|
|
255
|
+
async for chunk in _stream_responses_semantic_events(
|
|
256
|
+
events=events,
|
|
257
|
+
model=model,
|
|
258
|
+
session_id=session_id,
|
|
259
|
+
custom_metadata=custom_metadata,
|
|
260
|
+
include_agentengine_metadata=include_agentengine_metadata,
|
|
261
|
+
response_id=response_id,
|
|
262
|
+
):
|
|
263
|
+
yield chunk
|
|
264
|
+
|
|
265
|
+
|
|
266
|
+
async def stream_runtime_responses_conversation_turn(
|
|
267
|
+
*,
|
|
268
|
+
executor: RuntimeExecutor,
|
|
269
|
+
launch_context: RuntimeLaunchContext,
|
|
270
|
+
agent_id: str,
|
|
271
|
+
user_id: str,
|
|
272
|
+
messages: Sequence[Dict[str, Any]],
|
|
273
|
+
session_id: Optional[str],
|
|
274
|
+
model: Optional[str],
|
|
275
|
+
model_metadata: Mapping[str, Any] | None = None,
|
|
276
|
+
model_options: Mapping[str, Any] | None = None,
|
|
277
|
+
state_delta: Optional[dict[str, Any]] = None,
|
|
278
|
+
instructions: Optional[str] = None,
|
|
279
|
+
request_metadata: Mapping[str, Any] | None = None,
|
|
280
|
+
custom_metadata: Mapping[str, Any] | None = None,
|
|
281
|
+
include_agentengine_metadata: bool = False,
|
|
282
|
+
resume_input: Mapping[str, Any] | None = None,
|
|
283
|
+
account_id: str | None = None,
|
|
284
|
+
invocation_id: Optional[str] = None,
|
|
285
|
+
session_service_provider: Callable[[], Any] | None = None,
|
|
286
|
+
run_mode: str = RUN_MODE_FOREGROUND,
|
|
287
|
+
runtime_preparation: RuntimeStartPreparation | None = None,
|
|
288
|
+
) -> AsyncIterator[str]:
|
|
289
|
+
"""OpenAI Responses SSE driven by the canonical RuntimeExecutor."""
|
|
290
|
+
|
|
291
|
+
response_id = f"resp_{uuid.uuid4().hex}"
|
|
292
|
+
events = iter_runtime_conversation_semantic_events(
|
|
293
|
+
executor=executor,
|
|
294
|
+
launch_context=launch_context,
|
|
295
|
+
agent_id=agent_id,
|
|
296
|
+
user_id=user_id,
|
|
297
|
+
messages=messages,
|
|
298
|
+
session_id=session_id,
|
|
299
|
+
model=model,
|
|
300
|
+
model_metadata=model_metadata,
|
|
301
|
+
model_options=model_options,
|
|
302
|
+
state_delta=state_delta,
|
|
303
|
+
instructions=instructions,
|
|
304
|
+
request_metadata=request_metadata,
|
|
305
|
+
custom_metadata=custom_metadata,
|
|
306
|
+
resume_input=resume_input,
|
|
307
|
+
response_id=response_id,
|
|
308
|
+
account_id=account_id,
|
|
309
|
+
invocation_id=invocation_id,
|
|
310
|
+
session_service_provider=session_service_provider,
|
|
311
|
+
run_mode=run_mode,
|
|
312
|
+
runtime_preparation=runtime_preparation,
|
|
313
|
+
)
|
|
314
|
+
async for chunk in _stream_responses_semantic_events(
|
|
315
|
+
events=events,
|
|
316
|
+
model=model,
|
|
317
|
+
session_id=session_id,
|
|
318
|
+
custom_metadata=custom_metadata,
|
|
319
|
+
include_agentengine_metadata=include_agentengine_metadata,
|
|
320
|
+
response_id=response_id,
|
|
321
|
+
):
|
|
322
|
+
yield chunk
|
|
323
|
+
|
|
324
|
+
|
|
325
|
+
async def _stream_responses_semantic_events(
|
|
326
|
+
*,
|
|
327
|
+
events: AsyncIterator[dict[str, Any]],
|
|
328
|
+
model: Optional[str],
|
|
329
|
+
session_id: Optional[str],
|
|
330
|
+
custom_metadata: Mapping[str, Any] | None,
|
|
331
|
+
include_agentengine_metadata: bool,
|
|
332
|
+
response_id: str,
|
|
333
|
+
) -> AsyncIterator[str]:
|
|
334
|
+
"""Serialize one semantic event stream into the Responses wire format."""
|
|
335
|
+
|
|
336
|
+
created_at = int(time.time())
|
|
337
|
+
response_metadata = dict(custom_metadata or {})
|
|
338
|
+
|
|
339
|
+
message_item_id = f"msg_{uuid.uuid4().hex[:12]}"
|
|
340
|
+
reasoning_item_id = f"rs_{uuid.uuid4().hex[:12]}"
|
|
341
|
+
next_output_index = 0
|
|
342
|
+
text_output_index: int | None = None
|
|
343
|
+
reasoning_output_index: int | None = None
|
|
344
|
+
message_started = False
|
|
345
|
+
content_started = False
|
|
346
|
+
reasoning_started = False
|
|
347
|
+
completed_text = ""
|
|
348
|
+
lifecycle_started = False
|
|
349
|
+
|
|
350
|
+
def _start_response_lifecycle(current_session_id: str | None = None) -> list[str]:
|
|
351
|
+
nonlocal lifecycle_started, response_metadata
|
|
352
|
+
if lifecycle_started:
|
|
353
|
+
return []
|
|
354
|
+
lifecycle_started = True
|
|
355
|
+
initial_payload = build_responses_payload(
|
|
356
|
+
output_text="",
|
|
357
|
+
model=model,
|
|
358
|
+
session_id=current_session_id or session_id or "",
|
|
359
|
+
response_id=response_id,
|
|
360
|
+
created_at=created_at,
|
|
361
|
+
status="in_progress",
|
|
362
|
+
metadata=response_metadata,
|
|
363
|
+
)
|
|
364
|
+
return [
|
|
365
|
+
_response_sse("response.created", initial_payload),
|
|
366
|
+
_response_sse("response.in_progress", initial_payload),
|
|
367
|
+
]
|
|
368
|
+
|
|
369
|
+
def _message_item(status: str, text: str = "") -> dict[str, Any]:
|
|
370
|
+
content = [{"type": "output_text", "text": text}] if text or status == "completed" else []
|
|
371
|
+
return {
|
|
372
|
+
"id": message_item_id,
|
|
373
|
+
"type": "message",
|
|
374
|
+
"status": status,
|
|
375
|
+
"role": "assistant",
|
|
376
|
+
"content": content,
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
def _reasoning_item(status: str) -> dict[str, Any]:
|
|
380
|
+
return {
|
|
381
|
+
"id": reasoning_item_id,
|
|
382
|
+
"type": "reasoning",
|
|
383
|
+
"status": status,
|
|
384
|
+
"summary": [],
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
def _next_output_index() -> int:
|
|
388
|
+
nonlocal next_output_index
|
|
389
|
+
output_index = next_output_index
|
|
390
|
+
next_output_index += 1
|
|
391
|
+
return output_index
|
|
392
|
+
|
|
393
|
+
async for event in events:
|
|
394
|
+
if include_agentengine_metadata:
|
|
395
|
+
event_metadata = event.get("metadata")
|
|
396
|
+
agentengine_metadata = (
|
|
397
|
+
event_metadata.get("agentengine") if isinstance(event_metadata, Mapping) else None
|
|
398
|
+
)
|
|
399
|
+
if isinstance(agentengine_metadata, Mapping):
|
|
400
|
+
response_metadata["agentengine"] = dict(agentengine_metadata)
|
|
401
|
+
if not lifecycle_started:
|
|
402
|
+
for lifecycle_chunk in _start_response_lifecycle(str(event.get("session_id") or "")):
|
|
403
|
+
yield lifecycle_chunk
|
|
404
|
+
event_type = event.get("type")
|
|
405
|
+
if event_type == "compaction":
|
|
406
|
+
yield build_compaction_sse_event(
|
|
407
|
+
phase=str(event.get("phase") or "start"),
|
|
408
|
+
trigger=str(event.get("trigger") or "auto"),
|
|
409
|
+
compacted_until_seq_id=event.get("compacted_until_seq_id"),
|
|
410
|
+
total_chars=event.get("total_chars"),
|
|
411
|
+
total_estimated_tokens=event.get("total_estimated_tokens"),
|
|
412
|
+
group_count=event.get("group_count"),
|
|
413
|
+
threshold_percentage=event.get("threshold_percentage"),
|
|
414
|
+
)
|
|
415
|
+
continue
|
|
416
|
+
|
|
417
|
+
if event_type == "thinking":
|
|
418
|
+
if not reasoning_started:
|
|
419
|
+
reasoning_started = True
|
|
420
|
+
reasoning_output_index = _next_output_index()
|
|
421
|
+
yield _response_sse(
|
|
422
|
+
"response.output_item.added",
|
|
423
|
+
{
|
|
424
|
+
"output_index": reasoning_output_index,
|
|
425
|
+
"item": _reasoning_item("in_progress"),
|
|
426
|
+
},
|
|
427
|
+
)
|
|
428
|
+
yield _response_sse(
|
|
429
|
+
"response.reasoning.delta",
|
|
430
|
+
{
|
|
431
|
+
"item_id": reasoning_item_id,
|
|
432
|
+
"output_index": reasoning_output_index,
|
|
433
|
+
"delta": event.get("delta", ""),
|
|
434
|
+
},
|
|
435
|
+
)
|
|
436
|
+
continue
|
|
437
|
+
|
|
438
|
+
if event_type == "text":
|
|
439
|
+
if not message_started:
|
|
440
|
+
message_started = True
|
|
441
|
+
text_output_index = _next_output_index()
|
|
442
|
+
yield _response_sse(
|
|
443
|
+
"response.output_item.added",
|
|
444
|
+
{"output_index": text_output_index, "item": _message_item("in_progress")},
|
|
445
|
+
)
|
|
446
|
+
if not content_started:
|
|
447
|
+
content_started = True
|
|
448
|
+
yield _response_sse(
|
|
449
|
+
"response.content_part.added",
|
|
450
|
+
{
|
|
451
|
+
"item_id": message_item_id,
|
|
452
|
+
"output_index": text_output_index,
|
|
453
|
+
"content_index": 0,
|
|
454
|
+
"part": {"type": "output_text", "text": ""},
|
|
455
|
+
},
|
|
456
|
+
)
|
|
457
|
+
delta = str(event.get("delta") or "")
|
|
458
|
+
replace = bool(event.get("replace"))
|
|
459
|
+
completed_text = delta if replace else completed_text + delta
|
|
460
|
+
text_delta_payload: dict[str, Any] = {
|
|
461
|
+
"item_id": message_item_id,
|
|
462
|
+
"output_index": text_output_index,
|
|
463
|
+
"content_index": 0,
|
|
464
|
+
"delta": delta,
|
|
465
|
+
}
|
|
466
|
+
if replace:
|
|
467
|
+
text_delta_payload["replace"] = True
|
|
468
|
+
yield _response_sse(
|
|
469
|
+
"response.output_text.delta",
|
|
470
|
+
text_delta_payload,
|
|
471
|
+
)
|
|
472
|
+
continue
|
|
473
|
+
|
|
474
|
+
if event_type == "tool_call":
|
|
475
|
+
args_json = json.dumps(event.get("args", {}) or {}, ensure_ascii=False)
|
|
476
|
+
call_id = str(event.get("run_id") or f"call_{uuid.uuid4().hex[:12]}")
|
|
477
|
+
item_id = f"fc_{uuid.uuid4().hex[:12]}"
|
|
478
|
+
call_output_index = _next_output_index()
|
|
479
|
+
item = {
|
|
480
|
+
"id": item_id,
|
|
481
|
+
"type": "function_call",
|
|
482
|
+
"status": "in_progress",
|
|
483
|
+
"call_id": call_id,
|
|
484
|
+
"name": event.get("name") or "unknown",
|
|
485
|
+
"arguments": "",
|
|
486
|
+
}
|
|
487
|
+
yield _response_sse(
|
|
488
|
+
"response.output_item.added", {"output_index": call_output_index, "item": item}
|
|
489
|
+
)
|
|
490
|
+
yield _response_sse(
|
|
491
|
+
"response.function_call_arguments.delta",
|
|
492
|
+
{"item_id": item_id, "output_index": call_output_index, "delta": args_json},
|
|
493
|
+
)
|
|
494
|
+
item["arguments"] = args_json
|
|
495
|
+
item["status"] = "completed"
|
|
496
|
+
yield _response_sse(
|
|
497
|
+
"response.function_call_arguments.done",
|
|
498
|
+
{"item_id": item_id, "output_index": call_output_index, "arguments": args_json},
|
|
499
|
+
)
|
|
500
|
+
yield _response_sse(
|
|
501
|
+
"response.output_item.done", {"output_index": call_output_index, "item": item}
|
|
502
|
+
)
|
|
503
|
+
if event.get("display_title") or event.get("display_summary"):
|
|
504
|
+
yield _response_sse(
|
|
505
|
+
"response.ksadk.tool_call",
|
|
506
|
+
{
|
|
507
|
+
"type": "tool_call",
|
|
508
|
+
"name": event.get("name"),
|
|
509
|
+
"args": event.get("args", {}),
|
|
510
|
+
"run_id": event.get("run_id"),
|
|
511
|
+
"stage": event.get("stage"),
|
|
512
|
+
"event_kind": event.get("event_kind"),
|
|
513
|
+
"display_title": event.get("display_title"),
|
|
514
|
+
"display_summary": event.get("display_summary"),
|
|
515
|
+
},
|
|
516
|
+
)
|
|
517
|
+
continue
|
|
518
|
+
|
|
519
|
+
if event_type == "tool_result":
|
|
520
|
+
yield _response_sse(
|
|
521
|
+
"response.ksadk.tool_result",
|
|
522
|
+
{
|
|
523
|
+
"name": event.get("name"),
|
|
524
|
+
"output": event.get("output", ""),
|
|
525
|
+
"run_id": event.get("run_id"),
|
|
526
|
+
},
|
|
527
|
+
)
|
|
528
|
+
continue
|
|
529
|
+
|
|
530
|
+
if event_type in {"stage_tool_call", "stage_tool_result"}:
|
|
531
|
+
yield _response_sse(
|
|
532
|
+
f"response.ksadk.{event_type}",
|
|
533
|
+
{
|
|
534
|
+
"type": event_type,
|
|
535
|
+
"name": event.get("name"),
|
|
536
|
+
"args": event.get("args", {}),
|
|
537
|
+
"output": event.get("output", ""),
|
|
538
|
+
"run_id": event.get("run_id"),
|
|
539
|
+
"stage": event.get("stage"),
|
|
540
|
+
"event_kind": event.get("event_kind"),
|
|
541
|
+
"display_title": event.get("display_title"),
|
|
542
|
+
"display_summary": event.get("display_summary"),
|
|
543
|
+
},
|
|
544
|
+
)
|
|
545
|
+
continue
|
|
546
|
+
|
|
547
|
+
if event_type == "interrupt":
|
|
548
|
+
interrupt_info = event.get("interrupt_info")
|
|
549
|
+
if isinstance(interrupt_info, Mapping) and interrupt_info.get("tool_name"):
|
|
550
|
+
raw_arguments = (
|
|
551
|
+
interrupt_info.get("arguments")
|
|
552
|
+
or interrupt_info.get("tool_args")
|
|
553
|
+
or interrupt_info.get("args")
|
|
554
|
+
or {}
|
|
555
|
+
)
|
|
556
|
+
arguments = (
|
|
557
|
+
raw_arguments
|
|
558
|
+
if isinstance(raw_arguments, str)
|
|
559
|
+
else json.dumps(raw_arguments, ensure_ascii=False)
|
|
560
|
+
)
|
|
561
|
+
approval_item = {
|
|
562
|
+
"id": str(
|
|
563
|
+
interrupt_info.get("approval_request_id")
|
|
564
|
+
or interrupt_info.get("id")
|
|
565
|
+
or f"appr_{uuid.uuid4().hex[:12]}"
|
|
566
|
+
),
|
|
567
|
+
"type": "mcp_approval_request",
|
|
568
|
+
"name": str(interrupt_info.get("tool_name")),
|
|
569
|
+
"arguments": arguments,
|
|
570
|
+
"server_label": str(interrupt_info.get("server_label") or "ksadk"),
|
|
571
|
+
}
|
|
572
|
+
approval_output_index = _next_output_index()
|
|
573
|
+
yield _response_sse(
|
|
574
|
+
"response.output_item.added",
|
|
575
|
+
{"output_index": approval_output_index, "item": approval_item},
|
|
576
|
+
)
|
|
577
|
+
yield _response_sse(
|
|
578
|
+
"response.output_item.done",
|
|
579
|
+
{"output_index": approval_output_index, "item": approval_item},
|
|
580
|
+
)
|
|
581
|
+
else:
|
|
582
|
+
yield _response_sse(
|
|
583
|
+
"response.ksadk.approval_request", {"interrupt_info": interrupt_info}
|
|
584
|
+
)
|
|
585
|
+
incomplete_payload = build_responses_payload(
|
|
586
|
+
output_text=completed_text,
|
|
587
|
+
model=model,
|
|
588
|
+
session_id=str(event.get("session_id") or session_id or ""),
|
|
589
|
+
response_id=response_id,
|
|
590
|
+
created_at=created_at,
|
|
591
|
+
status="incomplete",
|
|
592
|
+
metadata=response_metadata,
|
|
593
|
+
incomplete_details={
|
|
594
|
+
"reason": "approval_required",
|
|
595
|
+
"ksadk_interrupt": interrupt_info,
|
|
596
|
+
},
|
|
597
|
+
)
|
|
598
|
+
yield _response_sse("response.incomplete", incomplete_payload)
|
|
599
|
+
return
|
|
600
|
+
|
|
601
|
+
if event_type == "error":
|
|
602
|
+
failed_payload = build_responses_payload(
|
|
603
|
+
output_text=completed_text,
|
|
604
|
+
model=model,
|
|
605
|
+
session_id=session_id or "",
|
|
606
|
+
response_id=response_id,
|
|
607
|
+
created_at=created_at,
|
|
608
|
+
status="failed",
|
|
609
|
+
metadata=response_metadata,
|
|
610
|
+
usage=event.get("usage") if isinstance(event.get("usage"), Mapping) else None,
|
|
611
|
+
error={"message": event.get("message") or "Agent 运行失败"},
|
|
612
|
+
)
|
|
613
|
+
yield _response_sse("response.failed", failed_payload)
|
|
614
|
+
return
|
|
615
|
+
|
|
616
|
+
if event_type == "cancelled":
|
|
617
|
+
cancelled_payload = build_responses_payload(
|
|
618
|
+
output_text=completed_text,
|
|
619
|
+
model=model,
|
|
620
|
+
session_id=str(event.get("session_id") or session_id or ""),
|
|
621
|
+
response_id=response_id,
|
|
622
|
+
created_at=created_at,
|
|
623
|
+
status="cancelled",
|
|
624
|
+
metadata=response_metadata,
|
|
625
|
+
usage=event.get("usage") if isinstance(event.get("usage"), Mapping) else None,
|
|
626
|
+
)
|
|
627
|
+
yield _response_sse("response.cancelled", cancelled_payload)
|
|
628
|
+
return
|
|
629
|
+
|
|
630
|
+
if event_type == "completed":
|
|
631
|
+
completed_text = str(event.get("output_text") or completed_text)
|
|
632
|
+
if completed_text and not message_started:
|
|
633
|
+
message_started = True
|
|
634
|
+
text_output_index = _next_output_index()
|
|
635
|
+
yield _response_sse(
|
|
636
|
+
"response.output_item.added",
|
|
637
|
+
{"output_index": text_output_index, "item": _message_item("in_progress")},
|
|
638
|
+
)
|
|
639
|
+
content_started = True
|
|
640
|
+
yield _response_sse(
|
|
641
|
+
"response.content_part.added",
|
|
642
|
+
{
|
|
643
|
+
"item_id": message_item_id,
|
|
644
|
+
"output_index": text_output_index,
|
|
645
|
+
"content_index": 0,
|
|
646
|
+
"part": {"type": "output_text", "text": ""},
|
|
647
|
+
},
|
|
648
|
+
)
|
|
649
|
+
if message_started:
|
|
650
|
+
yield _response_sse(
|
|
651
|
+
"response.output_text.done",
|
|
652
|
+
{
|
|
653
|
+
"item_id": message_item_id,
|
|
654
|
+
"output_index": text_output_index,
|
|
655
|
+
"content_index": 0,
|
|
656
|
+
"text": completed_text,
|
|
657
|
+
},
|
|
658
|
+
)
|
|
659
|
+
yield _response_sse(
|
|
660
|
+
"response.content_part.done",
|
|
661
|
+
{
|
|
662
|
+
"item_id": message_item_id,
|
|
663
|
+
"output_index": text_output_index,
|
|
664
|
+
"content_index": 0,
|
|
665
|
+
"part": {"type": "output_text", "text": completed_text},
|
|
666
|
+
},
|
|
667
|
+
)
|
|
668
|
+
yield _response_sse(
|
|
669
|
+
"response.output_item.done",
|
|
670
|
+
{
|
|
671
|
+
"output_index": text_output_index,
|
|
672
|
+
"item": _message_item("completed", completed_text),
|
|
673
|
+
},
|
|
674
|
+
)
|
|
675
|
+
if reasoning_started:
|
|
676
|
+
yield _response_sse(
|
|
677
|
+
"response.output_item.done",
|
|
678
|
+
{"output_index": reasoning_output_index, "item": _reasoning_item("completed")},
|
|
679
|
+
)
|
|
680
|
+
final_payload = build_responses_payload(
|
|
681
|
+
output_text=completed_text,
|
|
682
|
+
model=event.get("model") or model,
|
|
683
|
+
session_id=str(event.get("session_id") or session_id or ""),
|
|
684
|
+
response_id=str(event.get("response_id") or response_id),
|
|
685
|
+
created_at=created_at,
|
|
686
|
+
status="completed",
|
|
687
|
+
metadata=response_metadata,
|
|
688
|
+
usage=event.get("usage") if isinstance(event.get("usage"), Mapping) else None,
|
|
689
|
+
output_items=(
|
|
690
|
+
event.get("responses_output")
|
|
691
|
+
if isinstance(event.get("responses_output"), Sequence)
|
|
692
|
+
else None
|
|
693
|
+
),
|
|
694
|
+
)
|
|
695
|
+
yield _response_sse("response.completed", final_payload)
|
|
696
|
+
return
|
|
697
|
+
|
|
698
|
+
if not lifecycle_started:
|
|
699
|
+
for lifecycle_chunk in _start_response_lifecycle():
|
|
700
|
+
yield lifecycle_chunk
|