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,15 @@
1
+ """可观测性 logging 子域:配置、上下文契约、Debug Burst。"""
2
+
3
+ from .debug_burst import DebugBurstController, DebugBurstSession
4
+ from .logging_config import LoggingConfigBuilder, configure_logging_once
5
+ from .logging_contract import LogContext, ObservabilityLoggerAdapter, build_log_context
6
+
7
+ __all__ = [
8
+ "DebugBurstController",
9
+ "DebugBurstSession",
10
+ "LogContext",
11
+ "LoggingConfigBuilder",
12
+ "ObservabilityLoggerAdapter",
13
+ "build_log_context",
14
+ "configure_logging_once",
15
+ ]
@@ -0,0 +1,95 @@
1
+ """
2
+ observability/logging/debug_burst.py — 会话级调试放大控制器
3
+
4
+ 职责:
5
+ 提供 Debug Burst 的短时启停能力:临时提高日志详细度、挂载专用诊断 handler,
6
+ 到期后自动回落,避免长期日志噪音。
7
+ """
8
+
9
+ from __future__ import annotations
10
+
11
+ import logging
12
+ import time
13
+ from dataclasses import dataclass
14
+ from pathlib import Path
15
+
16
+ from .logging_config import LoggingDirectoryResolver
17
+
18
+
19
+ @dataclass
20
+ class DebugBurstSession:
21
+ started_at_ts: float
22
+ ttl_sec: float
23
+ level: int
24
+ scope: str
25
+ session_id: str | None = None
26
+ handler: logging.Handler | None = None
27
+
28
+ def is_active(self) -> bool:
29
+ return (time.time() - self.started_at_ts) <= self.ttl_sec
30
+
31
+
32
+ class DebugBurstController:
33
+ """Debug Burst 运行期控制器。"""
34
+
35
+ def __init__(
36
+ self,
37
+ *,
38
+ logger_name: str = "langchain_agentx",
39
+ directory_resolver: LoggingDirectoryResolver | None = None,
40
+ ) -> None:
41
+ self._logger = logging.getLogger(logger_name)
42
+ self._resolver = directory_resolver or LoggingDirectoryResolver()
43
+ self._session: DebugBurstSession | None = None
44
+ self._original_level: int | None = None
45
+
46
+ def start(
47
+ self,
48
+ *,
49
+ workspace_root: str | Path | None = None,
50
+ ttl_sec: float = 120.0,
51
+ level: int = logging.DEBUG,
52
+ scope: str = "session",
53
+ session_id: str | None = None,
54
+ ) -> DebugBurstSession:
55
+ self.stop()
56
+ layout = self._resolver.resolve(workspace_root=workspace_root)
57
+ layout.diagnostics_dir.mkdir(parents=True, exist_ok=True)
58
+ burst_file = layout.diagnostics_dir / "debug-burst.log"
59
+ handler = logging.FileHandler(burst_file, encoding="utf-8")
60
+ handler.setLevel(level)
61
+ handler.setFormatter(
62
+ logging.Formatter(
63
+ "%(asctime)s %(levelname)s %(name)s run_id=%(run_id)s session_id=%(session_id)s "
64
+ "task_id=%(task_id)s tool_call_id=%(tool_call_id)s agent_id=%(agent_id)s %(message)s"
65
+ )
66
+ )
67
+ self._logger.addHandler(handler)
68
+ self._original_level = self._logger.level
69
+ self._logger.setLevel(min(self._logger.level or level, level))
70
+ self._session = DebugBurstSession(
71
+ started_at_ts=time.time(),
72
+ ttl_sec=ttl_sec,
73
+ level=level,
74
+ scope=scope,
75
+ session_id=session_id,
76
+ handler=handler,
77
+ )
78
+ return self._session
79
+
80
+ def stop(self) -> None:
81
+ if self._session is None:
82
+ return
83
+ if self._session.handler is not None:
84
+ self._logger.removeHandler(self._session.handler)
85
+ self._session.handler.close()
86
+ if self._original_level is not None:
87
+ self._logger.setLevel(self._original_level)
88
+ self._session = None
89
+ self._original_level = None
90
+
91
+ def tick(self) -> None:
92
+ if self._session is None:
93
+ return
94
+ if not self._session.is_active():
95
+ self.stop()
@@ -0,0 +1,178 @@
1
+ """
2
+ observability/logging/logging_config.py — Python logging 配置构建协作者
3
+
4
+ 职责:
5
+ 提供 dictConfig 构建与应用入口,统一日志目录、级别、formatter、handler。
6
+ 默认目录:<workspace_root>/workspace(可由 AGENTX_LOG_ROOT 覆盖)。
7
+
8
+ 在整体链路中的位置:
9
+ 进程启动或测试入口
10
+ -> LoggingConfigBuilder.build_dict_config()
11
+ -> logging.config.dictConfig(...)
12
+ """
13
+
14
+ from __future__ import annotations
15
+
16
+ import logging
17
+ import logging.config
18
+ import os
19
+ from dataclasses import dataclass
20
+ from pathlib import Path
21
+ from typing import Any
22
+
23
+ from langchain_agentx.workspace import resolve_agent_workspace_config
24
+
25
+
26
+ ENV_LOG_ROOT = "AGENTX_LOG_ROOT"
27
+ ENV_LOG_LEVEL = "AGENTX_LOG_LEVEL"
28
+ ENV_LOG_JSON = "AGENTX_LOG_JSON"
29
+
30
+
31
+ class _ContextDefaultsFilter(logging.Filter):
32
+ def filter(self, record: logging.LogRecord) -> bool:
33
+ for key in ("run_id", "session_id", "task_id", "tool_call_id", "agent_id"):
34
+ if not hasattr(record, key):
35
+ setattr(record, key, "-")
36
+ return True
37
+
38
+
39
+ @dataclass(frozen=True)
40
+ class LoggingDirectoryLayout:
41
+ workspace_root: Path
42
+ log_root: Path
43
+ runtime_dir: Path
44
+ diagnostics_dir: Path
45
+
46
+
47
+ class LoggingDirectoryResolver:
48
+ """日志目录解析器。"""
49
+
50
+ def resolve(
51
+ self,
52
+ *,
53
+ workspace_root: str | Path | None = None,
54
+ log_root: str | Path | None = None,
55
+ ) -> LoggingDirectoryLayout:
56
+ workspace_cfg = resolve_agent_workspace_config(workspace_root=workspace_root)
57
+ ws_root = workspace_cfg.workspace_root
58
+ root = Path(log_root or os.getenv(ENV_LOG_ROOT) or (ws_root / "workspace"))
59
+ resolved_root = root.expanduser().resolve()
60
+ return LoggingDirectoryLayout(
61
+ workspace_root=ws_root,
62
+ log_root=resolved_root,
63
+ runtime_dir=resolved_root / "runtime",
64
+ diagnostics_dir=resolved_root / "diagnostics",
65
+ )
66
+
67
+
68
+ class LoggingConfigBuilder:
69
+ """logging dictConfig 构建器。"""
70
+
71
+ def __init__(
72
+ self,
73
+ *,
74
+ directory_resolver: LoggingDirectoryResolver | None = None,
75
+ ) -> None:
76
+ self._resolver = directory_resolver or LoggingDirectoryResolver()
77
+
78
+ def build_dict_config(
79
+ self,
80
+ *,
81
+ workspace_root: str | Path | None = None,
82
+ log_root: str | Path | None = None,
83
+ level: str | None = None,
84
+ ) -> dict[str, Any]:
85
+ layout = self._resolver.resolve(workspace_root=workspace_root, log_root=log_root)
86
+ layout.runtime_dir.mkdir(parents=True, exist_ok=True)
87
+ layout.diagnostics_dir.mkdir(parents=True, exist_ok=True)
88
+
89
+ resolved_level = (level or os.getenv(ENV_LOG_LEVEL, "INFO")).upper()
90
+ use_json = os.getenv(ENV_LOG_JSON, "0") == "1"
91
+ formatter = (
92
+ "%(message)s"
93
+ if use_json
94
+ else (
95
+ "%(asctime)s %(levelname)s %(name)s "
96
+ "run_id=%(run_id)s session_id=%(session_id)s task_id=%(task_id)s "
97
+ "tool_call_id=%(tool_call_id)s agent_id=%(agent_id)s %(message)s"
98
+ )
99
+ )
100
+ return {
101
+ "version": 1,
102
+ "disable_existing_loggers": False,
103
+ "filters": {
104
+ "context_defaults": {
105
+ "()": _ContextDefaultsFilter,
106
+ }
107
+ },
108
+ "formatters": {
109
+ "standard": {
110
+ "format": formatter,
111
+ }
112
+ },
113
+ "handlers": {
114
+ "console": {
115
+ "class": "logging.StreamHandler",
116
+ "level": resolved_level,
117
+ "formatter": "standard",
118
+ "filters": ["context_defaults"],
119
+ },
120
+ "runtime_file": {
121
+ "class": "logging.handlers.TimedRotatingFileHandler",
122
+ "filename": str(layout.runtime_dir / "app.log"),
123
+ "when": "D",
124
+ "interval": 1,
125
+ "backupCount": 7,
126
+ "encoding": "utf-8",
127
+ "level": resolved_level,
128
+ "formatter": "standard",
129
+ "filters": ["context_defaults"],
130
+ },
131
+ "error_file": {
132
+ "class": "logging.handlers.TimedRotatingFileHandler",
133
+ "filename": str(layout.runtime_dir / "error.log"),
134
+ "when": "D",
135
+ "interval": 1,
136
+ "backupCount": 14,
137
+ "encoding": "utf-8",
138
+ "level": "ERROR",
139
+ "formatter": "standard",
140
+ "filters": ["context_defaults"],
141
+ },
142
+ },
143
+ "root": {
144
+ "handlers": ["console", "runtime_file", "error_file"],
145
+ "level": resolved_level,
146
+ },
147
+ }
148
+
149
+ def apply(
150
+ self,
151
+ *,
152
+ workspace_root: str | Path | None = None,
153
+ log_root: str | Path | None = None,
154
+ level: str | None = None,
155
+ ) -> None:
156
+ logging.config.dictConfig(
157
+ self.build_dict_config(
158
+ workspace_root=workspace_root,
159
+ log_root=log_root,
160
+ level=level,
161
+ )
162
+ )
163
+
164
+
165
+ _CONFIGURED = False
166
+
167
+
168
+ def configure_logging_once(
169
+ *,
170
+ workspace_root: str | Path | None = None,
171
+ log_root: str | Path | None = None,
172
+ level: str | None = None,
173
+ ) -> None:
174
+ global _CONFIGURED
175
+ if _CONFIGURED:
176
+ return
177
+ LoggingConfigBuilder().apply(workspace_root=workspace_root, log_root=log_root, level=level)
178
+ _CONFIGURED = True
@@ -0,0 +1,65 @@
1
+ """
2
+ observability/logging/logging_contract.py — 日志上下文字段契约协作者
3
+
4
+ 职责:
5
+ 提供统一日志上下文构建与 logger 适配器,确保 run/session/task/tool_call
6
+ 等关联字段在日志层可用,便于与 trace/replay 互相定位。
7
+
8
+ 在整体链路中的位置:
9
+ 业务入口(loop/task_runtime/tools)
10
+ -> build_log_context(...)
11
+ -> ObservabilityLoggerAdapter(logger, context)
12
+ -> logger.info/warning/error(...)
13
+ """
14
+
15
+ from __future__ import annotations
16
+
17
+ import logging
18
+ from dataclasses import dataclass
19
+ from typing import Any
20
+
21
+
22
+ @dataclass(frozen=True)
23
+ class LogContext:
24
+ run_id: str = "-"
25
+ session_id: str = "-"
26
+ task_id: str = "-"
27
+ tool_call_id: str = "-"
28
+ agent_id: str = "-"
29
+
30
+ def as_extra(self) -> dict[str, str]:
31
+ return {
32
+ "run_id": self.run_id,
33
+ "session_id": self.session_id,
34
+ "task_id": self.task_id,
35
+ "tool_call_id": self.tool_call_id,
36
+ "agent_id": self.agent_id,
37
+ }
38
+
39
+
40
+ def build_log_context(
41
+ *,
42
+ run_id: str | None = None,
43
+ session_id: str | None = None,
44
+ task_id: str | None = None,
45
+ tool_call_id: str | None = None,
46
+ agent_id: str | None = None,
47
+ ) -> LogContext:
48
+ return LogContext(
49
+ run_id=run_id or "-",
50
+ session_id=session_id or "-",
51
+ task_id=task_id or "-",
52
+ tool_call_id=tool_call_id or "-",
53
+ agent_id=agent_id or "-",
54
+ )
55
+
56
+
57
+ class ObservabilityLoggerAdapter(logging.LoggerAdapter):
58
+ """在日志记录中注入统一上下文字段。"""
59
+
60
+ def process(self, msg: str, kwargs: dict[str, Any]) -> tuple[str, dict[str, Any]]:
61
+ kwargs.setdefault("extra", {})
62
+ merged = dict(self.extra or {})
63
+ merged.update(kwargs["extra"])
64
+ kwargs["extra"] = merged
65
+ return msg, kwargs
@@ -0,0 +1,35 @@
1
+ """
2
+ Replay:trace 存储、查询 façade、CLI、UI 投影。
3
+ """
4
+
5
+ from .service import (
6
+ export_call_chain,
7
+ list_replayable_tool_calls,
8
+ query_replays,
9
+ replay_tool_call,
10
+ tail_tool_call_events,
11
+ visualize_call_chain_mermaid,
12
+ )
13
+ from .store import (
14
+ DECISION_LAYERS,
15
+ OBS_SCHEMA_VERSION,
16
+ REASON_CODES,
17
+ get_global_trace_store,
18
+ sample_events,
19
+ sanitize_value,
20
+ )
21
+
22
+ __all__ = [
23
+ "DECISION_LAYERS",
24
+ "OBS_SCHEMA_VERSION",
25
+ "REASON_CODES",
26
+ "export_call_chain",
27
+ "get_global_trace_store",
28
+ "list_replayable_tool_calls",
29
+ "query_replays",
30
+ "replay_tool_call",
31
+ "sample_events",
32
+ "sanitize_value",
33
+ "tail_tool_call_events",
34
+ "visualize_call_chain_mermaid",
35
+ ]
@@ -0,0 +1,91 @@
1
+ """
2
+ runtime/observability_cli.py — 可观测性 CLI 适配入口
3
+
4
+ 职责:
5
+ 为命令行场景提供统一回放/查询接口,作为 runtime replay 服务的
6
+ 交互层适配器,支持 list/replay/query 等子命令。
7
+
8
+ OOP 边界:
9
+ - CLI 仅负责参数解析与输出渲染;
10
+ - 业务逻辑委托 `runtime/replay.py`;
11
+ - 不直接操作存储层(JSONL/gzip)。
12
+
13
+ 与 CC 对比:
14
+ 对齐 CC 在交互排障中的“可查询、可导出、可回放”路径,
15
+ 以标准命令形式提供给运维与开发流程。
16
+ """
17
+
18
+ from __future__ import annotations
19
+
20
+ import argparse
21
+ import logging
22
+ from pprint import pprint
23
+
24
+ from .service import (
25
+ export_call_chain,
26
+ list_replayable_tool_calls,
27
+ query_replays,
28
+ visualize_call_chain_mermaid,
29
+ )
30
+ from ..logging import ObservabilityLoggerAdapter, build_log_context
31
+
32
+ logger = logging.getLogger(__name__)
33
+
34
+
35
+ def main() -> None:
36
+ parser = argparse.ArgumentParser(description="AgentX observability CLI")
37
+ sub = parser.add_subparsers(dest="cmd", required=True)
38
+
39
+ sub.add_parser("list")
40
+
41
+ replay_p = sub.add_parser("replay")
42
+ replay_p.add_argument("--tool-call-id", required=True)
43
+ replay_p.add_argument("--mermaid", action="store_true")
44
+
45
+ query_p = sub.add_parser("query")
46
+ query_p.add_argument("--tool-name")
47
+ query_p.add_argument("--status")
48
+ query_p.add_argument("--start-ts", type=int)
49
+ query_p.add_argument("--end-ts", type=int)
50
+ query_p.add_argument("--limit", type=int, default=50)
51
+
52
+ args = parser.parse_args()
53
+ log = ObservabilityLoggerAdapter(logger, build_log_context().as_extra())
54
+ log.info("replay cli command=%s", args.cmd)
55
+ if args.cmd == "list":
56
+ rows = list_replayable_tool_calls()
57
+ log.info("replay cli list rows=%s", len(rows))
58
+ pprint(rows)
59
+ return
60
+ if args.cmd == "replay":
61
+ replay_log = ObservabilityLoggerAdapter(
62
+ logger,
63
+ build_log_context(tool_call_id=args.tool_call_id).as_extra(),
64
+ )
65
+ if args.mermaid:
66
+ replay_log.info("replay cli export mermaid")
67
+ print(visualize_call_chain_mermaid(args.tool_call_id))
68
+ else:
69
+ replay_log.info("replay cli export call chain")
70
+ pprint(export_call_chain(args.tool_call_id))
71
+ return
72
+ if args.cmd == "query":
73
+ rows = query_replays(
74
+ tool_name=args.tool_name,
75
+ status=args.status,
76
+ start_ts=args.start_ts,
77
+ end_ts=args.end_ts,
78
+ limit=args.limit,
79
+ )
80
+ log.info(
81
+ "replay cli query rows=%s tool_name=%s status=%s",
82
+ len(rows),
83
+ args.tool_name or "-",
84
+ args.status or "-",
85
+ )
86
+ pprint(rows)
87
+
88
+
89
+ if __name__ == "__main__":
90
+ main()
91
+
@@ -0,0 +1,83 @@
1
+ """
2
+ runtime/replay.py — 运行时观测回放服务接口
3
+
4
+ 职责:
5
+ 提供基于 `tool_call_id` 的回放能力,对外暴露:
6
+ - 单次调用链查询
7
+ - 可回放列表
8
+ - 增量事件 tail(实时轮询)
9
+ - 条件过滤查询
10
+ - 导出与可视化(mermaid)
11
+
12
+ OOP 边界:
13
+ 该模块是 `ObservabilityTraceStore` 的 façade 层,
14
+ 统一封装调用入口,避免业务侧直接依赖底层存储实现。
15
+
16
+ 与 CC 对比:
17
+ 对齐 CC “问题复盘/归因追踪”的使用方式,先提供稳定 API,
18
+ 再逐步演进为更强的可视化与外部系统集成。
19
+ """
20
+
21
+ from __future__ import annotations
22
+
23
+ from typing import Any
24
+
25
+ from .store import get_global_trace_store
26
+
27
+
28
+ def replay_tool_call(tool_call_id: str) -> dict[str, Any] | None:
29
+ """按 tool_call_id 获取最近一次观测记录。"""
30
+ return get_global_trace_store().get(tool_call_id)
31
+
32
+
33
+ def list_replayable_tool_calls() -> list[str]:
34
+ """列出可回放的 tool_call_id。"""
35
+ return get_global_trace_store().all_keys()
36
+
37
+
38
+ def tail_tool_call_events(tool_call_id: str, offset: int = 0) -> tuple[list[dict[str, Any]], int]:
39
+ """
40
+ 获取事件增量(用于 UI/CLI 轮询实时展示)。
41
+ 返回 (events, next_offset)。
42
+ """
43
+ return get_global_trace_store().tail_events(tool_call_id, offset=offset)
44
+
45
+
46
+ def query_replays(
47
+ *,
48
+ tool_name: str | None = None,
49
+ status: str | None = None,
50
+ start_ts: int | None = None,
51
+ end_ts: int | None = None,
52
+ limit: int = 200,
53
+ ) -> list[dict[str, Any]]:
54
+ """按条件查询回放记录。"""
55
+ return get_global_trace_store().query(
56
+ tool_name=tool_name,
57
+ status=status,
58
+ start_ts=start_ts,
59
+ end_ts=end_ts,
60
+ limit=limit,
61
+ )
62
+
63
+
64
+ def export_call_chain(tool_call_id: str) -> dict[str, Any] | None:
65
+ """一键导出完整调用链(decision_trace + observability events)。"""
66
+ return replay_tool_call(tool_call_id)
67
+
68
+
69
+ def visualize_call_chain_mermaid(tool_call_id: str) -> str:
70
+ """将调用链导出为简易 mermaid 时序图文本。"""
71
+ record = replay_tool_call(tool_call_id)
72
+ if not record:
73
+ return "sequenceDiagram\n participant U as User\n participant T as Tool\n U->>T: no replay record"
74
+ lines = ["sequenceDiagram", " participant U as User", " participant T as Tool"]
75
+ for step in record.get("decision_trace", []):
76
+ lines.append(
77
+ f" U->>T: decision {step.get('layer')} / {step.get('behavior')} / {step.get('policy_id')}"
78
+ )
79
+ events = (((record.get("observability") or {}).get("events")) or [])
80
+ for ev in events:
81
+ lines.append(f" T-->>U: {ev.get('event')}")
82
+ return "\n".join(lines)
83
+