agentengine-sdk-python 0.7.0__py3-none-any.whl → 0.8.0__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 (371) hide show
  1. {agentengine_sdk_python-0.7.0.dist-info → agentengine_sdk_python-0.8.0.dist-info}/METADATA +36 -20
  2. agentengine_sdk_python-0.8.0.dist-info/RECORD +578 -0
  3. ksadk/a2a/__init__.py +178 -11
  4. ksadk/a2a/bootstrap.py +334 -0
  5. ksadk/a2a/card.py +120 -0
  6. ksadk/a2a/context_store.py +203 -0
  7. ksadk/a2a/control_plane.py +818 -0
  8. ksadk/a2a/credential.py +99 -0
  9. ksadk/a2a/event_adapter.py +149 -0
  10. ksadk/a2a/executor.py +406 -89
  11. ksadk/a2a/external_transport.py +516 -0
  12. ksadk/a2a/identity.py +304 -0
  13. ksadk/a2a/ids.py +22 -0
  14. ksadk/a2a/langgraph.py +285 -0
  15. ksadk/a2a/resume_store.py +201 -0
  16. ksadk/a2a/routes.py +105 -0
  17. ksadk/a2a/server.py +107 -60
  18. ksadk/a2a/space_client.py +1101 -0
  19. ksadk/a2a/task_adapter.py +423 -0
  20. ksadk/a2a/task_event_dispatcher.py +167 -0
  21. ksadk/a2a/task_event_outbox.py +326 -0
  22. ksadk/a2a/task_store.py +206 -0
  23. ksadk/a2ui/__init__.py +27 -0
  24. ksadk/a2ui/core.py +186 -0
  25. ksadk/a2ui/models.py +166 -0
  26. ksadk/a2ui/renderer.py +198 -0
  27. ksadk/agui/__init__.py +9 -0
  28. ksadk/agui/a2ui_projection.py +92 -0
  29. ksadk/agui/agent.py +857 -0
  30. ksadk/agui/config.py +86 -0
  31. ksadk/agui/routes.py +55 -0
  32. ksadk/api/client.py +233 -191
  33. ksadk/builders/__init__.py +2 -0
  34. ksadk/builders/base.py +16 -14
  35. ksadk/builders/code_builder.py +318 -236
  36. ksadk/builders/container_builder.py +187 -167
  37. ksadk/builders/framework_requirements.py +29 -11
  38. ksadk/builders/ks3_uploader.py +58 -27
  39. ksadk/builders/managed_runtime_builder.py +145 -0
  40. ksadk/builders/mcp_builder.py +91 -92
  41. ksadk/builders/requirements_utils.py +1 -5
  42. ksadk/cli/__init__.py +89 -171
  43. ksadk/cli/cmd_a2a.py +254 -70
  44. ksadk/cli/cmd_agent.py +19 -5
  45. ksadk/cli/cmd_build.py +158 -29
  46. ksadk/cli/cmd_completion.py +47 -35
  47. ksadk/cli/cmd_config.py +267 -198
  48. ksadk/cli/cmd_create.py +500 -720
  49. ksadk/cli/cmd_dashboard.py +120 -45
  50. ksadk/cli/cmd_deploy.py +117 -58
  51. ksadk/cli/cmd_destroy.py +44 -14
  52. ksadk/cli/cmd_files.py +63 -24
  53. ksadk/cli/cmd_hermes.py +168 -89
  54. ksadk/cli/cmd_invoke.py +184 -122
  55. ksadk/cli/cmd_launch.py +64 -28
  56. ksadk/cli/cmd_mcp.py +98 -64
  57. ksadk/cli/cmd_model.py +14 -5
  58. ksadk/cli/cmd_openclaw.py +483 -227
  59. ksadk/cli/cmd_replay.py +71 -0
  60. ksadk/cli/cmd_run.py +33 -10
  61. ksadk/cli/cmd_status.py +80 -31
  62. ksadk/cli/cmd_version.py +20 -13
  63. ksadk/cli/cmd_web.py +89 -13
  64. ksadk/cli/deploy_utils.py +20 -20
  65. ksadk/cli/dry_run.py +5 -3
  66. ksadk/cli/error_utils.py +37 -12
  67. ksadk/cli/global_options.py +1 -2
  68. ksadk/cli/local_runtime.py +1 -2
  69. ksadk/cli/model_catalog.py +6 -2
  70. ksadk/cli/network_options.py +34 -14
  71. ksadk/cli/resource_common.py +6 -2
  72. ksadk/cli/storage.py +0 -1
  73. ksadk/cli/ui.py +5 -3
  74. ksadk/cli/workflow_common.py +51 -17
  75. ksadk/codex/__init__.py +12 -0
  76. ksadk/codex/client.py +408 -0
  77. ksadk/codex/phase.py +143 -0
  78. ksadk/codex/runtime.py +449 -0
  79. ksadk/common/aicp_env.py +0 -1
  80. ksadk/common/auth.py +2 -2
  81. ksadk/common/constants.py +1 -3
  82. ksadk/common/llm_utils.py +17 -13
  83. ksadk/compat/__init__.py +5 -0
  84. ksadk/compat/adk_compat.py +200 -0
  85. ksadk/compat/copilotkit_a2ui.py +330 -0
  86. ksadk/configs/__init__.py +12 -12
  87. ksadk/configs/env_registry.py +500 -100
  88. ksadk/configs/global_config.py +2 -1
  89. ksadk/configs/settings.py +151 -124
  90. ksadk/conversations/__init__.py +7 -5
  91. ksadk/conversations/attachment_storage.py +16 -11
  92. ksadk/conversations/attachments.py +44 -36
  93. ksadk/conversations/compaction_pipeline.py +12 -12
  94. ksadk/conversations/compaction_prompt.py +9 -5
  95. ksadk/conversations/context.py +221 -6
  96. ksadk/conversations/message_projection.py +438 -51
  97. ksadk/conversations/model_context.py +12 -6
  98. ksadk/conversations/model_options.py +0 -1
  99. ksadk/conversations/normalize.py +20 -16
  100. ksadk/conversations/reasoning_markup.py +1 -1
  101. ksadk/conversations/runtime.py +339 -5255
  102. ksadk/conversations/runtime_compaction.py +333 -0
  103. ksadk/conversations/runtime_constants.py +27 -0
  104. ksadk/conversations/runtime_governance.py +185 -0
  105. ksadk/conversations/runtime_input.py +652 -0
  106. ksadk/conversations/runtime_invocation.py +395 -0
  107. ksadk/conversations/runtime_metadata.py +475 -0
  108. ksadk/conversations/runtime_observability.py +355 -0
  109. ksadk/conversations/runtime_payloads.py +272 -0
  110. ksadk/conversations/runtime_persistence.py +440 -0
  111. ksadk/conversations/runtime_preparation.py +418 -0
  112. ksadk/conversations/runtime_resume.py +816 -0
  113. ksadk/conversations/runtime_stream_events.py +902 -0
  114. ksadk/conversations/runtime_streaming.py +547 -0
  115. ksadk/conversations/semantic_summary.py +17 -5
  116. ksadk/conversations/session_title.py +6 -3
  117. ksadk/deployment/__init__.py +15 -16
  118. ksadk/deployment/agent_access.py +12 -23
  119. ksadk/deployment/base.py +51 -38
  120. ksadk/deployment/manager.py +63 -65
  121. ksadk/deployment/providers/serverless.py +309 -202
  122. ksadk/deployment/registry.py +38 -32
  123. ksadk/deployment/state.py +11 -11
  124. ksadk/deployment/ui_config.py +1 -1
  125. ksadk/detection/__init__.py +1 -1
  126. ksadk/detection/detector.py +146 -83
  127. ksadk/detection/mcp_detector.py +9 -6
  128. ksadk/events/__init__.py +25 -0
  129. ksadk/events/parser.py +191 -0
  130. ksadk/events/replay.py +37 -0
  131. ksadk/events/runtime_event.py +264 -0
  132. ksadk/events/store.py +317 -0
  133. ksadk/harness/__init__.py +34 -0
  134. ksadk/harness/app.py +278 -0
  135. ksadk/harness/config.py +181 -0
  136. ksadk/harness/reasoner.py +105 -0
  137. ksadk/harness/runner.py +211 -0
  138. ksadk/harness/sandbox.py +141 -0
  139. ksadk/harness/tools.py +222 -0
  140. ksadk/hermes_terminal.py +23 -12
  141. ksadk/identity/resolver.py +15 -9
  142. ksadk/ids.py +32 -0
  143. ksadk/knowledge_base/adk_tool.py +1 -1
  144. ksadk/knowledge_base/client.py +23 -29
  145. ksadk/managed_runtime.py +188 -0
  146. ksadk/markdown.py +5 -2
  147. ksadk/mcp_runtime/__init__.py +9 -6
  148. ksadk/memory/__init__.py +1 -1
  149. ksadk/memory/adk/__init__.py +2 -0
  150. ksadk/memory/adk/backends/base_ltm_backend.py +2 -6
  151. ksadk/memory/adk/backends/http_ltm_backend.py +13 -21
  152. ksadk/memory/adk/backends/inmemory_ltm_backend.py +7 -13
  153. ksadk/memory/adk/backends/sdk_ltm_backend.py +26 -33
  154. ksadk/memory/adk/long_term_memory.py +31 -35
  155. ksadk/memory/adk/resilient_session_service.py +4 -5
  156. ksadk/memory/adk/short_term_memory.py +12 -21
  157. ksadk/memory/adk_tool.py +3 -2
  158. ksadk/memory/backends/base.py +19 -19
  159. ksadk/memory/backends/memory.py +24 -25
  160. ksadk/memory/backends/redis.py +31 -30
  161. ksadk/memory/langchain_tool.py +2 -1
  162. ksadk/memory/manager.py +52 -47
  163. ksadk/memory/service.py +10 -8
  164. ksadk/model_policy.py +15 -7
  165. ksadk/model_proxy/__init__.py +51 -0
  166. ksadk/model_proxy/bootstrap.py +80 -0
  167. ksadk/model_proxy/cache.py +165 -0
  168. ksadk/model_proxy/config.py +45 -0
  169. ksadk/model_proxy/demo_webui.py +115 -0
  170. ksadk/model_proxy/detect.py +145 -0
  171. ksadk/model_proxy/gate.py +68 -0
  172. ksadk/model_proxy/namespace.py +173 -0
  173. ksadk/model_proxy/protocol_proxy.py +22 -0
  174. ksadk/model_proxy/server.py +300 -0
  175. ksadk/model_proxy/transform.py +691 -0
  176. ksadk/openclaw_gateway.py +29 -14
  177. ksadk/runners/adk_runner.py +345 -120
  178. ksadk/runners/base_runner.py +46 -29
  179. ksadk/runners/codex_runner.py +132 -0
  180. ksadk/runners/deepagents_runner.py +0 -1
  181. ksadk/runners/factory.py +17 -5
  182. ksadk/runners/langchain_runner.py +29 -742
  183. ksadk/runners/langgraph_runner.py +352 -90
  184. ksadk/runners/patch_langchain.py +16 -16
  185. ksadk/runners/remote_runner.py +134 -33
  186. ksadk/runners/usage_accumulator.py +1 -0
  187. ksadk/runners/utils/langfuse.py +3 -3
  188. ksadk/runners/utils/loader.py +7 -7
  189. ksadk/runtime/__init__.py +41 -0
  190. ksadk/runtime/adapter.py +345 -0
  191. ksadk/runtime/framework_adapters.py +124 -0
  192. ksadk/runtime/preprocessing.py +118 -0
  193. ksadk/runtime/runner_adapter.py +873 -0
  194. ksadk/runtime_context.py +18 -3
  195. ksadk/runtime_state.py +0 -1
  196. ksadk/sandbox/__init__.py +4 -1
  197. ksadk/sandbox/backends/__init__.py +4 -1
  198. ksadk/sandbox/backends/e2b.py +13 -5
  199. ksadk/sandbox/backends/local_process.py +11 -3
  200. ksadk/sandbox/base.py +10 -15
  201. ksadk/sandbox/factory.py +14 -4
  202. ksadk/sandbox/registry.py +57 -6
  203. ksadk/server/api_models.py +15 -5
  204. ksadk/server/app.py +455 -3885
  205. ksadk/server/composition.py +21 -0
  206. ksadk/server/factory.py +624 -0
  207. ksadk/server/routes/__init__.py +1 -0
  208. ksadk/server/routes/checkpoint_resolution.py +116 -0
  209. ksadk/server/routes/common.py +713 -0
  210. ksadk/server/routes/control.py +327 -0
  211. ksadk/server/routes/dependencies.py +98 -0
  212. ksadk/server/routes/misc.py +448 -0
  213. ksadk/server/routes/models.py +443 -0
  214. ksadk/server/routes/openai_compat.py +207 -0
  215. ksadk/server/routes/projection.py +795 -0
  216. ksadk/server/routes/routers.py +52 -0
  217. ksadk/server/routes/run.py +726 -0
  218. ksadk/server/routes/sessions.py +649 -0
  219. ksadk/server/routes/streaming.py +223 -0
  220. ksadk/server/routes/workspace.py +381 -0
  221. ksadk/server/static/assets/{ArtifactsPanel-D-SSn2ee.js → ArtifactsPanel-Cjnqt-8W.js} +1 -1
  222. ksadk/server/static/assets/CodeBlock-BqyqZfuB.js +9 -0
  223. ksadk/server/static/assets/MathMessageMarkdown-BpH7jiFM.js +8 -0
  224. ksadk/server/static/assets/MermaidBlock-DWuxETaJ.js +303 -0
  225. ksadk/server/static/assets/NativeTerminalPanel-MDTopWMO.js +1 -0
  226. ksadk/server/static/assets/{arc-BA13sHc9.js → arc-CFKwSk_B.js} +1 -1
  227. ksadk/server/static/assets/architecture-7EHR7CIX-CynqOWjZ.js +1 -0
  228. ksadk/server/static/assets/{architectureDiagram-3BPJPVTR-DzJzgVoL.js → architectureDiagram-3BPJPVTR-Dej8jX8c.js} +1 -1
  229. ksadk/server/static/assets/{blockDiagram-GPEHLZMM-UTdVcZhn.js → blockDiagram-GPEHLZMM-1F64jqvy.js} +1 -1
  230. ksadk/server/static/assets/{c4Diagram-AAUBKEIU-Dix0GD4m.js → c4Diagram-AAUBKEIU-9q7AUAKb.js} +1 -1
  231. ksadk/server/static/assets/channel-iUGv2N24.js +1 -0
  232. ksadk/server/static/assets/{chunk-2J33WTMH-C2JxuZ42.js → chunk-2J33WTMH-6qgwJm7Q.js} +1 -1
  233. ksadk/server/static/assets/{chunk-4BX2VUAB-Be57QPgD.js → chunk-4BX2VUAB-CsWIQRhc.js} +1 -1
  234. ksadk/server/static/assets/{chunk-55IACEB6-WjSuy4nv.js → chunk-55IACEB6-BK8paA20.js} +1 -1
  235. ksadk/server/static/assets/{chunk-727SXJPM-BOovP-b5.js → chunk-727SXJPM-B-JEhy7h.js} +1 -1
  236. ksadk/server/static/assets/{chunk-AQP2D5EJ-DOmZNmWj.js → chunk-AQP2D5EJ-DYBvMHAa.js} +1 -1
  237. ksadk/server/static/assets/{chunk-FMBD7UC4-DzwlodkU.js → chunk-FMBD7UC4-BGhvzDYt.js} +1 -1
  238. ksadk/server/static/assets/{chunk-ND2GUHAM-DMqAikEU.js → chunk-ND2GUHAM-D98vPd-E.js} +1 -1
  239. ksadk/server/static/assets/chunk-QZHKN3VN-YQIEXeF6.js +1 -0
  240. ksadk/server/static/assets/classDiagram-4FO5ZUOK-CDAUuoXK.js +1 -0
  241. ksadk/server/static/assets/classDiagram-v2-Q7XG4LA2-CDAUuoXK.js +1 -0
  242. ksadk/server/static/assets/{cose-bilkent-S5V4N54A-Zhy2GBnP.js → cose-bilkent-S5V4N54A-CX3yotHq.js} +1 -1
  243. ksadk/server/static/assets/{dagre-BM42HDAG-CbKrtIUz.js → dagre-BM42HDAG-C7TguAWo.js} +1 -1
  244. ksadk/server/static/assets/{diagram-2AECGRRQ-BRApgQRK.js → diagram-2AECGRRQ-Dd17_kws.js} +1 -1
  245. ksadk/server/static/assets/{diagram-5GNKFQAL-D0xbnDiK.js → diagram-5GNKFQAL-DVIClIil.js} +1 -1
  246. ksadk/server/static/assets/{diagram-KO2AKTUF-CVugVI9L.js → diagram-KO2AKTUF-Df_3gYQa.js} +1 -1
  247. ksadk/server/static/assets/{diagram-LMA3HP47-DozUGgee.js → diagram-LMA3HP47-BhLk6ZtA.js} +1 -1
  248. ksadk/server/static/assets/{diagram-OG6HWLK6-ZOYsKlru.js → diagram-OG6HWLK6-D4GNGvuu.js} +1 -1
  249. ksadk/server/static/assets/{dist-DmFaq_Iy.js → dist-6CVKuTAe.js} +1 -1
  250. ksadk/server/static/assets/{dist-8EEyGgDx.js → dist-BUHRxvDG.js} +1 -1
  251. ksadk/server/static/assets/{dist-B0NP_Z0z.js → dist-BZ9n9AjO.js} +1 -1
  252. ksadk/server/static/assets/{dist-DMezvBGJ.js → dist-BibcG1V9.js} +1 -1
  253. ksadk/server/static/assets/{dist-C3HIIaN5.js → dist-Bs-jQcRX.js} +1 -1
  254. ksadk/server/static/assets/{dist-BrCcQ47T.js → dist-C2xjE7cO.js} +1 -1
  255. ksadk/server/static/assets/{dist-Dp0k7bWI.js → dist-C7-3jInC.js} +1 -1
  256. ksadk/server/static/assets/{dist-D-xOD048.js → dist-C99THtIA.js} +1 -1
  257. ksadk/server/static/assets/{dist-CkEKJFtk.js → dist-CGcp2ex8.js} +1 -1
  258. ksadk/server/static/assets/{dist-DyOkZmze.js → dist-CVQRZjPu.js} +1 -1
  259. ksadk/server/static/assets/{dist-BssVmjIo.js → dist-Cf23NY4L.js} +1 -1
  260. ksadk/server/static/assets/{dist-BIJVDMuB.js → dist-CgF3fj15.js} +1 -1
  261. ksadk/server/static/assets/{dist-2hInLS_J.js → dist-Cwt7koer.js} +1 -1
  262. ksadk/server/static/assets/{dist-DyWsb78Q.js → dist-D82mtD2s.js} +1 -1
  263. ksadk/server/static/assets/{dist-D-JMdWPQ.js → dist-DF06ORQo.js} +1 -1
  264. ksadk/server/static/assets/{dist-BmlMPsCc.js → dist-DHn6nBzr.js} +1 -1
  265. ksadk/server/static/assets/{dist-gX6GOLKq.js → dist-Djgl2wVZ.js} +1 -1
  266. ksadk/server/static/assets/{dist-DpKtt4Bo.js → dist-DlzCRy0S.js} +1 -1
  267. ksadk/server/static/assets/{dist-8_SfK1IP.js → dist-DqNnNFrw.js} +1 -1
  268. ksadk/server/static/assets/{dist-D57wnGWd.js → dist-DyvYLMW9.js} +1 -1
  269. ksadk/server/static/assets/{dist-CPBtqRTW.js → dist-eoW6tZXA.js} +1 -1
  270. ksadk/server/static/assets/{dist-DL_NKc_z.js → dist-ivOya1LD.js} +1 -1
  271. ksadk/server/static/assets/{erDiagram-TEJ5UH35-Bk-9bgE5.js → erDiagram-TEJ5UH35-CnfRcY2M.js} +1 -1
  272. ksadk/server/static/assets/eventmodeling-FCH6USID-ChYO-ijM.js +1 -0
  273. ksadk/server/static/assets/{flowDiagram-I6XJVG4X-Dn9kZVuZ.js → flowDiagram-I6XJVG4X-DGaJjGNJ.js} +1 -1
  274. ksadk/server/static/assets/{ganttDiagram-6RSMTGT7-BGxXlJqm.js → ganttDiagram-6RSMTGT7-DpCoB2g9.js} +1 -1
  275. ksadk/server/static/assets/gitGraph-WXDBUCRP-BN_0Fk-j.js +1 -0
  276. ksadk/server/static/assets/{gitGraphDiagram-PVQCEYII-C7Q0X-wi.js → gitGraphDiagram-PVQCEYII-9IKVFBVT.js} +1 -1
  277. ksadk/server/static/assets/index-QSwCHuB8.js +177 -0
  278. ksadk/server/static/assets/index-jOPmTOZH.css +2 -0
  279. ksadk/server/static/assets/info-J43DQDTF-Cp6o3vId.js +1 -0
  280. ksadk/server/static/assets/{infoDiagram-5YYISTIA-BO_CSqq5.js → infoDiagram-5YYISTIA-CYIIsb8y.js} +1 -1
  281. ksadk/server/static/assets/{ishikawaDiagram-YF4QCWOH-eYLPLd46.js → ishikawaDiagram-YF4QCWOH-DLOHGvWw.js} +1 -1
  282. ksadk/server/static/assets/{journeyDiagram-JHISSGLW-De9geSb0.js → journeyDiagram-JHISSGLW-BIzKeejT.js} +1 -1
  283. ksadk/server/static/assets/{kanban-definition-UN3LZRKU-Cs80kQto.js → kanban-definition-UN3LZRKU-BWHoFSw2.js} +1 -1
  284. ksadk/server/static/assets/{katex-DSrCFD8n.js → katex-DATssjp1.js} +1 -1
  285. ksadk/server/static/assets/{linear-CN9sbKTF.js → linear-CvMBw9cA.js} +1 -1
  286. ksadk/server/static/assets/{mermaid-parser.core-DlgSBU8l.js → mermaid-parser.core-mGAcEwcq.js} +2 -2
  287. ksadk/server/static/assets/{mindmap-definition-RKZ34NQL-9afz7Oug.js → mindmap-definition-RKZ34NQL-CSAQxEAe.js} +1 -1
  288. ksadk/server/static/assets/packet-YPE3B663-wQzct3cT.js +1 -0
  289. ksadk/server/static/assets/pie-LRSECV5Y-BgTQiv-9.js +1 -0
  290. ksadk/server/static/assets/{pieDiagram-4H26LBE5-DPv_VstN.js → pieDiagram-4H26LBE5-By-ra07M.js} +1 -1
  291. ksadk/server/static/assets/{quadrantDiagram-W4KKPZXB-o77wZ1XK.js → quadrantDiagram-W4KKPZXB-CxIR4JXI.js} +1 -1
  292. ksadk/server/static/assets/radar-GUYGQ44K-BIq5fXsn.js +1 -0
  293. ksadk/server/static/assets/{requirementDiagram-4Y6WPE33-BYVw81VC.js → requirementDiagram-4Y6WPE33-DpW90iu3.js} +1 -1
  294. ksadk/server/static/assets/{sankeyDiagram-5OEKKPKP-B7nZFMKT.js → sankeyDiagram-5OEKKPKP-DpGa6EAV.js} +1 -1
  295. ksadk/server/static/assets/{sequenceDiagram-3UESZ5HK-BGRRrFw5.js → sequenceDiagram-3UESZ5HK-NTKNGGe5.js} +1 -1
  296. ksadk/server/static/assets/{stateDiagram-AJRCARHV-BUfHCoPs.js → stateDiagram-AJRCARHV-DGpd9yFG.js} +1 -1
  297. ksadk/server/static/assets/stateDiagram-v2-BHNVJYJU-B3o579IQ.js +1 -0
  298. ksadk/server/static/assets/{timeline-definition-PNZ67QCA-FbCTGrf9.js → timeline-definition-PNZ67QCA-jqoYs3jQ.js} +1 -1
  299. ksadk/server/static/assets/treeView-BLDUP644-Dqi-E0EM.js +1 -0
  300. ksadk/server/static/assets/treemap-LRROVOQU-ClQP9CJ9.js +1 -0
  301. ksadk/server/static/assets/{vennDiagram-CIIHVFJN-DWgwtPsJ.js → vennDiagram-CIIHVFJN-l3Z7-wbP.js} +1 -1
  302. ksadk/server/static/assets/wardley-L42UT6IY-8XLvnNIs.js +1 -0
  303. ksadk/server/static/assets/{wardleyDiagram-YWT4CUSO-2x8G-tTM.js → wardleyDiagram-YWT4CUSO-BR54GPmr.js} +1 -1
  304. ksadk/server/static/assets/{xychartDiagram-2RQKCTM6-Drma3AYl.js → xychartDiagram-2RQKCTM6-SkiH8GsK.js} +1 -1
  305. ksadk/server/static/index.html +2 -2
  306. ksadk/server/terminal_sessions.py +111 -58
  307. ksadk/sessions/__init__.py +69 -19
  308. ksadk/sessions/base.py +31 -11
  309. ksadk/sessions/continuity.py +2 -3
  310. ksadk/sessions/in_memory.py +46 -2
  311. ksadk/sessions/local_service.py +148 -17
  312. ksadk/sessions/postgres_service.py +143 -25
  313. ksadk/sessions/resilient.py +36 -8
  314. ksadk/skills/models.py +17 -5
  315. ksadk/skills/package_store.py +5 -2
  316. ksadk/skills/runtime/agent.py +20 -5
  317. ksadk/skills/runtime/artifacts.py +1 -5
  318. ksadk/skills/runtime/backends/e2b.py +10 -4
  319. ksadk/skills/runtime/backends/local.py +15 -3
  320. ksadk/skills/runtime/base.py +1 -2
  321. ksadk/skills/runtime/executor.py +10 -3
  322. ksadk/skills/runtime/factory.py +4 -2
  323. ksadk/skills/runtime/loader.py +1 -2
  324. ksadk/skills/runtime/registry.py +15 -10
  325. ksadk/skills/runtime/request.py +3 -1
  326. ksadk/skills/service_client.py +38 -17
  327. ksadk/skills/tool_defs.py +15 -10
  328. ksadk/terminal_exec_policy.py +3 -4
  329. ksadk/tools/gateway.py +92 -15
  330. ksadk/tools/result_budget.py +12 -4
  331. ksadk/toolsets/__init__.py +134 -36
  332. ksadk/toolsets/platform.py +21 -5
  333. ksadk/toolsets/sandbox.py +82 -16
  334. ksadk/toolsets/skills.py +200 -39
  335. ksadk/toolsets/web.py +123 -26
  336. ksadk/toolsets/workspace.py +212 -101
  337. ksadk/tracing/exporters/inmemory_exporter.py +62 -51
  338. ksadk/tracing/exporters/langfuse_exporter.py +91 -76
  339. ksadk/tracing/setup.py +69 -53
  340. ksadk/tracing/span_utils.py +5 -2
  341. ksadk/tui/loop.py +78 -30
  342. ksadk/tui/stream_render.py +1 -0
  343. ksadk/ui_config.py +5 -3
  344. ksadk/version.py +1 -1
  345. ksadk_runtime_common/schemas/runtime_event_v1.json +95 -0
  346. agentengine_sdk_python-0.7.0.dist-info/RECORD +0 -482
  347. ksadk/server/static/assets/CodeBlock-P16VOLYi.js +0 -9
  348. ksadk/server/static/assets/MathMessageMarkdown-CdGiQWHR.js +0 -8
  349. ksadk/server/static/assets/MermaidBlock-IOcal8cm.js +0 -303
  350. ksadk/server/static/assets/NativeTerminalPanel-DGSDWsei.js +0 -1
  351. ksadk/server/static/assets/architecture-7EHR7CIX-BvUlsA6l.js +0 -1
  352. ksadk/server/static/assets/channel-CTuydARX.js +0 -1
  353. ksadk/server/static/assets/chunk-QZHKN3VN-BnCydivS.js +0 -1
  354. ksadk/server/static/assets/classDiagram-4FO5ZUOK-BNHg45Be.js +0 -1
  355. ksadk/server/static/assets/classDiagram-v2-Q7XG4LA2-BNHg45Be.js +0 -1
  356. ksadk/server/static/assets/eventmodeling-FCH6USID-DsAgWnlf.js +0 -1
  357. ksadk/server/static/assets/gitGraph-WXDBUCRP-BIao9Yjg.js +0 -1
  358. ksadk/server/static/assets/index-C00Lwg3L.js +0 -165
  359. ksadk/server/static/assets/index-DAURbCsP.css +0 -1
  360. ksadk/server/static/assets/info-J43DQDTF-CyipqGxU.js +0 -1
  361. ksadk/server/static/assets/packet-YPE3B663-CGkyRxlg.js +0 -1
  362. ksadk/server/static/assets/pie-LRSECV5Y-M0uWAf4n.js +0 -1
  363. ksadk/server/static/assets/radar-GUYGQ44K-Bdbm24-x.js +0 -1
  364. ksadk/server/static/assets/stateDiagram-v2-BHNVJYJU-8xBN_gLM.js +0 -1
  365. ksadk/server/static/assets/treeView-BLDUP644-npMo0ak1.js +0 -1
  366. ksadk/server/static/assets/treemap-LRROVOQU-CHdzrrdo.js +0 -1
  367. ksadk/server/static/assets/wardley-L42UT6IY-BEQz7wyy.js +0 -1
  368. {agentengine_sdk_python-0.7.0.dist-info → agentengine_sdk_python-0.8.0.dist-info}/WHEEL +0 -0
  369. {agentengine_sdk_python-0.7.0.dist-info → agentengine_sdk_python-0.8.0.dist-info}/entry_points.txt +0 -0
  370. {agentengine_sdk_python-0.7.0.dist-info → agentengine_sdk_python-0.8.0.dist-info}/licenses/LICENSE +0 -0
  371. {agentengine_sdk_python-0.7.0.dist-info → agentengine_sdk_python-0.8.0.dist-info}/top_level.txt +0 -0
@@ -4,112 +4,123 @@ InMemoryExporter - 内存 Trace 存储
4
4
  用于本地 Web UI 查看 Traces
5
5
  """
6
6
 
7
- from typing import List, Dict, Any, Optional
8
- from collections import deque
9
7
  import threading
10
- import time
8
+ from collections import deque
9
+ from collections.abc import Sequence
10
+ from typing import Any
11
+
12
+ from opentelemetry.sdk.trace import ReadableSpan
13
+ from opentelemetry.sdk.trace.export import SpanExporter, SpanExportResult
11
14
 
12
15
 
13
- class InMemoryExporter:
16
+ class InMemoryExporter(SpanExporter):
14
17
  """内存 Trace Exporter"""
15
-
18
+
16
19
  def __init__(self, max_traces: int = 1000):
17
20
  self.max_traces = max_traces
18
- self._traces: deque = deque(maxlen=max_traces)
21
+ self._traces: deque[dict[str, Any]] = deque(maxlen=max_traces)
19
22
  self._lock = threading.Lock()
20
-
21
- def export(self, spans) -> int:
23
+
24
+ def export(self, spans: Sequence[ReadableSpan]) -> SpanExportResult:
22
25
  """导出 Spans (符合 OpenTelemetry SpanExporter 接口)"""
23
- from opentelemetry.sdk.trace.export import SpanExportResult
24
-
25
26
  with self._lock:
26
27
  for span in spans:
27
28
  trace_data = self._span_to_dict(span)
28
29
  self._traces.append(trace_data)
29
-
30
+
30
31
  return SpanExportResult.SUCCESS
31
-
32
+
32
33
  def shutdown(self) -> None:
33
34
  """关闭 Exporter"""
34
35
  pass
35
-
36
+
36
37
  def force_flush(self, timeout_millis: int = 30000) -> bool:
37
38
  """强制刷新"""
38
39
  return True
39
-
40
- def _span_to_dict(self, span) -> Dict[str, Any]:
40
+
41
+ def _span_to_dict(self, span: ReadableSpan) -> dict[str, Any]:
41
42
  """将 Span 转换为字典"""
42
43
  ctx = span.get_span_context()
43
-
44
+ trace_id = ctx.trace_id if ctx is not None else 0
45
+ span_id = ctx.span_id if ctx is not None else 0
46
+ start_time = span.start_time or 0
47
+ end_time = span.end_time or 0
48
+
44
49
  return {
45
- "trace_id": format(ctx.trace_id, '032x'),
46
- "span_id": format(ctx.span_id, '016x'),
47
- "parent_span_id": format(span.parent.span_id, '016x') if span.parent else None,
50
+ "trace_id": format(trace_id, "032x"),
51
+ "span_id": format(span_id, "016x"),
52
+ "parent_span_id": format(span.parent.span_id, "016x") if span.parent else None,
48
53
  "name": span.name,
49
54
  "kind": str(span.kind),
50
55
  "start_time": span.start_time,
51
56
  "end_time": span.end_time,
52
- "duration_ns": span.end_time - span.start_time if span.end_time else 0,
57
+ "duration_ns": end_time - start_time if end_time else 0,
53
58
  "attributes": dict(span.attributes) if span.attributes else {},
54
59
  "status": {
55
60
  "code": str(span.status.status_code),
56
- "description": span.status.description
61
+ "description": span.status.description,
57
62
  },
58
- "events": [
59
- {
60
- "name": event.name,
61
- "timestamp": event.timestamp,
62
- "attributes": dict(event.attributes) if event.attributes else {}
63
- }
64
- for event in span.events
65
- ] if span.events else []
63
+ "events": (
64
+ [
65
+ {
66
+ "name": event.name,
67
+ "timestamp": event.timestamp,
68
+ "attributes": dict(event.attributes) if event.attributes else {},
69
+ }
70
+ for event in span.events
71
+ ]
72
+ if span.events
73
+ else []
74
+ ),
66
75
  }
67
-
68
- def get_traces(self, limit: int = 100) -> List[Dict[str, Any]]:
76
+
77
+ def get_traces(self, limit: int = 100) -> list[dict[str, Any]]:
69
78
  """获取 Traces"""
70
79
  with self._lock:
71
80
  traces = list(self._traces)[-limit:]
72
-
81
+
73
82
  # 按 trace_id 分组
74
- grouped: Dict[str, List[Dict]] = {}
83
+ grouped: dict[str, list[dict[str, Any]]] = {}
75
84
  for span in traces:
76
85
  trace_id = span["trace_id"]
77
86
  if trace_id not in grouped:
78
87
  grouped[trace_id] = []
79
88
  grouped[trace_id].append(span)
80
-
89
+
81
90
  # 转换为 trace 列表
82
- result = []
91
+ result: list[dict[str, Any]] = []
83
92
  for trace_id, spans in grouped.items():
84
- result.append({
85
- "trace_id": trace_id,
86
- "spans": sorted(spans, key=lambda x: x["start_time"]),
87
- "span_count": len(spans),
88
- "start_time": min(s["start_time"] for s in spans),
89
- "end_time": max(s["end_time"] for s in spans if s["end_time"]),
90
- })
91
-
93
+ result.append(
94
+ {
95
+ "trace_id": trace_id,
96
+ "spans": sorted(spans, key=lambda x: x["start_time"]),
97
+ "span_count": len(spans),
98
+ "start_time": min(s["start_time"] for s in spans),
99
+ "end_time": max(s["end_time"] for s in spans if s["end_time"]),
100
+ }
101
+ )
102
+
92
103
  return sorted(result, key=lambda x: x["start_time"], reverse=True)[:limit]
93
-
94
- def get_trace(self, trace_id: str) -> Optional[Dict[str, Any]]:
104
+
105
+ def get_trace(self, trace_id: str) -> dict[str, Any] | None:
95
106
  """获取单个 Trace"""
96
107
  with self._lock:
97
108
  spans = [s for s in self._traces if s["trace_id"] == trace_id]
98
-
109
+
99
110
  if not spans:
100
111
  return None
101
-
112
+
102
113
  return {
103
114
  "trace_id": trace_id,
104
115
  "spans": sorted(spans, key=lambda x: x["start_time"]),
105
- "span_count": len(spans)
116
+ "span_count": len(spans),
106
117
  }
107
-
108
- def get_finished_spans(self) -> List[Dict[str, Any]]:
118
+
119
+ def get_finished_spans(self) -> list[dict[str, Any]]:
109
120
  """返回所有已完成的 Spans (兼容 OpenTelemetry InMemorySpanExporter 接口)"""
110
121
  with self._lock:
111
122
  return list(self._traces)
112
-
123
+
113
124
  def clear(self) -> None:
114
125
  """清空 Traces"""
115
126
  with self._lock:
@@ -8,8 +8,6 @@ Compatible with Langfuse SDK v3.
8
8
  import json
9
9
  import logging
10
10
  import os
11
- from datetime import datetime
12
- from typing import Sequence, Optional
13
11
  from dataclasses import dataclass
14
12
 
15
13
  logger = logging.getLogger(__name__)
@@ -18,6 +16,7 @@ logger = logging.getLogger(__name__)
18
16
  @dataclass
19
17
  class LangfuseExporterConfig:
20
18
  """Configuration for Langfuse exporter"""
19
+
21
20
  public_key: str
22
21
  secret_key: str
23
22
  host: str = "http://localhost:3000"
@@ -30,24 +29,25 @@ LangfuseConfig = LangfuseExporterConfig
30
29
 
31
30
  class _LangfuseSpanExporter:
32
31
  """Internal span exporter that sends spans to Langfuse.
33
-
32
+
34
33
  Uses Langfuse low-level SDK API (v3 compatible).
35
34
  Agent metadata is loaded from ksadk.configs.settings.
36
35
  """
37
-
36
+
38
37
  def __init__(self, config: LangfuseExporterConfig):
39
38
  self.config = config
40
39
  self._langfuse = None
41
40
  self._agent_config = None # Lazy load
42
41
  self._init_langfuse()
43
-
42
+
44
43
  def _get_agent_config(self):
45
44
  """Lazy load agent config from unified settings"""
46
45
  if self._agent_config is None:
47
46
  try:
48
47
  from ksadk.configs import settings
48
+
49
49
  self._agent_config = settings.agent
50
-
50
+
51
51
  # Log loaded metadata
52
52
  if self._agent_config.agent_id:
53
53
  logger.info(f"Agent metadata loaded: agent_id={self._agent_config.agent_id}")
@@ -57,7 +57,7 @@ class _LangfuseSpanExporter:
57
57
  logger.warning("ksadk.configs not available, agent metadata disabled")
58
58
  self._agent_config = None
59
59
  return self._agent_config
60
-
60
+
61
61
  def _init_langfuse(self):
62
62
  """Initialize Langfuse client using low-level API"""
63
63
  try:
@@ -65,13 +65,14 @@ class _LangfuseSpanExporter:
65
65
  os.environ["LANGFUSE_PUBLIC_KEY"] = self.config.public_key
66
66
  os.environ["LANGFUSE_SECRET_KEY"] = self.config.secret_key
67
67
  os.environ["LANGFUSE_HOST"] = self.config.host
68
-
68
+
69
69
  # Use Langfuse low-level client
70
70
  from langfuse import Langfuse
71
+
71
72
  self._langfuse = Langfuse(
72
73
  public_key=self.config.public_key,
73
74
  secret_key=self.config.secret_key,
74
- host=self.config.host
75
+ host=self.config.host,
75
76
  )
76
77
  logger.info(f"Langfuse client initialized: {self.config.host}")
77
78
  except ImportError:
@@ -80,43 +81,48 @@ class _LangfuseSpanExporter:
80
81
  except Exception as e:
81
82
  logger.error(f"Failed to initialize Langfuse: {e}")
82
83
  self._langfuse = None
83
-
84
+
84
85
  def export(self, spans) -> int:
85
86
  """Export spans to Langfuse using low-level API"""
86
87
  if not self._langfuse:
87
88
  return 0
88
-
89
+
89
90
  from opentelemetry.sdk.trace.export import SpanExportResult
90
-
91
+
91
92
  try:
92
93
  # Group spans by trace_id
93
94
  traces = {}
94
95
  for span in spans:
95
- trace_id = format(span.context.trace_id, '032x')
96
+ trace_id = format(span.context.trace_id, "032x")
96
97
  if trace_id not in traces:
97
98
  traces[trace_id] = []
98
99
  traces[trace_id].append(span)
99
-
100
+
100
101
  # Process each trace group
101
102
  for trace_id, trace_spans in traces.items():
102
103
  self._export_trace(trace_id, trace_spans)
103
-
104
+
104
105
  self._langfuse.flush()
105
106
  return SpanExportResult.SUCCESS
106
-
107
+
107
108
  except Exception as e:
108
109
  logger.error(f"Failed to export to Langfuse: {e}")
109
110
  import traceback
111
+
110
112
  traceback.print_exc()
111
113
  return SpanExportResult.FAILURE
112
-
114
+
113
115
  def _export_trace(self, trace_id: str, spans):
114
116
  """Export spans using Langfuse ingestion API"""
117
+ langfuse = self._langfuse
118
+ if langfuse is None:
119
+ return
120
+
115
121
  # Find root span and categorize
116
122
  root_span = None
117
123
  llm_spans = []
118
124
  tool_spans = []
119
-
125
+
120
126
  for span in spans:
121
127
  # Robust Root Span Detection:
122
128
  # 1. Check if parent is None (standard OTEL way)
@@ -125,41 +131,49 @@ class _LangfuseSpanExporter:
125
131
  if hasattr(span, "parent") and span.parent:
126
132
  # Local parent exists
127
133
  is_root = False
128
- elif hasattr(span, "context") and hasattr(span.context, "is_remote") and span.context.is_remote:
129
- # Remote parent (distributed tracing) - treat as root for this service context?
130
- # For now, we treat standard root spans (no parent) as root.
131
- pass
134
+ elif (
135
+ hasattr(span, "context")
136
+ and hasattr(span.context, "is_remote")
137
+ and span.context.is_remote
138
+ ):
139
+ # Remote parent (distributed tracing) - treat as root for this service context?
140
+ # For now, we treat standard root spans (no parent) as root.
141
+ pass
132
142
  elif not span.parent:
133
143
  is_root = True
134
-
144
+
135
145
  # Fallback for SDKs that might not expose parent property easily or if it's None
136
146
  if not is_root:
137
147
  name = span.name
138
- if name.startswith("langgraph.") or name.startswith("langchain.") or name.startswith("adk."):
148
+ if (
149
+ name.startswith("langgraph.")
150
+ or name.startswith("langchain.")
151
+ or name.startswith("adk.")
152
+ ):
139
153
  is_root = True
140
-
154
+
141
155
  if is_root:
142
156
  root_span = span
143
157
  elif name == "call_llm":
144
158
  llm_spans.append(span)
145
159
  elif name.startswith("tool."):
146
160
  tool_spans.append(span)
147
-
161
+
148
162
  if not root_span:
149
163
  # If batch doesn't contain a clear root, use the first span to carry context if needed
150
164
  # But be careful not to treat random child spans as root for attributes
151
165
  root_span = spans[0] if spans else None
152
-
166
+
153
167
  if not root_span:
154
168
  return
155
-
169
+
156
170
  # Extract attributes
157
171
  attrs = dict(root_span.attributes) if root_span.attributes else {}
158
- # Use OTEL Trace ID as Langfuse Trace ID to ensure consistency between manual and auto-instrumented spans
159
- invocation_id = trace_id
172
+ # Preserve the OTEL trace ID across manual and auto-instrumented spans.
173
+ invocation_id = trace_id
160
174
  user_input = attrs.get("user.input", "")
161
175
  agent_output = attrs.get("agent.output", "")
162
-
176
+
163
177
  # Extract Langfuse-specific attributes from span
164
178
  span_session_id = (
165
179
  attrs.get("langfuse.session.id")
@@ -168,11 +182,9 @@ class _LangfuseSpanExporter:
168
182
  )
169
183
  span_tags = attrs.get("langfuse.tags", "")
170
184
  span_user_id = (
171
- attrs.get("langfuse.user.id")
172
- or attrs.get("langfuse.user_id")
173
- or attrs.get("user.id")
185
+ attrs.get("langfuse.user.id") or attrs.get("langfuse.user_id") or attrs.get("user.id")
174
186
  )
175
-
187
+
176
188
  # Create trace using ingestion endpoint
177
189
  try:
178
190
  # Build base metadata
@@ -180,31 +192,33 @@ class _LangfuseSpanExporter:
180
192
  "trace_id": trace_id,
181
193
  "framework": "ksadk",
182
194
  }
183
-
195
+
184
196
  # Get agent config from unified settings
185
197
  agent_config = self._get_agent_config()
186
-
198
+
187
199
  # Merge with agent metadata if available
188
200
  langfuse_params = {}
189
201
  trace_name = root_span.name
190
-
202
+
191
203
  if agent_config:
192
204
  agent_metadata = agent_config.to_langfuse_metadata()
193
205
  base_metadata.update(agent_metadata)
194
-
206
+
195
207
  langfuse_params = agent_config.to_langfuse_params()
196
-
208
+
197
209
  # Use agent_name if available (only if root span)
198
- if agent_config.agent_name and root_span == spans[0]: # Rough check if it's main Span
210
+ if (
211
+ agent_config.agent_name and root_span == spans[0]
212
+ ): # Rough check if it's main Span
199
213
  trace_name = agent_config.agent_name
200
-
214
+
201
215
  # 优先使用 span attributes 中的值 (从 runner 传递)
202
216
  if span_session_id:
203
217
  langfuse_params["session_id"] = span_session_id
204
-
218
+
205
219
  if span_user_id:
206
220
  langfuse_params["user_id"] = span_user_id
207
-
221
+
208
222
  # 处理 tags
209
223
  existing_tags = langfuse_params.get("tags", []) or []
210
224
  if span_tags:
@@ -212,13 +226,13 @@ class _LangfuseSpanExporter:
212
226
  for tag in span_tags_list:
213
227
  if tag not in existing_tags:
214
228
  existing_tags.append(tag)
215
-
229
+
216
230
  if agent_config:
217
- if agent_config.agent_name and agent_config.agent_name not in existing_tags:
231
+ if agent_config.agent_name and agent_config.agent_name not in existing_tags:
218
232
  existing_tags.append(agent_config.agent_name)
219
- if agent_config.environment and agent_config.environment not in existing_tags:
233
+ if agent_config.environment and agent_config.environment not in existing_tags:
220
234
  existing_tags.append(agent_config.environment)
221
-
235
+
222
236
  if existing_tags:
223
237
  langfuse_params["tags"] = existing_tags
224
238
 
@@ -227,21 +241,21 @@ class _LangfuseSpanExporter:
227
241
  "id": invocation_id,
228
242
  "name": trace_name,
229
243
  "metadata": base_metadata,
230
- **langfuse_params
244
+ **langfuse_params,
231
245
  }
232
-
246
+
233
247
  if user_input:
234
248
  trace_kwargs["input"] = {"text": user_input}
235
249
  if agent_output:
236
250
  trace_kwargs["output"] = {"text": agent_output}
237
-
251
+
238
252
  # Use create_trace method (available in v3)
239
- trace = self._langfuse.trace(**trace_kwargs)
240
-
253
+ trace = langfuse.trace(**trace_kwargs)
254
+
241
255
  # Add LLM generations
242
256
  for llm_span in llm_spans:
243
257
  self._add_generation(trace, llm_span)
244
-
258
+
245
259
  # Add tool spans
246
260
  for tool_span in tool_spans:
247
261
  self._add_tool_span(trace, tool_span)
@@ -251,32 +265,32 @@ class _LangfuseSpanExporter:
251
265
  except AttributeError:
252
266
  # Fallback: use score/event API if trace() not available
253
267
  self._export_via_events(invocation_id, root_span, llm_spans, tool_spans)
254
-
268
+
255
269
  def _add_generation(self, trace, span):
256
270
  """Add LLM generation to trace"""
257
271
  attrs = dict(span.attributes) if span.attributes else {}
258
-
272
+
259
273
  llm_request_str = attrs.get("gcp.vertex.agent.llm_request", "{}")
260
274
  llm_response_str = attrs.get("gcp.vertex.agent.llm_response", "{}")
261
-
275
+
262
276
  try:
263
277
  llm_request = json.loads(llm_request_str)
264
278
  llm_response = json.loads(llm_response_str)
265
279
  except json.JSONDecodeError:
266
280
  llm_request = {"raw": llm_request_str}
267
281
  llm_response = {"raw": llm_response_str}
268
-
282
+
269
283
  # Extract text content
270
284
  input_text = ""
271
285
  output_text = ""
272
-
286
+
273
287
  if "contents" in llm_request:
274
288
  contents = llm_request.get("contents", [])
275
289
  if contents and "parts" in contents[0]:
276
290
  parts = contents[0].get("parts", [])
277
291
  if parts and "text" in parts[0]:
278
292
  input_text = parts[0]["text"]
279
-
293
+
280
294
  if "candidates" in llm_response:
281
295
  candidates = llm_response.get("candidates", [])
282
296
  if candidates and "content" in candidates[0]:
@@ -285,9 +299,9 @@ class _LangfuseSpanExporter:
285
299
  parts = content["parts"]
286
300
  if parts and "text" in parts[0]:
287
301
  output_text = parts[0]["text"]
288
-
302
+
289
303
  model = attrs.get("model", attrs.get("gen_ai.request.model", "unknown"))
290
-
304
+
291
305
  try:
292
306
  trace.generation(
293
307
  name=span.name,
@@ -295,21 +309,21 @@ class _LangfuseSpanExporter:
295
309
  input=input_text or llm_request,
296
310
  output=output_text or llm_response,
297
311
  metadata={
298
- "span_id": format(span.context.span_id, '016x'),
299
- }
312
+ "span_id": format(span.context.span_id, "016x"),
313
+ },
300
314
  )
301
315
  except AttributeError:
302
316
  # Generation method not available, skip
303
317
  pass
304
-
318
+
305
319
  def _add_tool_span(self, trace, span):
306
320
  """Add tool execution span"""
307
321
  attrs = dict(span.attributes) if span.attributes else {}
308
-
322
+
309
323
  tool_name = attrs.get("tool.name", span.name.replace("tool.", ""))
310
324
  tool_input = attrs.get("tool.input", "")
311
325
  tool_output = attrs.get("tool.output", "")
312
-
326
+
313
327
  try:
314
328
  trace.span(
315
329
  name=f"tool:{tool_name}",
@@ -317,7 +331,7 @@ class _LangfuseSpanExporter:
317
331
  output={"result": tool_output} if tool_output else None,
318
332
  metadata={
319
333
  "tool_name": tool_name,
320
- }
334
+ },
321
335
  )
322
336
  except AttributeError:
323
337
  pass
@@ -387,14 +401,14 @@ class _LangfuseSpanExporter:
387
401
  self._langfuse.score(**score_kwargs)
388
402
  except AttributeError:
389
403
  pass
390
-
404
+
391
405
  def _export_via_events(self, trace_id: str, root_span, llm_spans, tool_spans):
392
406
  """Fallback export using event-based API"""
393
407
  # This is a fallback for when trace() method is not available
394
408
  logger.debug(f"Exporting trace {trace_id} via fallback method")
395
409
  # Just log for now - can be enhanced later
396
410
  pass
397
-
411
+
398
412
  def shutdown(self):
399
413
  """Shutdown the exporter"""
400
414
  if self._langfuse:
@@ -403,7 +417,7 @@ class _LangfuseSpanExporter:
403
417
  self._langfuse.shutdown()
404
418
  except Exception:
405
419
  pass
406
-
420
+
407
421
  def force_flush(self, timeout_millis: int = 30000) -> bool:
408
422
  """Force flush pending spans"""
409
423
  if self._langfuse:
@@ -416,26 +430,27 @@ class _LangfuseSpanExporter:
416
430
 
417
431
  class LangfuseExporter:
418
432
  """Langfuse exporter for KsADK tracing system.
419
-
433
+
420
434
  Compatible with Langfuse SDK v3.
421
435
  """
422
-
436
+
423
437
  def __init__(self, config: LangfuseExporterConfig):
424
438
  self.config = config
425
439
  self.name = "langfuse_exporter"
426
-
440
+
427
441
  self._exporter = _LangfuseSpanExporter(config)
428
442
  self.processor = self._create_processor()
429
-
443
+
430
444
  def _create_processor(self):
431
445
  """Create span processor for this exporter"""
432
446
  try:
433
447
  from opentelemetry.sdk.trace.export import SimpleSpanProcessor
448
+
434
449
  return SimpleSpanProcessor(self._exporter)
435
450
  except ImportError:
436
451
  logger.error("OpenTelemetry SDK not installed")
437
452
  return None
438
-
453
+
439
454
  @property
440
455
  def resource_attributes(self) -> dict:
441
456
  """Return resource attributes for this exporter"""