langchain-agentx-python 0.1__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (354) hide show
  1. langchain_agentx/__init__.py +46 -0
  2. langchain_agentx/command/__init__.py +28 -0
  3. langchain_agentx/command/builtin/__init__.py +25 -0
  4. langchain_agentx/command/builtin/clear.py +33 -0
  5. langchain_agentx/command/builtin/compact.py +33 -0
  6. langchain_agentx/command/builtin/memory.py +37 -0
  7. langchain_agentx/command/builtin/reload_plugins.py +42 -0
  8. langchain_agentx/command/context.py +30 -0
  9. langchain_agentx/command/dispatcher.py +183 -0
  10. langchain_agentx/command/registry.py +110 -0
  11. langchain_agentx/command/result.py +25 -0
  12. langchain_agentx/command/types.py +41 -0
  13. langchain_agentx/config/__init__.py +14 -0
  14. langchain_agentx/loop/__init__.py +47 -0
  15. langchain_agentx/loop/config/__init__.py +20 -0
  16. langchain_agentx/loop/config/agent_config.py +66 -0
  17. langchain_agentx/loop/config/agent_loop_config.py +72 -0
  18. langchain_agentx/loop/config/model_context_resolver.py +105 -0
  19. langchain_agentx/loop/config/runtime_settings.py +50 -0
  20. langchain_agentx/loop/config/token_estimator.py +133 -0
  21. langchain_agentx/loop/context/__init__.py +66 -0
  22. langchain_agentx/loop/context/blocking_guard.py +97 -0
  23. langchain_agentx/loop/context/compaction_service.py +60 -0
  24. langchain_agentx/loop/context/message_utils.py +56 -0
  25. langchain_agentx/loop/context/pipeline.py +127 -0
  26. langchain_agentx/loop/context/settings.py +103 -0
  27. langchain_agentx/loop/context/stages/__init__.py +29 -0
  28. langchain_agentx/loop/context/stages/autocompact.py +140 -0
  29. langchain_agentx/loop/context/stages/base.py +32 -0
  30. langchain_agentx/loop/context/stages/collapse.py +76 -0
  31. langchain_agentx/loop/context/stages/microcompact.py +76 -0
  32. langchain_agentx/loop/context/stages/noop.py +33 -0
  33. langchain_agentx/loop/context/stages/snip.py +71 -0
  34. langchain_agentx/loop/context/stages/tool_result_budget.py +69 -0
  35. langchain_agentx/loop/context/types.py +79 -0
  36. langchain_agentx/loop/exit/__init__.py +1 -0
  37. langchain_agentx/loop/exit/exit_logic.py +320 -0
  38. langchain_agentx/loop/exit/reason_codes.py +39 -0
  39. langchain_agentx/loop/graph/__init__.py +5 -0
  40. langchain_agentx/loop/graph/builtin_loop_control.py +197 -0
  41. langchain_agentx/loop/graph/factory.py +1409 -0
  42. langchain_agentx/loop/graph/graph_edges.py +820 -0
  43. langchain_agentx/loop/hook/__init__.py +48 -0
  44. langchain_agentx/loop/hook/async_hook_runner.py +62 -0
  45. langchain_agentx/loop/hook/config.py +280 -0
  46. langchain_agentx/loop/hook/engine.py +321 -0
  47. langchain_agentx/loop/hook/executors/__init__.py +9 -0
  48. langchain_agentx/loop/hook/executors/agent.py +107 -0
  49. langchain_agentx/loop/hook/executors/command.py +230 -0
  50. langchain_agentx/loop/hook/executors/http.py +114 -0
  51. langchain_agentx/loop/hook/executors/prompt.py +92 -0
  52. langchain_agentx/loop/hook/graph_wiring.py +134 -0
  53. langchain_agentx/loop/hook/registry.py +262 -0
  54. langchain_agentx/loop/hook/trust.py +43 -0
  55. langchain_agentx/loop/hook/types.py +110 -0
  56. langchain_agentx/loop/injection/__init__.py +13 -0
  57. langchain_agentx/loop/injection/dedup.py +74 -0
  58. langchain_agentx/loop/loop_abort.py +36 -0
  59. langchain_agentx/loop/model/__init__.py +1 -0
  60. langchain_agentx/loop/model/model_node.py +648 -0
  61. langchain_agentx/loop/model/model_nodes.py +661 -0
  62. langchain_agentx/loop/model/orphan_tool_results.py +38 -0
  63. langchain_agentx/loop/model/retrier.py +307 -0
  64. langchain_agentx/loop/model/retry_bridge.py +58 -0
  65. langchain_agentx/loop/model/retry_events.py +35 -0
  66. langchain_agentx/loop/model/retry_policy.py +56 -0
  67. langchain_agentx/loop/model/schema_and_format.py +153 -0
  68. langchain_agentx/loop/model/tool_and_model_binding.py +227 -0
  69. langchain_agentx/loop/model/tool_call_degradation_corrector.py +443 -0
  70. langchain_agentx/loop/model/tool_transcript_guard.py +225 -0
  71. langchain_agentx/loop/prompt/__init__.py +95 -0
  72. langchain_agentx/loop/prompt/builder.py +61 -0
  73. langchain_agentx/loop/prompt/builtin.py +218 -0
  74. langchain_agentx/loop/prompt/compact.py +408 -0
  75. langchain_agentx/loop/prompt/sections.py +120 -0
  76. langchain_agentx/loop/runtime/__init__.py +19 -0
  77. langchain_agentx/loop/runtime/context.py +34 -0
  78. langchain_agentx/loop/runtime/context_factory.py +107 -0
  79. langchain_agentx/loop/runtime/subagent_execution_paths.py +68 -0
  80. langchain_agentx/loop/subagent/__init__.py +53 -0
  81. langchain_agentx/loop/subagent/async_runner.py +215 -0
  82. langchain_agentx/loop/subagent/context.py +209 -0
  83. langchain_agentx/loop/subagent/fork_worktree_notice.py +25 -0
  84. langchain_agentx/loop/subagent/graph.py +72 -0
  85. langchain_agentx/loop/subagent/orchestrator.py +391 -0
  86. langchain_agentx/loop/subagent/progress.py +30 -0
  87. langchain_agentx/loop/subagent/prompt.py +52 -0
  88. langchain_agentx/loop/subagent/runner.py +504 -0
  89. langchain_agentx/loop/subagent/transcript.py +172 -0
  90. langchain_agentx/memory/__init__.py +2 -0
  91. langchain_agentx/memory/instruction/__init__.py +12 -0
  92. langchain_agentx/memory/instruction/loader.py +325 -0
  93. langchain_agentx/memory/instruction/resolver.py +24 -0
  94. langchain_agentx/memory/instruction/runtime.py +83 -0
  95. langchain_agentx/memory/instruction/sections.py +83 -0
  96. langchain_agentx/memory/instruction/types.py +59 -0
  97. langchain_agentx/memory/memdir/__init__.py +77 -0
  98. langchain_agentx/memory/memdir/age.py +36 -0
  99. langchain_agentx/memory/memdir/agent_memory.py +380 -0
  100. langchain_agentx/memory/memdir/extractor.py +309 -0
  101. langchain_agentx/memory/memdir/loader.py +187 -0
  102. langchain_agentx/memory/memdir/paths.py +63 -0
  103. langchain_agentx/memory/memdir/recall.py +45 -0
  104. langchain_agentx/memory/memdir/runtime.py +43 -0
  105. langchain_agentx/memory/memdir/scan.py +135 -0
  106. langchain_agentx/memory/memdir/types.py +104 -0
  107. langchain_agentx/memory/session/__init__.py +76 -0
  108. langchain_agentx/memory/session/compact_bridge.py +208 -0
  109. langchain_agentx/memory/session/prompts.py +172 -0
  110. langchain_agentx/memory/session/session_memory.py +282 -0
  111. langchain_agentx/observability/__init__.py +67 -0
  112. langchain_agentx/observability/evaluation/__init__.py +17 -0
  113. langchain_agentx/observability/evaluation/checkers/__init__.py +18 -0
  114. langchain_agentx/observability/evaluation/checkers/base.py +34 -0
  115. langchain_agentx/observability/evaluation/checkers/compaction.py +38 -0
  116. langchain_agentx/observability/evaluation/checkers/degradation.py +50 -0
  117. langchain_agentx/observability/evaluation/checkers/exit_quality.py +42 -0
  118. langchain_agentx/observability/evaluation/checkers/session_memory.py +45 -0
  119. langchain_agentx/observability/evaluation/checkers/tool_behavior.py +53 -0
  120. langchain_agentx/observability/evaluation/retention_scheduler.py +67 -0
  121. langchain_agentx/observability/evaluation/service.py +102 -0
  122. langchain_agentx/observability/evaluation/state.py +32 -0
  123. langchain_agentx/observability/evaluation/store.py +258 -0
  124. langchain_agentx/observability/events/__init__.py +15 -0
  125. langchain_agentx/observability/events/langchain_agentx_event_adapter.py +832 -0
  126. langchain_agentx/observability/logging/__init__.py +15 -0
  127. langchain_agentx/observability/logging/debug_burst.py +95 -0
  128. langchain_agentx/observability/logging/logging_config.py +178 -0
  129. langchain_agentx/observability/logging/logging_contract.py +65 -0
  130. langchain_agentx/observability/replay/__init__.py +35 -0
  131. langchain_agentx/observability/replay/cli.py +91 -0
  132. langchain_agentx/observability/replay/service.py +83 -0
  133. langchain_agentx/observability/replay/store.py +278 -0
  134. langchain_agentx/observability/replay/ui.py +47 -0
  135. langchain_agentx/observability/trace/__init__.py +25 -0
  136. langchain_agentx/observability/trace/collector.py +560 -0
  137. langchain_agentx/observability/trace/event_emitter.py +183 -0
  138. langchain_agentx/observability/trace/hook_event_emitter.py +49 -0
  139. langchain_agentx/observability/trace/models.py +144 -0
  140. langchain_agentx/observability/trace/sqlite_store.py +873 -0
  141. langchain_agentx/observability/trace/trace_callback.py +295 -0
  142. langchain_agentx/observability/trace/trace_lifecycle_collector.py +114 -0
  143. langchain_agentx/plugin/__init__.py +26 -0
  144. langchain_agentx/plugin/builtin.py +53 -0
  145. langchain_agentx/plugin/config.py +113 -0
  146. langchain_agentx/plugin/loader.py +386 -0
  147. langchain_agentx/plugin/manifest.py +154 -0
  148. langchain_agentx/plugin/registries.py +211 -0
  149. langchain_agentx/plugin/types.py +142 -0
  150. langchain_agentx/provider/__init__.py +27 -0
  151. langchain_agentx/provider/anthropic.py +121 -0
  152. langchain_agentx/provider/compatible_chat_openai.py +86 -0
  153. langchain_agentx/provider/env.py +45 -0
  154. langchain_agentx/provider/model_profile.py +156 -0
  155. langchain_agentx/provider/openai.py +89 -0
  156. langchain_agentx/session/__init__.py +17 -0
  157. langchain_agentx/session/agent_session.py +320 -0
  158. langchain_agentx/session/conversation_factory.py +87 -0
  159. langchain_agentx/session/conversation_recovery.py +156 -0
  160. langchain_agentx/session/conversation_session.py +198 -0
  161. langchain_agentx/session/factory.py +143 -0
  162. langchain_agentx/session/protocol.py +25 -0
  163. langchain_agentx/task_runtime/__init__.py +113 -0
  164. langchain_agentx/task_runtime/core/__init__.py +51 -0
  165. langchain_agentx/task_runtime/core/ids.py +33 -0
  166. langchain_agentx/task_runtime/core/interfaces.py +115 -0
  167. langchain_agentx/task_runtime/core/notification_priority.py +19 -0
  168. langchain_agentx/task_runtime/core/types.py +136 -0
  169. langchain_agentx/task_runtime/integrations/__init__.py +33 -0
  170. langchain_agentx/task_runtime/integrations/loop_adapter.py +91 -0
  171. langchain_agentx/task_runtime/integrations/loop_integration.py +61 -0
  172. langchain_agentx/task_runtime/integrations/prefetch_providers.py +108 -0
  173. langchain_agentx/task_runtime/integrations/provider_factory.py +103 -0
  174. langchain_agentx/task_runtime/integrations/queued_command_provider.py +184 -0
  175. langchain_agentx/task_runtime/integrations/sqlite_queued_command_provider.py +338 -0
  176. langchain_agentx/task_runtime/integrations/tool_use_summary_provider.py +254 -0
  177. langchain_agentx/task_runtime/orchestrator/__init__.py +5 -0
  178. langchain_agentx/task_runtime/orchestrator/runtime.py +386 -0
  179. langchain_agentx/task_runtime/output/__init__.py +5 -0
  180. langchain_agentx/task_runtime/output/sink.py +64 -0
  181. langchain_agentx/task_runtime/policy/__init__.py +11 -0
  182. langchain_agentx/task_runtime/policy/withhold_visibility.py +32 -0
  183. langchain_agentx/task_runtime/queue/__init__.py +5 -0
  184. langchain_agentx/task_runtime/queue/in_memory.py +55 -0
  185. langchain_agentx/task_runtime/skill_prefetch/__init__.py +4 -0
  186. langchain_agentx/task_runtime/skill_prefetch/attachments.py +46 -0
  187. langchain_agentx/task_runtime/skill_prefetch/models.py +37 -0
  188. langchain_agentx/task_runtime/skill_prefetch/provider.py +344 -0
  189. langchain_agentx/task_runtime/store/__init__.py +6 -0
  190. langchain_agentx/task_runtime/store/in_memory.py +81 -0
  191. langchain_agentx/task_runtime/store/sqlite_store.py +281 -0
  192. langchain_agentx/task_runtime/tasks/__init__.py +76 -0
  193. langchain_agentx/task_runtime/tasks/ai_analysis/__init__.py +15 -0
  194. langchain_agentx/task_runtime/tasks/ai_analysis/base.py +41 -0
  195. langchain_agentx/task_runtime/tasks/ai_analysis/evaluation.py +67 -0
  196. langchain_agentx/task_runtime/tasks/ai_analysis/registry.py +36 -0
  197. langchain_agentx/task_runtime/tasks/ai_analysis/scheduler.py +70 -0
  198. langchain_agentx/task_runtime/tasks/base/__init__.py +6 -0
  199. langchain_agentx/task_runtime/tasks/base/contracts.py +24 -0
  200. langchain_agentx/task_runtime/tasks/custom/__init__.py +7 -0
  201. langchain_agentx/task_runtime/tasks/custom/executor.py +60 -0
  202. langchain_agentx/task_runtime/tasks/custom/notification.py +7 -0
  203. langchain_agentx/task_runtime/tasks/custom/semantics.py +13 -0
  204. langchain_agentx/task_runtime/tasks/custom/spec.py +33 -0
  205. langchain_agentx/task_runtime/tasks/dream_task/__init__.py +15 -0
  206. langchain_agentx/task_runtime/tasks/dream_task/executor.py +61 -0
  207. langchain_agentx/task_runtime/tasks/dream_task/notification.py +19 -0
  208. langchain_agentx/task_runtime/tasks/dream_task/semantics.py +13 -0
  209. langchain_agentx/task_runtime/tasks/dream_task/spec.py +35 -0
  210. langchain_agentx/task_runtime/tasks/dream_task/state.py +17 -0
  211. langchain_agentx/task_runtime/tasks/in_process_teammate/__init__.py +12 -0
  212. langchain_agentx/task_runtime/tasks/in_process_teammate/executor.py +36 -0
  213. langchain_agentx/task_runtime/tasks/in_process_teammate/notification.py +25 -0
  214. langchain_agentx/task_runtime/tasks/in_process_teammate/semantics.py +13 -0
  215. langchain_agentx/task_runtime/tasks/in_process_teammate/spec.py +63 -0
  216. langchain_agentx/task_runtime/tasks/local_agent/__init__.py +14 -0
  217. langchain_agentx/task_runtime/tasks/local_agent/executor.py +33 -0
  218. langchain_agentx/task_runtime/tasks/local_agent/notification.py +21 -0
  219. langchain_agentx/task_runtime/tasks/local_agent/runner.py +43 -0
  220. langchain_agentx/task_runtime/tasks/local_agent/semantics.py +13 -0
  221. langchain_agentx/task_runtime/tasks/local_agent/spec.py +31 -0
  222. langchain_agentx/task_runtime/tasks/local_bash/__init__.py +13 -0
  223. langchain_agentx/task_runtime/tasks/local_bash/executor.py +95 -0
  224. langchain_agentx/task_runtime/tasks/local_bash/notification.py +22 -0
  225. langchain_agentx/task_runtime/tasks/local_bash/semantics.py +13 -0
  226. langchain_agentx/task_runtime/tasks/local_bash/spec.py +55 -0
  227. langchain_agentx/task_runtime/tasks/remote_agent/__init__.py +19 -0
  228. langchain_agentx/task_runtime/tasks/remote_agent/backend.py +76 -0
  229. langchain_agentx/task_runtime/tasks/remote_agent/executor.py +37 -0
  230. langchain_agentx/task_runtime/tasks/remote_agent/notification.py +22 -0
  231. langchain_agentx/task_runtime/tasks/remote_agent/semantics.py +13 -0
  232. langchain_agentx/task_runtime/tasks/remote_agent/spec.py +34 -0
  233. langchain_agentx/task_runtime/tasks/trace_cleanup/__init__.py +19 -0
  234. langchain_agentx/task_runtime/tasks/trace_cleanup/bootstrap.py +95 -0
  235. langchain_agentx/task_runtime/tasks/trace_cleanup/executor.py +66 -0
  236. langchain_agentx/task_runtime/tasks/trace_cleanup/scheduler.py +169 -0
  237. langchain_agentx/tool_runtime/__init__.py +90 -0
  238. langchain_agentx/tool_runtime/adapter.py +365 -0
  239. langchain_agentx/tool_runtime/base.py +319 -0
  240. langchain_agentx/tool_runtime/errors.py +190 -0
  241. langchain_agentx/tool_runtime/identical_call_cache.py +110 -0
  242. langchain_agentx/tool_runtime/loader.py +195 -0
  243. langchain_agentx/tool_runtime/models.py +260 -0
  244. langchain_agentx/tool_runtime/permission_context.py +78 -0
  245. langchain_agentx/tool_runtime/pipeline.py +621 -0
  246. langchain_agentx/tool_runtime/policy.py +447 -0
  247. langchain_agentx/tool_runtime/registry.py +81 -0
  248. langchain_agentx/tool_runtime/resolvers/__init__.py +27 -0
  249. langchain_agentx/tool_runtime/resolvers/agent_session.py +125 -0
  250. langchain_agentx/tool_runtime/resolvers/background.py +32 -0
  251. langchain_agentx/tool_runtime/resolvers/base.py +20 -0
  252. langchain_agentx/tool_runtime/resolvers/conversation.py +22 -0
  253. langchain_agentx/tool_runtime/resolvers/workflow.py +73 -0
  254. langchain_agentx/tool_runtime/session_store.py +132 -0
  255. langchain_agentx/tool_runtime/smoke_test_runtime.py +294 -0
  256. langchain_agentx/tool_runtime/state_bridge.py +164 -0
  257. langchain_agentx/tools/__init__.py +26 -0
  258. langchain_agentx/tools/agent/__init__.py +9 -0
  259. langchain_agentx/tools/agent/backend.py +53 -0
  260. langchain_agentx/tools/agent/built_in/__init__.py +19 -0
  261. langchain_agentx/tools/agent/built_in/agentx_guide.py +65 -0
  262. langchain_agentx/tools/agent/built_in/explore.py +80 -0
  263. langchain_agentx/tools/agent/built_in/general.py +57 -0
  264. langchain_agentx/tools/agent/built_in/plan.py +89 -0
  265. langchain_agentx/tools/agent/built_in/statusline_setup.py +64 -0
  266. langchain_agentx/tools/agent/built_in/verification.py +120 -0
  267. langchain_agentx/tools/agent/builtin_subagent_loader.py +89 -0
  268. langchain_agentx/tools/agent/cwd_resolution.py +119 -0
  269. langchain_agentx/tools/agent/limits.py +26 -0
  270. langchain_agentx/tools/agent/loader.py +270 -0
  271. langchain_agentx/tools/agent/models.py +85 -0
  272. langchain_agentx/tools/agent/prompt.py +120 -0
  273. langchain_agentx/tools/agent/registry/__init__.py +18 -0
  274. langchain_agentx/tools/agent/registry/config.py +29 -0
  275. langchain_agentx/tools/agent/registry/registry.py +47 -0
  276. langchain_agentx/tools/agent/scope.py +137 -0
  277. langchain_agentx/tools/agent/tool.py +256 -0
  278. langchain_agentx/tools/bash/__init__.py +9 -0
  279. langchain_agentx/tools/bash/ast_security.py +571 -0
  280. langchain_agentx/tools/bash/backend.py +1447 -0
  281. langchain_agentx/tools/bash/bash_hardening.py +734 -0
  282. langchain_agentx/tools/bash/bash_runtime_contract.py +41 -0
  283. langchain_agentx/tools/bash/cwd_reporter.py +95 -0
  284. langchain_agentx/tools/bash/limits.py +71 -0
  285. langchain_agentx/tools/bash/mode_validation.py +282 -0
  286. langchain_agentx/tools/bash/models.py +131 -0
  287. langchain_agentx/tools/bash/observability.py +148 -0
  288. langchain_agentx/tools/bash/output_utils.py +200 -0
  289. langchain_agentx/tools/bash/path_security.py +2429 -0
  290. langchain_agentx/tools/bash/prompt.py +68 -0
  291. langchain_agentx/tools/bash/read_only_validation.py +589 -0
  292. langchain_agentx/tools/bash/result_presenter.py +324 -0
  293. langchain_agentx/tools/bash/sandbox_decision.py +133 -0
  294. langchain_agentx/tools/bash/security.py +311 -0
  295. langchain_agentx/tools/bash/sed_edit_parser.py +243 -0
  296. langchain_agentx/tools/bash/sed_validation.py +163 -0
  297. langchain_agentx/tools/bash/semantics.py +111 -0
  298. langchain_agentx/tools/bash/session_manager.py +205 -0
  299. langchain_agentx/tools/bash/session_runtime.py +290 -0
  300. langchain_agentx/tools/bash/shell_locator.py +191 -0
  301. langchain_agentx/tools/bash/task_runtime.py +91 -0
  302. langchain_agentx/tools/bash/tool.py +939 -0
  303. langchain_agentx/tools/bash/windows_shell_quoting.py +45 -0
  304. langchain_agentx/tools/glob/__init__.py +9 -0
  305. langchain_agentx/tools/glob/models.py +57 -0
  306. langchain_agentx/tools/glob/pagination.py +30 -0
  307. langchain_agentx/tools/glob/prompt.py +24 -0
  308. langchain_agentx/tools/glob/rg_list_backend.py +139 -0
  309. langchain_agentx/tools/glob/rg_pattern.py +44 -0
  310. langchain_agentx/tools/glob/tool.py +327 -0
  311. langchain_agentx/tools/grep/__init__.py +7 -0
  312. langchain_agentx/tools/grep/backend.py +375 -0
  313. langchain_agentx/tools/grep/models.py +127 -0
  314. langchain_agentx/tools/grep/prompt.py +30 -0
  315. langchain_agentx/tools/grep/rg_subprocess_controller.py +114 -0
  316. langchain_agentx/tools/grep/tool.py +475 -0
  317. langchain_agentx/tools/read/__init__.py +9 -0
  318. langchain_agentx/tools/read/backend.py +415 -0
  319. langchain_agentx/tools/read/limits.py +67 -0
  320. langchain_agentx/tools/read/models.py +156 -0
  321. langchain_agentx/tools/read/prompt.py +73 -0
  322. langchain_agentx/tools/read/tool.py +494 -0
  323. langchain_agentx/tools/ripgrep_plugin_exclusions.py +137 -0
  324. langchain_agentx/tools/skill/__init__.py +4 -0
  325. langchain_agentx/tools/skill/argument_substitution.py +80 -0
  326. langchain_agentx/tools/skill/loader.py +196 -0
  327. langchain_agentx/tools/skill/models.py +88 -0
  328. langchain_agentx/tools/skill/policy.py +80 -0
  329. langchain_agentx/tools/skill/prompt.py +35 -0
  330. langchain_agentx/tools/skill/tool.py +222 -0
  331. langchain_agentx/utils/__init__.py +0 -0
  332. langchain_agentx/utils/cwd.py +124 -0
  333. langchain_agentx/utils/host_platform.py +112 -0
  334. langchain_agentx/utils/path_hierarchy.py +48 -0
  335. langchain_agentx/utils/path_user_input.py +66 -0
  336. langchain_agentx/utils/rg_executable.py +18 -0
  337. langchain_agentx/utils/subprocess_text.py +101 -0
  338. langchain_agentx/utils/temp_paths.py +77 -0
  339. langchain_agentx/utils/unc_path.py +25 -0
  340. langchain_agentx/utils/win_reserved_paths.py +51 -0
  341. langchain_agentx/workflow/__init__.py +7 -0
  342. langchain_agentx/workflow/base.py +97 -0
  343. langchain_agentx/workflow/batch.py +55 -0
  344. langchain_agentx/workflow/dag.py +54 -0
  345. langchain_agentx/workspace/__init__.py +13 -0
  346. langchain_agentx/workspace/config.py +140 -0
  347. langchain_agentx/workspace/path_key_normalizer.py +30 -0
  348. langchain_agentx/workspace/resolver.py +74 -0
  349. langchain_agentx/workspace/validators.py +41 -0
  350. langchain_agentx_python-0.1.dist-info/LICENSE +201 -0
  351. langchain_agentx_python-0.1.dist-info/METADATA +513 -0
  352. langchain_agentx_python-0.1.dist-info/RECORD +354 -0
  353. langchain_agentx_python-0.1.dist-info/WHEEL +5 -0
  354. langchain_agentx_python-0.1.dist-info/top_level.txt +1 -0
@@ -0,0 +1,67 @@
1
+ """可观测性:事件适配、trace 存储与 replay 能力。"""
2
+
3
+ from .events import (
4
+ EventAdapterState,
5
+ LangchainAgentEvent,
6
+ LangchainAgentEventType,
7
+ LangGraphToLangchainAgentEventAdapter,
8
+ )
9
+ from .replay.service import (
10
+ export_call_chain,
11
+ list_replayable_tool_calls,
12
+ query_replays,
13
+ replay_tool_call,
14
+ tail_tool_call_events,
15
+ visualize_call_chain_mermaid,
16
+ )
17
+ from .replay.store import (
18
+ DECISION_LAYERS,
19
+ OBS_SCHEMA_VERSION,
20
+ REASON_CODES,
21
+ get_global_trace_store,
22
+ sample_events,
23
+ sanitize_value,
24
+ )
25
+ from .logging import (
26
+ DebugBurstController,
27
+ DebugBurstSession,
28
+ LogContext,
29
+ LoggingConfigBuilder,
30
+ ObservabilityLoggerAdapter,
31
+ build_log_context,
32
+ configure_logging_once,
33
+ )
34
+ from .trace import (
35
+ TraceCollector,
36
+ TraceSession,
37
+ TraceSpan,
38
+ )
39
+
40
+ __all__ = [
41
+ "EventAdapterState",
42
+ "DECISION_LAYERS",
43
+ "DebugBurstController",
44
+ "DebugBurstSession",
45
+ "LogContext",
46
+ "LoggingConfigBuilder",
47
+ "OBS_SCHEMA_VERSION",
48
+ "ObservabilityLoggerAdapter",
49
+ "build_log_context",
50
+ "configure_logging_once",
51
+ "LangchainAgentEvent",
52
+ "LangchainAgentEventType",
53
+ "LangGraphToLangchainAgentEventAdapter",
54
+ "REASON_CODES",
55
+ "export_call_chain",
56
+ "get_global_trace_store",
57
+ "list_replayable_tool_calls",
58
+ "query_replays",
59
+ "replay_tool_call",
60
+ "sample_events",
61
+ "sanitize_value",
62
+ "tail_tool_call_events",
63
+ "TraceCollector",
64
+ "TraceSession",
65
+ "TraceSpan",
66
+ "visualize_call_chain_mermaid",
67
+ ]
@@ -0,0 +1,17 @@
1
+ """评估系统导出。"""
2
+
3
+ from .checkers.base import BaseChecker, CheckResult
4
+ from .retention_scheduler import RetentionScheduler
5
+ from .service import EvaluationService
6
+ from .state import AnalysisState
7
+ from .store import DiagnosticReport, EvaluationStore
8
+
9
+ __all__ = [
10
+ "EvaluationService",
11
+ "EvaluationStore",
12
+ "DiagnosticReport",
13
+ "RetentionScheduler",
14
+ "AnalysisState",
15
+ "BaseChecker",
16
+ "CheckResult",
17
+ ]
@@ -0,0 +1,18 @@
1
+ """内置 Checker 导出。"""
2
+
3
+ from .base import BaseChecker, CheckResult
4
+ from .compaction import CompactionChecker
5
+ from .degradation import DegradationChecker
6
+ from .exit_quality import ExitQualityChecker
7
+ from .session_memory import SessionMemoryTriggerChecker
8
+ from .tool_behavior import ToolBehaviorChecker
9
+
10
+ __all__ = [
11
+ "BaseChecker",
12
+ "CheckResult",
13
+ "SessionMemoryTriggerChecker",
14
+ "CompactionChecker",
15
+ "ToolBehaviorChecker",
16
+ "ExitQualityChecker",
17
+ "DegradationChecker",
18
+ ]
@@ -0,0 +1,34 @@
1
+ """
2
+ checkers/base.py — Checker 基类与 CheckResult 数据模型。
3
+
4
+ 职责:
5
+ 定义所有 Checker 的统一接口契约和结果数据结构。
6
+ """
7
+
8
+ from __future__ import annotations
9
+
10
+ from abc import ABC, abstractmethod
11
+ from dataclasses import dataclass, field
12
+ from typing import Any, Literal
13
+
14
+ from ...trace.models import TraceSession, TraceSpan
15
+
16
+
17
+ @dataclass
18
+ class CheckResult:
19
+ checker_name: str
20
+ status: Literal["pass", "fail", "warn", "skip"]
21
+ message: str
22
+ evidence: dict[str, Any] = field(default_factory=dict)
23
+
24
+
25
+ class BaseChecker(ABC):
26
+ name: str
27
+ description: str
28
+
29
+ @abstractmethod
30
+ def check(self, session: TraceSession, spans: list[TraceSpan]) -> CheckResult:
31
+ """执行单项检查并返回结果。"""
32
+
33
+
34
+ __all__ = ["BaseChecker", "CheckResult"]
@@ -0,0 +1,38 @@
1
+ """CompactionChecker — 检查上下文压缩是否按预期执行。"""
2
+
3
+ from __future__ import annotations
4
+
5
+ from ...trace.models import SpanStatus, SpanType, TraceSession, TraceSpan
6
+ from .base import BaseChecker, CheckResult
7
+
8
+ _LOOP_COUNT_THRESHOLD = 20
9
+
10
+
11
+ class CompactionChecker(BaseChecker):
12
+ name = "compaction"
13
+ description = "检查上下文压缩是否按预期执行"
14
+
15
+ def check(self, session: TraceSession, spans: list[TraceSpan]) -> CheckResult:
16
+ compaction_spans = [span for span in spans if span.span_type == SpanType.COMPACTION]
17
+
18
+ if session.loop_count > _LOOP_COUNT_THRESHOLD and not compaction_spans:
19
+ return CheckResult(
20
+ self.name,
21
+ "warn",
22
+ f"loop_count={session.loop_count} 但无 compaction span",
23
+ evidence={"loop_count": session.loop_count},
24
+ )
25
+
26
+ failed = [span for span in compaction_spans if span.status == SpanStatus.FAILED]
27
+ if failed:
28
+ return CheckResult(
29
+ self.name,
30
+ "fail",
31
+ "compaction 执行失败",
32
+ evidence={"error": failed[0].error},
33
+ )
34
+
35
+ return CheckResult(self.name, "pass", "compaction 正常")
36
+
37
+
38
+ __all__ = ["CompactionChecker"]
@@ -0,0 +1,50 @@
1
+ """DegradationChecker — 检查 tool_call 退化情况。"""
2
+
3
+ from __future__ import annotations
4
+
5
+ from ...trace.models import SpanType, TraceSession, TraceSpan
6
+ from .base import BaseChecker, CheckResult
7
+
8
+ _DEGRADATION_RATE_THRESHOLD = 0.2
9
+
10
+
11
+ class DegradationChecker(BaseChecker):
12
+ name = "degradation"
13
+ description = "检查 tool_call 退化率"
14
+
15
+ def check(self, session: TraceSession, spans: list[TraceSpan]) -> CheckResult:
16
+ del session
17
+ llm_spans = [span for span in spans if span.span_type == SpanType.LLM_CALL]
18
+ if not llm_spans:
19
+ return CheckResult(self.name, "skip", "无 LLM 调用记录")
20
+
21
+ degraded: list[TraceSpan] = []
22
+ for span in llm_spans:
23
+ degradation_meta = (span.metadata or {}).get("degradation")
24
+ if isinstance(degradation_meta, dict):
25
+ if bool(degradation_meta.get("detected")):
26
+ degraded.append(span)
27
+ elif degradation_meta is True:
28
+ degraded.append(span)
29
+ rate = len(degraded) / len(llm_spans)
30
+
31
+ if rate > _DEGRADATION_RATE_THRESHOLD:
32
+ tool_dist: dict[str, int] = {}
33
+ for span in degraded:
34
+ raw_tools = (span.metadata or {}).get("tool_names")
35
+ if isinstance(raw_tools, list) and raw_tools:
36
+ tool_name = str(raw_tools[0])
37
+ else:
38
+ tool_name = str((span.metadata or {}).get("tool_name", "unknown"))
39
+ tool_dist[tool_name] = tool_dist.get(tool_name, 0) + 1
40
+ return CheckResult(
41
+ self.name,
42
+ "fail",
43
+ f"tool_call 退化率 {rate:.0%} 超过阈值",
44
+ evidence={"degradation_rate": rate, "tool_distribution": tool_dist},
45
+ )
46
+
47
+ return CheckResult(self.name, "pass", "退化率正常")
48
+
49
+
50
+ __all__ = ["DegradationChecker"]
@@ -0,0 +1,42 @@
1
+ """ExitQualityChecker — 检查 session 退出质量。"""
2
+
3
+ from __future__ import annotations
4
+
5
+ from ...trace.models import TraceSession, TraceSpan
6
+ from .base import BaseChecker, CheckResult
7
+
8
+
9
+ class ExitQualityChecker(BaseChecker):
10
+ name = "exit_quality"
11
+ description = "检查 session 退出质量"
12
+
13
+ def check(self, session: TraceSession, spans: list[TraceSpan]) -> CheckResult:
14
+ del spans
15
+ reason = session.finish_reason
16
+
17
+ if reason == "error":
18
+ return CheckResult(
19
+ self.name,
20
+ "fail",
21
+ "session 以 error 退出",
22
+ evidence={"terminal_reason": session.terminal_reason},
23
+ )
24
+ if reason == "max_steps":
25
+ return CheckResult(
26
+ self.name,
27
+ "warn",
28
+ "session 触发 max_steps 退出,可能 loop 卡住",
29
+ evidence={"loop_count": session.loop_count},
30
+ )
31
+ if reason == "end_turn":
32
+ return CheckResult(self.name, "pass", "session 正常退出")
33
+
34
+ return CheckResult(
35
+ self.name,
36
+ "skip",
37
+ f"未知 finish_reason: {reason}",
38
+ evidence={"finish_reason": reason},
39
+ )
40
+
41
+
42
+ __all__ = ["ExitQualityChecker"]
@@ -0,0 +1,45 @@
1
+ """SessionMemoryTriggerChecker — 检查 session memory 是否在应触发时触发。"""
2
+
3
+ from __future__ import annotations
4
+
5
+ from ...trace.models import SpanStatus, SpanType, TraceSession, TraceSpan
6
+ from .base import BaseChecker, CheckResult
7
+
8
+ _FIRST_TRIGGER_TOKENS = 10_000
9
+
10
+
11
+ class SessionMemoryTriggerChecker(BaseChecker):
12
+ name = "session_memory_trigger"
13
+ description = "检查 session memory 是否在应触发时触发"
14
+
15
+ def check(self, session: TraceSession, spans: list[TraceSpan]) -> CheckResult:
16
+ if session.total_input_tokens < _FIRST_TRIGGER_TOKENS:
17
+ return CheckResult(self.name, "skip", "token 未达首次触发阈值")
18
+
19
+ memory_spans = [
20
+ span
21
+ for span in spans
22
+ if span.span_type == SpanType.TASK_EVENT and span.name == "session_memory_extraction"
23
+ ]
24
+
25
+ if not memory_spans:
26
+ return CheckResult(
27
+ self.name,
28
+ "fail",
29
+ "应触发 session memory 但无对应 span",
30
+ evidence={"total_input_tokens": session.total_input_tokens},
31
+ )
32
+
33
+ failed = [span for span in memory_spans if span.status == SpanStatus.FAILED]
34
+ if failed:
35
+ return CheckResult(
36
+ self.name,
37
+ "warn",
38
+ f"{len(failed)} 次 session memory 抽取失败",
39
+ evidence={"failed_spans": [span.span_id for span in failed]},
40
+ )
41
+
42
+ return CheckResult(self.name, "pass", "session memory 触发正常")
43
+
44
+
45
+ __all__ = ["SessionMemoryTriggerChecker"]
@@ -0,0 +1,53 @@
1
+ """ToolBehaviorChecker — 检查工具调用是否符合契约。"""
2
+
3
+ from __future__ import annotations
4
+
5
+ from collections import defaultdict
6
+
7
+ from ...trace.models import SpanStatus, SpanType, TraceSession, TraceSpan
8
+ from .base import BaseChecker, CheckResult
9
+
10
+ _FAIL_RATE_THRESHOLD = 0.3
11
+ _CONSECUTIVE_FAIL_THRESHOLD = 3
12
+
13
+
14
+ class ToolBehaviorChecker(BaseChecker):
15
+ name = "tool_behavior"
16
+ description = "检查工具调用失败率与连续失败"
17
+
18
+ def check(self, session: TraceSession, spans: list[TraceSpan]) -> CheckResult:
19
+ del session # 与统一签名保持一致,当前 checker 不依赖 session 聚合字段。
20
+ tool_spans = [span for span in spans if span.span_type == SpanType.TOOL_CALL]
21
+ if not tool_spans:
22
+ return CheckResult(self.name, "skip", "无工具调用")
23
+
24
+ failed = [span for span in tool_spans if span.status == SpanStatus.FAILED]
25
+ fail_rate = len(failed) / len(tool_spans)
26
+
27
+ if fail_rate > _FAIL_RATE_THRESHOLD:
28
+ return CheckResult(
29
+ self.name,
30
+ "fail",
31
+ f"工具调用失败率 {fail_rate:.0%} 超过阈值",
32
+ evidence={"fail_rate": fail_rate, "total": len(tool_spans), "failed": len(failed)},
33
+ )
34
+
35
+ consecutive: dict[str, int] = defaultdict(int)
36
+ for span in tool_spans:
37
+ tool_name = str((span.metadata or {}).get("tool_name", "unknown"))
38
+ if span.status == SpanStatus.FAILED:
39
+ consecutive[tool_name] += 1
40
+ if consecutive[tool_name] >= _CONSECUTIVE_FAIL_THRESHOLD:
41
+ return CheckResult(
42
+ self.name,
43
+ "fail",
44
+ f"工具 {tool_name} 连续失败 {consecutive[tool_name]} 次",
45
+ evidence={"tool_name": tool_name, "consecutive_fails": consecutive[tool_name]},
46
+ )
47
+ else:
48
+ consecutive[tool_name] = 0
49
+
50
+ return CheckResult(self.name, "pass", "工具调用行为正常")
51
+
52
+
53
+ __all__ = ["ToolBehaviorChecker"]
@@ -0,0 +1,67 @@
1
+ """
2
+ evaluation/retention_scheduler.py — 诊断存储清理调度器。
3
+
4
+ 职责:
5
+ 以固定周期执行 trace session 分层保留策略清理,避免数据库无限增长。
6
+
7
+ 链路位置:
8
+ FastAPI lifespan -> RetentionScheduler.start()。
9
+
10
+ 当前裁剪范围:
11
+ 仅清理 trace_sessions/trace_spans。SDK 已提供 ``EvaluationStore.cleanup_old_reports``(OB-D10),本模块 **仍不** 调用;诊断报告时间清理仅由显式 ``TraceCleanupTask(... cleanup_diagnostic_reports=True)`` 等路径触发。
12
+ """
13
+
14
+ from __future__ import annotations
15
+
16
+ import asyncio
17
+ import logging
18
+
19
+ from langchain_agentx.observability.trace.sqlite_store import SqliteTraceStore
20
+
21
+ logger = logging.getLogger(__name__)
22
+
23
+
24
+ class RetentionScheduler:
25
+ """按周期执行 session retention 清理任务。"""
26
+
27
+ def __init__(
28
+ self,
29
+ *,
30
+ trace_store: SqliteTraceStore,
31
+ interval_seconds: int = 24 * 3600,
32
+ failed_days: int = 180,
33
+ normal_days: int = 30,
34
+ ) -> None:
35
+ self._trace_store = trace_store
36
+ self._interval_seconds = int(interval_seconds)
37
+ self._failed_days = int(failed_days)
38
+ self._normal_days = int(normal_days)
39
+ self._task: asyncio.Task | None = None
40
+
41
+ def start(self) -> None:
42
+ if self._task is None or self._task.done():
43
+ self._task = asyncio.create_task(self._loop())
44
+
45
+ def stop(self) -> None:
46
+ if self._task is not None:
47
+ self._task.cancel()
48
+ self._task = None
49
+
50
+ async def _loop(self) -> None:
51
+ while True:
52
+ await asyncio.sleep(self._interval_seconds)
53
+ try:
54
+ deleted = self._trace_store.cleanup_sessions_by_retention(
55
+ failed_days=self._failed_days,
56
+ normal_days=self._normal_days,
57
+ )
58
+ logger.info(
59
+ "RetentionScheduler cleanup done deleted=%s failed_days=%s normal_days=%s",
60
+ deleted,
61
+ self._failed_days,
62
+ self._normal_days,
63
+ )
64
+ except asyncio.CancelledError:
65
+ raise
66
+ except Exception:
67
+ logger.exception("RetentionScheduler cleanup failed")
@@ -0,0 +1,102 @@
1
+ """
2
+ evaluation/service.py — EvaluationService,评估系统入口。
3
+
4
+ 职责:
5
+ 接收 session_end 信号,拉取 spans,逐个跑 Checker,并将结果写入 EvaluationStore。
6
+
7
+ 链路位置:
8
+ 由 after_session_end hook 触发(fire-and-forget),不阻塞主 Loop。
9
+
10
+ 当前裁剪范围:
11
+ LlmDiagnosticAnalyzer 仅保留触发位,暂不实现诊断正文生成。
12
+ """
13
+
14
+ from __future__ import annotations
15
+
16
+ import logging
17
+
18
+ from ..trace.collector import TraceCollector
19
+ from .checkers.base import BaseChecker, CheckResult
20
+ from .checkers.compaction import CompactionChecker
21
+ from .checkers.degradation import DegradationChecker
22
+ from .checkers.exit_quality import ExitQualityChecker
23
+ from .checkers.session_memory import SessionMemoryTriggerChecker
24
+ from .checkers.tool_behavior import ToolBehaviorChecker
25
+ from .store import EvaluationStore
26
+
27
+ logger = logging.getLogger(__name__)
28
+
29
+ _DEFAULT_CHECKERS: list[BaseChecker] = [
30
+ SessionMemoryTriggerChecker(),
31
+ CompactionChecker(),
32
+ ToolBehaviorChecker(),
33
+ ExitQualityChecker(),
34
+ DegradationChecker(),
35
+ ]
36
+
37
+
38
+ class EvaluationService:
39
+ """评估系统入口。评估失败需静默降级,不影响主 Loop。"""
40
+
41
+ def __init__(
42
+ self,
43
+ store: EvaluationStore,
44
+ trace_collector: TraceCollector,
45
+ checkers: list[BaseChecker] | None = None,
46
+ scheduler: object | None = None,
47
+ ) -> None:
48
+ self._store = store
49
+ self._collector = trace_collector
50
+ self._checkers = checkers if checkers is not None else list(_DEFAULT_CHECKERS)
51
+ self._scheduler = scheduler
52
+
53
+ async def on_session_end(self, session_id: str) -> None:
54
+ """after_session_end hook 回调入口。"""
55
+ try:
56
+ await self._evaluate(session_id)
57
+ except Exception:
58
+ logger.exception("EvaluationService: session %s 评估失败,静默降级", session_id)
59
+
60
+ async def _evaluate(self, session_id: str) -> None:
61
+ # flush() 在 on_session_end 触发前已清除内存 buffer,
62
+ # 改为通过 get_session/get_span_tree 读取(先查内存,再查 SQLite)。
63
+ session = self._collector.get_session(session_id)
64
+ if session is None:
65
+ logger.debug("EvaluationService: session %s 无 trace 数据,跳过", session_id)
66
+ return
67
+
68
+ spans = self._collector.get_span_tree(session_id)
69
+ results: list[CheckResult] = []
70
+ for checker in self._checkers:
71
+ try:
72
+ results.append(checker.check(session, spans))
73
+ except Exception:
74
+ logger.exception("Checker %s 执行异常,跳过", checker.name)
75
+
76
+ if session.status == "interrupted":
77
+ results.append(
78
+ CheckResult(
79
+ checker_name="session_interrupted",
80
+ status="fail",
81
+ message=f"Session 异常中断:{session.terminal_reason or 'unknown'}",
82
+ evidence={
83
+ "status": session.status,
84
+ "terminal_reason": session.terminal_reason,
85
+ },
86
+ )
87
+ )
88
+
89
+ self._store.save_results(session_id, results)
90
+ fails = [result for result in results if result.status == "fail"]
91
+ if fails:
92
+ logger.debug(
93
+ "EvaluationService: session %s 有 %d 个 fail,待 LlmDiagnosticAnalyzer 分析",
94
+ session_id,
95
+ len(fails),
96
+ )
97
+ enqueue = getattr(self._scheduler, "enqueue_priority", None)
98
+ if callable(enqueue):
99
+ enqueue(session_id)
100
+
101
+
102
+ __all__ = ["EvaluationService"]
@@ -0,0 +1,32 @@
1
+ """
2
+ evaluation/state.py — 诊断分析共享状态。
3
+
4
+ 职责:
5
+ 维护正在分析的 session 集合,协调“手动触发”和“后台轮询”避免重复分析。
6
+ """
7
+
8
+ from __future__ import annotations
9
+
10
+ import asyncio
11
+
12
+
13
+ class AnalysisState:
14
+ """手动触发与后台调度共享的分析互斥状态。"""
15
+
16
+ def __init__(self) -> None:
17
+ self._in_progress: set[str] = set()
18
+ self._lock = asyncio.Lock()
19
+
20
+ async def try_acquire(self, session_id: str) -> bool:
21
+ async with self._lock:
22
+ if session_id in self._in_progress:
23
+ return False
24
+ self._in_progress.add(session_id)
25
+ return True
26
+
27
+ async def release(self, session_id: str) -> None:
28
+ async with self._lock:
29
+ self._in_progress.discard(session_id)
30
+
31
+ def is_in_progress(self, session_id: str) -> bool:
32
+ return session_id in self._in_progress