agentengine-sdk-python 0.8.0__py3-none-any.whl → 0.8.2__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 (494) hide show
  1. {agentengine_sdk_python-0.8.0.dist-info → agentengine_sdk_python-0.8.2.dist-info}/METADATA +43 -7
  2. agentengine_sdk_python-0.8.2.dist-info/RECORD +778 -0
  3. {agentengine_sdk_python-0.8.0.dist-info → agentengine_sdk_python-0.8.2.dist-info}/WHEEL +1 -1
  4. ksadk/a2a/__init__.py +2 -0
  5. ksadk/a2a/_space_client_events.py +381 -0
  6. ksadk/a2a/bootstrap.py +0 -2
  7. ksadk/a2a/card.py +6 -111
  8. ksadk/a2a/control_plane.py +239 -1
  9. ksadk/a2a/event_adapter.py +156 -64
  10. ksadk/a2a/executor.py +195 -172
  11. ksadk/a2a/routes.py +12 -5
  12. ksadk/a2a/server.py +1 -8
  13. ksadk/a2a/service_env.py +33 -0
  14. ksadk/a2a/space_client.py +43 -349
  15. ksadk/a2a_card.py +101 -0
  16. ksadk/a2ui/core.py +222 -53
  17. ksadk/agui/_agent_helpers.py +243 -0
  18. ksadk/agui/a2ui_projection.py +12 -5
  19. ksadk/agui/agent.py +474 -275
  20. ksadk/agui/config.py +11 -5
  21. ksadk/agui/routes.py +7 -15
  22. ksadk/api/client.py +530 -40
  23. ksadk/api/environment.py +27 -0
  24. ksadk/builders/code_builder.py +352 -53
  25. ksadk/builders/container_builder.py +71 -44
  26. ksadk/builders/framework_requirements.py +2 -1
  27. ksadk/builders/ks3_uploader.py +2 -2
  28. ksadk/builders/managed_runtime_builder.py +60 -28
  29. ksadk/cli/__init__.py +25 -0
  30. ksadk/cli/cmd_a2a.py +18 -31
  31. ksadk/cli/cmd_create.py +13 -26
  32. ksadk/cli/cmd_dashboard.py +15 -1
  33. ksadk/cli/cmd_deploy.py +28 -3
  34. ksadk/cli/cmd_eval.py +443 -0
  35. ksadk/cli/cmd_evalset.py +284 -0
  36. ksadk/cli/cmd_files.py +5 -1
  37. ksadk/cli/cmd_hermes.py +137 -163
  38. ksadk/cli/cmd_invoke.py +28 -38
  39. ksadk/cli/cmd_launch.py +12 -0
  40. ksadk/cli/cmd_managed_runtime.py +95 -0
  41. ksadk/cli/cmd_observe.py +85 -0
  42. ksadk/cli/cmd_openclaw.py +85 -479
  43. ksadk/cli/cmd_replay.py +28 -4
  44. ksadk/cli/cmd_run.py +29 -67
  45. ksadk/cli/cmd_studio.py +201 -0
  46. ksadk/cli/cmd_web.py +15 -6
  47. ksadk/cli/dry_run.py +2 -1
  48. ksadk/cli/env_options.py +83 -0
  49. ksadk/cli/global_options.py +3 -1
  50. ksadk/cli/hermes_env.py +151 -0
  51. ksadk/cli/invoke_payload.py +49 -0
  52. ksadk/cli/network_options.py +7 -5
  53. ksadk/cli/openclaw_env.py +458 -0
  54. ksadk/cli/runtime_bootstrap.py +51 -0
  55. ksadk/cli/ui.py +6 -0
  56. ksadk/cli/workflow_common.py +5 -5
  57. ksadk/codex/__init__.py +3 -3
  58. ksadk/codex/client.py +833 -49
  59. ksadk/codex/phase.py +1 -1
  60. ksadk/codex/runtime.py +720 -127
  61. ksadk/common/kop_client.py +232 -0
  62. ksadk/configs/__init__.py +1 -3
  63. ksadk/configs/env_registry.py +244 -45
  64. ksadk/configs/env_registry_pcm.py +181 -0
  65. ksadk/configs/env_var_spec.py +18 -0
  66. ksadk/configs/global_config.py +6 -1
  67. ksadk/configs/settings.py +5 -108
  68. ksadk/context_engine/__init__.py +98 -0
  69. ksadk/context_engine/assembler.py +176 -0
  70. ksadk/context_engine/baseline.py +419 -0
  71. ksadk/context_engine/cache_observability.py +228 -0
  72. ksadk/context_engine/capabilities.py +443 -0
  73. ksadk/context_engine/contributors.py +344 -0
  74. ksadk/context_engine/hosted_pipeline.py +417 -0
  75. ksadk/context_engine/models.py +117 -0
  76. ksadk/context_engine/planner.py +698 -0
  77. ksadk/context_engine/policies.py +319 -0
  78. ksadk/context_engine/projection.py +31 -0
  79. ksadk/context_engine/shadow_plan.py +266 -0
  80. ksadk/context_engine/tokenizer.py +164 -0
  81. ksadk/conversations/__init__.py +85 -94
  82. ksadk/conversations/context.py +126 -6
  83. ksadk/conversations/message_projection.py +292 -28
  84. ksadk/conversations/model_context.py +49 -3
  85. ksadk/conversations/runtime_compaction.py +207 -5
  86. ksadk/conversations/runtime_input.py +193 -3
  87. ksadk/conversations/runtime_invocation.py +81 -3
  88. ksadk/conversations/runtime_observability.py +157 -4
  89. ksadk/conversations/runtime_payloads.py +42 -0
  90. ksadk/conversations/runtime_preparation.py +280 -2
  91. ksadk/conversations/runtime_resume.py +71 -32
  92. ksadk/conversations/runtime_stream_events.py +94 -9
  93. ksadk/conversations/runtime_streaming.py +175 -22
  94. ksadk/conversations/semantic_summary.py +311 -1
  95. ksadk/conversations/session_lock.py +51 -0
  96. ksadk/deployment/env_forward.py +72 -0
  97. ksadk/deployment/managed_runtime.py +38 -0
  98. ksadk/deployment/manager.py +24 -8
  99. ksadk/deployment/providers/serverless.py +228 -92
  100. ksadk/evaluation/__init__.py +116 -0
  101. ksadk/evaluation/a2a_adapter.py +452 -0
  102. ksadk/evaluation/adapters.py +67 -0
  103. ksadk/evaluation/agent_eval_client.py +395 -0
  104. ksadk/evaluation/cloud_binding.py +80 -0
  105. ksadk/evaluation/cloud_converter.py +194 -0
  106. ksadk/evaluation/cloud_service.py +199 -0
  107. ksadk/evaluation/contracts.py +478 -0
  108. ksadk/evaluation/evalset.py +351 -0
  109. ksadk/evaluation/evaluators.py +627 -0
  110. ksadk/evaluation/evidence.py +258 -0
  111. ksadk/evaluation/executor.py +143 -0
  112. ksadk/evaluation/local_adapter.py +550 -0
  113. ksadk/evaluation/service_env.py +27 -0
  114. ksadk/evaluation/storage.py +68 -0
  115. ksadk/evaluation/studio_build_adapter.py +253 -0
  116. ksadk/evaluation/target.py +82 -0
  117. ksadk/events/__init__.py +13 -13
  118. ksadk/events/_v1_compat/__init__.py +1 -0
  119. ksadk/events/_v1_compat/models.py +299 -0
  120. ksadk/events/_v1_compat/parser.py +247 -0
  121. ksadk/events/_v1_compat/projection.py +753 -0
  122. ksadk/events/adapters/__init__.py +34 -0
  123. ksadk/events/adapters/_a2a_snapshot.py +622 -0
  124. ksadk/events/adapters/_a2a_support.py +275 -0
  125. ksadk/events/adapters/_codex_interactions.py +375 -0
  126. ksadk/events/adapters/_codex_items.py +801 -0
  127. ksadk/events/adapters/_codex_validators.py +311 -0
  128. ksadk/events/adapters/_langgraph_support.py +785 -0
  129. ksadk/events/adapters/a2a.py +841 -0
  130. ksadk/events/adapters/adk.py +503 -0
  131. ksadk/events/adapters/codex.py +717 -0
  132. ksadk/events/adapters/langgraph.py +745 -0
  133. ksadk/events/canonical.py +440 -0
  134. ksadk/events/canonical_replay.py +497 -0
  135. ksadk/events/canonical_store.py +468 -0
  136. ksadk/events/cold_recovery.py +257 -0
  137. ksadk/events/content.py +89 -0
  138. ksadk/events/identity.py +86 -0
  139. ksadk/events/pipeline.py +455 -0
  140. ksadk/events/projections.py +66 -0
  141. ksadk/events/reducer.py +661 -0
  142. ksadk/events/replay.py +3 -36
  143. ksadk/events/runtime_event.py +20 -256
  144. ksadk/events/session_event.py +324 -0
  145. ksadk/events/store.py +3 -316
  146. ksadk/events/v1_compat.py +41 -0
  147. ksadk/harness/__init__.py +3 -2
  148. ksadk/harness/app.py +114 -123
  149. ksadk/harness/config.py +1 -1
  150. ksadk/harness/runtime.py +467 -0
  151. ksadk/hermes_terminal.py +5 -0
  152. ksadk/identity/resolver.py +4 -3
  153. ksadk/interaction/__init__.py +28 -0
  154. ksadk/interaction/contracts.py +136 -0
  155. ksadk/interaction/ledger.py +189 -0
  156. ksadk/interaction/provider.py +122 -0
  157. ksadk/interaction/providers/__init__.py +52 -0
  158. ksadk/interaction/providers/adk.py +40 -0
  159. ksadk/interaction/providers/codex.py +94 -0
  160. ksadk/interaction/providers/langgraph.py +58 -0
  161. ksadk/kernel/__init__.py +117 -0
  162. ksadk/kernel/authorization.py +258 -0
  163. ksadk/kernel/bootstrap.py +1074 -0
  164. ksadk/kernel/contract_fingerprints.py +61 -0
  165. ksadk/kernel/contracts.py +362 -0
  166. ksadk/kernel/control.py +219 -0
  167. ksadk/kernel/errors.py +79 -0
  168. ksadk/kernel/ingress.py +1102 -0
  169. ksadk/kernel/mapping.py +111 -0
  170. ksadk/kernel/memory_store.py +1133 -0
  171. ksadk/kernel/postgres_store.py +1756 -0
  172. ksadk/kernel/recovery.py +452 -0
  173. ksadk/kernel/runtime_identity.py +103 -0
  174. ksadk/kernel/sql/001_agent_kernel.sql +120 -0
  175. ksadk/kernel/sqlite_store.py +1410 -0
  176. ksadk/kernel/state.py +145 -0
  177. ksadk/kernel/store.py +232 -0
  178. ksadk/kernel/worker.py +953 -0
  179. ksadk/knowledge_base/client.py +22 -4
  180. ksadk/knowledge_base/service.py +32 -5
  181. ksadk/managed_a2a_card.py +160 -0
  182. ksadk/managed_runtime.py +16 -9
  183. ksadk/memory/__init__.py +61 -0
  184. ksadk/memory/adk/backends/base_ltm_backend.py +96 -1
  185. ksadk/memory/adk/backends/http_ltm_backend.py +14 -5
  186. ksadk/memory/adk/backends/inmemory_ltm_backend.py +136 -3
  187. ksadk/memory/adk/backends/sdk_ltm_backend.py +394 -5
  188. ksadk/memory/adk/backends/sqlite_ltm_backend.py +95 -0
  189. ksadk/memory/adk/long_term_memory.py +3 -2
  190. ksadk/memory/coordinator.py +461 -0
  191. ksadk/memory/events.py +202 -0
  192. ksadk/memory/extraction.py +228 -0
  193. ksadk/memory/ltm_backend_factory.py +16 -3
  194. ksadk/memory/models.py +316 -0
  195. ksadk/memory/policy.py +215 -0
  196. ksadk/memory/provider.py +47 -0
  197. ksadk/memory/provider_adapter.py +159 -0
  198. ksadk/memory/provider_resolver.py +71 -0
  199. ksadk/memory/providers/__init__.py +5 -0
  200. ksadk/memory/providers/local_sqlite.py +490 -0
  201. ksadk/memory/resolved_policy.py +145 -0
  202. ksadk/memory/service.py +198 -8
  203. ksadk/memory/tool.py +4 -0
  204. ksadk/model_proxy/bootstrap.py +16 -9
  205. ksadk/model_proxy/config.py +22 -1
  206. ksadk/model_proxy/detect.py +202 -9
  207. ksadk/model_proxy/namespace.py +67 -15
  208. ksadk/model_proxy/server.py +168 -6
  209. ksadk/model_proxy/transform.py +105 -3
  210. ksadk/observability/__init__.py +25 -0
  211. ksadk/observability/session_log.py +420 -0
  212. ksadk/observability/trajectory.py +105 -0
  213. ksadk/prompts/__init__.py +71 -0
  214. ksadk/prompts/compiler.py +215 -0
  215. ksadk/prompts/models.py +82 -0
  216. ksadk/prompts/projection.py +89 -0
  217. ksadk/prompts/resolved.py +137 -0
  218. ksadk/prompts/sources.py +233 -0
  219. ksadk/runners/_langgraph_runner_streams.py +822 -0
  220. ksadk/runners/adk_runner.py +14 -31
  221. ksadk/runners/base_runner.py +44 -3
  222. ksadk/runners/factory.py +3 -3
  223. ksadk/runners/langgraph_runner.py +252 -433
  224. ksadk/runners/utils/__init__.py +0 -10
  225. ksadk/runners/utils/loader.py +16 -0
  226. ksadk/runtime/__init__.py +67 -41
  227. ksadk/runtime/_runner_adapter/__init__.py +1 -0
  228. ksadk/runtime/_runner_adapter/stream_mapping.py +788 -0
  229. ksadk/runtime/adapter.py +199 -16
  230. ksadk/runtime/conversation_execution.py +687 -0
  231. ksadk/runtime/executor.py +392 -0
  232. ksadk/runtime/factory.py +342 -0
  233. ksadk/runtime/framework_adapters.py +6 -12
  234. ksadk/runtime/hosted_finalizer.py +268 -0
  235. ksadk/runtime/launch.py +61 -0
  236. ksadk/runtime/preprocessing.py +49 -14
  237. ksadk/runtime/runner_adapter.py +330 -391
  238. ksadk/runtime/runner_loading.py +36 -0
  239. ksadk/runtime/usage.py +33 -0
  240. ksadk/sandbox/backends/e2b.py +36 -3
  241. ksadk/server/__init__.py +39 -4
  242. ksadk/server/app.py +18 -492
  243. ksadk/server/composition.py +36 -2
  244. ksadk/server/factory.py +210 -149
  245. ksadk/server/routes/common.py +15 -46
  246. ksadk/server/routes/control.py +13 -9
  247. ksadk/server/routes/kernel_ingress.py +258 -0
  248. ksadk/server/routes/misc.py +10 -33
  249. ksadk/server/routes/models.py +14 -6
  250. ksadk/server/routes/openai_compat.py +129 -27
  251. ksadk/server/routes/projection.py +84 -16
  252. ksadk/server/routes/run.py +347 -460
  253. ksadk/server/routes/sessions.py +37 -40
  254. ksadk/server/routes/streaming.py +52 -7
  255. ksadk/server/routes/workspace.py +54 -21
  256. ksadk/server/static/assets/{ArtifactsPanel-Cjnqt-8W.js → ArtifactsPanel-DSU1sWD_.js} +1 -1
  257. ksadk/server/static/assets/{CodeBlock-BqyqZfuB.js → CodeBlock-DOH6MVcn.js} +4 -4
  258. ksadk/server/static/assets/{MathMessageMarkdown-BpH7jiFM.js → MathMessageMarkdown-BL8my1R2.js} +4 -4
  259. ksadk/server/static/assets/MathMessageMarkdown-BorAY7qD.css +1 -0
  260. ksadk/server/static/assets/MermaidBlock-Dz4IP-Tx.js +312 -0
  261. ksadk/server/static/assets/NativeTerminalPanel-DUrK0JpZ.js +1 -0
  262. ksadk/server/static/assets/abnfDiagram-VCTEODGH-g20pFzNV.js +1 -0
  263. ksadk/server/static/assets/arc-C4FzinUA.js +1 -0
  264. ksadk/server/static/assets/architecture-7GRP2DOG-DjKratdf.js +1 -0
  265. ksadk/server/static/assets/architectureDiagram-5GKGNRK7-DpIqL5h4.js +36 -0
  266. ksadk/server/static/assets/blockDiagram-NRAW4CY4-BjkljTNz.js +129 -0
  267. ksadk/server/static/assets/c4Diagram-UCG6FXSJ-Dk_ieq2X.js +38 -0
  268. ksadk/server/static/assets/channel-4cQHKtx1.js +1 -0
  269. ksadk/server/static/assets/chunk-2Q5K7J3B-DmgWkESh.js +1 -0
  270. ksadk/server/static/assets/{chunk-FMBD7UC4-BGhvzDYt.js → chunk-5VM5RSS4-BVHAchFb.js} +1 -1
  271. ksadk/server/static/assets/{chunk-ND2GUHAM-D98vPd-E.js → chunk-F27PBJKO-C-ipQzuS.js} +1 -1
  272. ksadk/server/static/assets/chunk-G27WJ6UU-C2EyJbIK.js +231 -0
  273. ksadk/server/static/assets/{chunk-4BX2VUAB-CsWIQRhc.js → chunk-JWPE2WC7-vYvVJb_M.js} +1 -1
  274. ksadk/server/static/assets/chunk-LCL6LL3I-BcI6ysPT.js +206 -0
  275. ksadk/server/static/assets/chunk-POPQ4Y6H-C030x_Z1.js +1 -0
  276. ksadk/server/static/assets/chunk-RHFEMEQ7-yyGpsz4n.js +168 -0
  277. ksadk/server/static/assets/chunk-SVP7TREG-BLTlmMU7.js +88 -0
  278. ksadk/server/static/assets/chunk-XXDRQBXY-C_32ArgP.js +1 -0
  279. ksadk/server/static/assets/classDiagram-DTDB5LWJ-DLFd9Xi0.js +1 -0
  280. ksadk/server/static/assets/classDiagram-v2-JRS7N3AN-DLFd9Xi0.js +1 -0
  281. ksadk/server/static/assets/{cose-bilkent-S5V4N54A-CX3yotHq.js → cose-bilkent-JH36ORCC-9YQYwdl0.js} +1 -1
  282. ksadk/server/static/assets/cynefin-OW5HDTMX-DjEM48Qp.js +1 -0
  283. ksadk/server/static/assets/cynefinDiagram-5FMLGOSQ-ErLF5N13.js +62 -0
  284. ksadk/server/static/assets/cytoscape.esm-CyCl8rPi.js +321 -0
  285. ksadk/server/static/assets/dagre-3AP2YEHR-DFiQF-6f.js +4 -0
  286. ksadk/server/static/assets/dagre-BuhGnRI1.js +1 -0
  287. ksadk/server/static/assets/diagram-S7CK7UJ4-Bt1v8-GC.js +30 -0
  288. ksadk/server/static/assets/diagram-UQ7AKVKN-DSCxJdBK.js +41 -0
  289. ksadk/server/static/assets/diagram-VSXAHHWV-DHfYwp_9.js +3 -0
  290. ksadk/server/static/assets/diagram-VX7I27RA-DdzD-4Le.js +24 -0
  291. ksadk/server/static/assets/diagram-Z3DM3KII-Du-nAJ9F.js +24 -0
  292. ksadk/server/static/assets/{dist-D82mtD2s.js → dist-8hqcx0sU.js} +1 -1
  293. ksadk/server/static/assets/dist-B7seoj3d.js +1 -0
  294. ksadk/server/static/assets/{dist-DHn6nBzr.js → dist-BE7bu-DL.js} +1 -1
  295. ksadk/server/static/assets/{dist-eoW6tZXA.js → dist-BVDffZ0U.js} +1 -1
  296. ksadk/server/static/assets/{dist-C2xjE7cO.js → dist-BX8z72IC.js} +1 -1
  297. ksadk/server/static/assets/{dist-CgF3fj15.js → dist-Bf2M8m3N.js} +1 -1
  298. ksadk/server/static/assets/{dist-Bs-jQcRX.js → dist-BjU6y-A2.js} +1 -1
  299. ksadk/server/static/assets/{dist-Djgl2wVZ.js → dist-BytlxIDT.js} +1 -1
  300. ksadk/server/static/assets/{dist-CVQRZjPu.js → dist-CSh_DE14.js} +1 -1
  301. ksadk/server/static/assets/{dist-6CVKuTAe.js → dist-CXYYBw3_.js} +1 -1
  302. ksadk/server/static/assets/{dist-DlzCRy0S.js → dist-C_wsv-Qd.js} +1 -1
  303. ksadk/server/static/assets/{dist-DF06ORQo.js → dist-ClxGviKw.js} +1 -1
  304. ksadk/server/static/assets/{dist-Cf23NY4L.js → dist-CttYUqzS.js} +1 -1
  305. ksadk/server/static/assets/{dist-ivOya1LD.js → dist-DNp6rLRA.js} +1 -1
  306. ksadk/server/static/assets/{dist-BibcG1V9.js → dist-DUX-id_F.js} +1 -1
  307. ksadk/server/static/assets/{dist-BUHRxvDG.js → dist-DmldrHd_.js} +1 -1
  308. ksadk/server/static/assets/{dist-BZ9n9AjO.js → dist-DnfXs8Vn.js} +2 -2
  309. ksadk/server/static/assets/{dist-DqNnNFrw.js → dist-Dq9gLD7L.js} +1 -1
  310. ksadk/server/static/assets/{dist-CGcp2ex8.js → dist-W-TIVntx.js} +1 -1
  311. ksadk/server/static/assets/{dist-Cwt7koer.js → dist-dDdADKFA.js} +1 -1
  312. ksadk/server/static/assets/{dist-C7-3jInC.js → dist-dydu68Fl.js} +1 -1
  313. ksadk/server/static/assets/{dist-C99THtIA.js → dist-ngtN0DJB.js} +1 -1
  314. ksadk/server/static/assets/ebnfDiagram-PWID7BFC-Da9C9NO1.js +1 -0
  315. ksadk/server/static/assets/erDiagram-SSCWMZ5O-EAGqqR79.js +99 -0
  316. ksadk/server/static/assets/eventmodeling-NTZA5JFV-CMgMaJrC.js +1 -0
  317. ksadk/server/static/assets/flowDiagram-A5DVABFB-BBKL0x3P.js +1 -0
  318. ksadk/server/static/assets/ganttDiagram-EL5Y4UJY-DqJsKb59.js +292 -0
  319. ksadk/server/static/assets/gitGraph-4MIJSDKK-Dw63mrhw.js +1 -0
  320. ksadk/server/static/assets/gitGraphDiagram-WWUBYQGX-B6g4dtDi.js +106 -0
  321. ksadk/server/static/assets/index-8ipRcQ-M.js +240 -0
  322. ksadk/server/static/assets/index-ByFCqjlh.css +2 -0
  323. ksadk/server/static/assets/info-A6RAGUB7-B6iAblII.js +1 -0
  324. ksadk/server/static/assets/infoDiagram-RXCK75RN-Djm_nbd5.js +2 -0
  325. ksadk/server/static/assets/{ishikawaDiagram-YF4QCWOH-DLOHGvWw.js → ishikawaDiagram-5VMMS53U-DWya9SG2.js} +6 -6
  326. ksadk/server/static/assets/{journeyDiagram-JHISSGLW-BIzKeejT.js → journeyDiagram-EYS64GPL-DutxhSNI.js} +6 -6
  327. ksadk/server/static/assets/{kanban-definition-UN3LZRKU-BWHoFSw2.js → kanban-definition-3QL26DDD-DJdOF8Fm.js} +10 -10
  328. ksadk/server/static/assets/katex-vFWytM5c.js +257 -0
  329. ksadk/server/static/assets/{linear-CvMBw9cA.js → linear-BHjG8b-J.js} +1 -1
  330. ksadk/server/static/assets/mermaid-parser.core-KGSy4jWT.js +166 -0
  331. ksadk/server/static/assets/{mindmap-definition-RKZ34NQL-CSAQxEAe.js → mindmap-definition-FBJOCRG2-9-HC88D4.js} +29 -29
  332. ksadk/server/static/assets/packet-AYTQ26CC-BOYAipuq.js +1 -0
  333. ksadk/server/static/assets/pegDiagram-XKGWAZYB-DrEZd4fD.js +1 -0
  334. ksadk/server/static/assets/pie-WAS4IAKB-Ctq0Kbku.js +1 -0
  335. ksadk/server/static/assets/pieDiagram-E7YTZNPT-DpjqOFFp.js +39 -0
  336. ksadk/server/static/assets/{quadrantDiagram-W4KKPZXB-CxIR4JXI.js → quadrantDiagram-AXDQQJYC-BiNhgOXX.js} +6 -6
  337. ksadk/server/static/assets/radar-RG4KPBEZ-DN0-ul_0.js +1 -0
  338. ksadk/server/static/assets/railroad-74A4TZTK-C6cC_to0.js +1 -0
  339. ksadk/server/static/assets/railroad-abnf-HS5TGJTU-BimjIuRc.js +1 -0
  340. ksadk/server/static/assets/railroad-ebnf-LZEXJU2U-CvY65ABq.js +1 -0
  341. ksadk/server/static/assets/railroad-peg-WCYAUIDC-D72Iq_Tv.js +1 -0
  342. ksadk/server/static/assets/railroadDiagram-O6MQD6OU-_Y3Ojg6G.js +1 -0
  343. ksadk/server/static/assets/requirementDiagram-EFPCY7ZU-DeCFdg9K.js +84 -0
  344. ksadk/server/static/assets/{sankeyDiagram-5OEKKPKP-DpGa6EAV.js → sankeyDiagram-P5KCCOFB-CPH75rhw.js} +7 -7
  345. ksadk/server/static/assets/{sequenceDiagram-3UESZ5HK-NTKNGGe5.js → sequenceDiagram-WJ2MYXX4-OEpQQdr4.js} +10 -10
  346. ksadk/server/static/assets/sizeCapture-X5ZJPWSS-heUErzhI.js +1 -0
  347. ksadk/server/static/assets/stateDiagram-HBIQ2CUA-DvA3jSMB.js +1 -0
  348. ksadk/server/static/assets/stateDiagram-v2-4QOOHH4V-BgQY03nz.js +1 -0
  349. ksadk/server/static/assets/swimlanes-XN3QIQJK-CR-dfN_t.js +1 -0
  350. ksadk/server/static/assets/swimlanesDiagram-VK2B7HYN-DLVw3q5Q.js +8 -0
  351. ksadk/server/static/assets/{timeline-definition-PNZ67QCA-jqoYs3jQ.js → timeline-definition-24CTP7MA-DAVJf1TX.js} +7 -7
  352. ksadk/server/static/assets/treeView-Q6P3EWNA-BMpO0wsB.js +1 -0
  353. ksadk/server/static/assets/treemap-WGGIJYW6-Et0aqzU3.js +1 -0
  354. ksadk/server/static/assets/vennDiagram-4TSXK5OY-DwM8eDkh.js +34 -0
  355. ksadk/server/static/assets/wardley-WFR3VGLG-CbY0mhpl.js +1 -0
  356. ksadk/server/static/assets/wardleyDiagram-VM6X3IG4-DZL-Zz2t.js +78 -0
  357. ksadk/server/static/assets/xychartDiagram-S5SC5T6Z-Dy6Yh_hu.js +7 -0
  358. ksadk/server/static/index.html +2 -2
  359. ksadk/sessions/__init__.py +26 -9
  360. ksadk/sessions/_local_service_sync.py +688 -0
  361. ksadk/sessions/_local_tables.py +21 -0
  362. ksadk/sessions/_postgres_schema.py +305 -0
  363. ksadk/sessions/_postgres_tables.py +15 -0
  364. ksadk/sessions/base.py +80 -1
  365. ksadk/sessions/in_memory.py +53 -2
  366. ksadk/sessions/local_service.py +63 -604
  367. ksadk/sessions/postgres_service.py +58 -148
  368. ksadk/sessions/resilient.py +35 -1
  369. ksadk/skills/runtime/backends/e2b.py +1 -1
  370. ksadk/skills/service_client.py +13 -3
  371. ksadk/studio/__init__.py +5 -0
  372. ksadk/studio/agent_avatar_assets.py +120 -0
  373. ksadk/studio/agent_lifecycle.py +51 -0
  374. ksadk/studio/api.py +1598 -0
  375. ksadk/studio/api_catalog_routes.py +324 -0
  376. ksadk/studio/api_contracts.py +286 -0
  377. ksadk/studio/api_helpers.py +132 -0
  378. ksadk/studio/api_memory_routes.py +82 -0
  379. ksadk/studio/authoring.py +749 -0
  380. ksadk/studio/authoring_coordinator.py +1017 -0
  381. ksadk/studio/builder.py +397 -0
  382. ksadk/studio/capabilities.py +368 -0
  383. ksadk/studio/cloud.py +2099 -0
  384. ksadk/studio/codex_agent_service.py +694 -0
  385. ksadk/studio/codex_authoring.py +469 -0
  386. ksadk/studio/codex_builder.py +437 -0
  387. ksadk/studio/codex_manifest.py +307 -0
  388. ksadk/studio/codex_run.py +395 -0
  389. ksadk/studio/compiler.py +190 -0
  390. ksadk/studio/contracts.py +755 -0
  391. ksadk/studio/errors.py +47 -0
  392. ksadk/studio/event_store.py +214 -0
  393. ksadk/studio/framework_run.py +342 -0
  394. ksadk/studio/hosted_kernel.py +317 -0
  395. ksadk/studio/identifiers.py +33 -0
  396. ksadk/studio/manifest_resolver.py +131 -0
  397. ksadk/studio/mcp_runtime.py +229 -0
  398. ksadk/studio/model_client.py +629 -0
  399. ksadk/studio/model_profile_service.py +214 -0
  400. ksadk/studio/operations.py +275 -0
  401. ksadk/studio/otel_trace.py +1060 -0
  402. ksadk/studio/pagination.py +182 -0
  403. ksadk/studio/pcm_memory.py +85 -0
  404. ksadk/studio/python_tool_inspection.py +183 -0
  405. ksadk/studio/repository.py +327 -0
  406. ksadk/studio/resource_catalog.py +1260 -0
  407. ksadk/studio/run_service.py +1133 -0
  408. ksadk/studio/runtime_catalog.py +74 -0
  409. ksadk/studio/runtime_source.py +365 -0
  410. ksadk/studio/service.py +2249 -0
  411. ksadk/studio/shared_web.py +1004 -0
  412. ksadk/studio/skill_discovery.py +628 -0
  413. ksadk/studio/static/assets/PrismRenderer-IYN-ffww.js +3 -0
  414. ksadk/studio/static/assets/index-BLpcdrgW.css +1 -0
  415. ksadk/studio/static/assets/index-CYekR2Xv.js +260 -0
  416. ksadk/studio/static/assets/react-vendor-BNmTiJ-I.js +9 -0
  417. ksadk/studio/static/assets/rolldown-runtime-hePW80VL.js +1 -0
  418. ksadk/studio/static/index.html +15 -0
  419. ksadk/studio/templates.py +722 -0
  420. ksadk/studio/validator.py +265 -0
  421. ksadk/studio/workspace.py +135 -0
  422. ksadk/tools/gateway.py +9 -0
  423. ksadk/toolsets/__init__.py +27 -1
  424. ksadk/toolsets/a2a.py +426 -0
  425. ksadk/tracing/__init__.py +19 -21
  426. ksadk/tracing/setup.py +317 -403
  427. ksadk/tracing/span_utils.py +0 -44
  428. ksadk/version.py +1 -1
  429. ksadk_runtime_common/memory_backend/registry.py +56 -56
  430. ksadk_runtime_common/schemas/runtime_event_v1.json +37 -0
  431. ksadk_runtime_common/schemas/runtime_event_v2.json +271 -0
  432. ksadk_runtime_common/workspace_files/router.py +8 -2
  433. agentengine_sdk_python-0.8.0.dist-info/RECORD +0 -578
  434. ksadk/a2a/card_builder.py +0 -64
  435. ksadk/a2a/client.py +0 -309
  436. ksadk/events/parser.py +0 -191
  437. ksadk/harness/runner.py +0 -211
  438. ksadk/runners/codex_runner.py +0 -132
  439. ksadk/runners/utils/langfuse.py +0 -230
  440. ksadk/server/static/assets/MathMessageMarkdown-DeYh8QPr.css +0 -1
  441. ksadk/server/static/assets/MermaidBlock-DWuxETaJ.js +0 -303
  442. ksadk/server/static/assets/NativeTerminalPanel-MDTopWMO.js +0 -1
  443. ksadk/server/static/assets/arc-CFKwSk_B.js +0 -1
  444. ksadk/server/static/assets/architecture-7EHR7CIX-CynqOWjZ.js +0 -1
  445. ksadk/server/static/assets/architectureDiagram-3BPJPVTR-Dej8jX8c.js +0 -36
  446. ksadk/server/static/assets/blockDiagram-GPEHLZMM-1F64jqvy.js +0 -132
  447. ksadk/server/static/assets/c4Diagram-AAUBKEIU-9q7AUAKb.js +0 -10
  448. ksadk/server/static/assets/channel-iUGv2N24.js +0 -1
  449. ksadk/server/static/assets/chunk-2J33WTMH-6qgwJm7Q.js +0 -1
  450. ksadk/server/static/assets/chunk-55IACEB6-BK8paA20.js +0 -1
  451. ksadk/server/static/assets/chunk-727SXJPM-B-JEhy7h.js +0 -206
  452. ksadk/server/static/assets/chunk-AQP2D5EJ-DYBvMHAa.js +0 -231
  453. ksadk/server/static/assets/chunk-QZHKN3VN-YQIEXeF6.js +0 -1
  454. ksadk/server/static/assets/classDiagram-4FO5ZUOK-CDAUuoXK.js +0 -1
  455. ksadk/server/static/assets/classDiagram-v2-Q7XG4LA2-CDAUuoXK.js +0 -1
  456. ksadk/server/static/assets/cytoscape.esm-DelgaX4f.js +0 -321
  457. ksadk/server/static/assets/dagre-BM42HDAG-C7TguAWo.js +0 -4
  458. ksadk/server/static/assets/dagre-Bx709z4p.js +0 -1
  459. ksadk/server/static/assets/diagram-2AECGRRQ-Dd17_kws.js +0 -43
  460. ksadk/server/static/assets/diagram-5GNKFQAL-DVIClIil.js +0 -10
  461. ksadk/server/static/assets/diagram-KO2AKTUF-Df_3gYQa.js +0 -3
  462. ksadk/server/static/assets/diagram-LMA3HP47-BhLk6ZtA.js +0 -24
  463. ksadk/server/static/assets/diagram-OG6HWLK6-D4GNGvuu.js +0 -24
  464. ksadk/server/static/assets/dist-DyvYLMW9.js +0 -1
  465. ksadk/server/static/assets/erDiagram-TEJ5UH35-CnfRcY2M.js +0 -85
  466. ksadk/server/static/assets/eventmodeling-FCH6USID-ChYO-ijM.js +0 -1
  467. ksadk/server/static/assets/flowDiagram-I6XJVG4X-DGaJjGNJ.js +0 -162
  468. ksadk/server/static/assets/ganttDiagram-6RSMTGT7-DpCoB2g9.js +0 -292
  469. ksadk/server/static/assets/gitGraph-WXDBUCRP-BN_0Fk-j.js +0 -1
  470. ksadk/server/static/assets/gitGraphDiagram-PVQCEYII-9IKVFBVT.js +0 -106
  471. ksadk/server/static/assets/graphlib-B8gBHxth.js +0 -1
  472. ksadk/server/static/assets/index-QSwCHuB8.js +0 -177
  473. ksadk/server/static/assets/index-jOPmTOZH.css +0 -2
  474. ksadk/server/static/assets/info-J43DQDTF-Cp6o3vId.js +0 -1
  475. ksadk/server/static/assets/infoDiagram-5YYISTIA-CYIIsb8y.js +0 -2
  476. ksadk/server/static/assets/katex-DATssjp1.js +0 -265
  477. ksadk/server/static/assets/mermaid-parser.core-mGAcEwcq.js +0 -161
  478. ksadk/server/static/assets/packet-YPE3B663-wQzct3cT.js +0 -1
  479. ksadk/server/static/assets/pie-LRSECV5Y-BgTQiv-9.js +0 -1
  480. ksadk/server/static/assets/pieDiagram-4H26LBE5-By-ra07M.js +0 -30
  481. ksadk/server/static/assets/radar-GUYGQ44K-BIq5fXsn.js +0 -1
  482. ksadk/server/static/assets/requirementDiagram-4Y6WPE33-DpW90iu3.js +0 -84
  483. ksadk/server/static/assets/stateDiagram-AJRCARHV-DGpd9yFG.js +0 -1
  484. ksadk/server/static/assets/stateDiagram-v2-BHNVJYJU-B3o579IQ.js +0 -1
  485. ksadk/server/static/assets/treeView-BLDUP644-Dqi-E0EM.js +0 -1
  486. ksadk/server/static/assets/treemap-LRROVOQU-ClQP9CJ9.js +0 -1
  487. ksadk/server/static/assets/vennDiagram-CIIHVFJN-l3Z7-wbP.js +0 -34
  488. ksadk/server/static/assets/wardley-L42UT6IY-8XLvnNIs.js +0 -1
  489. ksadk/server/static/assets/wardleyDiagram-YWT4CUSO-BR54GPmr.js +0 -78
  490. ksadk/server/static/assets/xychartDiagram-2RQKCTM6-SkiH8GsK.js +0 -7
  491. ksadk/tracing/exporters/langfuse_exporter.py +0 -460
  492. {agentengine_sdk_python-0.8.0.dist-info → agentengine_sdk_python-0.8.2.dist-info}/entry_points.txt +0 -0
  493. {agentengine_sdk_python-0.8.0.dist-info → agentengine_sdk_python-0.8.2.dist-info}/licenses/LICENSE +0 -0
  494. {agentengine_sdk_python-0.8.0.dist-info → agentengine_sdk_python-0.8.2.dist-info}/top_level.txt +0 -0
@@ -0,0 +1,745 @@
1
+ """LangGraph 1.2.x raw v3 ProtocolEvents to RuntimeEvent schema v2."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from collections.abc import AsyncIterator, Callable, Mapping, Sequence
6
+ from typing import Any
7
+
8
+ from langchain_core.messages import AIMessage, ToolMessage
9
+ from langgraph.stream import AsyncGraphRunStream
10
+
11
+ from ksadk.events.adapters._langgraph_support import (
12
+ _LIFECYCLE_QUIET_TYPES,
13
+ LangGraphAdapterContext,
14
+ LangGraphMappingError,
15
+ _block_index,
16
+ _envelope,
17
+ _fail,
18
+ _Frame,
19
+ _interrupt_reason,
20
+ _json_value,
21
+ _lane_completed,
22
+ _lane_for_content,
23
+ _lane_for_index,
24
+ _lane_source,
25
+ _lane_started,
26
+ _lane_updated,
27
+ _LifecycleState,
28
+ _map_data_channel,
29
+ _map_whole_message,
30
+ _mapping,
31
+ _message_data,
32
+ _MessageState,
33
+ _namespace,
34
+ _namespace_identity,
35
+ _new_lane,
36
+ _optional_string,
37
+ _parent_scope_id,
38
+ _part_id,
39
+ _protocol_timestamp,
40
+ _required_string,
41
+ _scope_id,
42
+ _server_tool_result_snapshot,
43
+ _source_ref,
44
+ _source_seq,
45
+ _text_block_delta,
46
+ _text_block_snapshot,
47
+ _tool_call_snapshot,
48
+ _ToolState,
49
+ _validate_tool_delta,
50
+ )
51
+ from ksadk.events.canonical import (
52
+ ApprovalRequest,
53
+ ContinuationCreated,
54
+ ErrorInfo,
55
+ InteractionRequested,
56
+ ItemCompleted,
57
+ ItemFailed,
58
+ ItemStarted,
59
+ ItemUpdated,
60
+ RunInterrupted,
61
+ RunProgress,
62
+ RuntimeEvent,
63
+ SourceRef,
64
+ )
65
+ from ksadk.events.content import (
66
+ ContentSnapshot,
67
+ DataContent,
68
+ ToolResultContent,
69
+ )
70
+ from ksadk.events.identity import (
71
+ stable_item_id,
72
+ )
73
+
74
+ # Native content-block types that carry a tool call identity.
75
+ _TOOL_CALL_BLOCKS = frozenset(
76
+ "tool_call tool_call_chunk server_tool_call server_tool_call_chunk".split()
77
+ )
78
+ # Native tool-call delta shapes accepted without a payload translation.
79
+ _TOOL_DELTA_TYPES = frozenset(
80
+ "tool_call tool_call_chunk tool_call-delta server_tool_call server_tool_call_chunk".split()
81
+ )
82
+
83
+
84
+ class LangGraphEventAdapter:
85
+ """Consume the lossless raw log exposed by ``AsyncGraphRunStream``."""
86
+
87
+ def __init__(self) -> None:
88
+ self._messages: dict[tuple[str, str], _MessageState] = {}
89
+ self._tools: dict[tuple[str, str], _ToolState] = {}
90
+ self._lifecycles: dict[str, _LifecycleState] = {}
91
+
92
+ async def stream_run(
93
+ self,
94
+ run: AsyncGraphRunStream,
95
+ context: LangGraphAdapterContext,
96
+ ) -> AsyncIterator[RuntimeEvent]:
97
+ """Map a public v3 run's raw ProtocolEvent log in source order."""
98
+
99
+ try:
100
+ async for native_event in run:
101
+ for canonical in self.map_protocol_event(native_event, context):
102
+ yield canonical
103
+ if self._messages or self._tools or self._lifecycles:
104
+ open_runs = ", ".join(sorted(state.llm_run_id for state in self._messages.values()))
105
+ open_calls = ", ".join(sorted(state.call_id for state in self._tools.values()))
106
+ open_scopes = ", ".join(sorted(self._lifecycles))
107
+ if self._messages and not self._tools and not self._lifecycles:
108
+ code, field_name = "open_messages_at_stream_end", "messages metadata.run_id"
109
+ elif self._tools and not self._messages and not self._lifecycles:
110
+ code, field_name = "open_tools_at_stream_end", "tools tool_call_id"
111
+ elif self._lifecycles and not self._messages and not self._tools:
112
+ code, field_name = "open_lifecycle_at_stream_end", "lifecycle namespace"
113
+ else:
114
+ code, field_name = "open_items_at_stream_end", "ProtocolEvent"
115
+ _fail(
116
+ code,
117
+ field_name,
118
+ "LangGraph stream ended with open native items: "
119
+ f"message_runs=[{open_runs}], tool_calls=[{open_calls}], "
120
+ f"lifecycle_scopes=[{open_scopes}]",
121
+ )
122
+ finally:
123
+ await run.abort()
124
+
125
+ def map_protocol_event(
126
+ self,
127
+ raw_event: Mapping[str, Any],
128
+ context: LangGraphAdapterContext,
129
+ ) -> tuple[RuntimeEvent, ...]:
130
+ """Map one real ProtocolEvent yielded by ``AsyncGraphRunStream``."""
131
+
132
+ event = _mapping(raw_event, "ProtocolEvent")
133
+ if event.get("type") != "event":
134
+ _fail(
135
+ "invalid_protocol_event",
136
+ "type",
137
+ "LangGraph ProtocolEvent.type must be 'event'",
138
+ )
139
+ method = _required_string(event.get("method"), "ProtocolEvent.method")
140
+ params = _mapping(event.get("params"), "ProtocolEvent.params")
141
+ namespace = _namespace(params.get("namespace"))
142
+ source_seq = _source_seq(event.get("seq"))
143
+ native_event_id = _optional_string(event.get("event_id"))
144
+ frame = _Frame(
145
+ namespace=namespace,
146
+ scope_id=_scope_id(context.graph_run_id, namespace),
147
+ parent_scope_id=_parent_scope_id(context.graph_run_id, namespace),
148
+ source_seq=source_seq,
149
+ native_event_id=native_event_id,
150
+ occurrence_key=native_event_id or f"seq:{source_seq}",
151
+ timestamp=_protocol_timestamp(params.get("timestamp")),
152
+ )
153
+
154
+ method_lane = {
155
+ "messages": self._map_message_event,
156
+ "tools": self._map_tool_event,
157
+ "lifecycle": self._map_lifecycle_event,
158
+ }.get(method)
159
+ if method_lane is not None:
160
+ return method_lane(params=params, context=context, frame=frame)
161
+
162
+ source = _source_ref(
163
+ channel=method,
164
+ native_run_id=context.graph_run_id,
165
+ native_item_id=None,
166
+ source_seq=source_seq,
167
+ native_event_id=native_event_id,
168
+ extra={"namespace": list(namespace)},
169
+ )
170
+ if "data" not in params:
171
+ _fail(
172
+ "missing_protocol_data",
173
+ "ProtocolEvent.params.data",
174
+ f"LangGraph {method} event requires params.data",
175
+ )
176
+ interrupts = params.get("interrupts", ())
177
+ if method == "values" and interrupts:
178
+ return self._map_interrupt(
179
+ context=context, frame=frame, source=source, interrupts=interrupts
180
+ )
181
+ return _map_data_channel(
182
+ context=context, frame=frame, method=method, source=source, value=params["data"]
183
+ )
184
+
185
+ def _map_lifecycle_event(
186
+ self,
187
+ *,
188
+ params: Mapping[str, Any],
189
+ context: LangGraphAdapterContext,
190
+ frame: _Frame,
191
+ ) -> tuple[RuntimeEvent, ...]:
192
+ env = _envelope(context, frame.occurrence_key, frame.timestamp)
193
+ payload = _mapping(params.get("data"), "lifecycle data")
194
+ native_type = _required_string(payload.get("event"), "lifecycle event")
195
+ target_namespace = _namespace(payload.get("namespace"))
196
+ if not target_namespace:
197
+ _fail(
198
+ "unsupported_root_lifecycle",
199
+ "lifecycle namespace",
200
+ "LangGraph v3 lifecycle events must identify a nested target scope",
201
+ )
202
+ scope_id = _scope_id(context.graph_run_id, target_namespace)
203
+ parent_scope_id = _parent_scope_id(context.graph_run_id, target_namespace)
204
+ item_id = stable_item_id(
205
+ "langgraph", scope_id, "lifecycle", _namespace_identity(target_namespace)
206
+ )
207
+ source = _source_ref(
208
+ channel="lifecycle",
209
+ native_run_id=context.graph_run_id,
210
+ native_item_id=target_namespace[-1],
211
+ source_seq=frame.source_seq,
212
+ native_event_id=frame.native_event_id,
213
+ extra={
214
+ "emitter_namespace": list(frame.namespace),
215
+ "target_namespace": list(target_namespace),
216
+ },
217
+ )
218
+ part = DataContent(
219
+ part_id=_part_id(item_id, "lifecycle-status"),
220
+ data=_json_value(payload),
221
+ )
222
+ envelope = lambda event_type: env( # noqa: E731
223
+ scope_id, parent_scope_id, item_id, event_type, part.part_id, source
224
+ )
225
+
226
+ if native_type == "started":
227
+ if scope_id in self._lifecycles:
228
+ _fail(
229
+ "lifecycle_already_started",
230
+ "lifecycle namespace",
231
+ "LangGraph nested lifecycle started twice",
232
+ )
233
+ start_state = _LifecycleState(
234
+ scope_id=scope_id,
235
+ parent_scope_id=parent_scope_id,
236
+ item_id=item_id,
237
+ namespace=target_namespace,
238
+ )
239
+ self._lifecycles[scope_id] = start_state
240
+ return (
241
+ RunProgress(
242
+ **envelope("run.progress"),
243
+ status="running",
244
+ message=f"LangGraph subgraph {native_type}",
245
+ ),
246
+ ItemStarted(
247
+ **envelope("item.started"),
248
+ item_id=item_id,
249
+ item_kind="status",
250
+ phase="commentary",
251
+ initial=ContentSnapshot(parts=(part,)),
252
+ ),
253
+ )
254
+
255
+ terminal_state = self._lifecycles.get(scope_id)
256
+ if terminal_state is None:
257
+ _fail(
258
+ "lifecycle_not_started",
259
+ "lifecycle namespace",
260
+ "LangGraph nested lifecycle terminated before started",
261
+ )
262
+ if native_type == "failed":
263
+ del self._lifecycles[scope_id]
264
+ message = str(payload.get("error") or "LangGraph subgraph failed")
265
+ return (
266
+ ItemFailed(
267
+ **envelope("item.failed"),
268
+ item_id=item_id,
269
+ item_kind="status",
270
+ error=ErrorInfo(
271
+ code="langgraph_subgraph_failed",
272
+ message=message,
273
+ source="langgraph",
274
+ scope_id=scope_id,
275
+ item_id=item_id,
276
+ source_ref=source,
277
+ ),
278
+ ),
279
+ )
280
+ if native_type not in {"completed", "interrupted", "drained"}:
281
+ _fail(
282
+ "unsupported_lifecycle_event",
283
+ "lifecycle event",
284
+ f"Unsupported LangGraph lifecycle event: {native_type}",
285
+ )
286
+ del self._lifecycles[scope_id]
287
+ progress = (
288
+ RunProgress(
289
+ **envelope("run.progress"),
290
+ status="running",
291
+ message=f"LangGraph subgraph {native_type}",
292
+ )
293
+ if native_type not in _LIFECYCLE_QUIET_TYPES
294
+ else None
295
+ )
296
+ completed = ItemCompleted(
297
+ **envelope("item.completed"),
298
+ item_id=item_id,
299
+ item_kind="status",
300
+ snapshot=ContentSnapshot(parts=(part,)),
301
+ )
302
+ if progress is not None:
303
+ return (progress, completed)
304
+ return (completed,)
305
+
306
+ def _map_tool_event(
307
+ self,
308
+ *,
309
+ params: Mapping[str, Any],
310
+ context: LangGraphAdapterContext,
311
+ frame: _Frame,
312
+ ) -> tuple[RuntimeEvent, ...]:
313
+ env = _envelope(context, frame.occurrence_key, frame.timestamp)
314
+ payload = _mapping(params.get("data"), "tools data")
315
+ native_type = _required_string(payload.get("event"), "tools event")
316
+ call_id = _required_string(payload.get("tool_call_id"), "tools tool_call_id")
317
+ state_key = (frame.scope_id, call_id)
318
+ source = _source_ref(
319
+ channel="tools",
320
+ native_run_id=context.graph_run_id,
321
+ native_item_id=call_id,
322
+ source_seq=frame.source_seq,
323
+ native_event_id=frame.native_event_id,
324
+ extra={"namespace": list(frame.namespace)},
325
+ )
326
+ if native_type == "tool-started":
327
+ if state_key in self._tools:
328
+ _fail(
329
+ "tool_already_started",
330
+ "tools tool_call_id",
331
+ f"LangGraph tool call {call_id!r} started twice",
332
+ )
333
+ name = _required_string(payload.get("tool_name"), "tools tool_name")
334
+ item_id = stable_item_id("langgraph", frame.scope_id, "tool_result", call_id)
335
+ self._tools[state_key] = _ToolState(
336
+ scope_id=frame.scope_id,
337
+ parent_scope_id=frame.parent_scope_id,
338
+ call_id=call_id,
339
+ name=name,
340
+ item_id=item_id,
341
+ )
342
+ return (
343
+ ItemStarted(
344
+ **env(
345
+ frame.scope_id,
346
+ frame.parent_scope_id,
347
+ item_id,
348
+ "item.started",
349
+ "tool-result",
350
+ source,
351
+ ),
352
+ item_id=item_id,
353
+ item_kind="tool_result",
354
+ phase="commentary",
355
+ ),
356
+ )
357
+
358
+ state = self._tools.get(state_key)
359
+ if state is None:
360
+ _fail(
361
+ "tool_not_started",
362
+ "tools tool_call_id",
363
+ f"LangGraph tool call {call_id!r} mutated before tool-started",
364
+ )
365
+ envelope = lambda event_type, part_id: env( # noqa: E731
366
+ frame.scope_id, frame.parent_scope_id, state.item_id, event_type, part_id, source
367
+ )
368
+
369
+ if native_type == "tool-output-delta":
370
+ part = DataContent(
371
+ part_id=_part_id(state.item_id, "tool-output-deltas"),
372
+ data=[_json_value(payload.get("delta"))],
373
+ )
374
+ return (
375
+ ItemUpdated(
376
+ **envelope("item.updated", part.part_id),
377
+ item_id=state.item_id,
378
+ item_kind="tool_result",
379
+ op="append",
380
+ update=part,
381
+ ),
382
+ )
383
+ if native_type == "tool-finished":
384
+ output = payload.get("output")
385
+ result_value = output.content if isinstance(output, ToolMessage) else output
386
+ is_error = isinstance(output, ToolMessage) and output.status == "error"
387
+ result = ToolResultContent(
388
+ part_id=_part_id(state.item_id, "tool-result", call_id),
389
+ call_id=call_id,
390
+ result=_json_value(result_value),
391
+ is_error=is_error,
392
+ )
393
+ del self._tools[state_key]
394
+ return (
395
+ ItemCompleted(
396
+ **envelope("item.completed", result.part_id),
397
+ item_id=state.item_id,
398
+ item_kind="tool_result",
399
+ snapshot=ContentSnapshot(parts=(result,)),
400
+ ),
401
+ )
402
+ if native_type == "tool-error":
403
+ del self._tools[state_key]
404
+ message = str(payload.get("message") or "LangGraph tool call failed")
405
+ return (
406
+ ItemFailed(
407
+ **envelope("item.failed", "tool-result"),
408
+ item_id=state.item_id,
409
+ item_kind="tool_result",
410
+ error=ErrorInfo(
411
+ code="langgraph_tool_error",
412
+ message=message,
413
+ source="langgraph",
414
+ scope_id=frame.scope_id,
415
+ item_id=state.item_id,
416
+ source_ref=source,
417
+ ),
418
+ ),
419
+ )
420
+ _fail(
421
+ "unsupported_tools_event",
422
+ "tools event",
423
+ f"Unsupported LangGraph tools event: {native_type}",
424
+ )
425
+
426
+ def _map_message_event(
427
+ self,
428
+ *,
429
+ params: Mapping[str, Any],
430
+ context: LangGraphAdapterContext,
431
+ frame: _Frame,
432
+ ) -> tuple[RuntimeEvent, ...]:
433
+ payload, metadata = _message_data(params.get("data"))
434
+ node = _required_string(metadata.get("langgraph_node"), "messages metadata.langgraph_node")
435
+ if isinstance(payload, AIMessage):
436
+ return _map_whole_message(
437
+ payload=payload,
438
+ metadata=metadata,
439
+ context=context,
440
+ frame=frame,
441
+ node=node,
442
+ )
443
+
444
+ payload = _mapping(payload, "params.data[0]")
445
+ native_type = _required_string(payload.get("event"), "MessagesData.event")
446
+ llm_run_id = _required_string(metadata.get("run_id"), "messages metadata.run_id")
447
+ state_key = (frame.scope_id, llm_run_id)
448
+
449
+ if native_type == "message-start":
450
+ message_id = _required_string(payload.get("id"), "message-start.id")
451
+ if state_key in self._messages:
452
+ _fail(
453
+ "message_already_started",
454
+ "messages metadata.run_id",
455
+ "LangGraph LLM run emitted a second message-start",
456
+ )
457
+ self._messages[state_key] = _MessageState(
458
+ scope_id=frame.scope_id,
459
+ parent_scope_id=frame.parent_scope_id,
460
+ llm_run_id=llm_run_id,
461
+ message_id=message_id,
462
+ node=node,
463
+ )
464
+ return ()
465
+
466
+ state = self._messages.get(state_key)
467
+ if state is None:
468
+ _fail(
469
+ "message_not_started",
470
+ "messages metadata.run_id",
471
+ "LangGraph message mutation arrived before message-start",
472
+ )
473
+ if state.node != node:
474
+ _fail(
475
+ "conflicting_message_node",
476
+ "messages metadata.langgraph_node",
477
+ "LangGraph LLM run changed node during one message",
478
+ )
479
+ source = _source_ref(
480
+ channel="messages",
481
+ native_run_id=state.llm_run_id,
482
+ native_item_id=state.message_id,
483
+ source_seq=frame.source_seq,
484
+ native_event_id=frame.native_event_id,
485
+ extra={
486
+ "graph_run_id": context.graph_run_id,
487
+ "namespace": list(frame.namespace),
488
+ "node": state.node,
489
+ },
490
+ )
491
+ env = _envelope(context, frame.occurrence_key, frame.timestamp)
492
+ lane_env = lambda lane, event_type, part_id, ordinal=0: env( # noqa: E731
493
+ state.scope_id,
494
+ state.parent_scope_id,
495
+ lane.item_id,
496
+ event_type,
497
+ part_id,
498
+ _lane_source(source, lane),
499
+ ordinal,
500
+ )
501
+
502
+ if native_type in {"content-block-start", "content-block-delta", "content-block-finish"}:
503
+ return self._map_content_block_event(
504
+ payload=payload,
505
+ native_type=native_type,
506
+ state=state,
507
+ lane_env=lane_env,
508
+ source=source,
509
+ )
510
+
511
+ if native_type == "message-finish":
512
+ unfinished_blocks = sorted(set(state.block_lanes).difference(state.finished_blocks))
513
+ if unfinished_blocks:
514
+ _fail(
515
+ "incomplete_content_block",
516
+ "content-block-finish",
517
+ "LangGraph message finished before native block completion: "
518
+ f"{unfinished_blocks}",
519
+ )
520
+ del self._messages[state_key]
521
+ if not state.lanes:
522
+ lane = _new_lane(state, "message", state.message_id)
523
+ state.lanes["message"] = lane
524
+ return (
525
+ _lane_started(lane_env, lane),
526
+ _lane_completed(lane_env, lane),
527
+ )
528
+ completed_events: list[RuntimeEvent] = []
529
+ for lane in state.lanes.values():
530
+ if lane.completed:
531
+ continue
532
+ lane.completed = True
533
+ completed_events.append(_lane_completed(lane_env, lane))
534
+ return tuple(completed_events)
535
+
536
+ if native_type == "error":
537
+ del self._messages[state_key]
538
+ _fail(
539
+ "message_stream_error",
540
+ "MessagesData.message",
541
+ str(payload.get("message") or "LangGraph message stream failed"),
542
+ )
543
+ _fail(
544
+ "unsupported_messages_event",
545
+ "MessagesData.event",
546
+ f"Unsupported LangGraph MessagesData event: {native_type}",
547
+ )
548
+
549
+ def _map_content_block_event(
550
+ self,
551
+ *,
552
+ payload: Mapping[str, Any],
553
+ native_type: str,
554
+ state: _MessageState,
555
+ lane_env: Callable[..., dict[str, Any]],
556
+ source: SourceRef,
557
+ ) -> tuple[RuntimeEvent, ...]:
558
+ index = _block_index(payload.get("index"))
559
+ if native_type == "content-block-start":
560
+ content = _mapping(payload.get("content"), "content-block-start.content")
561
+ lane, created = _lane_for_content(state, index, content)
562
+ emitted: list[RuntimeEvent] = []
563
+ if created:
564
+ emitted.append(_lane_started(lane_env, lane))
565
+ if lane.item_kind in {"tool_call", "tool_result"}:
566
+ return tuple(emitted)
567
+ update = _text_block_snapshot(lane.item_id, index, content)
568
+ lane.parts[index] = update
569
+ emitted.append(_lane_updated(lane_env, lane, update, "replace", index))
570
+ return tuple(emitted)
571
+
572
+ if index in state.finished_blocks:
573
+ _fail(
574
+ "content_block_already_finished",
575
+ f"{native_type}.index",
576
+ f"LangGraph content block {index} mutated after native completion",
577
+ )
578
+ lane = _lane_for_index(state, index)
579
+ if native_type == "content-block-delta":
580
+ delta = _mapping(payload.get("delta"), "content-block-delta.delta")
581
+ if lane.item_kind == "tool_call":
582
+ _validate_tool_delta(delta)
583
+ return ()
584
+ update = _text_block_delta(lane.item_id, index, delta, lane.item_kind)
585
+ return (_lane_updated(lane_env, lane, update, "append", index),)
586
+
587
+ content = _mapping(payload.get("content"), "content-block-finish.content")
588
+ if lane.item_kind in {"tool_call", "tool_result"}:
589
+ if lane.item_kind == "tool_call":
590
+ lane.parts[index] = _tool_call_snapshot(lane.item_id, index, content)
591
+ else:
592
+ lane.parts[index] = _server_tool_result_snapshot(lane.item_id, index, content)
593
+ lane.completed = True
594
+ state.finished_blocks.add(index)
595
+ return (_lane_completed(lane_env, lane),)
596
+ update = _text_block_snapshot(lane.item_id, index, content)
597
+ lane.parts[index] = update
598
+ state.finished_blocks.add(index)
599
+ return (_lane_updated(lane_env, lane, update, "replace", index),)
600
+
601
+ def _map_interrupt(
602
+ self,
603
+ *,
604
+ context: LangGraphAdapterContext,
605
+ frame: _Frame,
606
+ source: SourceRef,
607
+ interrupts: Any,
608
+ ) -> tuple[RuntimeEvent, ...]:
609
+ env = _envelope(context, frame.occurrence_key, frame.timestamp)
610
+ reason = _interrupt_reason(interrupts)
611
+ # Emit InteractionRequested events for each interrupt so downstream
612
+ # consumers (e.g. agui agent) can track pending approvals before
613
+ # RunInterrupted arrives.
614
+ interaction_events = self._interaction_events_from_interrupts(
615
+ context=context, frame=frame, source=source, env=env, interrupts=interrupts
616
+ )
617
+ if context.checkpoint_ref is None:
618
+ return (
619
+ *interaction_events,
620
+ RunInterrupted(
621
+ **env(
622
+ frame.scope_id,
623
+ frame.parent_scope_id,
624
+ context.graph_run_id,
625
+ "run.interrupted",
626
+ "run",
627
+ source,
628
+ ),
629
+ status="interrupted",
630
+ reason=reason,
631
+ ),
632
+ )
633
+
634
+ checkpoint = context.checkpoint_ref
635
+ thread_id = _required_string(checkpoint.get("thread_id"), "checkpoint.thread_id")
636
+ checkpoint_ns = checkpoint.get("checkpoint_ns")
637
+ if not isinstance(checkpoint_ns, str):
638
+ _fail(
639
+ "invalid_checkpoint_ref",
640
+ "checkpoint.checkpoint_ns",
641
+ "LangGraph checkpoint_ns must be a string; empty root namespace is valid",
642
+ )
643
+ checkpoint_id = _required_string(
644
+ checkpoint.get("checkpoint_id"), "checkpoint.checkpoint_id"
645
+ )
646
+ continuation_id = stable_item_id(
647
+ "langgraph",
648
+ frame.scope_id,
649
+ "continuation",
650
+ "graph-checkpoint",
651
+ thread_id,
652
+ f"checkpoint-ns:{checkpoint_ns}",
653
+ checkpoint_id,
654
+ )
655
+ return (
656
+ ContinuationCreated(
657
+ **env(
658
+ frame.scope_id,
659
+ frame.parent_scope_id,
660
+ continuation_id,
661
+ "continuation.created",
662
+ "checkpoint",
663
+ source,
664
+ ),
665
+ continuation_id=continuation_id,
666
+ continuation_kind="graph_checkpoint",
667
+ resumable=True,
668
+ ref={
669
+ "thread_id": thread_id,
670
+ "checkpoint_ns": checkpoint_ns,
671
+ "checkpoint_id": checkpoint_id,
672
+ },
673
+ ),
674
+ *interaction_events,
675
+ RunInterrupted(
676
+ **env(
677
+ frame.scope_id,
678
+ frame.parent_scope_id,
679
+ continuation_id,
680
+ "run.interrupted",
681
+ "run",
682
+ source,
683
+ ),
684
+ status="interrupted",
685
+ reason=reason,
686
+ continuation_id=continuation_id,
687
+ ),
688
+ )
689
+
690
+ def _interaction_events_from_interrupts(
691
+ self,
692
+ *,
693
+ context: LangGraphAdapterContext,
694
+ frame: _Frame,
695
+ source: SourceRef,
696
+ env: Callable[..., dict[str, Any]],
697
+ interrupts: Any,
698
+ ) -> tuple[RuntimeEvent, ...]:
699
+ """Emit InteractionRequested for each langgraph interrupt."""
700
+ if not isinstance(interrupts, Sequence) or isinstance(interrupts, (str, bytes)):
701
+ return ()
702
+ events: list[RuntimeEvent] = []
703
+ for idx, intr in enumerate(interrupts):
704
+ intr_id = ""
705
+ detail_value: Any = None
706
+ if isinstance(intr, Mapping):
707
+ intr_id = str(intr.get("id") or intr.get("approval_request_id") or "")
708
+ detail_value = intr.get("value")
709
+ else:
710
+ intr_id = str(getattr(intr, "id", "") or "")
711
+ detail_value = getattr(intr, "value", None)
712
+ item_id = stable_item_id("langgraph", frame.scope_id, "interaction", str(idx))
713
+ interaction_id = intr_id or item_id
714
+ detail_json: Any = (
715
+ detail_value
716
+ if isinstance(detail_value, (dict, list, str, int, float, bool, type(None)))
717
+ else None
718
+ )
719
+ events.append(
720
+ InteractionRequested(
721
+ **env(
722
+ frame.scope_id,
723
+ frame.parent_scope_id,
724
+ item_id,
725
+ "interaction.requested",
726
+ "interaction",
727
+ source,
728
+ ),
729
+ interaction_id=interaction_id,
730
+ interaction_kind="approval",
731
+ request=ApprovalRequest(
732
+ call_id=intr_id or None,
733
+ kind="tool",
734
+ detail=detail_json,
735
+ ),
736
+ )
737
+ )
738
+ return tuple(events)
739
+
740
+
741
+ __all__ = [
742
+ "LangGraphAdapterContext",
743
+ "LangGraphEventAdapter",
744
+ "LangGraphMappingError",
745
+ ]