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,85 @@
1
+ """
2
+ tools/agent/models.py — AgentRuntimeTool 输入输出模型
3
+
4
+ 职责:定义 Agent 工具对模型暴露的输入/输出 schema,不承载执行逻辑。
5
+ 在整体链路中的位置:ToolExecutorPipeline 的 schema 校验层;invoke() 与 present() 的数据契约。
6
+ CC 对照:src/tools/AgentTool/AgentTool.tsx 的 inputSchema / outputSchema(Zod)。
7
+ 当前裁剪范围:v1 实现同步输出与异步输出模型;异步执行链路留给 v2。
8
+ """
9
+
10
+ from __future__ import annotations
11
+
12
+ from typing import Any, Literal
13
+
14
+ from pydantic import BaseModel, Field
15
+
16
+
17
+ class AgentToolInput(BaseModel):
18
+ """Agent 工具输入参数。"""
19
+
20
+ prompt: str = Field(..., description="The task for the agent to perform")
21
+ description: str = Field(
22
+ ...,
23
+ description="A short (3-5 word) description of the task",
24
+ )
25
+ subagent_type: str | None = Field(
26
+ default=None,
27
+ description=(
28
+ "The type of specialized agent to use for this task. "
29
+ "If omitted, defaults to 'general-purpose'."
30
+ ),
31
+ )
32
+ model: Any | None = Field(
33
+ default=None,
34
+ description="Optional model override for the subagent.",
35
+ )
36
+ run_in_background: bool = Field(
37
+ default=False,
38
+ description="If true, run subagent in background mode.",
39
+ )
40
+ isolation: Literal["none", "worktree"] = Field(
41
+ default="none",
42
+ description=(
43
+ 'Execution isolation mode for subagent. When "worktree", a temporary '
44
+ "directory is created; if `cwd` is also set, the effective process cwd "
45
+ "uses `cwd` first (CC: cwd ?? worktreePath)."
46
+ ),
47
+ )
48
+ cwd: str | None = Field(
49
+ default=None,
50
+ description=(
51
+ "Optional working directory override for subagent. "
52
+ "Relative paths are resolved against workspace_root; "
53
+ "validate_input normalizes to an absolute path when workspace_root is set."
54
+ ),
55
+ )
56
+ fork_from_parent: bool = Field(
57
+ default=False,
58
+ description="If true, inherit parent message history when creating subagent context.",
59
+ )
60
+
61
+
62
+ class AgentToolOutput(BaseModel):
63
+ """同步执行输出。"""
64
+
65
+ status: Literal["completed", "error", "interrupted", "async_launched"]
66
+ content: str = ""
67
+ agent_id: str = ""
68
+ total_steps: int = 0
69
+ terminal_reason: str | None = None
70
+ error_message: str | None = None
71
+ task_id: str | None = None
72
+ output_file: str | None = None
73
+ child_run_id: str | None = None # 子会话 trace session_id
74
+
75
+
76
+ class AgentToolAsyncOutput(BaseModel):
77
+ """异步执行输出(v2 预留)。"""
78
+
79
+ status: Literal["async_launched"]
80
+ agent_id: str
81
+ task_id: str
82
+ output_file: str
83
+ description: str
84
+ prompt: str
85
+ can_read_output_file: bool = True
@@ -0,0 +1,120 @@
1
+ """
2
+ tools/agent/prompt.py — Agent 工具描述生成
3
+
4
+ 职责:按当前可用 subagent 类型动态生成给模型看的工具描述。
5
+ 在整体链路中的位置:AgentRuntimeTool.description 属性调用 get_prompt()。
6
+ CC 对照:src/tools/AgentTool/prompt.ts 的 getPrompt()/formatAgentLine()。
7
+ 当前裁剪范围:v3 对齐 CC 主提示词核心段落,并按本工程能力做最小差异收敛。
8
+ """
9
+
10
+ from __future__ import annotations
11
+
12
+ from typing import TYPE_CHECKING
13
+
14
+ if TYPE_CHECKING:
15
+ from .registry.config import SubagentConfig
16
+
17
+ TOOL_NAME = "Agent"
18
+ LEGACY_TOOL_NAME = "agent"
19
+
20
+
21
+ def format_agent_line(config: "SubagentConfig") -> str:
22
+ """格式化单个 subagent 条目。CC 对照:formatAgentLine(),含 whenToUse 字段。"""
23
+ when_to_use = config.when_to_use or config.description
24
+ return f"- {config.name}: {when_to_use} (Tools: {config.tools_description})"
25
+
26
+
27
+ def get_prompt(available_agents: list["SubagentConfig"]) -> str:
28
+ """生成 Agent 工具完整描述。"""
29
+ agent_lines = "\n".join(format_agent_line(cfg) for cfg in available_agents) or "- None"
30
+ return (
31
+ "Launch a new agent to handle complex, multi-step tasks autonomously.\n\n"
32
+ "The Agent tool launches specialized agents that can handle focused work.\n"
33
+ "Each subagent type has different strengths and tool access.\n\n"
34
+ "Available agent types and their tools:\n"
35
+ f"{agent_lines}\n\n"
36
+ "When using Agent, pass subagent_type to select a specialist.\n"
37
+ "If subagent_type is omitted, general-purpose is used.\n\n"
38
+ "When NOT to use Agent:\n"
39
+ "- If you need to read one known file, call Read directly.\n"
40
+ "- If you only need 1-2 quick searches in nearby files, use Glob/Grep directly.\n"
41
+ "- If the task is a single-step edit you can do immediately, do it directly.\n\n"
42
+ "Usage notes:\n"
43
+ "- Always include a short description (3-5 words).\n"
44
+ "- The subagent result is not automatically shown to the user; summarize it yourself.\n"
45
+ "- If user asks for parallel subagents, emit multiple Agent tool calls in one message.\n"
46
+ "- Use run_in_background=true only for genuinely independent work.\n"
47
+ "- For foreground runs, wait for the subagent result before continuing.\n"
48
+ "- You can set isolation='worktree' to run in a temporary git worktree.\n"
49
+ "- You can set fork_from_parent=true to inherit parent context (fork style).\n"
50
+ "- If cwd is provided, it must point to a safe workspace path.\n"
51
+ "- Do not invent background subagent results before completion notifications arrive.\n\n"
52
+ "Prompt writing guidance:\n"
53
+ "- Brief the subagent like a new teammate: goal, context, constraints, and done criteria.\n"
54
+ "- For research tasks, provide the question and scope, not rigid step scripts.\n"
55
+ "- For implementation tasks, include concrete files/symbols and expected changes.\n"
56
+ )
57
+
58
+
59
+ DESCRIPTION = get_prompt([])
60
+
61
+ # CC 对照:EXPLORE_AGENT_MIN_QUERIES(exploreAgent.ts)
62
+ _EXPLORE_MIN_QUERIES = 3
63
+ _DEFAULT_SEARCH_TOOLS = "Glob, Grep, and Bash"
64
+
65
+
66
+ def build_agent_guidance_section(
67
+ available_tools: list,
68
+ search_tools: str = _DEFAULT_SEARCH_TOOLS,
69
+ ) -> str | None:
70
+ """生成主 system prompt 中的 Agent 使用引导段落。
71
+
72
+ CC 对照:prompts.ts 第 374-380 行的条件性注入。
73
+ 完全 registry 驱动:只有已注册的 agent 才会出现在引导中。
74
+ - 若 Explore 已注册,追加 Explore 专项引导(CC 原文)。
75
+ - 若其他 agent 有 when_to_use,追加通用 agent 选择引导。
76
+ 返回 None 表示 Agent 工具不存在或无任何 when_to_use 可注入。
77
+ """
78
+ agent_tool = next(
79
+ (t for t in available_tools if getattr(t, "name", "") in (TOOL_NAME, LEGACY_TOOL_NAME)),
80
+ None,
81
+ )
82
+ if agent_tool is None:
83
+ return None
84
+ registry = getattr(agent_tool, "_registry", None)
85
+ if registry is None:
86
+ return None
87
+
88
+ registered = registry.list_all()
89
+ registered_names = {cfg.name for cfg in registered}
90
+ agents_with_guidance = [cfg for cfg in registered if cfg.when_to_use]
91
+
92
+ if not agents_with_guidance:
93
+ return None
94
+
95
+ parts: list[str] = []
96
+
97
+ # Explore 专项引导(CC 原文对照)
98
+ if "Explore" in registered_names:
99
+ parts.append(
100
+ f"For simple, directed codebase searches (e.g. for a specific file/class/function) "
101
+ f"use {search_tools} directly.\n"
102
+ f"For broader codebase exploration and deep research, use the {TOOL_NAME} tool with "
103
+ f"subagent_type=Explore. This is slower than using {search_tools} directly, so use "
104
+ f"this only when a simple, directed search proves to be insufficient or when your task "
105
+ f"will clearly require more than {_EXPLORE_MIN_QUERIES} queries."
106
+ )
107
+
108
+ # 其余有 when_to_use 的 agent(排除 Explore,已单独处理)
109
+ others = [cfg for cfg in agents_with_guidance if cfg.name != "Explore"]
110
+ if others:
111
+ lines = "\n".join(f"- {cfg.name}: {cfg.when_to_use}" for cfg in others)
112
+ parts.append(
113
+ f"When delegating to a specialized agent, choose based on the task:\n{lines}"
114
+ )
115
+
116
+ return "\n\n".join(parts) if parts else None
117
+
118
+
119
+ # 向后兼容别名
120
+ build_explore_plan_guidance = build_agent_guidance_section
@@ -0,0 +1,18 @@
1
+ """
2
+ tools/agent/registry — 能力原语注册表
3
+
4
+ 职责:导出 SubagentConfig / SubagentRegistry,供工具层使用。
5
+ 在整体链路中的位置:built_in/*.py 构造配置 → registry 管理 → tool.py 消费。
6
+ CC 对照:src/tools/AgentTool/builtInAgents.ts 的内置类型集合(扩展为可变注册表)。
7
+ 当前裁剪范围:v1 仅导出能力原语相关类型;SubagentComposition/presets 属于编排层,不在此导出。
8
+ """
9
+
10
+ from .config import SubagentConfig
11
+ from .registry import SubagentRegistry, get_global_registry
12
+
13
+ __all__ = [
14
+ "SubagentConfig",
15
+ "SubagentRegistry",
16
+ "get_global_registry",
17
+ ]
18
+
@@ -0,0 +1,29 @@
1
+ """
2
+ tools/agent/registry/config.py — SubagentConfig 数据结构
3
+
4
+ 职责:描述单个 subagent 类型的稳定配置,不承载注册与组合逻辑。
5
+ 在整体链路中的位置:built_in/*.py 构造配置 → registry/composition/tool 消费。
6
+ CC 对照:src/tools/AgentTool/loadAgentsDir.ts 的 AgentDefinition(简化版)。
7
+ 当前裁剪范围:v1 仅支持内置类型配置与工具过滤策略注入。
8
+ """
9
+
10
+ from __future__ import annotations
11
+
12
+ from dataclasses import dataclass, field
13
+ from typing import Callable
14
+
15
+
16
+ @dataclass
17
+ class SubagentConfig:
18
+ """单个 subagent 类型完整描述。"""
19
+
20
+ name: str
21
+ description: str
22
+ system_prompt_factory: Callable[[], str]
23
+ tool_filter: Callable[[list], list] | None = None
24
+ tools_description: str = "All tools"
25
+ default_max_steps: int | None = None
26
+ default_model: str | None = None
27
+ allow_async: bool = True
28
+ tags: set[str] = field(default_factory=set)
29
+ when_to_use: str | None = None # CC 对照:BuiltInAgentDefinition.whenToUse
@@ -0,0 +1,47 @@
1
+ """
2
+ tools/agent/registry/registry.py — SubagentRegistry 全局注册表
3
+
4
+ 职责:管理 subagent 类型注册与查询,不承载场景组合决策。
5
+ 在整体链路中的位置:built_in 模块注册;composition/tool 查询可用类型。
6
+ CC 对照:src/tools/AgentTool/builtInAgents.ts 的内置类型集合(扩展为可变注册表)。
7
+ 当前裁剪范围:v1 提供 register/get/list/filter 基础能力。
8
+ """
9
+
10
+ from __future__ import annotations
11
+
12
+ from dataclasses import dataclass, field
13
+
14
+ from .config import SubagentConfig
15
+
16
+
17
+ @dataclass
18
+ class SubagentRegistry:
19
+ """subagent 类型注册表。"""
20
+
21
+ _registry: dict[str, SubagentConfig] = field(default_factory=dict)
22
+
23
+ def register(self, config: SubagentConfig) -> None:
24
+ """注册或覆盖同名 subagent 类型。"""
25
+ self._registry[config.name] = config
26
+
27
+ def get(self, name: str) -> SubagentConfig:
28
+ """按名称获取类型配置,不存在时抛 KeyError。"""
29
+ return self._registry[name]
30
+
31
+ def list_all(self) -> list[SubagentConfig]:
32
+ """返回所有已注册类型。"""
33
+ return list(self._registry.values())
34
+
35
+ def filter_by_tags(self, tags: set[str]) -> list[SubagentConfig]:
36
+ """按标签过滤类型。"""
37
+ if not tags:
38
+ return self.list_all()
39
+ return [cfg for cfg in self._registry.values() if cfg.tags & tags]
40
+
41
+
42
+ _global_registry = SubagentRegistry()
43
+
44
+
45
+ def get_global_registry() -> SubagentRegistry:
46
+ """获取进程级全局注册表。"""
47
+ return _global_registry
@@ -0,0 +1,137 @@
1
+ """
2
+ tools/agent/scope.py — Tool Scope 统一裁决入口
3
+
4
+ 职责:统一计算 candidate/agent-filter/skill-allow/deny 之后的有效工具范围与自动批准集合。
5
+ 在整体链路中的位置:由 skill 执行路径调用,用于生成可观测的 scope 决策结果。
6
+ CC 对照:forkedAgent.ts 中 alwaysAllowRules union + alwaysDenyRules 优先级语义。
7
+ 当前裁剪范围:v1 仅提供纯函数裁决与 explain,不直接改写 runtime 状态。
8
+ """
9
+
10
+ from __future__ import annotations
11
+
12
+ from dataclasses import dataclass
13
+ from typing import TYPE_CHECKING
14
+
15
+ from .backend import _ALWAYS_DISALLOWED_FOR_SUBAGENT
16
+
17
+ if TYPE_CHECKING:
18
+ from .registry.config import SubagentConfig
19
+
20
+
21
+ @dataclass(frozen=True)
22
+ class EffectiveToolScope:
23
+ """工具范围裁决结果。"""
24
+
25
+ candidate_tools: frozenset[str]
26
+ agent_filter_result: frozenset[str]
27
+ skill_auto_approved: frozenset[str]
28
+ policy_denied: frozenset[str]
29
+ final_allowed: frozenset[str]
30
+ auto_approved: frozenset[str]
31
+ explain: list[str]
32
+
33
+
34
+ def _normalize_tool_names(
35
+ names: list[str] | None,
36
+ known: frozenset[str],
37
+ ) -> tuple[frozenset[str], frozenset[str]]:
38
+ """将输入工具名对齐到 known 的 canonical 名称,返回 (matched, unknown)。"""
39
+ if not names:
40
+ return frozenset(), frozenset()
41
+
42
+ known_lower = {name.lower(): name for name in known}
43
+ matched: set[str] = set()
44
+ unknown: set[str] = set()
45
+ for name in names:
46
+ if not isinstance(name, str):
47
+ unknown.add(str(name))
48
+ continue
49
+ canonical = known_lower.get(name.strip().lower())
50
+ if canonical:
51
+ matched.add(canonical)
52
+ else:
53
+ unknown.add(name)
54
+ return frozenset(matched), frozenset(unknown)
55
+
56
+
57
+ def resolve_effective_tools(
58
+ *,
59
+ candidate_tools: list,
60
+ agent_config: "SubagentConfig | None",
61
+ skill_allowed_tools: list[str] | None,
62
+ parent_auto_approved: set[str] | frozenset[str] | None,
63
+ global_deny: set[str] | frozenset[str] | None,
64
+ ) -> EffectiveToolScope:
65
+ """
66
+ 统一工具范围裁决入口。
67
+
68
+ 规则:
69
+ 1) Agent filter 收窄(若 agent_config=None 则视为 identity)
70
+ 2) Skill allowed-tools 以 union 方式追加到 auto_approved
71
+ 3) deny 永远优先,final_allowed/auto_approved 都要剔除 deny
72
+ """
73
+ explain: list[str] = []
74
+ candidate = frozenset(
75
+ name for t in candidate_tools if (name := getattr(t, "name", ""))
76
+ )
77
+
78
+ # Step 1: agent filter + always disallowed
79
+ if agent_config is not None and agent_config.tool_filter is not None:
80
+ filtered_tools = agent_config.tool_filter(candidate_tools)
81
+ else:
82
+ filtered_tools = list(candidate_tools)
83
+ filtered_names_raw = frozenset(
84
+ name for t in filtered_tools if (name := getattr(t, "name", ""))
85
+ )
86
+ filtered_names = filtered_names_raw - frozenset(_ALWAYS_DISALLOWED_FOR_SUBAGENT)
87
+ explain.append(f"agent_filter: {len(candidate)} -> {len(filtered_names)} tools")
88
+ removed_by_always_disallowed = filtered_names_raw - filtered_names
89
+ if removed_by_always_disallowed:
90
+ explain.append(
91
+ "agent_filter: removed "
92
+ f"{removed_by_always_disallowed} (always_disallowed_for_subagent)"
93
+ )
94
+
95
+ # Step 2: skill union on auto-approved only
96
+ normalized_skill_allowed, unknown_skill_allowed = _normalize_tool_names(
97
+ skill_allowed_tools,
98
+ filtered_names,
99
+ )
100
+ base_approved, _ = _normalize_tool_names(
101
+ list(parent_auto_approved or set()),
102
+ filtered_names,
103
+ )
104
+ raw_parent_approved = frozenset(str(x) for x in (parent_auto_approved or set()))
105
+ dropped_parent_approved = raw_parent_approved - base_approved
106
+ if dropped_parent_approved:
107
+ explain.append(
108
+ "parent_auto_approved: dropped out-of-scope tools "
109
+ f"{dropped_parent_approved}"
110
+ )
111
+ auto_approved = base_approved | normalized_skill_allowed
112
+ if normalized_skill_allowed:
113
+ explain.append(
114
+ f"skill_auto_approved: added {normalized_skill_allowed} (from skill frontmatter)"
115
+ )
116
+ if unknown_skill_allowed:
117
+ explain.append(
118
+ f"skill_auto_approved: unknown tools ignored: {unknown_skill_allowed}"
119
+ )
120
+
121
+ # Step 3: deny highest priority
122
+ denied_normalized, _ = _normalize_tool_names(list(global_deny or set()), filtered_names)
123
+ final_allowed = filtered_names - denied_normalized
124
+ final_auto_approved = auto_approved - denied_normalized
125
+ if denied_normalized:
126
+ explain.append(f"policy_denied: removed {denied_normalized} (global deny rule)")
127
+
128
+ return EffectiveToolScope(
129
+ candidate_tools=candidate,
130
+ agent_filter_result=filtered_names,
131
+ skill_auto_approved=normalized_skill_allowed,
132
+ policy_denied=denied_normalized,
133
+ final_allowed=final_allowed,
134
+ auto_approved=final_auto_approved,
135
+ explain=explain,
136
+ )
137
+