agentengine-sdk-python 0.8.1__py3-none-any.whl → 0.8.3__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.
Files changed (476) hide show
  1. {agentengine_sdk_python-0.8.1.dist-info → agentengine_sdk_python-0.8.3.dist-info}/METADATA +25 -12
  2. {agentengine_sdk_python-0.8.1.dist-info → agentengine_sdk_python-0.8.3.dist-info}/RECORD +421 -232
  3. ksadk/_build_provenance.json +1 -0
  4. ksadk/a2a/_space_client_events.py +381 -0
  5. ksadk/a2a/event_adapter.py +156 -64
  6. ksadk/a2a/executor.py +179 -63
  7. ksadk/a2a/space_client.py +6 -333
  8. ksadk/a2ui/core.py +222 -53
  9. ksadk/agui/_agent_helpers.py +247 -0
  10. ksadk/agui/a2ui_projection.py +12 -5
  11. ksadk/agui/agent.py +443 -259
  12. ksadk/api/client.py +528 -27
  13. ksadk/builders/code_builder.py +284 -8
  14. ksadk/builders/container_builder.py +8 -1
  15. ksadk/builders/managed_runtime_builder.py +42 -35
  16. ksadk/cli/__init__.py +23 -0
  17. ksadk/cli/cmd_dashboard.py +15 -1
  18. ksadk/cli/cmd_deploy.py +10 -2
  19. ksadk/cli/cmd_eval.py +66 -9
  20. ksadk/cli/cmd_evalset.py +284 -0
  21. ksadk/cli/cmd_files.py +5 -1
  22. ksadk/cli/cmd_hermes.py +1 -126
  23. ksadk/cli/cmd_invoke.py +28 -38
  24. ksadk/cli/cmd_managed_runtime.py +95 -0
  25. ksadk/cli/cmd_observe.py +85 -0
  26. ksadk/cli/cmd_openclaw.py +1 -435
  27. ksadk/cli/cmd_plugin.py +657 -0
  28. ksadk/cli/cmd_replay.py +28 -4
  29. ksadk/cli/cmd_studio.py +99 -8
  30. ksadk/cli/cmd_web.py +10 -2
  31. ksadk/cli/hermes_env.py +151 -0
  32. ksadk/cli/invoke_payload.py +49 -0
  33. ksadk/cli/openclaw_env.py +458 -0
  34. ksadk/codex/client.py +180 -30
  35. ksadk/codex/runtime.py +475 -331
  36. ksadk/configs/env_registry.py +94 -12
  37. ksadk/configs/env_registry_pcm.py +181 -0
  38. ksadk/configs/env_var_spec.py +18 -0
  39. ksadk/configs/global_config.py +5 -0
  40. ksadk/configs/settings.py +9 -0
  41. ksadk/context_engine/__init__.py +98 -0
  42. ksadk/context_engine/assembler.py +176 -0
  43. ksadk/context_engine/baseline.py +419 -0
  44. ksadk/context_engine/cache_observability.py +228 -0
  45. ksadk/context_engine/capabilities.py +443 -0
  46. ksadk/context_engine/contributors.py +409 -0
  47. ksadk/context_engine/hosted_pipeline.py +417 -0
  48. ksadk/context_engine/models.py +117 -0
  49. ksadk/context_engine/planner.py +698 -0
  50. ksadk/context_engine/policies.py +319 -0
  51. ksadk/context_engine/projection.py +31 -0
  52. ksadk/context_engine/shadow_plan.py +266 -0
  53. ksadk/context_engine/tokenizer.py +164 -0
  54. ksadk/conversations/__init__.py +19 -0
  55. ksadk/conversations/context.py +230 -30
  56. ksadk/conversations/contracts.py +266 -0
  57. ksadk/conversations/message_projection.py +308 -26
  58. ksadk/conversations/model_context.py +49 -3
  59. ksadk/conversations/projector.py +616 -0
  60. ksadk/conversations/reducer.py +98 -0
  61. ksadk/conversations/runtime_compaction.py +207 -5
  62. ksadk/conversations/runtime_input.py +184 -2
  63. ksadk/conversations/runtime_invocation.py +81 -3
  64. ksadk/conversations/runtime_observability.py +141 -0
  65. ksadk/conversations/runtime_payloads.py +42 -0
  66. ksadk/conversations/runtime_preparation.py +272 -2
  67. ksadk/conversations/runtime_resume.py +20 -1
  68. ksadk/conversations/runtime_stream_events.py +94 -9
  69. ksadk/conversations/semantic_summary.py +311 -1
  70. ksadk/conversations/session_lock.py +51 -0
  71. ksadk/deployment/env_forward.py +72 -0
  72. ksadk/deployment/managed_runtime.py +5 -0
  73. ksadk/deployment/providers/serverless.py +143 -69
  74. ksadk/evaluation/__init__.py +32 -0
  75. ksadk/evaluation/a2a_adapter.py +9 -1
  76. ksadk/evaluation/adapters.py +18 -5
  77. ksadk/evaluation/agent_eval_client.py +395 -0
  78. ksadk/evaluation/cloud_binding.py +80 -0
  79. ksadk/evaluation/cloud_converter.py +194 -0
  80. ksadk/evaluation/cloud_service.py +199 -0
  81. ksadk/evaluation/contracts.py +73 -4
  82. ksadk/evaluation/evaluators.py +183 -17
  83. ksadk/evaluation/evidence.py +258 -0
  84. ksadk/evaluation/executor.py +31 -6
  85. ksadk/evaluation/local_adapter.py +550 -0
  86. ksadk/evaluation/service_env.py +27 -0
  87. ksadk/evaluation/studio_build_adapter.py +253 -0
  88. ksadk/evaluation/target.py +15 -6
  89. ksadk/events/__init__.py +13 -13
  90. ksadk/events/_v1_compat/__init__.py +1 -0
  91. ksadk/events/_v1_compat/models.py +299 -0
  92. ksadk/events/_v1_compat/parser.py +247 -0
  93. ksadk/events/_v1_compat/projection.py +755 -0
  94. ksadk/events/adapters/__init__.py +34 -0
  95. ksadk/events/adapters/_a2a_snapshot.py +622 -0
  96. ksadk/events/adapters/_a2a_support.py +275 -0
  97. ksadk/events/adapters/_codex_interactions.py +375 -0
  98. ksadk/events/adapters/_codex_items.py +801 -0
  99. ksadk/events/adapters/_codex_validators.py +311 -0
  100. ksadk/events/adapters/_langgraph_support.py +785 -0
  101. ksadk/events/adapters/a2a.py +841 -0
  102. ksadk/events/adapters/adk.py +503 -0
  103. ksadk/events/adapters/codex.py +907 -0
  104. ksadk/events/adapters/langgraph.py +745 -0
  105. ksadk/events/canonical.py +440 -0
  106. ksadk/events/canonical_replay.py +497 -0
  107. ksadk/events/canonical_store.py +468 -0
  108. ksadk/events/cold_recovery.py +257 -0
  109. ksadk/events/content.py +89 -0
  110. ksadk/events/identity.py +86 -0
  111. ksadk/events/pipeline.py +455 -0
  112. ksadk/events/projections.py +66 -0
  113. ksadk/events/reducer.py +661 -0
  114. ksadk/events/replay.py +3 -36
  115. ksadk/events/runtime_event.py +20 -265
  116. ksadk/events/session_event.py +324 -0
  117. ksadk/events/store.py +3 -316
  118. ksadk/events/v1_compat.py +41 -0
  119. ksadk/harness/__init__.py +45 -35
  120. ksadk/harness/runtime.py +220 -58
  121. ksadk/identity/resolver.py +4 -3
  122. ksadk/interaction/__init__.py +28 -0
  123. ksadk/interaction/contracts.py +136 -0
  124. ksadk/interaction/ledger.py +189 -0
  125. ksadk/interaction/provider.py +122 -0
  126. ksadk/interaction/providers/__init__.py +52 -0
  127. ksadk/interaction/providers/adk.py +40 -0
  128. ksadk/interaction/providers/codex.py +94 -0
  129. ksadk/interaction/providers/langgraph.py +58 -0
  130. ksadk/kernel/__init__.py +117 -0
  131. ksadk/kernel/authorization.py +258 -0
  132. ksadk/kernel/bootstrap.py +1074 -0
  133. ksadk/kernel/contract_fingerprints.py +62 -0
  134. ksadk/kernel/contracts.py +370 -0
  135. ksadk/kernel/control.py +220 -0
  136. ksadk/kernel/errors.py +79 -0
  137. ksadk/kernel/ingress.py +1123 -0
  138. ksadk/kernel/mapping.py +111 -0
  139. ksadk/kernel/memory_store.py +1134 -0
  140. ksadk/kernel/postgres_store.py +1757 -0
  141. ksadk/kernel/recovery.py +452 -0
  142. ksadk/kernel/runtime_identity.py +103 -0
  143. ksadk/kernel/sql/001_agent_kernel.sql +120 -0
  144. ksadk/kernel/sqlite_store.py +1411 -0
  145. ksadk/kernel/state.py +145 -0
  146. ksadk/kernel/store.py +232 -0
  147. ksadk/kernel/worker.py +964 -0
  148. ksadk/knowledge_base/client.py +7 -0
  149. ksadk/knowledge_base/service.py +32 -5
  150. ksadk/memory/__init__.py +61 -0
  151. ksadk/memory/adk/backends/base_ltm_backend.py +96 -1
  152. ksadk/memory/adk/backends/http_ltm_backend.py +14 -5
  153. ksadk/memory/adk/backends/inmemory_ltm_backend.py +136 -3
  154. ksadk/memory/adk/backends/sdk_ltm_backend.py +384 -2
  155. ksadk/memory/adk/backends/sqlite_ltm_backend.py +95 -0
  156. ksadk/memory/coordinator.py +461 -0
  157. ksadk/memory/events.py +202 -0
  158. ksadk/memory/extraction.py +228 -0
  159. ksadk/memory/ltm_backend_factory.py +16 -3
  160. ksadk/memory/models.py +316 -0
  161. ksadk/memory/policy.py +215 -0
  162. ksadk/memory/provider.py +47 -0
  163. ksadk/memory/provider_adapter.py +159 -0
  164. ksadk/memory/provider_resolver.py +71 -0
  165. ksadk/memory/providers/__init__.py +5 -0
  166. ksadk/memory/providers/local_sqlite.py +497 -0
  167. ksadk/memory/resolved_policy.py +145 -0
  168. ksadk/memory/service.py +188 -6
  169. ksadk/model_proxy/bootstrap.py +16 -9
  170. ksadk/model_proxy/detect.py +202 -9
  171. ksadk/model_proxy/namespace.py +39 -15
  172. ksadk/model_proxy/server.py +24 -5
  173. ksadk/model_proxy/transform.py +60 -2
  174. ksadk/observability/__init__.py +25 -0
  175. ksadk/observability/session_log.py +420 -0
  176. ksadk/observability/trajectory.py +105 -0
  177. ksadk/plugins/__init__.py +167 -0
  178. ksadk/plugins/bridges/__init__.py +45 -0
  179. ksadk/plugins/bridges/codex.py +552 -0
  180. ksadk/plugins/bridges/dsh.py +1116 -0
  181. ksadk/plugins/builtins.py +747 -0
  182. ksadk/plugins/bundle.py +246 -0
  183. ksadk/plugins/bundle_security.py +167 -0
  184. ksadk/plugins/composition.py +529 -0
  185. ksadk/plugins/context_contributor.py +437 -0
  186. ksadk/plugins/contracts.py +451 -0
  187. ksadk/plugins/dsh_toolchain.py +935 -0
  188. ksadk/plugins/ecosystem_bridge.py +1105 -0
  189. ksadk/plugins/ecosystem_probe.py +191 -0
  190. ksadk/plugins/host.py +724 -0
  191. ksadk/plugins/providers/__init__.py +85 -0
  192. ksadk/plugins/providers/bundles/ksadk-codex/cordis.patch.yml +3 -0
  193. ksadk/plugins/providers/bundles/ksadk-codex/index.mjs +18 -0
  194. ksadk/plugins/providers/bundles/ksadk-codex/package.json +19 -0
  195. ksadk/plugins/providers/bundles/ksadk-harness/cordis.patch.yml +3 -0
  196. ksadk/plugins/providers/bundles/ksadk-harness/index.mjs +19 -0
  197. ksadk/plugins/providers/bundles/ksadk-harness/package.json +19 -0
  198. ksadk/plugins/providers/codex.py +722 -0
  199. ksadk/plugins/providers/codex_dsh.py +83 -0
  200. ksadk/plugins/providers/dsh.py +951 -0
  201. ksadk/plugins/providers/dsh_descriptor_host.py +226 -0
  202. ksadk/plugins/providers/harness.py +627 -0
  203. ksadk/plugins/providers/harness_dsh.py +91 -0
  204. ksadk/plugins/providers/legacy.py +215 -0
  205. ksadk/plugins/providers/legacy_catalog.py +100 -0
  206. ksadk/plugins/providers/shipped_dsh.py +370 -0
  207. ksadk/plugins/resolver.py +331 -0
  208. ksadk/plugins/subagent_providers/__init__.py +12 -0
  209. ksadk/plugins/subagent_providers/codex.py +443 -0
  210. ksadk/plugins/subagents.py +333 -0
  211. ksadk/prompts/__init__.py +71 -0
  212. ksadk/prompts/compiler.py +215 -0
  213. ksadk/prompts/models.py +82 -0
  214. ksadk/prompts/projection.py +89 -0
  215. ksadk/prompts/resolved.py +137 -0
  216. ksadk/prompts/sources.py +233 -0
  217. ksadk/runners/_langgraph_runner_streams.py +822 -0
  218. ksadk/runners/adk_runner.py +5 -5
  219. ksadk/runners/base_runner.py +16 -0
  220. ksadk/runners/factory.py +1 -2
  221. ksadk/runners/langgraph_runner.py +198 -437
  222. ksadk/runtime/_runner_adapter/__init__.py +1 -0
  223. ksadk/runtime/_runner_adapter/stream_mapping.py +797 -0
  224. ksadk/runtime/adapter.py +119 -2
  225. ksadk/runtime/conversation_execution.py +316 -182
  226. ksadk/runtime/executor.py +144 -3
  227. ksadk/runtime/factory.py +268 -8
  228. ksadk/runtime/framework_adapters.py +18 -0
  229. ksadk/runtime/hosted_finalizer.py +268 -0
  230. ksadk/runtime/launch.py +14 -1
  231. ksadk/runtime/preprocessing.py +25 -3
  232. ksadk/runtime/runner_adapter.py +293 -508
  233. ksadk/runtime/usage.py +33 -0
  234. ksadk/sandbox/__init__.py +2 -1
  235. ksadk/sandbox/backends/e2b.py +35 -2
  236. ksadk/sandbox/factory.py +72 -0
  237. ksadk/scheduler/__init__.py +18 -0
  238. ksadk/scheduler/calendar.py +102 -0
  239. ksadk/scheduler/contracts.py +254 -0
  240. ksadk/scheduler/dispatcher.py +129 -0
  241. ksadk/scheduler/engine.py +416 -0
  242. ksadk/scheduler/sqlite_store.py +563 -0
  243. ksadk/server/composition.py +8 -0
  244. ksadk/server/factory.py +69 -6
  245. ksadk/server/routes/kernel_ingress.py +258 -0
  246. ksadk/server/routes/openai_compat.py +88 -8
  247. ksadk/server/routes/projection.py +35 -20
  248. ksadk/server/routes/run.py +94 -0
  249. ksadk/server/routes/sessions.py +2 -0
  250. ksadk/server/routes/streaming.py +5 -2
  251. ksadk/server/static/assets/{ArtifactsPanel-CakCqxEN.js → ArtifactsPanel-10GPXIJ6.js} +1 -1
  252. ksadk/server/static/assets/{CodeBlock-CynLknyO.js → CodeBlock-BXk1l-G1.js} +4 -4
  253. ksadk/server/static/assets/MathMessageMarkdown-BorAY7qD.css +1 -0
  254. ksadk/server/static/assets/{MathMessageMarkdown-3sQdOysS.js → MathMessageMarkdown-D9uB55Oh.js} +4 -4
  255. ksadk/server/static/assets/MermaidBlock--OEYoXIJ.js +312 -0
  256. ksadk/server/static/assets/NativeTerminalPanel-DrEe1syq.js +1 -0
  257. ksadk/server/static/assets/abnfDiagram-VCTEODGH-eeTFJLvo.js +1 -0
  258. ksadk/server/static/assets/arc-S3ZNbIAd.js +1 -0
  259. ksadk/server/static/assets/architecture-7GRP2DOG-Dk9nRQ6-.js +1 -0
  260. ksadk/server/static/assets/architectureDiagram-5GKGNRK7-CRjgEJDX.js +36 -0
  261. ksadk/server/static/assets/blockDiagram-NRAW4CY4-C7bsBoNH.js +129 -0
  262. ksadk/server/static/assets/c4Diagram-UCG6FXSJ-BX3c33Ob.js +38 -0
  263. ksadk/server/static/assets/channel-s354Yo6o.js +1 -0
  264. ksadk/server/static/assets/chunk-2Q5K7J3B-CDpPpKR5.js +1 -0
  265. ksadk/server/static/assets/{chunk-FMBD7UC4-B_fH2YuH.js → chunk-5VM5RSS4-bZ7ws-8m.js} +1 -1
  266. ksadk/server/static/assets/{chunk-ND2GUHAM-D6rFLaVV.js → chunk-F27PBJKO-D2r0pvhY.js} +1 -1
  267. ksadk/server/static/assets/chunk-G27WJ6UU-CZwF3oUP.js +231 -0
  268. ksadk/server/static/assets/{chunk-4BX2VUAB-B9drTgOW.js → chunk-JWPE2WC7-DigFYCML.js} +1 -1
  269. ksadk/server/static/assets/chunk-LCL6LL3I-CnorGV5q.js +206 -0
  270. ksadk/server/static/assets/chunk-POPQ4Y6H-CexntQA-.js +1 -0
  271. ksadk/server/static/assets/chunk-RHFEMEQ7-CHTC7UxA.js +168 -0
  272. ksadk/server/static/assets/chunk-SVP7TREG-BC1EWt_-.js +88 -0
  273. ksadk/server/static/assets/chunk-XXDRQBXY-BTG24xN0.js +1 -0
  274. ksadk/server/static/assets/classDiagram-DTDB5LWJ-Dd0nucl9.js +1 -0
  275. ksadk/server/static/assets/classDiagram-v2-JRS7N3AN-Dd0nucl9.js +1 -0
  276. ksadk/server/static/assets/{cose-bilkent-S5V4N54A-ChNs_Mdk.js → cose-bilkent-JH36ORCC-CkonRdAS.js} +1 -1
  277. ksadk/server/static/assets/cynefin-OW5HDTMX-BBlT4uMf.js +1 -0
  278. ksadk/server/static/assets/cynefinDiagram-5FMLGOSQ-DEOCBe15.js +62 -0
  279. ksadk/server/static/assets/cytoscape.esm-CyCl8rPi.js +321 -0
  280. ksadk/server/static/assets/dagre-3AP2YEHR-DBThPuLa.js +4 -0
  281. ksadk/server/static/assets/dagre-ClTPrTht.js +1 -0
  282. ksadk/server/static/assets/diagram-S7CK7UJ4-DsZHrnpJ.js +30 -0
  283. ksadk/server/static/assets/diagram-UQ7AKVKN-BJR4nhVr.js +41 -0
  284. ksadk/server/static/assets/diagram-VSXAHHWV-xzcERX0a.js +3 -0
  285. ksadk/server/static/assets/diagram-VX7I27RA-tn2xM1xu.js +24 -0
  286. ksadk/server/static/assets/diagram-Z3DM3KII-BZPGBkw5.js +24 -0
  287. ksadk/server/static/assets/{dist-gLnrGsoU.js → dist-4zN1_tq5.js} +1 -1
  288. ksadk/server/static/assets/{dist-C1sz5Eo3.js → dist-8VWI-2bZ.js} +1 -1
  289. ksadk/server/static/assets/{dist-BjOdlDjj.js → dist-B-46q3Hk.js} +1 -1
  290. ksadk/server/static/assets/{dist-o2OVmKvt.js → dist-B0gdk4rl.js} +1 -1
  291. ksadk/server/static/assets/{dist-4N2NMVYg.js → dist-B1oWRmrH.js} +1 -1
  292. ksadk/server/static/assets/{dist-CmZHzlwZ.js → dist-BI1qQH4n.js} +1 -1
  293. ksadk/server/static/assets/{dist-X4TnqwOK.js → dist-BJLUwH6W.js} +1 -1
  294. ksadk/server/static/assets/{dist-B5oS1zcj.js → dist-Bbwqa8TG.js} +1 -1
  295. ksadk/server/static/assets/{dist-j6Dxmf_j.js → dist-Btyo4vX4.js} +1 -1
  296. ksadk/server/static/assets/{dist-DQU9EWw-.js → dist-C71CsujO.js} +1 -1
  297. ksadk/server/static/assets/{dist-BIlKoW0k.js → dist-CXpH_Rdd.js} +1 -1
  298. ksadk/server/static/assets/{dist-DJN_6Y39.js → dist-Cq4OL6nO.js} +1 -1
  299. ksadk/server/static/assets/{dist-Dli7qW-B.js → dist-D1V3f1B4.js} +1 -1
  300. ksadk/server/static/assets/{dist-fhOuWds5.js → dist-DJmCPRVB.js} +1 -1
  301. ksadk/server/static/assets/{dist-CWV4lDr1.js → dist-DQAB0qn_.js} +2 -2
  302. ksadk/server/static/assets/{dist-D6MpCZtz.js → dist-DUwKa_l6.js} +1 -1
  303. ksadk/server/static/assets/dist-DdRBIceA.js +1 -0
  304. ksadk/server/static/assets/{dist-DWKByxWV.js → dist-DfGFrb0v.js} +1 -1
  305. ksadk/server/static/assets/{dist-DsHPdk3W.js → dist-DjhwGUgZ.js} +1 -1
  306. ksadk/server/static/assets/{dist-B-jNR6Vn.js → dist-DyqV4fL4.js} +1 -1
  307. ksadk/server/static/assets/{dist-BB3-OwTQ.js → dist-M67Hwu0n.js} +1 -1
  308. ksadk/server/static/assets/{dist-_pHPTyZ-.js → dist-u8tVH5Ak.js} +1 -1
  309. ksadk/server/static/assets/ebnfDiagram-PWID7BFC-DVfMsLge.js +1 -0
  310. ksadk/server/static/assets/erDiagram-SSCWMZ5O-CWEZSYaw.js +99 -0
  311. ksadk/server/static/assets/eventmodeling-NTZA5JFV-Dr5okd8V.js +1 -0
  312. ksadk/server/static/assets/flowDiagram-A5DVABFB-VEO-cVcO.js +1 -0
  313. ksadk/server/static/assets/ganttDiagram-EL5Y4UJY-TWIxoyYL.js +292 -0
  314. ksadk/server/static/assets/gitGraph-4MIJSDKK-CKiKY9Cf.js +1 -0
  315. ksadk/server/static/assets/gitGraphDiagram-WWUBYQGX-DDh2hd2S.js +106 -0
  316. ksadk/server/static/assets/index-B2k_urY8.js +241 -0
  317. ksadk/server/static/assets/index-ILPt6IWF.css +2 -0
  318. ksadk/server/static/assets/info-A6RAGUB7-ubA4Nm_p.js +1 -0
  319. ksadk/server/static/assets/infoDiagram-RXCK75RN-CgoyWiDR.js +2 -0
  320. ksadk/server/static/assets/{ishikawaDiagram-YF4QCWOH-K0OOfVna.js → ishikawaDiagram-5VMMS53U-CyRIu_om.js} +6 -6
  321. ksadk/server/static/assets/{journeyDiagram-JHISSGLW-8LeOJaZp.js → journeyDiagram-EYS64GPL-DN5JXHzN.js} +6 -6
  322. ksadk/server/static/assets/{kanban-definition-UN3LZRKU-C6uCgZrW.js → kanban-definition-3QL26DDD-CNP3ui66.js} +10 -10
  323. ksadk/server/static/assets/katex-DWEzQy1d.js +257 -0
  324. ksadk/server/static/assets/{linear-hdBcYzM8.js → linear-C-qHp7d2.js} +1 -1
  325. ksadk/server/static/assets/mermaid-parser.core-Cl-K943T.js +166 -0
  326. ksadk/server/static/assets/{mindmap-definition-RKZ34NQL-Bjy_2v4_.js → mindmap-definition-FBJOCRG2-D5DB5mYm.js} +29 -29
  327. ksadk/server/static/assets/packet-AYTQ26CC-C7R3NUlK.js +1 -0
  328. ksadk/server/static/assets/pegDiagram-XKGWAZYB-BQVc9ia_.js +1 -0
  329. ksadk/server/static/assets/pie-WAS4IAKB-BIT6qjr3.js +1 -0
  330. ksadk/server/static/assets/pieDiagram-E7YTZNPT-B6UCAvtY.js +39 -0
  331. ksadk/server/static/assets/{quadrantDiagram-W4KKPZXB-BmkRbwCg.js → quadrantDiagram-AXDQQJYC-mIr2d3eb.js} +6 -6
  332. ksadk/server/static/assets/radar-RG4KPBEZ-l5noef9X.js +1 -0
  333. ksadk/server/static/assets/railroad-74A4TZTK-Baea6ZvM.js +1 -0
  334. ksadk/server/static/assets/railroad-abnf-HS5TGJTU-OKn8zZnU.js +1 -0
  335. ksadk/server/static/assets/railroad-ebnf-LZEXJU2U-DdKAKC4l.js +1 -0
  336. ksadk/server/static/assets/railroad-peg-WCYAUIDC-Bds8udlG.js +1 -0
  337. ksadk/server/static/assets/railroadDiagram-O6MQD6OU-Dt3FFDmK.js +1 -0
  338. ksadk/server/static/assets/requirementDiagram-EFPCY7ZU-Cz_vQtgF.js +84 -0
  339. ksadk/server/static/assets/{sankeyDiagram-5OEKKPKP-l6iXmU65.js → sankeyDiagram-P5KCCOFB-wlO1TsH5.js} +7 -7
  340. ksadk/server/static/assets/{sequenceDiagram-3UESZ5HK-Cq6UBeQB.js → sequenceDiagram-WJ2MYXX4-CHRbElYq.js} +10 -10
  341. ksadk/server/static/assets/sizeCapture-X5ZJPWSS-DXX54iyO.js +1 -0
  342. ksadk/server/static/assets/stateDiagram-HBIQ2CUA-Dp_lw9II.js +1 -0
  343. ksadk/server/static/assets/stateDiagram-v2-4QOOHH4V-5b-8o2iS.js +1 -0
  344. ksadk/server/static/assets/swimlanes-XN3QIQJK-D8O5UlLG.js +1 -0
  345. ksadk/server/static/assets/swimlanesDiagram-VK2B7HYN-uf6WPRA4.js +8 -0
  346. ksadk/server/static/assets/{timeline-definition-PNZ67QCA-DEz24vV0.js → timeline-definition-24CTP7MA-8mfKcxvG.js} +7 -7
  347. ksadk/server/static/assets/treeView-Q6P3EWNA-CK5CSrSO.js +1 -0
  348. ksadk/server/static/assets/treemap-WGGIJYW6-Ch2BKgAM.js +1 -0
  349. ksadk/server/static/assets/vennDiagram-4TSXK5OY-EnNl0DE7.js +34 -0
  350. ksadk/server/static/assets/wardley-WFR3VGLG-YW3Q0ml_.js +1 -0
  351. ksadk/server/static/assets/wardleyDiagram-VM6X3IG4-DBu5fbYr.js +78 -0
  352. ksadk/server/static/assets/xychartDiagram-S5SC5T6Z-BSVXs4IY.js +7 -0
  353. ksadk/server/static/index.html +2 -2
  354. ksadk/sessions/__init__.py +26 -9
  355. ksadk/sessions/_local_service_sync.py +688 -0
  356. ksadk/sessions/_local_tables.py +21 -0
  357. ksadk/sessions/_postgres_schema.py +305 -0
  358. ksadk/sessions/_postgres_tables.py +15 -0
  359. ksadk/sessions/base.py +80 -1
  360. ksadk/sessions/in_memory.py +53 -2
  361. ksadk/sessions/local_service.py +63 -604
  362. ksadk/sessions/postgres_service.py +58 -148
  363. ksadk/sessions/resilient.py +35 -1
  364. ksadk/skills/service_client.py +48 -0
  365. ksadk/studio/agent_lifecycle.py +26 -20
  366. ksadk/studio/api.py +1063 -69
  367. ksadk/studio/api_catalog_routes.py +5 -0
  368. ksadk/studio/api_contracts.py +148 -6
  369. ksadk/studio/api_memory_routes.py +82 -0
  370. ksadk/studio/api_plugin_routes.py +480 -0
  371. ksadk/studio/attachment_store.py +187 -0
  372. ksadk/studio/authoring.py +259 -28
  373. ksadk/studio/authoring_coordinator.py +809 -67
  374. ksadk/studio/builder.py +197 -40
  375. ksadk/studio/capabilities.py +17 -0
  376. ksadk/studio/cloud.py +1920 -95
  377. ksadk/studio/codex_agent_service.py +137 -15
  378. ksadk/studio/codex_authoring.py +469 -0
  379. ksadk/studio/codex_builder.py +177 -25
  380. ksadk/studio/codex_manifest.py +71 -22
  381. ksadk/studio/codex_run.py +59 -4
  382. ksadk/studio/compatibility_report.py +445 -0
  383. ksadk/studio/compiler.py +7 -1
  384. ksadk/studio/contracts.py +234 -4
  385. ksadk/studio/dsh_provider_registration.py +768 -0
  386. ksadk/studio/event_store.py +79 -101
  387. ksadk/studio/framework_run.py +264 -3
  388. ksadk/studio/hosted_kernel.py +317 -0
  389. ksadk/studio/manifest_resolver.py +131 -0
  390. ksadk/studio/model_client.py +95 -9
  391. ksadk/studio/model_profile_service.py +1 -1
  392. ksadk/studio/operations.py +47 -5
  393. ksadk/studio/otel_trace.py +348 -42
  394. ksadk/studio/pcm_memory.py +85 -0
  395. ksadk/studio/plugin_composition.py +301 -0
  396. ksadk/studio/plugin_kernel_adapter.py +128 -0
  397. ksadk/studio/plugin_runtime.py +652 -0
  398. ksadk/studio/repository.py +23 -2
  399. ksadk/studio/resource_catalog.py +49 -1
  400. ksadk/studio/run_service.py +1266 -202
  401. ksadk/studio/runtime_source.py +51 -17
  402. ksadk/studio/scheduler_runtime.py +374 -0
  403. ksadk/studio/scheduler_service.py +211 -0
  404. ksadk/studio/service.py +1815 -117
  405. ksadk/studio/shared_web.py +199 -50
  406. ksadk/studio/soul.py +52 -0
  407. ksadk/studio/static/assets/index-DXs1Eq4M.css +1 -0
  408. ksadk/studio/static/assets/index-DeDqwTsD.js +283 -0
  409. ksadk/studio/static/index.html +2 -2
  410. ksadk/studio/templates.py +100 -8
  411. ksadk/studio/validator.py +20 -1
  412. ksadk/studio/workspace.py +31 -32
  413. ksadk/tracing/setup.py +304 -3
  414. ksadk/version.py +1 -1
  415. ksadk_runtime_common/schemas/runtime_event_v1.json +37 -0
  416. ksadk_runtime_common/schemas/runtime_event_v2.json +271 -0
  417. ksadk_runtime_common/workspace_files/path_utils.py +41 -0
  418. ksadk/events/parser.py +0 -191
  419. ksadk/server/static/assets/MathMessageMarkdown-DeYh8QPr.css +0 -1
  420. ksadk/server/static/assets/MermaidBlock-NERD_ef7.js +0 -303
  421. ksadk/server/static/assets/NativeTerminalPanel-CiHWf82q.js +0 -1
  422. ksadk/server/static/assets/arc-DrgjcKhl.js +0 -1
  423. ksadk/server/static/assets/architecture-7EHR7CIX-CpZLRCcY.js +0 -1
  424. ksadk/server/static/assets/architectureDiagram-3BPJPVTR-BXoVRbQ6.js +0 -36
  425. ksadk/server/static/assets/blockDiagram-GPEHLZMM-BnaB3Ywv.js +0 -132
  426. ksadk/server/static/assets/c4Diagram-AAUBKEIU-Dw4weZcp.js +0 -10
  427. ksadk/server/static/assets/channel-Dt3rQTFI.js +0 -1
  428. ksadk/server/static/assets/chunk-2J33WTMH-ChjpLK7j.js +0 -1
  429. ksadk/server/static/assets/chunk-55IACEB6-CK4ROATy.js +0 -1
  430. ksadk/server/static/assets/chunk-727SXJPM-B9KtTTgw.js +0 -206
  431. ksadk/server/static/assets/chunk-AQP2D5EJ-1O1mki3m.js +0 -231
  432. ksadk/server/static/assets/chunk-QZHKN3VN-iXEZtKQc.js +0 -1
  433. ksadk/server/static/assets/classDiagram-4FO5ZUOK-DIveV17Q.js +0 -1
  434. ksadk/server/static/assets/classDiagram-v2-Q7XG4LA2-DIveV17Q.js +0 -1
  435. ksadk/server/static/assets/cytoscape.esm-DelgaX4f.js +0 -321
  436. ksadk/server/static/assets/dagre-BM42HDAG-D0QXg_MQ.js +0 -4
  437. ksadk/server/static/assets/dagre-Bx709z4p.js +0 -1
  438. ksadk/server/static/assets/diagram-2AECGRRQ-DBDDKwBQ.js +0 -43
  439. ksadk/server/static/assets/diagram-5GNKFQAL-BkwDOxmO.js +0 -10
  440. ksadk/server/static/assets/diagram-KO2AKTUF-Bv8waYvY.js +0 -3
  441. ksadk/server/static/assets/diagram-LMA3HP47-e1VECDdu.js +0 -24
  442. ksadk/server/static/assets/diagram-OG6HWLK6-Ds9adfRl.js +0 -24
  443. ksadk/server/static/assets/dist-B5J2uhNk.js +0 -1
  444. ksadk/server/static/assets/erDiagram-TEJ5UH35-BPItFKH6.js +0 -85
  445. ksadk/server/static/assets/eventmodeling-FCH6USID-DYFSxbqr.js +0 -1
  446. ksadk/server/static/assets/flowDiagram-I6XJVG4X-BbYB9w5Y.js +0 -162
  447. ksadk/server/static/assets/ganttDiagram-6RSMTGT7-TQXa0KXv.js +0 -292
  448. ksadk/server/static/assets/gitGraph-WXDBUCRP-DyNYp6BN.js +0 -1
  449. ksadk/server/static/assets/gitGraphDiagram-PVQCEYII-bKblCnpa.js +0 -106
  450. ksadk/server/static/assets/graphlib-B8gBHxth.js +0 -1
  451. ksadk/server/static/assets/index-R52pJJvg.js +0 -177
  452. ksadk/server/static/assets/index-jJr3_955.css +0 -2
  453. ksadk/server/static/assets/info-J43DQDTF-WUx7qTde.js +0 -1
  454. ksadk/server/static/assets/infoDiagram-5YYISTIA-BGVT7J_i.js +0 -2
  455. ksadk/server/static/assets/katex-CYWseY5E.js +0 -265
  456. ksadk/server/static/assets/mermaid-parser.core-BWrDjSZM.js +0 -161
  457. ksadk/server/static/assets/packet-YPE3B663-BN13y_xl.js +0 -1
  458. ksadk/server/static/assets/pie-LRSECV5Y-ftSLXhhc.js +0 -1
  459. ksadk/server/static/assets/pieDiagram-4H26LBE5-GmmqNiVH.js +0 -30
  460. ksadk/server/static/assets/radar-GUYGQ44K-jaICkIeO.js +0 -1
  461. ksadk/server/static/assets/requirementDiagram-4Y6WPE33-DSWFqL7c.js +0 -84
  462. ksadk/server/static/assets/stateDiagram-AJRCARHV-qzTQpg3Y.js +0 -1
  463. ksadk/server/static/assets/stateDiagram-v2-BHNVJYJU-BYCoYGAN.js +0 -1
  464. ksadk/server/static/assets/treeView-BLDUP644-Cpib_vlz.js +0 -1
  465. ksadk/server/static/assets/treemap-LRROVOQU-DQxfmVHK.js +0 -1
  466. ksadk/server/static/assets/vennDiagram-CIIHVFJN-CMCixki2.js +0 -34
  467. ksadk/server/static/assets/wardley-L42UT6IY-BQYHnnkU.js +0 -1
  468. ksadk/server/static/assets/wardleyDiagram-YWT4CUSO-CVzB8F9K.js +0 -78
  469. ksadk/server/static/assets/xychartDiagram-2RQKCTM6-BFBqBLc1.js +0 -7
  470. ksadk/studio/evaluation.py +0 -192
  471. ksadk/studio/static/assets/index-CaEN0eTR.css +0 -1
  472. ksadk/studio/static/assets/index-DI2eY_NH.js +0 -252
  473. {agentengine_sdk_python-0.8.1.dist-info → agentengine_sdk_python-0.8.3.dist-info}/WHEEL +0 -0
  474. {agentengine_sdk_python-0.8.1.dist-info → agentengine_sdk_python-0.8.3.dist-info}/entry_points.txt +0 -0
  475. {agentengine_sdk_python-0.8.1.dist-info → agentengine_sdk_python-0.8.3.dist-info}/licenses/LICENSE +0 -0
  476. {agentengine_sdk_python-0.8.1.dist-info → agentengine_sdk_python-0.8.3.dist-info}/top_level.txt +0 -0
ksadk/api/client.py CHANGED
@@ -4,6 +4,7 @@ AgentEngine Server API 客户端
4
4
  支持 AWS V4 签名认证,用于通过 KOP 网关访问 AgentEngine Server。
5
5
  """
6
6
 
7
+ import asyncio
7
8
  import json
8
9
  import logging
9
10
  import mimetypes
@@ -14,7 +15,7 @@ import uuid
14
15
  from contextlib import contextmanager
15
16
  from dataclasses import dataclass
16
17
  from pathlib import Path
17
- from typing import Any, Callable, Dict, Iterator, Optional, Sequence
18
+ from typing import Any, AsyncIterator, Callable, Dict, Iterator, Optional, Sequence
18
19
  from urllib.parse import quote, unquote, urlparse, urlsplit
19
20
 
20
21
  import requests
@@ -36,6 +37,69 @@ class AttachmentContent:
36
37
  display_name: str
37
38
 
38
39
 
40
+ def _next_stream_chunk(iterator: Iterator[bytes]) -> bytes | None:
41
+ """Read one non-empty requests chunk without leaking StopIteration to asyncio."""
42
+
43
+ while True:
44
+ try:
45
+ chunk = next(iterator)
46
+ except StopIteration:
47
+ return None
48
+ if chunk:
49
+ return chunk
50
+
51
+
52
+ class AgentEngineSSEStream(AsyncIterator[bytes]):
53
+ """Async owner for one dedicated blocking requests SSE connection."""
54
+
55
+ def __init__(self, response: requests.Response, session: requests.Session) -> None:
56
+ self._response: requests.Response | None = response
57
+ self._session: requests.Session | None = session
58
+ # Read SSE as logical lines with the smallest requests read size. A
59
+ # fixed 8 KiB ``iter_content`` block makes short runs appear
60
+ # non-streaming, while ``chunk_size=None`` waits for EOF on urllib3.
61
+ # ``iter_lines`` performs the byte-at-a-time buffering inside the
62
+ # blocking worker and yields complete lines, avoiding one thread hop
63
+ # per byte. Re-add the delimiter so downstream SSE parsers keep their
64
+ # normal framing, including the blank line between events.
65
+ self._chunks = (line + b"\n" for line in response.iter_lines(chunk_size=1))
66
+ self._closed = False
67
+
68
+ def __aiter__(self) -> "AgentEngineSSEStream":
69
+ return self
70
+
71
+ async def __anext__(self) -> bytes:
72
+ if self._closed:
73
+ raise StopAsyncIteration
74
+ try:
75
+ chunk = await asyncio.to_thread(_next_stream_chunk, self._chunks)
76
+ except BaseException:
77
+ await self.aclose()
78
+ raise
79
+ if chunk is None:
80
+ await self.aclose()
81
+ raise StopAsyncIteration
82
+ return chunk
83
+
84
+ async def aclose(self) -> None:
85
+ if self._closed:
86
+ return
87
+ self._closed = True
88
+ response, session = self._response, self._session
89
+ self._response = None
90
+ self._session = None
91
+
92
+ def close_transport() -> None:
93
+ try:
94
+ if response is not None:
95
+ response.close()
96
+ finally:
97
+ if session is not None:
98
+ session.close()
99
+
100
+ await asyncio.to_thread(close_transport)
101
+
102
+
39
103
  class DryRunExit(Exception):
40
104
  """DryRun 模式退出异常。"""
41
105
 
@@ -127,7 +191,16 @@ class AgentEngineClient:
127
191
  logger.debug("AgentEngineClient: No credentials, signing disabled")
128
192
 
129
193
  self._session: Optional[requests.Session] = None
194
+ # The public client keeps synchronous ``requests`` transport for CLI
195
+ # compatibility. Async callers (notably Studio's FastAPI process)
196
+ # must not run that transport on the event-loop thread, and the shared
197
+ # requests.Session must not be used by several worker threads at once.
198
+ self._async_action_lock = asyncio.Lock()
130
199
  self._http_error_log_suppressors: list[HttpErrorLogSuppressor] = []
200
+ # A Server Action can be deployed before the external KOP publication
201
+ # finishes. Remember that result per client so an approval retry does
202
+ # not repeatedly hit the known-unpublished control-plane route.
203
+ self._unpublished_kop_actions: set[str] = set()
131
204
  # 反查身份的实例缓存(避免同会话重复调 IAM);None=未尝试,ResolvedIdentity|None=已反查
132
205
  self._resolved_identity: Any = None
133
206
  self._identity_resolve_attempted: bool = False
@@ -708,6 +781,17 @@ class AgentEngineClient:
708
781
  self._session.close()
709
782
  self._session = None
710
783
 
784
+ async def _action_async(
785
+ self,
786
+ action: str,
787
+ params: Optional[Dict[str, Any]] = None,
788
+ **kwargs: Any,
789
+ ) -> Dict[str, Any]:
790
+ """Run the legacy blocking Action transport without freezing an event loop."""
791
+
792
+ async with self._async_action_lock:
793
+ return await asyncio.to_thread(self._action, action, params, **kwargs)
794
+
711
795
  async def __aenter__(self):
712
796
  return self
713
797
 
@@ -912,6 +996,83 @@ class AgentEngineClient:
912
996
  )
913
997
  return AgentEngineAPIError(response.status_code, message)
914
998
 
999
+ @staticmethod
1000
+ def _is_unregistered_kop_action(error: AgentEngineAPIError, action: str) -> bool:
1001
+ """Return whether KOP rejected an otherwise valid Server Action.
1002
+
1003
+ Public Action publication is an infrastructure step independent of a
1004
+ Server rollout. During that window the per-Agent Gateway route is
1005
+ already authenticated and still forwards the exact same Action to
1006
+ Server admission, so callers can safely use it as the data-plane
1007
+ fallback instead of losing an approval response.
1008
+ """
1009
+
1010
+ message = str(error.message or "").strip().lower()
1011
+ return (
1012
+ error.code == 400
1013
+ and f"action {action.lower()}" in message
1014
+ and "not valid for this web service" in message
1015
+ )
1016
+
1017
+ def _runtime_action(
1018
+ self,
1019
+ *,
1020
+ access: Dict[str, Any],
1021
+ action: str,
1022
+ params: Dict[str, Any],
1023
+ ) -> Dict[str, Any]:
1024
+ endpoint = str(access.get("endpoint") or "").strip().rstrip("/")
1025
+ api_key = str(access.get("api_key") or "").strip()
1026
+ if not endpoint or not api_key:
1027
+ raise AgentEngineAPIError(404, "Agent runtime access is not ready")
1028
+ response = self._get_session().request(
1029
+ method="POST",
1030
+ url=f"{endpoint}/agentengine/api/v1/{action}",
1031
+ headers={"Authorization": f"Bearer {api_key}"},
1032
+ json=params,
1033
+ timeout=self.timeout,
1034
+ verify=self._ssl_verify_enabled(),
1035
+ )
1036
+ if response.status_code >= 400:
1037
+ raise self._workspace_runtime_error(response)
1038
+ try:
1039
+ result = response.json()
1040
+ except Exception as exc:
1041
+ raise AgentEngineAPIError(502, "Runtime Action returned invalid JSON") from exc
1042
+ if not isinstance(result, dict):
1043
+ raise AgentEngineAPIError(502, "Runtime Action returned a non-object payload")
1044
+ code = result.get("Code", 0)
1045
+ if code != 0:
1046
+ raise AgentEngineAPIError(
1047
+ code,
1048
+ str(result.get("Message") or "Unknown API error"),
1049
+ details={
1050
+ "request_id": result.get("RequestId"),
1051
+ "action": result.get("Action") or action,
1052
+ },
1053
+ )
1054
+ data = result.get("Data") if result.get("Data") is not None else result
1055
+ normalized = self._to_snake_case(data)
1056
+ if not isinstance(normalized, dict):
1057
+ raise AgentEngineAPIError(502, "Runtime Action returned non-object Data")
1058
+ return normalized
1059
+
1060
+ async def _runtime_action_for_agent(
1061
+ self,
1062
+ *,
1063
+ agent_id: str,
1064
+ action: str,
1065
+ params: Dict[str, Any],
1066
+ ) -> Dict[str, Any]:
1067
+ detail = await self.get_agent(agent_id, include_api_key=True)
1068
+ access = self._extract_runtime_access(detail)
1069
+ return await asyncio.to_thread(
1070
+ self._runtime_action,
1071
+ access=access,
1072
+ action=action,
1073
+ params=params,
1074
+ )
1075
+
915
1076
  @staticmethod
916
1077
  def _compact_params(params: Dict[str, Any] | None) -> Dict[str, Any]:
917
1078
  return {key: value for key, value in (params or {}).items() if value is not None}
@@ -1310,8 +1471,45 @@ class AgentEngineClient:
1310
1471
  payload[key] = text
1311
1472
  return payload
1312
1473
 
1474
+ @staticmethod
1475
+ def _managed_runtime_config_payload(data: Dict[str, Any]) -> Dict[str, Any]:
1476
+ """Build the public declaration accepted by Server Create/UpdateAgent.
1477
+
1478
+ ``runtime_config`` remains readable for older SDK callers, but it is a
1479
+ resolved read-model. New callers must send ``managed_runtime_config``
1480
+ so retries carry the complete YAML declaration Server needs to resolve
1481
+ a compatible immutable runtime image.
1482
+ """
1483
+ declaration = data.get("managed_runtime_config")
1484
+ if isinstance(declaration, dict):
1485
+ manifest = str(declaration.get("manifest") or "").strip()
1486
+ runtime_name = declaration.get("runtime_name")
1487
+ runtime_version = declaration.get("runtime_version")
1488
+ manifest_sha256 = declaration.get("manifest_sha256")
1489
+ else:
1490
+ legacy = data.get("runtime_config") or {}
1491
+ manifest = str(legacy.get("manifest") or "").strip()
1492
+ runtime_name = legacy.get("name")
1493
+ runtime_version = legacy.get("version")
1494
+ manifest_sha256 = legacy.get("manifest_sha256")
1495
+ if not manifest:
1496
+ raise ValueError("ManagedRuntime requires managed_runtime_config.manifest")
1497
+ payload: Dict[str, Any] = {
1498
+ "Manifest": manifest,
1499
+ "RuntimeName": runtime_name,
1500
+ "RuntimeVersion": runtime_version,
1501
+ }
1502
+ if manifest_sha256:
1503
+ payload["ManifestSHA256"] = manifest_sha256
1504
+ return payload
1505
+
1313
1506
  async def create_agent(self, data: Dict[str, Any]) -> Dict[str, Any]:
1314
- """创建 Agent (通过 CreateAgentProduct 走订单流程)"""
1507
+ """Create an Agent through the established order workflow.
1508
+
1509
+ The control plane invokes the existing ``CreateAgent`` callback after
1510
+ ``CreateAgentProduct``. Calling it a second time from Studio races
1511
+ that callback and can create an inconsistent lifecycle result.
1512
+ """
1315
1513
  framework = self._normalize_framework_name(data.get("framework"))
1316
1514
  params = {
1317
1515
  "Name": data.get("name"),
@@ -1357,7 +1555,7 @@ class AgentEngineClient:
1357
1555
  "IamRole": data.get("iam_role", "KsyunAgentEngineDefaultRole"),
1358
1556
  }
1359
1557
 
1360
- if params["DeploymentType"] in {"Code", "ManagedRuntime"}:
1558
+ if params["DeploymentType"] == "Code":
1361
1559
  ks3 = data.get("ks3", {})
1362
1560
  params["CodeConfig"] = {
1363
1561
  "Path": data.get("artifact_path", ""),
@@ -1365,14 +1563,11 @@ class AgentEngineClient:
1365
1563
  "SecretKey": ks3.get("secret_key"),
1366
1564
  "Region": self._normalize_payload_region(ks3.get("region", "cn-beijing-6")),
1367
1565
  "Bucket": ks3.get("bucket"),
1566
+ "Command": data.get("code_command"),
1567
+ "Checksum": data.get("code_checksum"),
1368
1568
  }
1369
- if params["DeploymentType"] == "ManagedRuntime":
1370
- runtime_config = data.get("runtime_config") or {}
1371
- params["RuntimeConfig"] = {
1372
- "Name": runtime_config.get("name"),
1373
- "Version": runtime_config.get("version"),
1374
- "ManifestSha256": runtime_config.get("manifest_sha256"),
1375
- }
1569
+ elif params["DeploymentType"] == "ManagedRuntime":
1570
+ params["ManagedRuntimeConfig"] = self._managed_runtime_config_payload(data)
1376
1571
  else:
1377
1572
  ic = data.get("image_credential", {}) or {}
1378
1573
  artifact = (data.get("artifact_path", "") or "").strip()
@@ -1387,8 +1582,18 @@ class AgentEngineClient:
1387
1582
  else:
1388
1583
  env_vars = []
1389
1584
 
1585
+ # Keep create and update semantics aligned. In particular, an
1586
+ # explicit ``--no-observability`` must not be silently rewritten to
1587
+ # true while the order is being created.
1588
+ observability = data.get("observability")
1589
+ if isinstance(observability, dict) and "langfuse_enabled" in observability:
1590
+ enable_observability = bool(observability.get("langfuse_enabled"))
1591
+ elif "enable_observability" in data:
1592
+ enable_observability = bool(data.get("enable_observability"))
1593
+ else:
1594
+ enable_observability = True
1390
1595
  advanced = {
1391
- "EnableObservability": True,
1596
+ "EnableObservability": enable_observability,
1392
1597
  "EnvironmentVariables": env_vars,
1393
1598
  }
1394
1599
  inbound_identity_auth = data.get("inbound_identity_auth")
@@ -1399,7 +1604,21 @@ class AgentEngineClient:
1399
1604
  advanced["ProjectId"] = project_id
1400
1605
  params["Advanced"] = advanced
1401
1606
 
1402
- return self._action("CreateAgentProduct", params)
1607
+ # ManagedRuntime is an already-paid, platform-owned YAML runtime. It
1608
+ # has no Code/Container order callback to materialize later, so use
1609
+ # the existing CreateAgent action to create its Agent/Runtime now.
1610
+ # Code and Container keep the established CreateAgentProduct flow.
1611
+ action = (
1612
+ "CreateAgent"
1613
+ if params["DeploymentType"] == "ManagedRuntime"
1614
+ else "CreateAgentProduct"
1615
+ )
1616
+ if action == "CreateAgent":
1617
+ # CreateAgent is also used as an order callback and therefore
1618
+ # requires an InstanceId. A declarative runtime has no order to
1619
+ # allocate one for us, so the SDK supplies a stable request UUID.
1620
+ params["InstanceId"] = str(data.get("instance_id") or uuid.uuid4())
1621
+ return self._action(action, params)
1403
1622
 
1404
1623
  async def get_agent(
1405
1624
  self,
@@ -1639,7 +1858,9 @@ class AgentEngineClient:
1639
1858
  if data.get("description"):
1640
1859
  params["Description"] = data["description"]
1641
1860
 
1642
- if data.get("artifact_path"):
1861
+ if artifact_type == "ManagedRuntime":
1862
+ params["ManagedRuntimeConfig"] = self._managed_runtime_config_payload(data)
1863
+ elif data.get("artifact_path"):
1643
1864
  artifact = (data.get("artifact_path", "") or "").strip()
1644
1865
  if (artifact_type or "").lower() == "container":
1645
1866
  ic = data.get("image_credential", {}) or {}
@@ -1655,14 +1876,9 @@ class AgentEngineClient:
1655
1876
  "SecretKey": ks3.get("secret_key"),
1656
1877
  "Region": self._normalize_payload_region(ks3.get("region", "cn-beijing-6")),
1657
1878
  "Bucket": ks3.get("bucket"),
1879
+ "Command": data.get("code_command"),
1880
+ "Checksum": data.get("code_checksum"),
1658
1881
  }
1659
- if artifact_type == "ManagedRuntime":
1660
- runtime_config = data.get("runtime_config") or {}
1661
- params["RuntimeConfig"] = {
1662
- "Name": runtime_config.get("name"),
1663
- "Version": runtime_config.get("version"),
1664
- "ManifestSha256": runtime_config.get("manifest_sha256"),
1665
- }
1666
1882
 
1667
1883
  if data.get("resources"):
1668
1884
  params["Resource"] = {
@@ -1729,26 +1945,140 @@ class AgentEngineClient:
1729
1945
  self, agent_id: str, user_id: Optional[str] = None, expires_hours: int = 24
1730
1946
  ) -> Dict[str, Any]:
1731
1947
  """创建会话"""
1732
- return self._action(
1948
+ return await self._action_async(
1733
1949
  "CreateSession", {"AgentId": agent_id, "UserId": user_id, "ExpiresHours": expires_hours}
1734
1950
  )
1735
1951
 
1736
1952
  async def get_session(self, session_id: str) -> Dict[str, Any]:
1737
1953
  """获取会话详情"""
1738
- return self._action("GetSession", {"Id": session_id})
1954
+ return await self._action_async("GetSession", {"Id": session_id})
1739
1955
 
1740
1956
  async def list_sessions(self, agent_id: str, page: int = 1, size: int = 20) -> Dict[str, Any]:
1741
1957
  """列出会话"""
1742
- return self._action("ListSessions", {"AgentId": agent_id, "Page": page, "PageSize": size})
1958
+ return await self._action_async(
1959
+ "ListSessions", {"AgentId": agent_id, "Page": page, "PageSize": size}
1960
+ )
1743
1961
 
1744
1962
  async def delete_session(self, session_id: str) -> bool:
1745
1963
  """删除会话"""
1746
1964
  try:
1747
- self._action("DeleteSession", {"Id": session_id})
1748
- return True
1965
+ result = await self._action_async("DeleteSession", {"Id": session_id})
1966
+ # Server may accept the request but retain the control-plane
1967
+ # record when runtime-side deletion is still pending. Do not
1968
+ # present that state as a completed delete to Studio callers.
1969
+ return bool(result.get("deleted"))
1749
1970
  except Exception:
1750
1971
  return False
1751
1972
 
1973
+ async def list_session_messages(
1974
+ self,
1975
+ *,
1976
+ agent_id: str,
1977
+ session_id: str,
1978
+ after_seq_id: int | None = None,
1979
+ before_seq_id: int | None = None,
1980
+ cursor_source: str | None = None,
1981
+ limit: int = 50,
1982
+ include_reasoning: bool = False,
1983
+ include_tool_events: bool = False,
1984
+ include_attachments: bool = True,
1985
+ ) -> Dict[str, Any]:
1986
+ """Read the Server-owned message projection for one cloud session.
1987
+
1988
+ This is intentionally an AgentEngine Action client method rather than
1989
+ a Hosted UI shortcut. Local Studio can retain AK/SK in its backend,
1990
+ call the same authenticated Server read path as the cloud console, and
1991
+ keep cursor ownership on the Server/Runtime boundary.
1992
+ """
1993
+
1994
+ params: Dict[str, Any] = {
1995
+ "AgentId": agent_id,
1996
+ "SessionId": session_id,
1997
+ "Limit": limit,
1998
+ "IncludeReasoning": include_reasoning,
1999
+ "IncludeToolEvents": include_tool_events,
2000
+ "IncludeAttachments": include_attachments,
2001
+ }
2002
+ if after_seq_id is not None:
2003
+ params["AfterSeqId"] = after_seq_id
2004
+ if before_seq_id is not None:
2005
+ params["BeforeSeqId"] = before_seq_id
2006
+ if cursor_source is not None:
2007
+ params["CursorSource"] = cursor_source
2008
+ return await self._action_async("ListSessionMessages", params)
2009
+
2010
+ async def list_session_events(
2011
+ self,
2012
+ *,
2013
+ agent_id: str,
2014
+ session_id: str,
2015
+ after_seq_id: int | None = None,
2016
+ offset: int | None = None,
2017
+ limit: int = 100,
2018
+ ) -> Dict[str, Any]:
2019
+ """Read canonical cloud session events through the Server Action API."""
2020
+
2021
+ params: Dict[str, Any] = {
2022
+ "AgentId": agent_id,
2023
+ "SessionId": session_id,
2024
+ "Limit": limit,
2025
+ }
2026
+ if after_seq_id is not None:
2027
+ params["AfterSeqId"] = after_seq_id
2028
+ if offset is not None:
2029
+ params["Offset"] = offset
2030
+ return await self._action_async("ListSessionEvents", params)
2031
+
2032
+ async def submit_interaction(
2033
+ self,
2034
+ *,
2035
+ agent_id: str,
2036
+ session_id: str,
2037
+ run_id: str,
2038
+ interaction_id: str,
2039
+ expected_revision: int,
2040
+ action: str,
2041
+ response: Dict[str, Any] | None = None,
2042
+ idempotency_key: str,
2043
+ ) -> Dict[str, Any]:
2044
+ """Submit one Interaction/v1 response via Server admission.
2045
+
2046
+ The caller supplies only public interaction fields. Tenant,
2047
+ principal, AgentInstance and permit remain Server-derived.
2048
+ """
2049
+
2050
+ params = {
2051
+ "AgentId": agent_id,
2052
+ "SessionId": session_id,
2053
+ "RunId": run_id,
2054
+ "InteractionId": interaction_id,
2055
+ "ExpectedRevision": expected_revision,
2056
+ # ``Action`` is reserved by the KOP envelope for the API operation
2057
+ # name. Keep the SDK argument ergonomic while using an
2058
+ # unambiguous public wire field.
2059
+ "InteractionAction": action,
2060
+ "Response": response or {},
2061
+ "IdempotencyKey": idempotency_key,
2062
+ }
2063
+ if "SubmitInteraction" not in self._unpublished_kop_actions:
2064
+ try:
2065
+ return await self._action_async("SubmitInteraction", params)
2066
+ except AgentEngineAPIError as exc:
2067
+ if not self._is_unregistered_kop_action(exc, "SubmitInteraction"):
2068
+ raise
2069
+ self._unpublished_kop_actions.add("SubmitInteraction")
2070
+ if "SubmitInteraction" in self._unpublished_kop_actions:
2071
+ # KOP publication can lag the Server/Gateway rollout. The
2072
+ # per-Agent endpoint is authenticated with the API key returned by
2073
+ # signed GetAgent and still traverses Gateway -> Server admission;
2074
+ # it never submits directly to Runtime.
2075
+ return await self._runtime_action_for_agent(
2076
+ agent_id=agent_id,
2077
+ action="SubmitInteraction",
2078
+ params=params,
2079
+ )
2080
+ raise AssertionError("unreachable SubmitInteraction transport state")
2081
+
1752
2082
  async def list_workspace_files(
1753
2083
  self,
1754
2084
  *,
@@ -2200,17 +2530,188 @@ class AgentEngineClient:
2200
2530
  # ===== Chat Actions =====
2201
2531
 
2202
2532
  async def chat(
2203
- self, agent_id: str, message: str, session_id: Optional[str] = None
2533
+ self,
2534
+ agent_id: str,
2535
+ message: Any,
2536
+ session_id: Optional[str] = None,
2537
+ *,
2538
+ model: Optional[str] = None,
2539
+ model_options: Optional[Dict[str, Any]] = None,
2540
+ tool_approval_mode: Optional[str] = None,
2541
+ collaboration_mode: Optional[str] = None,
2542
+ goal_objective: Optional[str] = None,
2204
2543
  ) -> Dict[str, Any]:
2205
2544
  """调用 Agent"""
2206
2545
  params = {
2207
2546
  "AgentId": agent_id,
2547
+ # The public KOP contract validates ApiFormat before forwarding the
2548
+ # request to Server. Keep this legacy string helper on the chat
2549
+ # completions shape instead of relying on Server's newer Responses
2550
+ # default, otherwise KOP rejects an otherwise valid request.
2551
+ "ApiFormat": "chat_completions",
2208
2552
  "Messages": [{"role": "user", "content": message}],
2209
2553
  "Stream": False,
2210
2554
  }
2211
2555
  if session_id:
2212
2556
  params["SessionId"] = session_id
2213
- return self._action("RunAgent", params)
2557
+ if model:
2558
+ params["Model"] = model
2559
+ if model_options:
2560
+ params["ModelOptions"] = dict(model_options)
2561
+ execution_metadata: Dict[str, Any] = {}
2562
+ if tool_approval_mode:
2563
+ execution_metadata["tool_approval_mode"] = tool_approval_mode
2564
+ if collaboration_mode:
2565
+ execution_metadata["collaboration_mode"] = collaboration_mode
2566
+ if goal_objective:
2567
+ execution_metadata["goal_objective"] = goal_objective
2568
+ if execution_metadata:
2569
+ params["Metadata"] = {"agentengine": execution_metadata}
2570
+ return await self._action_async("RunAgent", params)
2571
+
2572
+ def _open_chat_stream(self, params: Dict[str, Any]) -> AgentEngineSSEStream:
2573
+ """Open RunAgent SSE synchronously in a worker-owned requests session."""
2574
+
2575
+ path = "/agentengine/api/v1/RunAgent"
2576
+ _kop_mode, headers, full_url = self._build_action_request_target(path, "RunAgent")
2577
+ body_str = json.dumps(params, ensure_ascii=False)
2578
+ if self.dry_run:
2579
+ # Reuse the established dry-run contract, which raises DryRunExit
2580
+ # with the signed request rather than opening a socket.
2581
+ self._request("POST", path, params)
2582
+ raise AssertionError("dry-run request unexpectedly returned")
2583
+
2584
+ session = requests.Session()
2585
+ response: requests.Response | None = None
2586
+ retried_inner_endpoint = False
2587
+ try:
2588
+ while True:
2589
+ response = session.request(
2590
+ method="POST",
2591
+ url=full_url,
2592
+ data=body_str.encode("utf-8"),
2593
+ headers=headers,
2594
+ auth=self._auth.get_auth(),
2595
+ # A foreground Agent turn can legitimately spend minutes
2596
+ # reasoning before its next SSE chunk. Bound connection
2597
+ # establishment, not the lifetime of an admitted stream.
2598
+ timeout=(self.timeout, None),
2599
+ verify=self._ssl_verify_enabled(),
2600
+ stream=True,
2601
+ )
2602
+ content_type = str(response.headers.get("content-type") or "").lower()
2603
+ if response.status_code < 400 and "text/event-stream" in content_type:
2604
+ return AgentEngineSSEStream(response, session)
2605
+
2606
+ resp_text = response.text or ""
2607
+ details = self._extract_http_error_details(resp_text)
2608
+ details.setdefault("http_status", response.status_code)
2609
+ if response.status_code < 400:
2610
+ details["content_type"] = content_type or "<missing>"
2611
+ try:
2612
+ envelope = json.loads(resp_text)
2613
+ except (TypeError, ValueError):
2614
+ envelope = {}
2615
+ if not isinstance(envelope, dict):
2616
+ envelope = {}
2617
+ envelope_code = envelope.get("Code")
2618
+ error_code = (
2619
+ envelope_code
2620
+ if envelope_code not in {None, 0, "0"}
2621
+ else details.get("remote_error_code") or 502
2622
+ )
2623
+ message = (
2624
+ str(
2625
+ details.get("remote_error_message")
2626
+ or details.get("message")
2627
+ or ""
2628
+ ).strip()
2629
+ or "RunAgent stream did not return text/event-stream"
2630
+ )
2631
+ raise AgentEngineAPIError(
2632
+ error_code,
2633
+ message,
2634
+ details=details,
2635
+ )
2636
+ if not retried_inner_endpoint and self._can_retry_with_inner_aicp_endpoint(details):
2637
+ retried_inner_endpoint = True
2638
+ response.close()
2639
+ response = None
2640
+ self._switch_to_inner_aicp_endpoint()
2641
+ _kop_mode, headers, full_url = self._build_action_request_target(
2642
+ path, "RunAgent"
2643
+ )
2644
+ continue
2645
+
2646
+ self._log_http_error(
2647
+ method="POST",
2648
+ full_url=full_url,
2649
+ status_code=response.status_code,
2650
+ details=details,
2651
+ )
2652
+ message = (
2653
+ str(
2654
+ details.get("remote_error_message")
2655
+ or details.get("message")
2656
+ or ""
2657
+ ).strip()
2658
+ or resp_text
2659
+ )
2660
+ raise AgentEngineAPIError(
2661
+ response.status_code,
2662
+ message,
2663
+ details=details or None,
2664
+ )
2665
+ except BaseException:
2666
+ try:
2667
+ if response is not None:
2668
+ response.close()
2669
+ finally:
2670
+ session.close()
2671
+ raise
2672
+
2673
+ async def chat_stream(
2674
+ self,
2675
+ agent_id: str,
2676
+ message: Any,
2677
+ session_id: Optional[str] = None,
2678
+ *,
2679
+ model: Optional[str] = None,
2680
+ model_options: Optional[Dict[str, Any]] = None,
2681
+ tool_approval_mode: Optional[str] = None,
2682
+ collaboration_mode: Optional[str] = None,
2683
+ goal_objective: Optional[str] = None,
2684
+ ) -> AgentEngineSSEStream:
2685
+ """Open a signed foreground RunAgent SSE stream.
2686
+
2687
+ The upstream response is established before this method returns so an
2688
+ HTTP error remains a structured ``AgentEngineAPIError`` instead of a
2689
+ late exception after a downstream proxy has already emitted 200.
2690
+ """
2691
+
2692
+ params: Dict[str, Any] = {
2693
+ "AgentId": agent_id,
2694
+ "ApiFormat": "chat_completions",
2695
+ "Messages": [{"role": "user", "content": message}],
2696
+ "Stream": True,
2697
+ "Background": False,
2698
+ }
2699
+ if session_id:
2700
+ params["SessionId"] = session_id
2701
+ if model:
2702
+ params["Model"] = model
2703
+ if model_options:
2704
+ params["ModelOptions"] = dict(model_options)
2705
+ execution_metadata: Dict[str, Any] = {}
2706
+ if tool_approval_mode:
2707
+ execution_metadata["tool_approval_mode"] = tool_approval_mode
2708
+ if collaboration_mode:
2709
+ execution_metadata["collaboration_mode"] = collaboration_mode
2710
+ if goal_objective:
2711
+ execution_metadata["goal_objective"] = goal_objective
2712
+ if execution_metadata:
2713
+ params["Metadata"] = {"agentengine": execution_metadata}
2714
+ return await asyncio.to_thread(self._open_chat_stream, params)
2214
2715
 
2215
2716
  # ===== Version Actions =====
2216
2717