agentengine-sdk-python 0.8.1__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 (411) hide show
  1. {agentengine_sdk_python-0.8.1.dist-info → agentengine_sdk_python-0.8.2.dist-info}/METADATA +22 -2
  2. {agentengine_sdk_python-0.8.1.dist-info → agentengine_sdk_python-0.8.2.dist-info}/RECORD +356 -222
  3. ksadk/a2a/_space_client_events.py +381 -0
  4. ksadk/a2a/event_adapter.py +156 -64
  5. ksadk/a2a/executor.py +179 -63
  6. ksadk/a2a/space_client.py +6 -333
  7. ksadk/a2ui/core.py +222 -53
  8. ksadk/agui/_agent_helpers.py +243 -0
  9. ksadk/agui/a2ui_projection.py +12 -5
  10. ksadk/agui/agent.py +443 -259
  11. ksadk/api/client.py +525 -27
  12. ksadk/builders/code_builder.py +284 -8
  13. ksadk/builders/container_builder.py +8 -1
  14. ksadk/builders/managed_runtime_builder.py +39 -35
  15. ksadk/cli/__init__.py +17 -0
  16. ksadk/cli/cmd_dashboard.py +15 -1
  17. ksadk/cli/cmd_deploy.py +10 -2
  18. ksadk/cli/cmd_eval.py +66 -9
  19. ksadk/cli/cmd_evalset.py +284 -0
  20. ksadk/cli/cmd_files.py +5 -1
  21. ksadk/cli/cmd_hermes.py +1 -126
  22. ksadk/cli/cmd_invoke.py +28 -38
  23. ksadk/cli/cmd_managed_runtime.py +95 -0
  24. ksadk/cli/cmd_observe.py +85 -0
  25. ksadk/cli/cmd_openclaw.py +1 -435
  26. ksadk/cli/cmd_replay.py +28 -4
  27. ksadk/cli/cmd_studio.py +99 -8
  28. ksadk/cli/cmd_web.py +10 -2
  29. ksadk/cli/hermes_env.py +151 -0
  30. ksadk/cli/invoke_payload.py +49 -0
  31. ksadk/cli/openclaw_env.py +458 -0
  32. ksadk/codex/client.py +180 -30
  33. ksadk/codex/runtime.py +428 -326
  34. ksadk/configs/env_registry.py +66 -12
  35. ksadk/configs/env_registry_pcm.py +181 -0
  36. ksadk/configs/env_var_spec.py +18 -0
  37. ksadk/configs/global_config.py +5 -0
  38. ksadk/context_engine/__init__.py +98 -0
  39. ksadk/context_engine/assembler.py +176 -0
  40. ksadk/context_engine/baseline.py +419 -0
  41. ksadk/context_engine/cache_observability.py +228 -0
  42. ksadk/context_engine/capabilities.py +443 -0
  43. ksadk/context_engine/contributors.py +344 -0
  44. ksadk/context_engine/hosted_pipeline.py +417 -0
  45. ksadk/context_engine/models.py +117 -0
  46. ksadk/context_engine/planner.py +698 -0
  47. ksadk/context_engine/policies.py +319 -0
  48. ksadk/context_engine/projection.py +31 -0
  49. ksadk/context_engine/shadow_plan.py +266 -0
  50. ksadk/context_engine/tokenizer.py +164 -0
  51. ksadk/conversations/context.py +126 -6
  52. ksadk/conversations/message_projection.py +292 -28
  53. ksadk/conversations/model_context.py +49 -3
  54. ksadk/conversations/runtime_compaction.py +207 -5
  55. ksadk/conversations/runtime_input.py +184 -2
  56. ksadk/conversations/runtime_invocation.py +81 -3
  57. ksadk/conversations/runtime_observability.py +141 -0
  58. ksadk/conversations/runtime_payloads.py +42 -0
  59. ksadk/conversations/runtime_preparation.py +272 -2
  60. ksadk/conversations/runtime_resume.py +20 -1
  61. ksadk/conversations/runtime_stream_events.py +94 -9
  62. ksadk/conversations/semantic_summary.py +311 -1
  63. ksadk/conversations/session_lock.py +51 -0
  64. ksadk/deployment/env_forward.py +72 -0
  65. ksadk/deployment/managed_runtime.py +5 -0
  66. ksadk/deployment/providers/serverless.py +143 -69
  67. ksadk/evaluation/__init__.py +32 -0
  68. ksadk/evaluation/a2a_adapter.py +9 -1
  69. ksadk/evaluation/adapters.py +18 -5
  70. ksadk/evaluation/agent_eval_client.py +395 -0
  71. ksadk/evaluation/cloud_binding.py +80 -0
  72. ksadk/evaluation/cloud_converter.py +194 -0
  73. ksadk/evaluation/cloud_service.py +199 -0
  74. ksadk/evaluation/contracts.py +73 -4
  75. ksadk/evaluation/evaluators.py +183 -17
  76. ksadk/evaluation/evidence.py +258 -0
  77. ksadk/evaluation/executor.py +31 -6
  78. ksadk/evaluation/local_adapter.py +550 -0
  79. ksadk/evaluation/service_env.py +27 -0
  80. ksadk/evaluation/studio_build_adapter.py +253 -0
  81. ksadk/evaluation/target.py +15 -6
  82. ksadk/events/__init__.py +13 -13
  83. ksadk/events/_v1_compat/__init__.py +1 -0
  84. ksadk/events/_v1_compat/models.py +299 -0
  85. ksadk/events/_v1_compat/parser.py +247 -0
  86. ksadk/events/_v1_compat/projection.py +753 -0
  87. ksadk/events/adapters/__init__.py +34 -0
  88. ksadk/events/adapters/_a2a_snapshot.py +622 -0
  89. ksadk/events/adapters/_a2a_support.py +275 -0
  90. ksadk/events/adapters/_codex_interactions.py +375 -0
  91. ksadk/events/adapters/_codex_items.py +801 -0
  92. ksadk/events/adapters/_codex_validators.py +311 -0
  93. ksadk/events/adapters/_langgraph_support.py +785 -0
  94. ksadk/events/adapters/a2a.py +841 -0
  95. ksadk/events/adapters/adk.py +503 -0
  96. ksadk/events/adapters/codex.py +717 -0
  97. ksadk/events/adapters/langgraph.py +745 -0
  98. ksadk/events/canonical.py +440 -0
  99. ksadk/events/canonical_replay.py +497 -0
  100. ksadk/events/canonical_store.py +468 -0
  101. ksadk/events/cold_recovery.py +257 -0
  102. ksadk/events/content.py +89 -0
  103. ksadk/events/identity.py +86 -0
  104. ksadk/events/pipeline.py +455 -0
  105. ksadk/events/projections.py +66 -0
  106. ksadk/events/reducer.py +661 -0
  107. ksadk/events/replay.py +3 -36
  108. ksadk/events/runtime_event.py +20 -265
  109. ksadk/events/session_event.py +324 -0
  110. ksadk/events/store.py +3 -316
  111. ksadk/events/v1_compat.py +41 -0
  112. ksadk/harness/runtime.py +160 -57
  113. ksadk/identity/resolver.py +4 -3
  114. ksadk/interaction/__init__.py +28 -0
  115. ksadk/interaction/contracts.py +136 -0
  116. ksadk/interaction/ledger.py +189 -0
  117. ksadk/interaction/provider.py +122 -0
  118. ksadk/interaction/providers/__init__.py +52 -0
  119. ksadk/interaction/providers/adk.py +40 -0
  120. ksadk/interaction/providers/codex.py +94 -0
  121. ksadk/interaction/providers/langgraph.py +58 -0
  122. ksadk/kernel/__init__.py +117 -0
  123. ksadk/kernel/authorization.py +258 -0
  124. ksadk/kernel/bootstrap.py +1074 -0
  125. ksadk/kernel/contract_fingerprints.py +61 -0
  126. ksadk/kernel/contracts.py +362 -0
  127. ksadk/kernel/control.py +219 -0
  128. ksadk/kernel/errors.py +79 -0
  129. ksadk/kernel/ingress.py +1102 -0
  130. ksadk/kernel/mapping.py +111 -0
  131. ksadk/kernel/memory_store.py +1133 -0
  132. ksadk/kernel/postgres_store.py +1756 -0
  133. ksadk/kernel/recovery.py +452 -0
  134. ksadk/kernel/runtime_identity.py +103 -0
  135. ksadk/kernel/sql/001_agent_kernel.sql +120 -0
  136. ksadk/kernel/sqlite_store.py +1410 -0
  137. ksadk/kernel/state.py +145 -0
  138. ksadk/kernel/store.py +232 -0
  139. ksadk/kernel/worker.py +953 -0
  140. ksadk/knowledge_base/client.py +7 -0
  141. ksadk/knowledge_base/service.py +32 -5
  142. ksadk/memory/__init__.py +61 -0
  143. ksadk/memory/adk/backends/base_ltm_backend.py +96 -1
  144. ksadk/memory/adk/backends/http_ltm_backend.py +14 -5
  145. ksadk/memory/adk/backends/inmemory_ltm_backend.py +136 -3
  146. ksadk/memory/adk/backends/sdk_ltm_backend.py +384 -2
  147. ksadk/memory/adk/backends/sqlite_ltm_backend.py +95 -0
  148. ksadk/memory/coordinator.py +461 -0
  149. ksadk/memory/events.py +202 -0
  150. ksadk/memory/extraction.py +228 -0
  151. ksadk/memory/ltm_backend_factory.py +16 -3
  152. ksadk/memory/models.py +316 -0
  153. ksadk/memory/policy.py +215 -0
  154. ksadk/memory/provider.py +47 -0
  155. ksadk/memory/provider_adapter.py +159 -0
  156. ksadk/memory/provider_resolver.py +71 -0
  157. ksadk/memory/providers/__init__.py +5 -0
  158. ksadk/memory/providers/local_sqlite.py +490 -0
  159. ksadk/memory/resolved_policy.py +145 -0
  160. ksadk/memory/service.py +188 -6
  161. ksadk/model_proxy/bootstrap.py +16 -9
  162. ksadk/model_proxy/detect.py +202 -9
  163. ksadk/model_proxy/namespace.py +39 -15
  164. ksadk/model_proxy/server.py +24 -5
  165. ksadk/model_proxy/transform.py +60 -2
  166. ksadk/observability/__init__.py +25 -0
  167. ksadk/observability/session_log.py +420 -0
  168. ksadk/observability/trajectory.py +105 -0
  169. ksadk/prompts/__init__.py +71 -0
  170. ksadk/prompts/compiler.py +215 -0
  171. ksadk/prompts/models.py +82 -0
  172. ksadk/prompts/projection.py +89 -0
  173. ksadk/prompts/resolved.py +137 -0
  174. ksadk/prompts/sources.py +233 -0
  175. ksadk/runners/_langgraph_runner_streams.py +822 -0
  176. ksadk/runners/adk_runner.py +5 -5
  177. ksadk/runners/base_runner.py +16 -0
  178. ksadk/runners/factory.py +1 -2
  179. ksadk/runners/langgraph_runner.py +198 -437
  180. ksadk/runtime/_runner_adapter/__init__.py +1 -0
  181. ksadk/runtime/_runner_adapter/stream_mapping.py +788 -0
  182. ksadk/runtime/adapter.py +118 -2
  183. ksadk/runtime/conversation_execution.py +316 -182
  184. ksadk/runtime/executor.py +144 -3
  185. ksadk/runtime/factory.py +193 -7
  186. ksadk/runtime/hosted_finalizer.py +268 -0
  187. ksadk/runtime/launch.py +14 -1
  188. ksadk/runtime/preprocessing.py +25 -3
  189. ksadk/runtime/runner_adapter.py +288 -508
  190. ksadk/runtime/usage.py +33 -0
  191. ksadk/sandbox/backends/e2b.py +35 -2
  192. ksadk/server/composition.py +8 -0
  193. ksadk/server/factory.py +69 -6
  194. ksadk/server/routes/kernel_ingress.py +258 -0
  195. ksadk/server/routes/openai_compat.py +88 -8
  196. ksadk/server/routes/projection.py +35 -20
  197. ksadk/server/routes/run.py +94 -0
  198. ksadk/server/routes/sessions.py +2 -0
  199. ksadk/server/routes/streaming.py +5 -2
  200. ksadk/server/static/assets/{ArtifactsPanel-CakCqxEN.js → ArtifactsPanel-DSU1sWD_.js} +1 -1
  201. ksadk/server/static/assets/{CodeBlock-CynLknyO.js → CodeBlock-DOH6MVcn.js} +4 -4
  202. ksadk/server/static/assets/{MathMessageMarkdown-3sQdOysS.js → MathMessageMarkdown-BL8my1R2.js} +4 -4
  203. ksadk/server/static/assets/MathMessageMarkdown-BorAY7qD.css +1 -0
  204. ksadk/server/static/assets/MermaidBlock-Dz4IP-Tx.js +312 -0
  205. ksadk/server/static/assets/NativeTerminalPanel-DUrK0JpZ.js +1 -0
  206. ksadk/server/static/assets/abnfDiagram-VCTEODGH-g20pFzNV.js +1 -0
  207. ksadk/server/static/assets/arc-C4FzinUA.js +1 -0
  208. ksadk/server/static/assets/architecture-7GRP2DOG-DjKratdf.js +1 -0
  209. ksadk/server/static/assets/architectureDiagram-5GKGNRK7-DpIqL5h4.js +36 -0
  210. ksadk/server/static/assets/blockDiagram-NRAW4CY4-BjkljTNz.js +129 -0
  211. ksadk/server/static/assets/c4Diagram-UCG6FXSJ-Dk_ieq2X.js +38 -0
  212. ksadk/server/static/assets/channel-4cQHKtx1.js +1 -0
  213. ksadk/server/static/assets/chunk-2Q5K7J3B-DmgWkESh.js +1 -0
  214. ksadk/server/static/assets/{chunk-FMBD7UC4-B_fH2YuH.js → chunk-5VM5RSS4-BVHAchFb.js} +1 -1
  215. ksadk/server/static/assets/{chunk-ND2GUHAM-D6rFLaVV.js → chunk-F27PBJKO-C-ipQzuS.js} +1 -1
  216. ksadk/server/static/assets/chunk-G27WJ6UU-C2EyJbIK.js +231 -0
  217. ksadk/server/static/assets/{chunk-4BX2VUAB-B9drTgOW.js → chunk-JWPE2WC7-vYvVJb_M.js} +1 -1
  218. ksadk/server/static/assets/chunk-LCL6LL3I-BcI6ysPT.js +206 -0
  219. ksadk/server/static/assets/chunk-POPQ4Y6H-C030x_Z1.js +1 -0
  220. ksadk/server/static/assets/chunk-RHFEMEQ7-yyGpsz4n.js +168 -0
  221. ksadk/server/static/assets/chunk-SVP7TREG-BLTlmMU7.js +88 -0
  222. ksadk/server/static/assets/chunk-XXDRQBXY-C_32ArgP.js +1 -0
  223. ksadk/server/static/assets/classDiagram-DTDB5LWJ-DLFd9Xi0.js +1 -0
  224. ksadk/server/static/assets/classDiagram-v2-JRS7N3AN-DLFd9Xi0.js +1 -0
  225. ksadk/server/static/assets/{cose-bilkent-S5V4N54A-ChNs_Mdk.js → cose-bilkent-JH36ORCC-9YQYwdl0.js} +1 -1
  226. ksadk/server/static/assets/cynefin-OW5HDTMX-DjEM48Qp.js +1 -0
  227. ksadk/server/static/assets/cynefinDiagram-5FMLGOSQ-ErLF5N13.js +62 -0
  228. ksadk/server/static/assets/cytoscape.esm-CyCl8rPi.js +321 -0
  229. ksadk/server/static/assets/dagre-3AP2YEHR-DFiQF-6f.js +4 -0
  230. ksadk/server/static/assets/dagre-BuhGnRI1.js +1 -0
  231. ksadk/server/static/assets/diagram-S7CK7UJ4-Bt1v8-GC.js +30 -0
  232. ksadk/server/static/assets/diagram-UQ7AKVKN-DSCxJdBK.js +41 -0
  233. ksadk/server/static/assets/diagram-VSXAHHWV-DHfYwp_9.js +3 -0
  234. ksadk/server/static/assets/diagram-VX7I27RA-DdzD-4Le.js +24 -0
  235. ksadk/server/static/assets/diagram-Z3DM3KII-Du-nAJ9F.js +24 -0
  236. ksadk/server/static/assets/{dist-Dli7qW-B.js → dist-8hqcx0sU.js} +1 -1
  237. ksadk/server/static/assets/dist-B7seoj3d.js +1 -0
  238. ksadk/server/static/assets/{dist-C1sz5Eo3.js → dist-BE7bu-DL.js} +1 -1
  239. ksadk/server/static/assets/{dist-fhOuWds5.js → dist-BVDffZ0U.js} +1 -1
  240. ksadk/server/static/assets/{dist-BjOdlDjj.js → dist-BX8z72IC.js} +1 -1
  241. ksadk/server/static/assets/{dist-DsHPdk3W.js → dist-Bf2M8m3N.js} +1 -1
  242. ksadk/server/static/assets/{dist-o2OVmKvt.js → dist-BjU6y-A2.js} +1 -1
  243. ksadk/server/static/assets/{dist-DWKByxWV.js → dist-BytlxIDT.js} +1 -1
  244. ksadk/server/static/assets/{dist-DJN_6Y39.js → dist-CSh_DE14.js} +1 -1
  245. ksadk/server/static/assets/{dist-DQU9EWw-.js → dist-CXYYBw3_.js} +1 -1
  246. ksadk/server/static/assets/{dist-4N2NMVYg.js → dist-C_wsv-Qd.js} +1 -1
  247. ksadk/server/static/assets/{dist-gLnrGsoU.js → dist-ClxGviKw.js} +1 -1
  248. ksadk/server/static/assets/{dist-j6Dxmf_j.js → dist-CttYUqzS.js} +1 -1
  249. ksadk/server/static/assets/{dist-D6MpCZtz.js → dist-DNp6rLRA.js} +1 -1
  250. ksadk/server/static/assets/{dist-BB3-OwTQ.js → dist-DUX-id_F.js} +1 -1
  251. ksadk/server/static/assets/{dist-_pHPTyZ-.js → dist-DmldrHd_.js} +1 -1
  252. ksadk/server/static/assets/{dist-CWV4lDr1.js → dist-DnfXs8Vn.js} +2 -2
  253. ksadk/server/static/assets/{dist-B5oS1zcj.js → dist-Dq9gLD7L.js} +1 -1
  254. ksadk/server/static/assets/{dist-B-jNR6Vn.js → dist-W-TIVntx.js} +1 -1
  255. ksadk/server/static/assets/{dist-BIlKoW0k.js → dist-dDdADKFA.js} +1 -1
  256. ksadk/server/static/assets/{dist-X4TnqwOK.js → dist-dydu68Fl.js} +1 -1
  257. ksadk/server/static/assets/{dist-CmZHzlwZ.js → dist-ngtN0DJB.js} +1 -1
  258. ksadk/server/static/assets/ebnfDiagram-PWID7BFC-Da9C9NO1.js +1 -0
  259. ksadk/server/static/assets/erDiagram-SSCWMZ5O-EAGqqR79.js +99 -0
  260. ksadk/server/static/assets/eventmodeling-NTZA5JFV-CMgMaJrC.js +1 -0
  261. ksadk/server/static/assets/flowDiagram-A5DVABFB-BBKL0x3P.js +1 -0
  262. ksadk/server/static/assets/ganttDiagram-EL5Y4UJY-DqJsKb59.js +292 -0
  263. ksadk/server/static/assets/gitGraph-4MIJSDKK-Dw63mrhw.js +1 -0
  264. ksadk/server/static/assets/gitGraphDiagram-WWUBYQGX-B6g4dtDi.js +106 -0
  265. ksadk/server/static/assets/index-8ipRcQ-M.js +240 -0
  266. ksadk/server/static/assets/index-ByFCqjlh.css +2 -0
  267. ksadk/server/static/assets/info-A6RAGUB7-B6iAblII.js +1 -0
  268. ksadk/server/static/assets/infoDiagram-RXCK75RN-Djm_nbd5.js +2 -0
  269. ksadk/server/static/assets/{ishikawaDiagram-YF4QCWOH-K0OOfVna.js → ishikawaDiagram-5VMMS53U-DWya9SG2.js} +6 -6
  270. ksadk/server/static/assets/{journeyDiagram-JHISSGLW-8LeOJaZp.js → journeyDiagram-EYS64GPL-DutxhSNI.js} +6 -6
  271. ksadk/server/static/assets/{kanban-definition-UN3LZRKU-C6uCgZrW.js → kanban-definition-3QL26DDD-DJdOF8Fm.js} +10 -10
  272. ksadk/server/static/assets/katex-vFWytM5c.js +257 -0
  273. ksadk/server/static/assets/{linear-hdBcYzM8.js → linear-BHjG8b-J.js} +1 -1
  274. ksadk/server/static/assets/mermaid-parser.core-KGSy4jWT.js +166 -0
  275. ksadk/server/static/assets/{mindmap-definition-RKZ34NQL-Bjy_2v4_.js → mindmap-definition-FBJOCRG2-9-HC88D4.js} +29 -29
  276. ksadk/server/static/assets/packet-AYTQ26CC-BOYAipuq.js +1 -0
  277. ksadk/server/static/assets/pegDiagram-XKGWAZYB-DrEZd4fD.js +1 -0
  278. ksadk/server/static/assets/pie-WAS4IAKB-Ctq0Kbku.js +1 -0
  279. ksadk/server/static/assets/pieDiagram-E7YTZNPT-DpjqOFFp.js +39 -0
  280. ksadk/server/static/assets/{quadrantDiagram-W4KKPZXB-BmkRbwCg.js → quadrantDiagram-AXDQQJYC-BiNhgOXX.js} +6 -6
  281. ksadk/server/static/assets/radar-RG4KPBEZ-DN0-ul_0.js +1 -0
  282. ksadk/server/static/assets/railroad-74A4TZTK-C6cC_to0.js +1 -0
  283. ksadk/server/static/assets/railroad-abnf-HS5TGJTU-BimjIuRc.js +1 -0
  284. ksadk/server/static/assets/railroad-ebnf-LZEXJU2U-CvY65ABq.js +1 -0
  285. ksadk/server/static/assets/railroad-peg-WCYAUIDC-D72Iq_Tv.js +1 -0
  286. ksadk/server/static/assets/railroadDiagram-O6MQD6OU-_Y3Ojg6G.js +1 -0
  287. ksadk/server/static/assets/requirementDiagram-EFPCY7ZU-DeCFdg9K.js +84 -0
  288. ksadk/server/static/assets/{sankeyDiagram-5OEKKPKP-l6iXmU65.js → sankeyDiagram-P5KCCOFB-CPH75rhw.js} +7 -7
  289. ksadk/server/static/assets/{sequenceDiagram-3UESZ5HK-Cq6UBeQB.js → sequenceDiagram-WJ2MYXX4-OEpQQdr4.js} +10 -10
  290. ksadk/server/static/assets/sizeCapture-X5ZJPWSS-heUErzhI.js +1 -0
  291. ksadk/server/static/assets/stateDiagram-HBIQ2CUA-DvA3jSMB.js +1 -0
  292. ksadk/server/static/assets/stateDiagram-v2-4QOOHH4V-BgQY03nz.js +1 -0
  293. ksadk/server/static/assets/swimlanes-XN3QIQJK-CR-dfN_t.js +1 -0
  294. ksadk/server/static/assets/swimlanesDiagram-VK2B7HYN-DLVw3q5Q.js +8 -0
  295. ksadk/server/static/assets/{timeline-definition-PNZ67QCA-DEz24vV0.js → timeline-definition-24CTP7MA-DAVJf1TX.js} +7 -7
  296. ksadk/server/static/assets/treeView-Q6P3EWNA-BMpO0wsB.js +1 -0
  297. ksadk/server/static/assets/treemap-WGGIJYW6-Et0aqzU3.js +1 -0
  298. ksadk/server/static/assets/vennDiagram-4TSXK5OY-DwM8eDkh.js +34 -0
  299. ksadk/server/static/assets/wardley-WFR3VGLG-CbY0mhpl.js +1 -0
  300. ksadk/server/static/assets/wardleyDiagram-VM6X3IG4-DZL-Zz2t.js +78 -0
  301. ksadk/server/static/assets/xychartDiagram-S5SC5T6Z-Dy6Yh_hu.js +7 -0
  302. ksadk/server/static/index.html +2 -2
  303. ksadk/sessions/__init__.py +26 -9
  304. ksadk/sessions/_local_service_sync.py +688 -0
  305. ksadk/sessions/_local_tables.py +21 -0
  306. ksadk/sessions/_postgres_schema.py +305 -0
  307. ksadk/sessions/_postgres_tables.py +15 -0
  308. ksadk/sessions/base.py +80 -1
  309. ksadk/sessions/in_memory.py +53 -2
  310. ksadk/sessions/local_service.py +63 -604
  311. ksadk/sessions/postgres_service.py +58 -148
  312. ksadk/sessions/resilient.py +35 -1
  313. ksadk/studio/api.py +577 -25
  314. ksadk/studio/api_contracts.py +114 -5
  315. ksadk/studio/api_memory_routes.py +82 -0
  316. ksadk/studio/authoring.py +252 -27
  317. ksadk/studio/authoring_coordinator.py +799 -67
  318. ksadk/studio/builder.py +88 -11
  319. ksadk/studio/capabilities.py +17 -0
  320. ksadk/studio/cloud.py +1916 -95
  321. ksadk/studio/codex_agent_service.py +125 -14
  322. ksadk/studio/codex_authoring.py +469 -0
  323. ksadk/studio/codex_builder.py +138 -25
  324. ksadk/studio/codex_manifest.py +51 -22
  325. ksadk/studio/codex_run.py +46 -3
  326. ksadk/studio/compiler.py +1 -0
  327. ksadk/studio/contracts.py +114 -3
  328. ksadk/studio/event_store.py +25 -95
  329. ksadk/studio/framework_run.py +231 -3
  330. ksadk/studio/hosted_kernel.py +317 -0
  331. ksadk/studio/manifest_resolver.py +131 -0
  332. ksadk/studio/model_client.py +95 -9
  333. ksadk/studio/model_profile_service.py +1 -1
  334. ksadk/studio/operations.py +37 -5
  335. ksadk/studio/otel_trace.py +348 -42
  336. ksadk/studio/pcm_memory.py +85 -0
  337. ksadk/studio/repository.py +23 -2
  338. ksadk/studio/resource_catalog.py +43 -0
  339. ksadk/studio/run_service.py +563 -137
  340. ksadk/studio/runtime_source.py +42 -16
  341. ksadk/studio/service.py +1180 -72
  342. ksadk/studio/shared_web.py +32 -22
  343. ksadk/studio/static/assets/index-BLpcdrgW.css +1 -0
  344. ksadk/studio/static/assets/index-CYekR2Xv.js +260 -0
  345. ksadk/studio/static/index.html +2 -2
  346. ksadk/studio/templates.py +100 -8
  347. ksadk/studio/validator.py +19 -0
  348. ksadk/studio/workspace.py +30 -32
  349. ksadk/tracing/setup.py +304 -3
  350. ksadk/version.py +1 -1
  351. ksadk_runtime_common/schemas/runtime_event_v1.json +37 -0
  352. ksadk_runtime_common/schemas/runtime_event_v2.json +271 -0
  353. ksadk/events/parser.py +0 -191
  354. ksadk/server/static/assets/MathMessageMarkdown-DeYh8QPr.css +0 -1
  355. ksadk/server/static/assets/MermaidBlock-NERD_ef7.js +0 -303
  356. ksadk/server/static/assets/NativeTerminalPanel-CiHWf82q.js +0 -1
  357. ksadk/server/static/assets/arc-DrgjcKhl.js +0 -1
  358. ksadk/server/static/assets/architecture-7EHR7CIX-CpZLRCcY.js +0 -1
  359. ksadk/server/static/assets/architectureDiagram-3BPJPVTR-BXoVRbQ6.js +0 -36
  360. ksadk/server/static/assets/blockDiagram-GPEHLZMM-BnaB3Ywv.js +0 -132
  361. ksadk/server/static/assets/c4Diagram-AAUBKEIU-Dw4weZcp.js +0 -10
  362. ksadk/server/static/assets/channel-Dt3rQTFI.js +0 -1
  363. ksadk/server/static/assets/chunk-2J33WTMH-ChjpLK7j.js +0 -1
  364. ksadk/server/static/assets/chunk-55IACEB6-CK4ROATy.js +0 -1
  365. ksadk/server/static/assets/chunk-727SXJPM-B9KtTTgw.js +0 -206
  366. ksadk/server/static/assets/chunk-AQP2D5EJ-1O1mki3m.js +0 -231
  367. ksadk/server/static/assets/chunk-QZHKN3VN-iXEZtKQc.js +0 -1
  368. ksadk/server/static/assets/classDiagram-4FO5ZUOK-DIveV17Q.js +0 -1
  369. ksadk/server/static/assets/classDiagram-v2-Q7XG4LA2-DIveV17Q.js +0 -1
  370. ksadk/server/static/assets/cytoscape.esm-DelgaX4f.js +0 -321
  371. ksadk/server/static/assets/dagre-BM42HDAG-D0QXg_MQ.js +0 -4
  372. ksadk/server/static/assets/dagre-Bx709z4p.js +0 -1
  373. ksadk/server/static/assets/diagram-2AECGRRQ-DBDDKwBQ.js +0 -43
  374. ksadk/server/static/assets/diagram-5GNKFQAL-BkwDOxmO.js +0 -10
  375. ksadk/server/static/assets/diagram-KO2AKTUF-Bv8waYvY.js +0 -3
  376. ksadk/server/static/assets/diagram-LMA3HP47-e1VECDdu.js +0 -24
  377. ksadk/server/static/assets/diagram-OG6HWLK6-Ds9adfRl.js +0 -24
  378. ksadk/server/static/assets/dist-B5J2uhNk.js +0 -1
  379. ksadk/server/static/assets/erDiagram-TEJ5UH35-BPItFKH6.js +0 -85
  380. ksadk/server/static/assets/eventmodeling-FCH6USID-DYFSxbqr.js +0 -1
  381. ksadk/server/static/assets/flowDiagram-I6XJVG4X-BbYB9w5Y.js +0 -162
  382. ksadk/server/static/assets/ganttDiagram-6RSMTGT7-TQXa0KXv.js +0 -292
  383. ksadk/server/static/assets/gitGraph-WXDBUCRP-DyNYp6BN.js +0 -1
  384. ksadk/server/static/assets/gitGraphDiagram-PVQCEYII-bKblCnpa.js +0 -106
  385. ksadk/server/static/assets/graphlib-B8gBHxth.js +0 -1
  386. ksadk/server/static/assets/index-R52pJJvg.js +0 -177
  387. ksadk/server/static/assets/index-jJr3_955.css +0 -2
  388. ksadk/server/static/assets/info-J43DQDTF-WUx7qTde.js +0 -1
  389. ksadk/server/static/assets/infoDiagram-5YYISTIA-BGVT7J_i.js +0 -2
  390. ksadk/server/static/assets/katex-CYWseY5E.js +0 -265
  391. ksadk/server/static/assets/mermaid-parser.core-BWrDjSZM.js +0 -161
  392. ksadk/server/static/assets/packet-YPE3B663-BN13y_xl.js +0 -1
  393. ksadk/server/static/assets/pie-LRSECV5Y-ftSLXhhc.js +0 -1
  394. ksadk/server/static/assets/pieDiagram-4H26LBE5-GmmqNiVH.js +0 -30
  395. ksadk/server/static/assets/radar-GUYGQ44K-jaICkIeO.js +0 -1
  396. ksadk/server/static/assets/requirementDiagram-4Y6WPE33-DSWFqL7c.js +0 -84
  397. ksadk/server/static/assets/stateDiagram-AJRCARHV-qzTQpg3Y.js +0 -1
  398. ksadk/server/static/assets/stateDiagram-v2-BHNVJYJU-BYCoYGAN.js +0 -1
  399. ksadk/server/static/assets/treeView-BLDUP644-Cpib_vlz.js +0 -1
  400. ksadk/server/static/assets/treemap-LRROVOQU-DQxfmVHK.js +0 -1
  401. ksadk/server/static/assets/vennDiagram-CIIHVFJN-CMCixki2.js +0 -34
  402. ksadk/server/static/assets/wardley-L42UT6IY-BQYHnnkU.js +0 -1
  403. ksadk/server/static/assets/wardleyDiagram-YWT4CUSO-CVzB8F9K.js +0 -78
  404. ksadk/server/static/assets/xychartDiagram-2RQKCTM6-BFBqBLc1.js +0 -7
  405. ksadk/studio/evaluation.py +0 -192
  406. ksadk/studio/static/assets/index-CaEN0eTR.css +0 -1
  407. ksadk/studio/static/assets/index-DI2eY_NH.js +0 -252
  408. {agentengine_sdk_python-0.8.1.dist-info → agentengine_sdk_python-0.8.2.dist-info}/WHEEL +0 -0
  409. {agentengine_sdk_python-0.8.1.dist-info → agentengine_sdk_python-0.8.2.dist-info}/entry_points.txt +0 -0
  410. {agentengine_sdk_python-0.8.1.dist-info → agentengine_sdk_python-0.8.2.dist-info}/licenses/LICENSE +0 -0
  411. {agentengine_sdk_python-0.8.1.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
+ ]