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,553 @@
|
|
|
1
|
+
"""Conversation preparation and persistence around the canonical RuntimeExecutor."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import asyncio
|
|
6
|
+
from collections.abc import AsyncIterator, Callable, Mapping, Sequence
|
|
7
|
+
from dataclasses import asdict
|
|
8
|
+
from typing import Any
|
|
9
|
+
|
|
10
|
+
from ksadk.conversations.run_kinds import RUN_MODE_FOREGROUND
|
|
11
|
+
from ksadk.conversations.runtime_compaction import preview_auto_compaction
|
|
12
|
+
from ksadk.conversations.runtime_metadata import (
|
|
13
|
+
_update_session_metadata_after_assistant_turn,
|
|
14
|
+
)
|
|
15
|
+
from ksadk.conversations.runtime_persistence import append_run_status_event
|
|
16
|
+
from ksadk.conversations.runtime_preparation import build_run_input
|
|
17
|
+
from ksadk.events.runtime_event import EventType, RuntimeEvent
|
|
18
|
+
from ksadk.events.store import RuntimeEventStore
|
|
19
|
+
from ksadk.runtime.adapter import (
|
|
20
|
+
CONVERSATION_PREPROCESSING_METADATA_KEY,
|
|
21
|
+
RESUME_START_REQUEST_NATIVE_KEY,
|
|
22
|
+
ResumePayload,
|
|
23
|
+
ResumeTarget,
|
|
24
|
+
RunHandle,
|
|
25
|
+
StartRequest,
|
|
26
|
+
)
|
|
27
|
+
from ksadk.runtime.executor import RuntimeExecutor, RuntimeStartPreparation
|
|
28
|
+
from ksadk.runtime.launch import RuntimeLaunchContext
|
|
29
|
+
from ksadk.sessions import resolve_session_service
|
|
30
|
+
|
|
31
|
+
_TERMINAL_EVENTS = frozenset(
|
|
32
|
+
{
|
|
33
|
+
EventType.RUN_COMPLETED,
|
|
34
|
+
EventType.RUN_FAILED,
|
|
35
|
+
EventType.RUN_CANCELED,
|
|
36
|
+
}
|
|
37
|
+
)
|
|
38
|
+
|
|
39
|
+
_RUN_STATUS_BY_EVENT = {
|
|
40
|
+
EventType.RUN_STARTED: "in_progress",
|
|
41
|
+
EventType.RUN_INTERRUPTED: "interrupted",
|
|
42
|
+
EventType.RUN_COMPLETED: "completed",
|
|
43
|
+
EventType.RUN_FAILED: "failed",
|
|
44
|
+
EventType.RUN_CANCELED: "cancelled",
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
async def iter_runtime_conversation_events(
|
|
49
|
+
*,
|
|
50
|
+
executor: RuntimeExecutor,
|
|
51
|
+
launch_context: RuntimeLaunchContext,
|
|
52
|
+
agent_id: str,
|
|
53
|
+
user_id: str,
|
|
54
|
+
messages: Sequence[dict[str, Any]],
|
|
55
|
+
session_id: str | None,
|
|
56
|
+
model: str | None,
|
|
57
|
+
model_metadata: Mapping[str, Any] | None = None,
|
|
58
|
+
model_options: Mapping[str, Any] | None = None,
|
|
59
|
+
state_delta: dict[str, Any] | None = None,
|
|
60
|
+
instructions: str | None = None,
|
|
61
|
+
request_metadata: Mapping[str, Any] | None = None,
|
|
62
|
+
custom_metadata: Mapping[str, Any] | None = None,
|
|
63
|
+
resume_input: Mapping[str, Any] | None = None,
|
|
64
|
+
response_id: str | None = None,
|
|
65
|
+
account_id: str | None = None,
|
|
66
|
+
invocation_id: str | None = None,
|
|
67
|
+
session_service_provider: Callable[[], Any] | None = None,
|
|
68
|
+
run_mode: str = RUN_MODE_FOREGROUND,
|
|
69
|
+
runtime_preparation: RuntimeStartPreparation | None = None,
|
|
70
|
+
) -> AsyncIterator[RuntimeEvent]:
|
|
71
|
+
"""Prepare once, execute through RuntimeExecutor, and persist RuntimeEvents."""
|
|
72
|
+
|
|
73
|
+
provider = session_service_provider or resolve_session_service
|
|
74
|
+
compaction_preview = await preview_auto_compaction(
|
|
75
|
+
agent_id=agent_id,
|
|
76
|
+
user_id=user_id,
|
|
77
|
+
session_id=session_id,
|
|
78
|
+
messages=messages,
|
|
79
|
+
model=model,
|
|
80
|
+
model_metadata=model_metadata,
|
|
81
|
+
session_service_provider=provider,
|
|
82
|
+
)
|
|
83
|
+
prepared = await build_run_input(
|
|
84
|
+
agent_id=agent_id,
|
|
85
|
+
user_id=user_id,
|
|
86
|
+
session_id=session_id,
|
|
87
|
+
messages=messages,
|
|
88
|
+
model=model,
|
|
89
|
+
model_metadata=model_metadata,
|
|
90
|
+
model_options=model_options,
|
|
91
|
+
state_delta=state_delta,
|
|
92
|
+
instructions=instructions,
|
|
93
|
+
request_metadata=request_metadata,
|
|
94
|
+
custom_metadata=custom_metadata,
|
|
95
|
+
resume_input=resume_input,
|
|
96
|
+
invocation_id=invocation_id,
|
|
97
|
+
session_service_provider=provider,
|
|
98
|
+
run_mode=run_mode,
|
|
99
|
+
)
|
|
100
|
+
canonical_messages = prepared.responses_history or [dict(item) for item in messages]
|
|
101
|
+
conversation_request = {
|
|
102
|
+
"messages": canonical_messages,
|
|
103
|
+
"model_metadata": prepared.model_metadata,
|
|
104
|
+
"model_options": prepared.model_options,
|
|
105
|
+
"state_delta": dict(state_delta or {}),
|
|
106
|
+
"instructions": prepared.instructions,
|
|
107
|
+
"request_metadata": prepared.request_metadata,
|
|
108
|
+
"custom_metadata": dict(custom_metadata or {}),
|
|
109
|
+
"account_id": account_id,
|
|
110
|
+
"response_id": response_id,
|
|
111
|
+
"prepared_turn": asdict(prepared),
|
|
112
|
+
}
|
|
113
|
+
request = StartRequest(
|
|
114
|
+
input=prepared.user_input,
|
|
115
|
+
user_id=user_id,
|
|
116
|
+
session_id=prepared.session_id,
|
|
117
|
+
agent_id=agent_id,
|
|
118
|
+
model=model,
|
|
119
|
+
metadata={
|
|
120
|
+
"invocation_id": prepared.invocation_id,
|
|
121
|
+
CONVERSATION_PREPROCESSING_METADATA_KEY: conversation_request,
|
|
122
|
+
},
|
|
123
|
+
)
|
|
124
|
+
checkpoint_resume = _checkpoint_resume_input(prepared.resume_input)
|
|
125
|
+
if checkpoint_resume is None:
|
|
126
|
+
handle = await executor.start(
|
|
127
|
+
launch_context,
|
|
128
|
+
request,
|
|
129
|
+
preparation=runtime_preparation,
|
|
130
|
+
)
|
|
131
|
+
else:
|
|
132
|
+
handle = await _resume_runtime_handle(
|
|
133
|
+
executor=executor,
|
|
134
|
+
launch_context=launch_context,
|
|
135
|
+
session_id=prepared.session_id,
|
|
136
|
+
resume_input=checkpoint_resume,
|
|
137
|
+
request=request,
|
|
138
|
+
)
|
|
139
|
+
request = request.model_copy(
|
|
140
|
+
update={
|
|
141
|
+
"metadata": {
|
|
142
|
+
**request.metadata,
|
|
143
|
+
"invocation_id": handle.run_id,
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
)
|
|
147
|
+
store = RuntimeEventStore(provider())
|
|
148
|
+
terminal = False
|
|
149
|
+
interrupted = False
|
|
150
|
+
completed_assistant_text = ""
|
|
151
|
+
try:
|
|
152
|
+
for context_event in _compaction_runtime_events(
|
|
153
|
+
prepared=prepared,
|
|
154
|
+
preview=compaction_preview,
|
|
155
|
+
agent_id=agent_id,
|
|
156
|
+
user_id=user_id,
|
|
157
|
+
):
|
|
158
|
+
yield await store.append_one(context_event)
|
|
159
|
+
async for event in executor.stream(handle):
|
|
160
|
+
_validate_event_scope(event, request)
|
|
161
|
+
persisted = await store.append_one(event)
|
|
162
|
+
await _project_runtime_run_status(
|
|
163
|
+
persisted,
|
|
164
|
+
run_mode=prepared.run_mode,
|
|
165
|
+
run_trigger=prepared.run_trigger,
|
|
166
|
+
session_service_provider=provider,
|
|
167
|
+
)
|
|
168
|
+
if (
|
|
169
|
+
persisted.event_type == EventType.TEXT_COMPLETED
|
|
170
|
+
and persisted.phase == "final_answer"
|
|
171
|
+
):
|
|
172
|
+
completed_assistant_text = str(persisted.payload.get("text") or "")
|
|
173
|
+
terminal = persisted.event_type in _TERMINAL_EVENTS
|
|
174
|
+
interrupted = persisted.event_type == EventType.RUN_INTERRUPTED
|
|
175
|
+
yield persisted
|
|
176
|
+
if not terminal and not interrupted:
|
|
177
|
+
raise RuntimeError("runtime stream ended without a terminal or interrupted event")
|
|
178
|
+
except asyncio.CancelledError:
|
|
179
|
+
cancel_result = await executor.cancel(handle)
|
|
180
|
+
cancelled_event = RuntimeEvent.create(
|
|
181
|
+
EventType.RUN_CANCELED,
|
|
182
|
+
agent_id=str(request.agent_id or ""),
|
|
183
|
+
user_id=request.user_id,
|
|
184
|
+
session_id=request.session_id,
|
|
185
|
+
invocation_id=str(request.metadata["invocation_id"]),
|
|
186
|
+
seq_id=0,
|
|
187
|
+
payload={
|
|
188
|
+
"status": "cancelled",
|
|
189
|
+
"cancel_result": cancel_result.value,
|
|
190
|
+
},
|
|
191
|
+
)
|
|
192
|
+
persisted_cancelled = await store.append_one(cancelled_event)
|
|
193
|
+
await _project_runtime_run_status(
|
|
194
|
+
persisted_cancelled,
|
|
195
|
+
run_mode=prepared.run_mode,
|
|
196
|
+
run_trigger=prepared.run_trigger,
|
|
197
|
+
session_service_provider=provider,
|
|
198
|
+
)
|
|
199
|
+
await executor.close(handle)
|
|
200
|
+
raise
|
|
201
|
+
except BaseException:
|
|
202
|
+
if not interrupted:
|
|
203
|
+
await executor.close(handle)
|
|
204
|
+
raise
|
|
205
|
+
else:
|
|
206
|
+
if terminal and completed_assistant_text:
|
|
207
|
+
await _update_session_metadata_after_assistant_turn(
|
|
208
|
+
service=provider(),
|
|
209
|
+
session_id=prepared.session_id,
|
|
210
|
+
assistant_text=completed_assistant_text,
|
|
211
|
+
model=model,
|
|
212
|
+
)
|
|
213
|
+
if terminal:
|
|
214
|
+
await executor.close(handle)
|
|
215
|
+
|
|
216
|
+
|
|
217
|
+
def _compaction_runtime_events(
|
|
218
|
+
*,
|
|
219
|
+
prepared: Any,
|
|
220
|
+
preview: Any,
|
|
221
|
+
agent_id: str,
|
|
222
|
+
user_id: str,
|
|
223
|
+
) -> list[RuntimeEvent]:
|
|
224
|
+
if not prepared.compaction_triggered:
|
|
225
|
+
return []
|
|
226
|
+
trigger = str(prepared.compaction_trigger or "auto")
|
|
227
|
+
scope = {
|
|
228
|
+
"agent_id": agent_id,
|
|
229
|
+
"user_id": user_id,
|
|
230
|
+
"session_id": prepared.session_id,
|
|
231
|
+
"invocation_id": prepared.invocation_id,
|
|
232
|
+
}
|
|
233
|
+
preview_payload = {
|
|
234
|
+
"phase": "start",
|
|
235
|
+
"trigger": trigger,
|
|
236
|
+
"total_chars": preview.total_chars,
|
|
237
|
+
"total_estimated_tokens": preview.total_estimated_tokens,
|
|
238
|
+
"group_count": preview.group_count,
|
|
239
|
+
"threshold_percentage": preview.auto_compact_threshold_percentage,
|
|
240
|
+
}
|
|
241
|
+
completed_payload = {
|
|
242
|
+
**preview_payload,
|
|
243
|
+
"phase": "done",
|
|
244
|
+
"compacted_until_seq_id": int(prepared.compacted_until_seq_id or 0),
|
|
245
|
+
}
|
|
246
|
+
return [
|
|
247
|
+
RuntimeEvent.create(
|
|
248
|
+
EventType.CONTEXT_COMPACTION_STARTED,
|
|
249
|
+
seq_id=0,
|
|
250
|
+
payload=preview_payload,
|
|
251
|
+
**scope,
|
|
252
|
+
),
|
|
253
|
+
RuntimeEvent.create(
|
|
254
|
+
EventType.CONTEXT_COMPACTION_COMPLETED,
|
|
255
|
+
seq_id=0,
|
|
256
|
+
payload=completed_payload,
|
|
257
|
+
**scope,
|
|
258
|
+
),
|
|
259
|
+
]
|
|
260
|
+
|
|
261
|
+
|
|
262
|
+
async def _project_runtime_run_status(
|
|
263
|
+
event: RuntimeEvent,
|
|
264
|
+
*,
|
|
265
|
+
run_mode: str,
|
|
266
|
+
run_trigger: str,
|
|
267
|
+
session_service_provider: Callable[[], Any],
|
|
268
|
+
) -> None:
|
|
269
|
+
"""Project canonical lifecycle events into the session's active-run state."""
|
|
270
|
+
|
|
271
|
+
status = _RUN_STATUS_BY_EVENT.get(event.event_type)
|
|
272
|
+
if status is None:
|
|
273
|
+
return
|
|
274
|
+
detail = event.payload.get("error") or event.payload.get("detail")
|
|
275
|
+
await append_run_status_event(
|
|
276
|
+
session_id=event.session_id,
|
|
277
|
+
author=event.agent_id,
|
|
278
|
+
status=status,
|
|
279
|
+
invocation_id=event.invocation_id,
|
|
280
|
+
detail=str(detail) if detail else None,
|
|
281
|
+
metadata={
|
|
282
|
+
"runtime_event_id": event.event_id,
|
|
283
|
+
"runtime_event_type": event.event_type,
|
|
284
|
+
},
|
|
285
|
+
session_service_provider=session_service_provider,
|
|
286
|
+
run_mode=run_mode,
|
|
287
|
+
run_trigger=run_trigger,
|
|
288
|
+
)
|
|
289
|
+
|
|
290
|
+
|
|
291
|
+
def _checkpoint_resume_input(value: Any) -> dict[str, Any] | None:
|
|
292
|
+
if not isinstance(value, Mapping):
|
|
293
|
+
return None
|
|
294
|
+
if str(value.get("type") or "").strip() != "agentengine.resume_checkpoint":
|
|
295
|
+
return None
|
|
296
|
+
return dict(value)
|
|
297
|
+
|
|
298
|
+
|
|
299
|
+
async def _resume_runtime_handle(
|
|
300
|
+
*,
|
|
301
|
+
executor: RuntimeExecutor,
|
|
302
|
+
launch_context: RuntimeLaunchContext,
|
|
303
|
+
session_id: str,
|
|
304
|
+
resume_input: Mapping[str, Any],
|
|
305
|
+
request: StartRequest,
|
|
306
|
+
) -> RunHandle:
|
|
307
|
+
run_id = str(resume_input.get("run_id") or "").strip()
|
|
308
|
+
checkpoint_id = str(resume_input.get("checkpoint_id") or "").strip()
|
|
309
|
+
if not run_id or not checkpoint_id:
|
|
310
|
+
raise ValueError("checkpoint resume requires run_id and checkpoint_id")
|
|
311
|
+
|
|
312
|
+
handle = executor.find_handle(launch_context.runtime_type, run_id, session_id)
|
|
313
|
+
if handle is None:
|
|
314
|
+
native_ref = _persisted_resume_native_ref(resume_input)
|
|
315
|
+
native_ref.update({"agent_id": request.agent_id, "user_id": request.user_id})
|
|
316
|
+
handle = RunHandle(
|
|
317
|
+
run_id=run_id,
|
|
318
|
+
session_id=session_id,
|
|
319
|
+
runtime_type=launch_context.runtime_type,
|
|
320
|
+
native_ref=native_ref,
|
|
321
|
+
)
|
|
322
|
+
handle.native_ref[RESUME_START_REQUEST_NATIVE_KEY] = request.model_dump(mode="python")
|
|
323
|
+
handle = await executor.attach(launch_context, handle)
|
|
324
|
+
else:
|
|
325
|
+
handle.native_ref[RESUME_START_REQUEST_NATIVE_KEY] = request.model_dump(mode="python")
|
|
326
|
+
|
|
327
|
+
target = _resume_target(resume_input)
|
|
328
|
+
instruction = str(resume_input.get("resume_instruction") or "").strip()
|
|
329
|
+
payload = (
|
|
330
|
+
ResumePayload(kind="free_text", data=instruction)
|
|
331
|
+
if resume_input.get("resume_instruction_enabled") and instruction
|
|
332
|
+
else None
|
|
333
|
+
)
|
|
334
|
+
return await executor.resume(handle, target, payload)
|
|
335
|
+
|
|
336
|
+
|
|
337
|
+
def _resume_target(resume_input: Mapping[str, Any]) -> ResumeTarget:
|
|
338
|
+
framework = str(resume_input.get("framework") or "").strip().lower()
|
|
339
|
+
framework_ref = resume_input.get("framework_ref")
|
|
340
|
+
raw_runtime_ref = framework_ref.get(framework) if isinstance(framework_ref, Mapping) else None
|
|
341
|
+
runtime_ref: Mapping[str, Any] = (
|
|
342
|
+
raw_runtime_ref if isinstance(raw_runtime_ref, Mapping) else {}
|
|
343
|
+
)
|
|
344
|
+
checkpoint_id = str(resume_input.get("checkpoint_id") or "").strip()
|
|
345
|
+
run_id = str(resume_input.get("run_id") or "").strip()
|
|
346
|
+
if framework == "langgraph":
|
|
347
|
+
return ResumeTarget(kind="checkpoint_id", id=checkpoint_id)
|
|
348
|
+
if framework == "codex":
|
|
349
|
+
thread_id = str(runtime_ref.get("thread_id") or runtime_ref.get("resume_thread_id") or "")
|
|
350
|
+
return ResumeTarget(kind="thread_id", id=thread_id or run_id)
|
|
351
|
+
invocation_id = str(runtime_ref.get("invocation_id") or run_id)
|
|
352
|
+
return ResumeTarget(kind="invocation_id", id=invocation_id)
|
|
353
|
+
|
|
354
|
+
|
|
355
|
+
def _persisted_resume_native_ref(resume_input: Mapping[str, Any]) -> dict[str, Any]:
|
|
356
|
+
framework = str(resume_input.get("framework") or "").strip().lower()
|
|
357
|
+
checkpoint_id = str(resume_input.get("checkpoint_id") or "").strip()
|
|
358
|
+
framework_ref = resume_input.get("framework_ref")
|
|
359
|
+
normalized_ref = dict(framework_ref) if isinstance(framework_ref, Mapping) else {}
|
|
360
|
+
runtime_ref = normalized_ref.get(framework)
|
|
361
|
+
native_ref = dict(runtime_ref) if isinstance(runtime_ref, Mapping) else {}
|
|
362
|
+
native_ref["framework_ref"] = normalized_ref
|
|
363
|
+
if checkpoint_id:
|
|
364
|
+
native_ref.setdefault("checkpoint_id", checkpoint_id)
|
|
365
|
+
native_ref.setdefault("known_checkpoint_ids", [checkpoint_id])
|
|
366
|
+
return native_ref
|
|
367
|
+
|
|
368
|
+
|
|
369
|
+
def _validate_event_scope(event: RuntimeEvent, request: StartRequest) -> None:
|
|
370
|
+
expected = {
|
|
371
|
+
"agent_id": str(request.agent_id or ""),
|
|
372
|
+
"user_id": request.user_id,
|
|
373
|
+
"session_id": request.session_id,
|
|
374
|
+
"invocation_id": str(request.metadata["invocation_id"]),
|
|
375
|
+
}
|
|
376
|
+
mismatches = {
|
|
377
|
+
field: (expected_value, getattr(event, field))
|
|
378
|
+
for field, expected_value in expected.items()
|
|
379
|
+
if getattr(event, field) != expected_value
|
|
380
|
+
}
|
|
381
|
+
if mismatches:
|
|
382
|
+
raise ValueError(f"runtime event scope does not match request: {mismatches!r}")
|
|
383
|
+
|
|
384
|
+
|
|
385
|
+
async def iter_runtime_conversation_semantic_events(
|
|
386
|
+
**kwargs: Any,
|
|
387
|
+
) -> AsyncIterator[dict[str, Any]]:
|
|
388
|
+
"""Project canonical RuntimeEvents into the transport-neutral serializer input."""
|
|
389
|
+
|
|
390
|
+
accumulated_text = ""
|
|
391
|
+
usage: dict[str, Any] = {}
|
|
392
|
+
approval: dict[str, Any] | None = None
|
|
393
|
+
async for event in iter_runtime_conversation_events(**kwargs):
|
|
394
|
+
payload = event.payload
|
|
395
|
+
event_type = event.event_type
|
|
396
|
+
if event_type == EventType.RUN_STARTED:
|
|
397
|
+
yield {
|
|
398
|
+
"type": "started",
|
|
399
|
+
"session_id": event.session_id,
|
|
400
|
+
"metadata": dict(payload.get("metadata") or {}),
|
|
401
|
+
}
|
|
402
|
+
elif event_type in {
|
|
403
|
+
EventType.CONTEXT_COMPACTION_STARTED,
|
|
404
|
+
EventType.CONTEXT_COMPACTION_COMPLETED,
|
|
405
|
+
}:
|
|
406
|
+
yield {
|
|
407
|
+
"type": "compaction",
|
|
408
|
+
**dict(payload),
|
|
409
|
+
}
|
|
410
|
+
elif event_type == EventType.TEXT_DELTA:
|
|
411
|
+
delta = str(payload.get("text") or "")
|
|
412
|
+
replace = bool(payload.get("replace"))
|
|
413
|
+
accumulated_text = delta if replace else accumulated_text + delta
|
|
414
|
+
semantic: dict[str, Any] = {"type": "text", "delta": delta}
|
|
415
|
+
if replace:
|
|
416
|
+
semantic["replace"] = True
|
|
417
|
+
yield semantic
|
|
418
|
+
elif event_type == EventType.TEXT_COMPLETED:
|
|
419
|
+
snapshot = str(payload.get("text") or "")
|
|
420
|
+
if snapshot != accumulated_text:
|
|
421
|
+
if snapshot.startswith(accumulated_text):
|
|
422
|
+
delta = snapshot[len(accumulated_text) :]
|
|
423
|
+
if delta:
|
|
424
|
+
yield {"type": "text", "delta": delta}
|
|
425
|
+
else:
|
|
426
|
+
yield {"type": "text", "delta": snapshot, "replace": True}
|
|
427
|
+
accumulated_text = snapshot
|
|
428
|
+
elif event_type == EventType.REASONING_DELTA:
|
|
429
|
+
yield {"type": "thinking", "delta": str(payload.get("text") or "")}
|
|
430
|
+
elif event_type == EventType.TOOL_CALL_BEGIN:
|
|
431
|
+
yield {
|
|
432
|
+
"type": "tool_call",
|
|
433
|
+
"name": payload.get("name"),
|
|
434
|
+
"args": dict(payload.get("args") or {}),
|
|
435
|
+
"run_id": payload.get("call_id"),
|
|
436
|
+
"stage": payload.get("stage"),
|
|
437
|
+
"event_kind": payload.get("event_kind"),
|
|
438
|
+
"display_title": payload.get("display_title"),
|
|
439
|
+
"display_summary": payload.get("display_summary"),
|
|
440
|
+
}
|
|
441
|
+
elif event_type == EventType.TOOL_CALL_END:
|
|
442
|
+
yield {
|
|
443
|
+
"type": "tool_result",
|
|
444
|
+
"name": payload.get("name"),
|
|
445
|
+
"output": payload.get("result", payload.get("error", "")),
|
|
446
|
+
"run_id": payload.get("call_id"),
|
|
447
|
+
}
|
|
448
|
+
elif event_type == EventType.APPROVAL_REQUESTED:
|
|
449
|
+
detail = payload.get("detail")
|
|
450
|
+
approval = dict(detail) if isinstance(detail, Mapping) else {}
|
|
451
|
+
approval.setdefault("approval_request_id", payload.get("approval_id"))
|
|
452
|
+
approval.setdefault("id", payload.get("approval_id"))
|
|
453
|
+
approval.setdefault("call_id", payload.get("call_id"))
|
|
454
|
+
# ``kind=tool`` only describes the interrupt category. It is not
|
|
455
|
+
# a concrete tool name: inventing one would serialize a generic
|
|
456
|
+
# interrupt as an MCP approval request and lose the extension
|
|
457
|
+
# event that clients use to render a human-input prompt.
|
|
458
|
+
if payload.get("tool_name"):
|
|
459
|
+
approval.setdefault("tool_name", payload.get("tool_name"))
|
|
460
|
+
elif event_type == EventType.USAGE_REPORTED:
|
|
461
|
+
usage = dict(payload)
|
|
462
|
+
elif event_type == EventType.RUN_INTERRUPTED:
|
|
463
|
+
yield {
|
|
464
|
+
"type": "interrupt",
|
|
465
|
+
"interrupt_info": approval or dict(payload),
|
|
466
|
+
"session_id": event.session_id,
|
|
467
|
+
}
|
|
468
|
+
elif event_type == EventType.RUN_FAILED:
|
|
469
|
+
yield {
|
|
470
|
+
"type": "error",
|
|
471
|
+
"message": str(payload.get("error") or "Agent 运行失败"),
|
|
472
|
+
"session_id": event.session_id,
|
|
473
|
+
"usage": usage,
|
|
474
|
+
}
|
|
475
|
+
elif event_type == EventType.RUN_CANCELED:
|
|
476
|
+
yield {
|
|
477
|
+
"type": "cancelled",
|
|
478
|
+
"session_id": event.session_id,
|
|
479
|
+
"usage": usage,
|
|
480
|
+
}
|
|
481
|
+
elif event_type == EventType.RUN_COMPLETED:
|
|
482
|
+
raw_completion_metadata = payload.get("metadata")
|
|
483
|
+
completion_metadata = (
|
|
484
|
+
dict(raw_completion_metadata)
|
|
485
|
+
if isinstance(raw_completion_metadata, Mapping)
|
|
486
|
+
else {}
|
|
487
|
+
)
|
|
488
|
+
request_metadata = kwargs.get("request_metadata")
|
|
489
|
+
requested_agentengine = (
|
|
490
|
+
request_metadata.get("agentengine")
|
|
491
|
+
if isinstance(request_metadata, Mapping)
|
|
492
|
+
else None
|
|
493
|
+
)
|
|
494
|
+
if isinstance(requested_agentengine, Mapping):
|
|
495
|
+
completion_metadata["agentengine"] = dict(requested_agentengine)
|
|
496
|
+
if isinstance(payload.get("agentengine"), Mapping):
|
|
497
|
+
completion_metadata["agentengine"] = dict(payload["agentengine"])
|
|
498
|
+
completion_metadata["runtime"] = {
|
|
499
|
+
"duration_ms": payload.get("duration_ms"),
|
|
500
|
+
"runtime_type": kwargs["launch_context"].runtime_type,
|
|
501
|
+
}
|
|
502
|
+
yield {
|
|
503
|
+
"type": "completed",
|
|
504
|
+
"output_text": accumulated_text,
|
|
505
|
+
"session_id": event.session_id,
|
|
506
|
+
"usage": usage,
|
|
507
|
+
"metadata": completion_metadata,
|
|
508
|
+
}
|
|
509
|
+
|
|
510
|
+
|
|
511
|
+
async def invoke_runtime_conversation_once(
|
|
512
|
+
**kwargs: Any,
|
|
513
|
+
) -> tuple[str, dict[str, Any]]:
|
|
514
|
+
"""Collect one RuntimeExecutor turn for non-streaming protocol responses."""
|
|
515
|
+
|
|
516
|
+
session_id = str(kwargs.get("session_id") or "")
|
|
517
|
+
output_text = ""
|
|
518
|
+
usage: dict[str, Any] = {}
|
|
519
|
+
metadata: dict[str, Any] = {}
|
|
520
|
+
completed = False
|
|
521
|
+
async for event in iter_runtime_conversation_semantic_events(**kwargs):
|
|
522
|
+
event_type = event.get("type")
|
|
523
|
+
if event_type == "started":
|
|
524
|
+
session_id = str(event.get("session_id") or session_id)
|
|
525
|
+
elif event_type == "text":
|
|
526
|
+
delta = str(event.get("delta") or "")
|
|
527
|
+
output_text = delta if event.get("replace") else output_text + delta
|
|
528
|
+
elif event_type == "completed":
|
|
529
|
+
completed = True
|
|
530
|
+
session_id = str(event.get("session_id") or session_id)
|
|
531
|
+
output_text = str(event.get("output_text") or output_text)
|
|
532
|
+
usage = dict(event.get("usage") or {})
|
|
533
|
+
metadata = dict(event.get("metadata") or {})
|
|
534
|
+
elif event_type == "error":
|
|
535
|
+
raise RuntimeError(str(event.get("message") or "Agent 运行失败"))
|
|
536
|
+
elif event_type == "cancelled":
|
|
537
|
+
raise asyncio.CancelledError
|
|
538
|
+
elif event_type == "interrupt":
|
|
539
|
+
raise RuntimeError("runtime input is required before this run can complete")
|
|
540
|
+
if not completed:
|
|
541
|
+
raise RuntimeError("runtime did not produce a completed result")
|
|
542
|
+
return session_id, {
|
|
543
|
+
"output_text": output_text,
|
|
544
|
+
"usage": usage,
|
|
545
|
+
"metadata": metadata,
|
|
546
|
+
}
|
|
547
|
+
|
|
548
|
+
|
|
549
|
+
__all__ = [
|
|
550
|
+
"invoke_runtime_conversation_once",
|
|
551
|
+
"iter_runtime_conversation_events",
|
|
552
|
+
"iter_runtime_conversation_semantic_events",
|
|
553
|
+
]
|