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.
- langchain_agentx/__init__.py +46 -0
- langchain_agentx/command/__init__.py +28 -0
- langchain_agentx/command/builtin/__init__.py +25 -0
- langchain_agentx/command/builtin/clear.py +33 -0
- langchain_agentx/command/builtin/compact.py +33 -0
- langchain_agentx/command/builtin/memory.py +37 -0
- langchain_agentx/command/builtin/reload_plugins.py +42 -0
- langchain_agentx/command/context.py +30 -0
- langchain_agentx/command/dispatcher.py +183 -0
- langchain_agentx/command/registry.py +110 -0
- langchain_agentx/command/result.py +25 -0
- langchain_agentx/command/types.py +41 -0
- langchain_agentx/config/__init__.py +14 -0
- langchain_agentx/loop/__init__.py +47 -0
- langchain_agentx/loop/config/__init__.py +20 -0
- langchain_agentx/loop/config/agent_config.py +66 -0
- langchain_agentx/loop/config/agent_loop_config.py +72 -0
- langchain_agentx/loop/config/model_context_resolver.py +105 -0
- langchain_agentx/loop/config/runtime_settings.py +50 -0
- langchain_agentx/loop/config/token_estimator.py +133 -0
- langchain_agentx/loop/context/__init__.py +66 -0
- langchain_agentx/loop/context/blocking_guard.py +97 -0
- langchain_agentx/loop/context/compaction_service.py +60 -0
- langchain_agentx/loop/context/message_utils.py +56 -0
- langchain_agentx/loop/context/pipeline.py +127 -0
- langchain_agentx/loop/context/settings.py +103 -0
- langchain_agentx/loop/context/stages/__init__.py +29 -0
- langchain_agentx/loop/context/stages/autocompact.py +140 -0
- langchain_agentx/loop/context/stages/base.py +32 -0
- langchain_agentx/loop/context/stages/collapse.py +76 -0
- langchain_agentx/loop/context/stages/microcompact.py +76 -0
- langchain_agentx/loop/context/stages/noop.py +33 -0
- langchain_agentx/loop/context/stages/snip.py +71 -0
- langchain_agentx/loop/context/stages/tool_result_budget.py +69 -0
- langchain_agentx/loop/context/types.py +79 -0
- langchain_agentx/loop/exit/__init__.py +1 -0
- langchain_agentx/loop/exit/exit_logic.py +320 -0
- langchain_agentx/loop/exit/reason_codes.py +39 -0
- langchain_agentx/loop/graph/__init__.py +5 -0
- langchain_agentx/loop/graph/builtin_loop_control.py +197 -0
- langchain_agentx/loop/graph/factory.py +1409 -0
- langchain_agentx/loop/graph/graph_edges.py +820 -0
- langchain_agentx/loop/hook/__init__.py +48 -0
- langchain_agentx/loop/hook/async_hook_runner.py +62 -0
- langchain_agentx/loop/hook/config.py +280 -0
- langchain_agentx/loop/hook/engine.py +321 -0
- langchain_agentx/loop/hook/executors/__init__.py +9 -0
- langchain_agentx/loop/hook/executors/agent.py +107 -0
- langchain_agentx/loop/hook/executors/command.py +230 -0
- langchain_agentx/loop/hook/executors/http.py +114 -0
- langchain_agentx/loop/hook/executors/prompt.py +92 -0
- langchain_agentx/loop/hook/graph_wiring.py +134 -0
- langchain_agentx/loop/hook/registry.py +262 -0
- langchain_agentx/loop/hook/trust.py +43 -0
- langchain_agentx/loop/hook/types.py +110 -0
- langchain_agentx/loop/injection/__init__.py +13 -0
- langchain_agentx/loop/injection/dedup.py +74 -0
- langchain_agentx/loop/loop_abort.py +36 -0
- langchain_agentx/loop/model/__init__.py +1 -0
- langchain_agentx/loop/model/model_node.py +648 -0
- langchain_agentx/loop/model/model_nodes.py +661 -0
- langchain_agentx/loop/model/orphan_tool_results.py +38 -0
- langchain_agentx/loop/model/retrier.py +307 -0
- langchain_agentx/loop/model/retry_bridge.py +58 -0
- langchain_agentx/loop/model/retry_events.py +35 -0
- langchain_agentx/loop/model/retry_policy.py +56 -0
- langchain_agentx/loop/model/schema_and_format.py +153 -0
- langchain_agentx/loop/model/tool_and_model_binding.py +227 -0
- langchain_agentx/loop/model/tool_call_degradation_corrector.py +443 -0
- langchain_agentx/loop/model/tool_transcript_guard.py +225 -0
- langchain_agentx/loop/prompt/__init__.py +95 -0
- langchain_agentx/loop/prompt/builder.py +61 -0
- langchain_agentx/loop/prompt/builtin.py +218 -0
- langchain_agentx/loop/prompt/compact.py +408 -0
- langchain_agentx/loop/prompt/sections.py +120 -0
- langchain_agentx/loop/runtime/__init__.py +19 -0
- langchain_agentx/loop/runtime/context.py +34 -0
- langchain_agentx/loop/runtime/context_factory.py +107 -0
- langchain_agentx/loop/runtime/subagent_execution_paths.py +68 -0
- langchain_agentx/loop/subagent/__init__.py +53 -0
- langchain_agentx/loop/subagent/async_runner.py +215 -0
- langchain_agentx/loop/subagent/context.py +209 -0
- langchain_agentx/loop/subagent/fork_worktree_notice.py +25 -0
- langchain_agentx/loop/subagent/graph.py +72 -0
- langchain_agentx/loop/subagent/orchestrator.py +391 -0
- langchain_agentx/loop/subagent/progress.py +30 -0
- langchain_agentx/loop/subagent/prompt.py +52 -0
- langchain_agentx/loop/subagent/runner.py +504 -0
- langchain_agentx/loop/subagent/transcript.py +172 -0
- langchain_agentx/memory/__init__.py +2 -0
- langchain_agentx/memory/instruction/__init__.py +12 -0
- langchain_agentx/memory/instruction/loader.py +325 -0
- langchain_agentx/memory/instruction/resolver.py +24 -0
- langchain_agentx/memory/instruction/runtime.py +83 -0
- langchain_agentx/memory/instruction/sections.py +83 -0
- langchain_agentx/memory/instruction/types.py +59 -0
- langchain_agentx/memory/memdir/__init__.py +77 -0
- langchain_agentx/memory/memdir/age.py +36 -0
- langchain_agentx/memory/memdir/agent_memory.py +380 -0
- langchain_agentx/memory/memdir/extractor.py +309 -0
- langchain_agentx/memory/memdir/loader.py +187 -0
- langchain_agentx/memory/memdir/paths.py +63 -0
- langchain_agentx/memory/memdir/recall.py +45 -0
- langchain_agentx/memory/memdir/runtime.py +43 -0
- langchain_agentx/memory/memdir/scan.py +135 -0
- langchain_agentx/memory/memdir/types.py +104 -0
- langchain_agentx/memory/session/__init__.py +76 -0
- langchain_agentx/memory/session/compact_bridge.py +208 -0
- langchain_agentx/memory/session/prompts.py +172 -0
- langchain_agentx/memory/session/session_memory.py +282 -0
- langchain_agentx/observability/__init__.py +67 -0
- langchain_agentx/observability/evaluation/__init__.py +17 -0
- langchain_agentx/observability/evaluation/checkers/__init__.py +18 -0
- langchain_agentx/observability/evaluation/checkers/base.py +34 -0
- langchain_agentx/observability/evaluation/checkers/compaction.py +38 -0
- langchain_agentx/observability/evaluation/checkers/degradation.py +50 -0
- langchain_agentx/observability/evaluation/checkers/exit_quality.py +42 -0
- langchain_agentx/observability/evaluation/checkers/session_memory.py +45 -0
- langchain_agentx/observability/evaluation/checkers/tool_behavior.py +53 -0
- langchain_agentx/observability/evaluation/retention_scheduler.py +67 -0
- langchain_agentx/observability/evaluation/service.py +102 -0
- langchain_agentx/observability/evaluation/state.py +32 -0
- langchain_agentx/observability/evaluation/store.py +258 -0
- langchain_agentx/observability/events/__init__.py +15 -0
- langchain_agentx/observability/events/langchain_agentx_event_adapter.py +832 -0
- langchain_agentx/observability/logging/__init__.py +15 -0
- langchain_agentx/observability/logging/debug_burst.py +95 -0
- langchain_agentx/observability/logging/logging_config.py +178 -0
- langchain_agentx/observability/logging/logging_contract.py +65 -0
- langchain_agentx/observability/replay/__init__.py +35 -0
- langchain_agentx/observability/replay/cli.py +91 -0
- langchain_agentx/observability/replay/service.py +83 -0
- langchain_agentx/observability/replay/store.py +278 -0
- langchain_agentx/observability/replay/ui.py +47 -0
- langchain_agentx/observability/trace/__init__.py +25 -0
- langchain_agentx/observability/trace/collector.py +560 -0
- langchain_agentx/observability/trace/event_emitter.py +183 -0
- langchain_agentx/observability/trace/hook_event_emitter.py +49 -0
- langchain_agentx/observability/trace/models.py +144 -0
- langchain_agentx/observability/trace/sqlite_store.py +873 -0
- langchain_agentx/observability/trace/trace_callback.py +295 -0
- langchain_agentx/observability/trace/trace_lifecycle_collector.py +114 -0
- langchain_agentx/plugin/__init__.py +26 -0
- langchain_agentx/plugin/builtin.py +53 -0
- langchain_agentx/plugin/config.py +113 -0
- langchain_agentx/plugin/loader.py +386 -0
- langchain_agentx/plugin/manifest.py +154 -0
- langchain_agentx/plugin/registries.py +211 -0
- langchain_agentx/plugin/types.py +142 -0
- langchain_agentx/provider/__init__.py +27 -0
- langchain_agentx/provider/anthropic.py +121 -0
- langchain_agentx/provider/compatible_chat_openai.py +86 -0
- langchain_agentx/provider/env.py +45 -0
- langchain_agentx/provider/model_profile.py +156 -0
- langchain_agentx/provider/openai.py +89 -0
- langchain_agentx/session/__init__.py +17 -0
- langchain_agentx/session/agent_session.py +320 -0
- langchain_agentx/session/conversation_factory.py +87 -0
- langchain_agentx/session/conversation_recovery.py +156 -0
- langchain_agentx/session/conversation_session.py +198 -0
- langchain_agentx/session/factory.py +143 -0
- langchain_agentx/session/protocol.py +25 -0
- langchain_agentx/task_runtime/__init__.py +113 -0
- langchain_agentx/task_runtime/core/__init__.py +51 -0
- langchain_agentx/task_runtime/core/ids.py +33 -0
- langchain_agentx/task_runtime/core/interfaces.py +115 -0
- langchain_agentx/task_runtime/core/notification_priority.py +19 -0
- langchain_agentx/task_runtime/core/types.py +136 -0
- langchain_agentx/task_runtime/integrations/__init__.py +33 -0
- langchain_agentx/task_runtime/integrations/loop_adapter.py +91 -0
- langchain_agentx/task_runtime/integrations/loop_integration.py +61 -0
- langchain_agentx/task_runtime/integrations/prefetch_providers.py +108 -0
- langchain_agentx/task_runtime/integrations/provider_factory.py +103 -0
- langchain_agentx/task_runtime/integrations/queued_command_provider.py +184 -0
- langchain_agentx/task_runtime/integrations/sqlite_queued_command_provider.py +338 -0
- langchain_agentx/task_runtime/integrations/tool_use_summary_provider.py +254 -0
- langchain_agentx/task_runtime/orchestrator/__init__.py +5 -0
- langchain_agentx/task_runtime/orchestrator/runtime.py +386 -0
- langchain_agentx/task_runtime/output/__init__.py +5 -0
- langchain_agentx/task_runtime/output/sink.py +64 -0
- langchain_agentx/task_runtime/policy/__init__.py +11 -0
- langchain_agentx/task_runtime/policy/withhold_visibility.py +32 -0
- langchain_agentx/task_runtime/queue/__init__.py +5 -0
- langchain_agentx/task_runtime/queue/in_memory.py +55 -0
- langchain_agentx/task_runtime/skill_prefetch/__init__.py +4 -0
- langchain_agentx/task_runtime/skill_prefetch/attachments.py +46 -0
- langchain_agentx/task_runtime/skill_prefetch/models.py +37 -0
- langchain_agentx/task_runtime/skill_prefetch/provider.py +344 -0
- langchain_agentx/task_runtime/store/__init__.py +6 -0
- langchain_agentx/task_runtime/store/in_memory.py +81 -0
- langchain_agentx/task_runtime/store/sqlite_store.py +281 -0
- langchain_agentx/task_runtime/tasks/__init__.py +76 -0
- langchain_agentx/task_runtime/tasks/ai_analysis/__init__.py +15 -0
- langchain_agentx/task_runtime/tasks/ai_analysis/base.py +41 -0
- langchain_agentx/task_runtime/tasks/ai_analysis/evaluation.py +67 -0
- langchain_agentx/task_runtime/tasks/ai_analysis/registry.py +36 -0
- langchain_agentx/task_runtime/tasks/ai_analysis/scheduler.py +70 -0
- langchain_agentx/task_runtime/tasks/base/__init__.py +6 -0
- langchain_agentx/task_runtime/tasks/base/contracts.py +24 -0
- langchain_agentx/task_runtime/tasks/custom/__init__.py +7 -0
- langchain_agentx/task_runtime/tasks/custom/executor.py +60 -0
- langchain_agentx/task_runtime/tasks/custom/notification.py +7 -0
- langchain_agentx/task_runtime/tasks/custom/semantics.py +13 -0
- langchain_agentx/task_runtime/tasks/custom/spec.py +33 -0
- langchain_agentx/task_runtime/tasks/dream_task/__init__.py +15 -0
- langchain_agentx/task_runtime/tasks/dream_task/executor.py +61 -0
- langchain_agentx/task_runtime/tasks/dream_task/notification.py +19 -0
- langchain_agentx/task_runtime/tasks/dream_task/semantics.py +13 -0
- langchain_agentx/task_runtime/tasks/dream_task/spec.py +35 -0
- langchain_agentx/task_runtime/tasks/dream_task/state.py +17 -0
- langchain_agentx/task_runtime/tasks/in_process_teammate/__init__.py +12 -0
- langchain_agentx/task_runtime/tasks/in_process_teammate/executor.py +36 -0
- langchain_agentx/task_runtime/tasks/in_process_teammate/notification.py +25 -0
- langchain_agentx/task_runtime/tasks/in_process_teammate/semantics.py +13 -0
- langchain_agentx/task_runtime/tasks/in_process_teammate/spec.py +63 -0
- langchain_agentx/task_runtime/tasks/local_agent/__init__.py +14 -0
- langchain_agentx/task_runtime/tasks/local_agent/executor.py +33 -0
- langchain_agentx/task_runtime/tasks/local_agent/notification.py +21 -0
- langchain_agentx/task_runtime/tasks/local_agent/runner.py +43 -0
- langchain_agentx/task_runtime/tasks/local_agent/semantics.py +13 -0
- langchain_agentx/task_runtime/tasks/local_agent/spec.py +31 -0
- langchain_agentx/task_runtime/tasks/local_bash/__init__.py +13 -0
- langchain_agentx/task_runtime/tasks/local_bash/executor.py +95 -0
- langchain_agentx/task_runtime/tasks/local_bash/notification.py +22 -0
- langchain_agentx/task_runtime/tasks/local_bash/semantics.py +13 -0
- langchain_agentx/task_runtime/tasks/local_bash/spec.py +55 -0
- langchain_agentx/task_runtime/tasks/remote_agent/__init__.py +19 -0
- langchain_agentx/task_runtime/tasks/remote_agent/backend.py +76 -0
- langchain_agentx/task_runtime/tasks/remote_agent/executor.py +37 -0
- langchain_agentx/task_runtime/tasks/remote_agent/notification.py +22 -0
- langchain_agentx/task_runtime/tasks/remote_agent/semantics.py +13 -0
- langchain_agentx/task_runtime/tasks/remote_agent/spec.py +34 -0
- langchain_agentx/task_runtime/tasks/trace_cleanup/__init__.py +19 -0
- langchain_agentx/task_runtime/tasks/trace_cleanup/bootstrap.py +95 -0
- langchain_agentx/task_runtime/tasks/trace_cleanup/executor.py +66 -0
- langchain_agentx/task_runtime/tasks/trace_cleanup/scheduler.py +169 -0
- langchain_agentx/tool_runtime/__init__.py +90 -0
- langchain_agentx/tool_runtime/adapter.py +365 -0
- langchain_agentx/tool_runtime/base.py +319 -0
- langchain_agentx/tool_runtime/errors.py +190 -0
- langchain_agentx/tool_runtime/identical_call_cache.py +110 -0
- langchain_agentx/tool_runtime/loader.py +195 -0
- langchain_agentx/tool_runtime/models.py +260 -0
- langchain_agentx/tool_runtime/permission_context.py +78 -0
- langchain_agentx/tool_runtime/pipeline.py +621 -0
- langchain_agentx/tool_runtime/policy.py +447 -0
- langchain_agentx/tool_runtime/registry.py +81 -0
- langchain_agentx/tool_runtime/resolvers/__init__.py +27 -0
- langchain_agentx/tool_runtime/resolvers/agent_session.py +125 -0
- langchain_agentx/tool_runtime/resolvers/background.py +32 -0
- langchain_agentx/tool_runtime/resolvers/base.py +20 -0
- langchain_agentx/tool_runtime/resolvers/conversation.py +22 -0
- langchain_agentx/tool_runtime/resolvers/workflow.py +73 -0
- langchain_agentx/tool_runtime/session_store.py +132 -0
- langchain_agentx/tool_runtime/smoke_test_runtime.py +294 -0
- langchain_agentx/tool_runtime/state_bridge.py +164 -0
- langchain_agentx/tools/__init__.py +26 -0
- langchain_agentx/tools/agent/__init__.py +9 -0
- langchain_agentx/tools/agent/backend.py +53 -0
- langchain_agentx/tools/agent/built_in/__init__.py +19 -0
- langchain_agentx/tools/agent/built_in/agentx_guide.py +65 -0
- langchain_agentx/tools/agent/built_in/explore.py +80 -0
- langchain_agentx/tools/agent/built_in/general.py +57 -0
- langchain_agentx/tools/agent/built_in/plan.py +89 -0
- langchain_agentx/tools/agent/built_in/statusline_setup.py +64 -0
- langchain_agentx/tools/agent/built_in/verification.py +120 -0
- langchain_agentx/tools/agent/builtin_subagent_loader.py +89 -0
- langchain_agentx/tools/agent/cwd_resolution.py +119 -0
- langchain_agentx/tools/agent/limits.py +26 -0
- langchain_agentx/tools/agent/loader.py +270 -0
- langchain_agentx/tools/agent/models.py +85 -0
- langchain_agentx/tools/agent/prompt.py +120 -0
- langchain_agentx/tools/agent/registry/__init__.py +18 -0
- langchain_agentx/tools/agent/registry/config.py +29 -0
- langchain_agentx/tools/agent/registry/registry.py +47 -0
- langchain_agentx/tools/agent/scope.py +137 -0
- langchain_agentx/tools/agent/tool.py +256 -0
- langchain_agentx/tools/bash/__init__.py +9 -0
- langchain_agentx/tools/bash/ast_security.py +571 -0
- langchain_agentx/tools/bash/backend.py +1447 -0
- langchain_agentx/tools/bash/bash_hardening.py +734 -0
- langchain_agentx/tools/bash/bash_runtime_contract.py +41 -0
- langchain_agentx/tools/bash/cwd_reporter.py +95 -0
- langchain_agentx/tools/bash/limits.py +71 -0
- langchain_agentx/tools/bash/mode_validation.py +282 -0
- langchain_agentx/tools/bash/models.py +131 -0
- langchain_agentx/tools/bash/observability.py +148 -0
- langchain_agentx/tools/bash/output_utils.py +200 -0
- langchain_agentx/tools/bash/path_security.py +2429 -0
- langchain_agentx/tools/bash/prompt.py +68 -0
- langchain_agentx/tools/bash/read_only_validation.py +589 -0
- langchain_agentx/tools/bash/result_presenter.py +324 -0
- langchain_agentx/tools/bash/sandbox_decision.py +133 -0
- langchain_agentx/tools/bash/security.py +311 -0
- langchain_agentx/tools/bash/sed_edit_parser.py +243 -0
- langchain_agentx/tools/bash/sed_validation.py +163 -0
- langchain_agentx/tools/bash/semantics.py +111 -0
- langchain_agentx/tools/bash/session_manager.py +205 -0
- langchain_agentx/tools/bash/session_runtime.py +290 -0
- langchain_agentx/tools/bash/shell_locator.py +191 -0
- langchain_agentx/tools/bash/task_runtime.py +91 -0
- langchain_agentx/tools/bash/tool.py +939 -0
- langchain_agentx/tools/bash/windows_shell_quoting.py +45 -0
- langchain_agentx/tools/glob/__init__.py +9 -0
- langchain_agentx/tools/glob/models.py +57 -0
- langchain_agentx/tools/glob/pagination.py +30 -0
- langchain_agentx/tools/glob/prompt.py +24 -0
- langchain_agentx/tools/glob/rg_list_backend.py +139 -0
- langchain_agentx/tools/glob/rg_pattern.py +44 -0
- langchain_agentx/tools/glob/tool.py +327 -0
- langchain_agentx/tools/grep/__init__.py +7 -0
- langchain_agentx/tools/grep/backend.py +375 -0
- langchain_agentx/tools/grep/models.py +127 -0
- langchain_agentx/tools/grep/prompt.py +30 -0
- langchain_agentx/tools/grep/rg_subprocess_controller.py +114 -0
- langchain_agentx/tools/grep/tool.py +475 -0
- langchain_agentx/tools/read/__init__.py +9 -0
- langchain_agentx/tools/read/backend.py +415 -0
- langchain_agentx/tools/read/limits.py +67 -0
- langchain_agentx/tools/read/models.py +156 -0
- langchain_agentx/tools/read/prompt.py +73 -0
- langchain_agentx/tools/read/tool.py +494 -0
- langchain_agentx/tools/ripgrep_plugin_exclusions.py +137 -0
- langchain_agentx/tools/skill/__init__.py +4 -0
- langchain_agentx/tools/skill/argument_substitution.py +80 -0
- langchain_agentx/tools/skill/loader.py +196 -0
- langchain_agentx/tools/skill/models.py +88 -0
- langchain_agentx/tools/skill/policy.py +80 -0
- langchain_agentx/tools/skill/prompt.py +35 -0
- langchain_agentx/tools/skill/tool.py +222 -0
- langchain_agentx/utils/__init__.py +0 -0
- langchain_agentx/utils/cwd.py +124 -0
- langchain_agentx/utils/host_platform.py +112 -0
- langchain_agentx/utils/path_hierarchy.py +48 -0
- langchain_agentx/utils/path_user_input.py +66 -0
- langchain_agentx/utils/rg_executable.py +18 -0
- langchain_agentx/utils/subprocess_text.py +101 -0
- langchain_agentx/utils/temp_paths.py +77 -0
- langchain_agentx/utils/unc_path.py +25 -0
- langchain_agentx/utils/win_reserved_paths.py +51 -0
- langchain_agentx/workflow/__init__.py +7 -0
- langchain_agentx/workflow/base.py +97 -0
- langchain_agentx/workflow/batch.py +55 -0
- langchain_agentx/workflow/dag.py +54 -0
- langchain_agentx/workspace/__init__.py +13 -0
- langchain_agentx/workspace/config.py +140 -0
- langchain_agentx/workspace/path_key_normalizer.py +30 -0
- langchain_agentx/workspace/resolver.py +74 -0
- langchain_agentx/workspace/validators.py +41 -0
- langchain_agentx_python-0.1.dist-info/LICENSE +201 -0
- langchain_agentx_python-0.1.dist-info/METADATA +513 -0
- langchain_agentx_python-0.1.dist-info/RECORD +354 -0
- langchain_agentx_python-0.1.dist-info/WHEEL +5 -0
- langchain_agentx_python-0.1.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
"""
|
|
2
|
+
runtime/state_bridge.py — 工具级最小共享状态管理
|
|
3
|
+
|
|
4
|
+
职责:
|
|
5
|
+
管理工具执行过程中的跨工具共享状态,维护:
|
|
6
|
+
- last_read_map:记录每个文件最近一次被读取的信息,
|
|
7
|
+
为 write/edit 工具的 read-before-write 约束提供基础
|
|
8
|
+
- tool_audit:工具调用审计日志,记录每次工具执行的关键信息
|
|
9
|
+
- last_glob_summary(v2-D):最近一次 Glob 的摘要,供 Read/Grep 等读侧 **hint**(不替代授权)
|
|
10
|
+
|
|
11
|
+
状态存储在 ToolExecutionContext.state(LangGraph state)中,
|
|
12
|
+
通过固定 key 读写,不引入独立的状态存储。
|
|
13
|
+
|
|
14
|
+
与 CC 对比:
|
|
15
|
+
CC 中通过 ToolUseContext.readFileState 维护文件读取状态,
|
|
16
|
+
通过 getAppState / setAppState 读写应用级状态。
|
|
17
|
+
本框架将这些能力收敛到 ToolStateBridge,通过 LangGraph state
|
|
18
|
+
作为底层存储,保持与 agent loop 的状态一致性。
|
|
19
|
+
v1:last_read_map、tool_audit;v2-D:last_glob_summary(可选写入,见 GlobRuntimeTool.after_invoke)。
|
|
20
|
+
不承担业务 workflow state。
|
|
21
|
+
"""
|
|
22
|
+
|
|
23
|
+
from __future__ import annotations
|
|
24
|
+
|
|
25
|
+
from typing import Any
|
|
26
|
+
|
|
27
|
+
from .models import ToolExecutionContext
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
class ToolStateBridge:
|
|
31
|
+
"""
|
|
32
|
+
工具级最小共享状态管理器。
|
|
33
|
+
|
|
34
|
+
通过 ToolExecutionContext.state(LangGraph state dict)读写状态,
|
|
35
|
+
使用固定 key 隔离工具框架状态与业务状态。
|
|
36
|
+
|
|
37
|
+
维护:
|
|
38
|
+
last_read_map — 文件最近读取记录(为 read-before-write 规则服务)
|
|
39
|
+
tool_audit — 工具调用审计日志
|
|
40
|
+
last_glob_summary — 最近一次 Glob 摘要(仅路径样本,防 state 膨胀)
|
|
41
|
+
|
|
42
|
+
不承担:
|
|
43
|
+
业务 workflow state
|
|
44
|
+
UI 临时态
|
|
45
|
+
task state
|
|
46
|
+
"""
|
|
47
|
+
|
|
48
|
+
LAST_READ_MAP_KEY = "_tool_last_read_map"
|
|
49
|
+
AUDIT_LOG_KEY = "_tool_audit_log"
|
|
50
|
+
LAST_GLOB_SUMMARY_KEY = "_tool_last_glob_summary"
|
|
51
|
+
MAX_GLOB_SAMPLE_PATHS = 32
|
|
52
|
+
|
|
53
|
+
# ---- last_read_map ----
|
|
54
|
+
|
|
55
|
+
def get_last_read_map(self, ctx: ToolExecutionContext) -> dict[str, Any]:
|
|
56
|
+
"""
|
|
57
|
+
获取 last_read_map。
|
|
58
|
+
|
|
59
|
+
结构:{ file_path: { tool_call_id, ts, line_start, line_end } }
|
|
60
|
+
不存在时返回空 dict(不修改 state)。
|
|
61
|
+
"""
|
|
62
|
+
return ctx.state.get(self.LAST_READ_MAP_KEY) or {}
|
|
63
|
+
|
|
64
|
+
def set_last_read_map(
|
|
65
|
+
self,
|
|
66
|
+
ctx: ToolExecutionContext,
|
|
67
|
+
value: dict[str, Any],
|
|
68
|
+
) -> None:
|
|
69
|
+
"""更新 last_read_map,整体替换。"""
|
|
70
|
+
ctx.state[self.LAST_READ_MAP_KEY] = value
|
|
71
|
+
|
|
72
|
+
def record_read(
|
|
73
|
+
self,
|
|
74
|
+
ctx: ToolExecutionContext,
|
|
75
|
+
file_path: str,
|
|
76
|
+
*,
|
|
77
|
+
line_start: int | None = None,
|
|
78
|
+
line_end: int | None = None,
|
|
79
|
+
) -> None:
|
|
80
|
+
"""
|
|
81
|
+
记录一次文件读取,更新 last_read_map 中对应条目。
|
|
82
|
+
|
|
83
|
+
ReadRuntimeTool.after_invoke() 调用此方法,
|
|
84
|
+
WriteRuntimeTool / EditRuntimeTool 的 check_permissions() 检查此记录。
|
|
85
|
+
"""
|
|
86
|
+
last_read_map = self.get_last_read_map(ctx)
|
|
87
|
+
last_read_map[file_path] = {
|
|
88
|
+
"tool_call_id": ctx.tool_call_id,
|
|
89
|
+
"ts": ctx.now_ts,
|
|
90
|
+
"line_start": line_start,
|
|
91
|
+
"line_end": line_end,
|
|
92
|
+
}
|
|
93
|
+
self.set_last_read_map(ctx, last_read_map)
|
|
94
|
+
|
|
95
|
+
def has_been_read(self, ctx: ToolExecutionContext, file_path: str) -> bool:
|
|
96
|
+
"""
|
|
97
|
+
检查文件是否已被读取过(用于 read-before-write 约束)。
|
|
98
|
+
"""
|
|
99
|
+
return file_path in self.get_last_read_map(ctx)
|
|
100
|
+
|
|
101
|
+
# ---- tool_audit ----
|
|
102
|
+
|
|
103
|
+
def append_audit(
|
|
104
|
+
self,
|
|
105
|
+
ctx: ToolExecutionContext,
|
|
106
|
+
record: dict[str, Any],
|
|
107
|
+
) -> None:
|
|
108
|
+
"""
|
|
109
|
+
追加一条审计记录到 tool_audit 列表。
|
|
110
|
+
|
|
111
|
+
record 建议包含:
|
|
112
|
+
tool — 工具名
|
|
113
|
+
tool_call_id — 调用 ID
|
|
114
|
+
ts — 时间戳
|
|
115
|
+
以及工具特定的关键字段(如 file_path、lines_read 等)
|
|
116
|
+
"""
|
|
117
|
+
audit_log: list = ctx.state.get(self.AUDIT_LOG_KEY) or []
|
|
118
|
+
audit_log.append(record)
|
|
119
|
+
ctx.state[self.AUDIT_LOG_KEY] = audit_log
|
|
120
|
+
|
|
121
|
+
def get_audit_log(self, ctx: ToolExecutionContext) -> list[dict[str, Any]]:
|
|
122
|
+
"""获取完整审计日志,不存在时返回空列表。"""
|
|
123
|
+
return ctx.state.get(self.AUDIT_LOG_KEY) or []
|
|
124
|
+
|
|
125
|
+
# ---- last_glob_summary(v2-D,本工程专有;CC 无对等)----
|
|
126
|
+
|
|
127
|
+
def record_last_glob(
|
|
128
|
+
self,
|
|
129
|
+
ctx: ToolExecutionContext,
|
|
130
|
+
*,
|
|
131
|
+
pattern: str,
|
|
132
|
+
search_root: str,
|
|
133
|
+
filenames: list[str],
|
|
134
|
+
num_files_page: int,
|
|
135
|
+
total_matches: int,
|
|
136
|
+
truncated: bool,
|
|
137
|
+
offset: int,
|
|
138
|
+
) -> None:
|
|
139
|
+
"""
|
|
140
|
+
覆盖写入最近一次 Glob 摘要(**不**用于 PolicyEngine,仅供 hint)。
|
|
141
|
+
|
|
142
|
+
``filenames`` 为当前页相对路径列表;仅持久化前 ``MAX_GLOB_SAMPLE_PATHS`` 条。
|
|
143
|
+
"""
|
|
144
|
+
sample = list(filenames[: self.MAX_GLOB_SAMPLE_PATHS])
|
|
145
|
+
ctx.state[self.LAST_GLOB_SUMMARY_KEY] = {
|
|
146
|
+
"pattern": pattern,
|
|
147
|
+
"search_root": search_root,
|
|
148
|
+
"sample_paths": sample,
|
|
149
|
+
"num_files_page": int(num_files_page),
|
|
150
|
+
"total_matches": int(total_matches),
|
|
151
|
+
"truncated": bool(truncated),
|
|
152
|
+
"offset": int(offset),
|
|
153
|
+
"tool_call_id": ctx.tool_call_id,
|
|
154
|
+
"ts": ctx.now_ts,
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
def get_last_glob_summary(self, ctx: ToolExecutionContext) -> dict[str, Any] | None:
|
|
158
|
+
"""读取最近一次 Glob 摘要;不存在或类型不对时返回 ``None``。"""
|
|
159
|
+
raw = ctx.state.get(self.LAST_GLOB_SUMMARY_KEY)
|
|
160
|
+
return raw if isinstance(raw, dict) else None
|
|
161
|
+
|
|
162
|
+
def clear_last_glob_summary(self, ctx: ToolExecutionContext) -> None:
|
|
163
|
+
"""清除摘要(测试或显式重置会话工具态时使用)。"""
|
|
164
|
+
ctx.state.pop(self.LAST_GLOB_SUMMARY_KEY, None)
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"""
|
|
2
|
+
内置工具包(见 `docs/design-docs/tool-runtime/langchain-tool-runtime-framework.md`)。
|
|
3
|
+
|
|
4
|
+
工具体系实现状态:
|
|
5
|
+
P1(已完成):ReadRuntimeTool — 文本/图片/PDF/Notebook 读取
|
|
6
|
+
P2(已完成):GrepRuntimeTool / GlobRuntimeTool — 只读搜索工具
|
|
7
|
+
P3(待实现):WriteRuntimeTool / EditRuntimeTool
|
|
8
|
+
P4(已完成):BashRuntimeTool
|
|
9
|
+
"""
|
|
10
|
+
|
|
11
|
+
from .agent import AgentRuntimeTool
|
|
12
|
+
from .bash import BashRuntimeTool
|
|
13
|
+
from .glob import GlobRuntimeTool
|
|
14
|
+
from .grep import GrepRuntimeTool
|
|
15
|
+
from .read import ReadRuntimeTool
|
|
16
|
+
from .skill import SkillRuntimeTool
|
|
17
|
+
|
|
18
|
+
__all__ = [
|
|
19
|
+
"ReadRuntimeTool",
|
|
20
|
+
"AgentRuntimeTool",
|
|
21
|
+
"BashRuntimeTool",
|
|
22
|
+
"GlobRuntimeTool",
|
|
23
|
+
"GrepRuntimeTool",
|
|
24
|
+
"SkillRuntimeTool",
|
|
25
|
+
]
|
|
26
|
+
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
"""
|
|
2
|
+
tools/agent/backend.py — Agent 工具池与执行模式决策
|
|
3
|
+
|
|
4
|
+
职责:提供 should_run_async 与 assemble_tool_pool,避免策略细节堆入 tool.py。
|
|
5
|
+
在整体链路中的位置:AgentRuntimeTool.invoke() 调用本模块后再调 run_subagent()。
|
|
6
|
+
CC 对照:src/tools/AgentTool/agentToolUtils.ts 与 AgentTool.tsx 的 shouldRunAsync。
|
|
7
|
+
当前裁剪范围:v1 默认同步,支持 run_in_background 显式触发与全局禁用开关。
|
|
8
|
+
"""
|
|
9
|
+
|
|
10
|
+
from __future__ import annotations
|
|
11
|
+
|
|
12
|
+
import os
|
|
13
|
+
from typing import TYPE_CHECKING
|
|
14
|
+
|
|
15
|
+
if TYPE_CHECKING:
|
|
16
|
+
from langchain_agentx.tool_runtime.models import ToolExecutionContext
|
|
17
|
+
|
|
18
|
+
from .models import AgentToolInput
|
|
19
|
+
from .registry.config import SubagentConfig
|
|
20
|
+
|
|
21
|
+
# 不变量:子 Agent 永远不能调用 Agent 工具本身,避免递归绕过深度限制。
|
|
22
|
+
_ALWAYS_DISALLOWED_FOR_SUBAGENT = {"Agent", "agent"}
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
def _background_disabled() -> bool:
|
|
26
|
+
raw = os.getenv("LANGCHAIN_AGENTX_DISABLE_BACKGROUND_TASKS", "")
|
|
27
|
+
return raw.strip().lower() in {"1", "true", "yes", "on"}
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
def should_run_async(data: "AgentToolInput", ctx: "ToolExecutionContext") -> bool:
|
|
31
|
+
"""决定是否走异步路径。"""
|
|
32
|
+
if _background_disabled():
|
|
33
|
+
return False
|
|
34
|
+
return bool(data.run_in_background)
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
def assemble_tool_pool(
|
|
38
|
+
all_tools: list,
|
|
39
|
+
config: "SubagentConfig",
|
|
40
|
+
is_async: bool = False,
|
|
41
|
+
) -> list:
|
|
42
|
+
"""
|
|
43
|
+
组装子 Agent 工具池。
|
|
44
|
+
|
|
45
|
+
规则:先应用 config.tool_filter(若有),再强制移除 always-disallowed。
|
|
46
|
+
"""
|
|
47
|
+
_ = is_async # v1 预留参数,v2 可按异步模式再收紧工具集。
|
|
48
|
+
filtered = config.tool_filter(all_tools) if config.tool_filter else list(all_tools)
|
|
49
|
+
return [
|
|
50
|
+
tool
|
|
51
|
+
for tool in filtered
|
|
52
|
+
if getattr(tool, "name", "") not in _ALWAYS_DISALLOWED_FOR_SUBAGENT
|
|
53
|
+
]
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"""
|
|
2
|
+
tools/agent/built_in — 内置 Subagent 类型定义(仅配置 + register)
|
|
3
|
+
|
|
4
|
+
职责:各子模块提供 SubagentConfig 与 register(registry),不在包级做自注册。
|
|
5
|
+
在整体链路中的位置:builtin_subagent_loader 按需 import 子模块并调用 register;
|
|
6
|
+
也可在测试中 `from langchain_agentx.tools.agent.built_in import general` 等单独引用。
|
|
7
|
+
CC 对照:src/tools/AgentTool/built-in/ 目录。
|
|
8
|
+
|
|
9
|
+
注意:装载策略与进程单例见同目录上一级的 ``builtin_subagent_loader.py``。
|
|
10
|
+
"""
|
|
11
|
+
|
|
12
|
+
__all__ = [
|
|
13
|
+
"general",
|
|
14
|
+
"explore",
|
|
15
|
+
"plan",
|
|
16
|
+
"verification",
|
|
17
|
+
"statusline_setup",
|
|
18
|
+
"agentx_guide",
|
|
19
|
+
]
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
"""
|
|
2
|
+
tools/agent/built_in/agentx_guide.py — agentx-guide 内置类型
|
|
3
|
+
|
|
4
|
+
职责:定义面向 langchain_agentx 项目的文档与配置指导 subagent。
|
|
5
|
+
在整体链路中的位置:builtin_subagent_loader 在 LANGCHAIN_AGENTX_BUILTIN_AGENTX_GUIDE 时调用 register()。
|
|
6
|
+
CC 对照:src/tools/AgentTool/built-in/claudeCodeGuideAgent.ts(语义本地化)。
|
|
7
|
+
当前裁剪范围:v3 保留 guide 能力,但名称与语义切换为本工程。
|
|
8
|
+
|
|
9
|
+
典型使用场景:
|
|
10
|
+
1) 用户询问本工程能力、目录结构、配置方式、运行/测试命令;
|
|
11
|
+
2) 用户询问 `agent_home`、workspace、tool runtime、loop/observability 等约定;
|
|
12
|
+
3) 用户需要基于仓库文档给出排障路径或最佳实践建议。
|
|
13
|
+
"""
|
|
14
|
+
|
|
15
|
+
from __future__ import annotations
|
|
16
|
+
|
|
17
|
+
from ..registry.config import SubagentConfig
|
|
18
|
+
from ..registry.registry import SubagentRegistry
|
|
19
|
+
|
|
20
|
+
_ALLOWED = frozenset({"Read", "Glob", "Grep", "WebFetch", "WebSearch"})
|
|
21
|
+
|
|
22
|
+
_SYSTEM_PROMPT = """You are the project guide agent for langchain_agentx.
|
|
23
|
+
|
|
24
|
+
Your goal is to answer "how to use / how to configure / where to find" questions
|
|
25
|
+
for this repository with evidence and actionable steps.
|
|
26
|
+
|
|
27
|
+
Primary sources (in order):
|
|
28
|
+
1. Local project docs and rules first (`CLAUDE.md`, `README.md`, `docs/`).
|
|
29
|
+
2. Local code and tests as behavior truth source.
|
|
30
|
+
3. Web search/fetch only when local docs do not cover the question.
|
|
31
|
+
|
|
32
|
+
Guidelines:
|
|
33
|
+
- Always prioritize repository-local documentation and code reality.
|
|
34
|
+
- Cite exact local file paths used for your answer.
|
|
35
|
+
- Keep responses concise, practical, and configuration-aware.
|
|
36
|
+
- If information is missing, state uncertainty and propose the next best check.
|
|
37
|
+
- Do not assume Claude Code official documentation applies unless explicitly asked.
|
|
38
|
+
"""
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
def _guide_tool_filter(all_tools: list) -> list:
|
|
42
|
+
return [t for t in all_tools if getattr(t, "name", "") in _ALLOWED]
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
AGENTX_GUIDE_AGENT = SubagentConfig(
|
|
46
|
+
name="agentx-guide",
|
|
47
|
+
description=(
|
|
48
|
+
"Guide agent for langchain_agentx usage, configuration, troubleshooting, "
|
|
49
|
+
"and workflow best practices."
|
|
50
|
+
),
|
|
51
|
+
when_to_use=(
|
|
52
|
+
"Use this agent when the user asks questions about langchain_agentx: features, "
|
|
53
|
+
"configuration, agent_home/workspace conventions, tool runtime, loop/observability, "
|
|
54
|
+
"or how to run/test the project. Answers from local docs and code first."
|
|
55
|
+
),
|
|
56
|
+
system_prompt_factory=lambda: _SYSTEM_PROMPT,
|
|
57
|
+
tool_filter=_guide_tool_filter,
|
|
58
|
+
tools_description="Read, Glob, Grep, WebFetch, WebSearch",
|
|
59
|
+
default_max_steps=None,
|
|
60
|
+
allow_async=False,
|
|
61
|
+
tags={"guide", "docs", "project-specific"},
|
|
62
|
+
)
|
|
63
|
+
|
|
64
|
+
def register(registry: SubagentRegistry) -> None:
|
|
65
|
+
registry.register(AGENTX_GUIDE_AGENT)
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
"""
|
|
2
|
+
tools/agent/built_in/explore.py — Explore 内置类型
|
|
3
|
+
|
|
4
|
+
职责:定义只读探索型 subagent,并提供工具过滤函数。
|
|
5
|
+
在整体链路中的位置:backend.assemble_tool_pool() 调用 config.tool_filter 执行过滤。
|
|
6
|
+
CC 对照:src/tools/AgentTool/built-in/exploreAgent.ts。
|
|
7
|
+
当前裁剪范围:v1 禁写工具集合固定,异步执行关闭。
|
|
8
|
+
"""
|
|
9
|
+
|
|
10
|
+
from __future__ import annotations
|
|
11
|
+
|
|
12
|
+
from ..registry.config import SubagentConfig
|
|
13
|
+
from ..registry.registry import SubagentRegistry
|
|
14
|
+
|
|
15
|
+
_DISALLOWED = frozenset({"Agent", "agent", "Edit", "Write", "NotebookEdit"})
|
|
16
|
+
|
|
17
|
+
_SYSTEM_PROMPT = """You are a file search specialist for langchain_agentx. \
|
|
18
|
+
You excel at thoroughly navigating and exploring codebases.
|
|
19
|
+
|
|
20
|
+
=== CRITICAL: READ-ONLY MODE - NO FILE MODIFICATIONS ===
|
|
21
|
+
You are STRICTLY PROHIBITED from:
|
|
22
|
+
- Creating new files (no Write, touch, or file creation of any kind)
|
|
23
|
+
- Modifying existing files (no Edit operations)
|
|
24
|
+
- Deleting, moving, or copying files
|
|
25
|
+
- Creating temporary files anywhere, including /tmp
|
|
26
|
+
- Running ANY commands that change system state
|
|
27
|
+
|
|
28
|
+
Your role is EXCLUSIVELY to search and analyze existing code.
|
|
29
|
+
|
|
30
|
+
Your strengths:
|
|
31
|
+
- Rapidly finding files using glob patterns
|
|
32
|
+
- Searching code and text with powerful regex patterns
|
|
33
|
+
- Reading and analyzing file contents
|
|
34
|
+
|
|
35
|
+
Guidelines:
|
|
36
|
+
- Use Glob for broad file pattern matching
|
|
37
|
+
- Use Grep for searching file contents with regex
|
|
38
|
+
- Use Read when you know the specific file path you need to read
|
|
39
|
+
- Use Bash ONLY for read-only operations (ls, git status, git log, git diff, find, cat, head, tail)
|
|
40
|
+
- NEVER use Bash for: mkdir, touch, rm, cp, mv, git add, git commit, or any file creation/modification
|
|
41
|
+
- Adapt your search thoroughness based on the caller's request: "quick" for basic searches, \
|
|
42
|
+
"medium" for moderate exploration, "very thorough" for comprehensive analysis
|
|
43
|
+
- Wherever possible spawn multiple parallel tool calls for grepping and reading files
|
|
44
|
+
- Communicate your final report directly as a regular message — do NOT attempt to create files
|
|
45
|
+
|
|
46
|
+
Complete the search request efficiently and report findings clearly."""
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
def _explore_tool_filter(all_tools: list) -> list:
|
|
50
|
+
"""只保留 Explore 可用工具。"""
|
|
51
|
+
return [t for t in all_tools if getattr(t, "name", "") not in _DISALLOWED]
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
EXPLORE_AGENT_MIN_QUERIES = 3 # CC 对照:exploreAgent.ts EXPLORE_AGENT_MIN_QUERIES
|
|
55
|
+
|
|
56
|
+
EXPLORE_AGENT = SubagentConfig(
|
|
57
|
+
name="Explore",
|
|
58
|
+
description=(
|
|
59
|
+
"Fast readonly agent specialized for exploring codebases, finding files, "
|
|
60
|
+
"and answering structure/usage questions."
|
|
61
|
+
),
|
|
62
|
+
when_to_use=(
|
|
63
|
+
'Fast agent specialized for exploring codebases. Use this when you need to quickly find files '
|
|
64
|
+
'by patterns (eg. "src/components/**/*.tsx"), search code for keywords (eg. "API endpoints"), '
|
|
65
|
+
'or answer questions about the codebase (eg. "how do API endpoints work?"). '
|
|
66
|
+
'When calling this agent, specify the desired thoroughness level: "quick" for basic searches, '
|
|
67
|
+
'"medium" for moderate exploration, or "very thorough" for comprehensive analysis across '
|
|
68
|
+
"multiple locations and naming conventions."
|
|
69
|
+
),
|
|
70
|
+
system_prompt_factory=lambda: _SYSTEM_PROMPT,
|
|
71
|
+
tool_filter=_explore_tool_filter,
|
|
72
|
+
tools_description="All tools except Agent/Edit/Write/NotebookEdit",
|
|
73
|
+
default_max_steps=None,
|
|
74
|
+
allow_async=False,
|
|
75
|
+
tags={"readonly", "search", "explore"},
|
|
76
|
+
)
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
def register(registry: SubagentRegistry) -> None:
|
|
80
|
+
registry.register(EXPLORE_AGENT)
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
"""
|
|
2
|
+
tools/agent/built_in/general.py — general-purpose 内置类型
|
|
3
|
+
|
|
4
|
+
职责:定义通用 subagent 配置并完成自注册,不承载组合决策。
|
|
5
|
+
在整体链路中的位置:builtin_subagent_loader / 测试调用 register() 装入 SubagentRegistry;被 AgentRuntimeTool 使用。
|
|
6
|
+
CC 对照:src/tools/AgentTool/built-in/generalPurposeAgent.ts。
|
|
7
|
+
当前裁剪范围:v1 全工具集(tool_filter=None),异步允许标记仅保留配置位。
|
|
8
|
+
"""
|
|
9
|
+
|
|
10
|
+
from __future__ import annotations
|
|
11
|
+
|
|
12
|
+
from ..registry.config import SubagentConfig
|
|
13
|
+
from ..registry.registry import SubagentRegistry
|
|
14
|
+
|
|
15
|
+
_SYSTEM_PROMPT = """You are an agent for langchain_agentx. Given the user's message, \
|
|
16
|
+
use available tools to complete the task fully and efficiently. \
|
|
17
|
+
When you complete the task, respond with a concise report covering what was done \
|
|
18
|
+
and any key findings — the caller will relay this to the user, so it only needs the essentials.
|
|
19
|
+
|
|
20
|
+
Your strengths:
|
|
21
|
+
- Searching for code, configurations, and patterns across large codebases.
|
|
22
|
+
- Analyzing multiple files to understand system architecture.
|
|
23
|
+
- Investigating complex questions that require exploring many files.
|
|
24
|
+
- Performing multi-step research and implementation tasks.
|
|
25
|
+
|
|
26
|
+
Guidelines:
|
|
27
|
+
- For file searches: search broadly when you don't know where something lives. Use Read when you know the specific file path.
|
|
28
|
+
- For analysis: start broad and narrow down. Use multiple search strategies if the first doesn't yield results.
|
|
29
|
+
- Be thorough: check multiple locations, consider different naming conventions, look for related files.
|
|
30
|
+
- NEVER create files unless they're absolutely necessary for achieving your goal. ALWAYS prefer editing an existing file to creating a new one.
|
|
31
|
+
- NEVER proactively create documentation files (*.md) or README files unless explicitly requested.
|
|
32
|
+
"""
|
|
33
|
+
|
|
34
|
+
GENERAL_PURPOSE_AGENT = SubagentConfig(
|
|
35
|
+
name="general-purpose",
|
|
36
|
+
description=(
|
|
37
|
+
"General-purpose agent for researching complex questions, searching for code, "
|
|
38
|
+
"and executing multi-step tasks."
|
|
39
|
+
),
|
|
40
|
+
when_to_use=(
|
|
41
|
+
"General-purpose agent for researching complex questions, searching for code, "
|
|
42
|
+
"and executing multi-step tasks. When you are searching for a keyword or file and "
|
|
43
|
+
"are not confident that you will find the right match in the first few tries use "
|
|
44
|
+
"this agent to perform the search for you."
|
|
45
|
+
),
|
|
46
|
+
system_prompt_factory=lambda: _SYSTEM_PROMPT,
|
|
47
|
+
tool_filter=None,
|
|
48
|
+
tools_description="All tools",
|
|
49
|
+
default_max_steps=None,
|
|
50
|
+
allow_async=True,
|
|
51
|
+
tags={"general", "multi-step"},
|
|
52
|
+
)
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
def register(registry: SubagentRegistry) -> None:
|
|
56
|
+
"""将本内置类型注册到给定 registry(不做全局副作用)。"""
|
|
57
|
+
registry.register(GENERAL_PURPOSE_AGENT)
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
"""
|
|
2
|
+
tools/agent/built_in/plan.py — Plan 内置类型
|
|
3
|
+
|
|
4
|
+
职责:定义规划型 subagent,并提供偏规划场景工具过滤函数。
|
|
5
|
+
在整体链路中的位置:backend.assemble_tool_pool() 通过 config.tool_filter 生效。
|
|
6
|
+
CC 对照:src/tools/AgentTool/built-in/planAgent.ts。
|
|
7
|
+
当前裁剪范围:v1 禁 Agent/Edit/Bash,保留 Write 便于产出计划文本。
|
|
8
|
+
"""
|
|
9
|
+
|
|
10
|
+
from __future__ import annotations
|
|
11
|
+
|
|
12
|
+
from ..registry.config import SubagentConfig
|
|
13
|
+
from ..registry.registry import SubagentRegistry
|
|
14
|
+
|
|
15
|
+
_DISALLOWED = frozenset({"Agent", "agent", "Edit", "Write", "NotebookEdit"})
|
|
16
|
+
|
|
17
|
+
_SYSTEM_PROMPT = """You are a software architect and planning specialist for langchain_agentx. \
|
|
18
|
+
Your role is to explore the codebase and design implementation plans.
|
|
19
|
+
|
|
20
|
+
=== CRITICAL: READ-ONLY MODE - NO FILE MODIFICATIONS ===
|
|
21
|
+
This is a READ-ONLY planning task. You are STRICTLY PROHIBITED from:
|
|
22
|
+
- Creating new files (no Write, touch, or file creation of any kind)
|
|
23
|
+
- Modifying existing files (no Edit operations)
|
|
24
|
+
- Deleting, moving, or copying files
|
|
25
|
+
- Running ANY commands that change system state
|
|
26
|
+
|
|
27
|
+
Your role is EXCLUSIVELY to explore the codebase and design implementation plans.
|
|
28
|
+
|
|
29
|
+
## Your Process
|
|
30
|
+
|
|
31
|
+
1. **Understand Requirements**: Focus on the requirements provided throughout the design process.
|
|
32
|
+
|
|
33
|
+
2. **Explore Thoroughly**:
|
|
34
|
+
- Read any files provided to you in the initial prompt
|
|
35
|
+
- Find existing patterns and conventions using Glob, Grep, and Read
|
|
36
|
+
- Understand the current architecture
|
|
37
|
+
- Identify similar features as reference
|
|
38
|
+
- Trace through relevant code paths
|
|
39
|
+
- Use Bash ONLY for read-only operations (ls, git status, git log, git diff, find, cat, head, tail)
|
|
40
|
+
- NEVER use Bash for: mkdir, touch, rm, cp, mv, git add, git commit, or any file creation/modification
|
|
41
|
+
|
|
42
|
+
3. **Design Solution**:
|
|
43
|
+
- Create implementation approach based on existing patterns
|
|
44
|
+
- Consider trade-offs and architectural decisions
|
|
45
|
+
- Follow existing conventions where appropriate
|
|
46
|
+
|
|
47
|
+
4. **Detail the Plan**:
|
|
48
|
+
- Provide step-by-step implementation strategy
|
|
49
|
+
- Identify dependencies and sequencing
|
|
50
|
+
- Anticipate potential challenges
|
|
51
|
+
|
|
52
|
+
## Required Output
|
|
53
|
+
|
|
54
|
+
End your response with:
|
|
55
|
+
|
|
56
|
+
### Critical Files for Implementation
|
|
57
|
+
List 3-5 files most critical for implementing this plan:
|
|
58
|
+
- path/to/file1.py
|
|
59
|
+
- path/to/file2.py
|
|
60
|
+
|
|
61
|
+
REMEMBER: You can ONLY explore and plan. You CANNOT modify any files."""
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
def _plan_tool_filter(all_tools: list) -> list:
|
|
65
|
+
return [t for t in all_tools if getattr(t, "name", "") not in _DISALLOWED]
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
PLAN_AGENT = SubagentConfig(
|
|
69
|
+
name="Plan",
|
|
70
|
+
description=(
|
|
71
|
+
"Planning-focused agent for architecture decisions, implementation plans, "
|
|
72
|
+
"and scoped task decomposition."
|
|
73
|
+
),
|
|
74
|
+
when_to_use=(
|
|
75
|
+
"Software architect agent for designing implementation plans. "
|
|
76
|
+
"Use this when you need to plan the implementation strategy for a task. "
|
|
77
|
+
"Returns step-by-step plans, identifies critical files, and considers architectural trade-offs."
|
|
78
|
+
),
|
|
79
|
+
system_prompt_factory=lambda: _SYSTEM_PROMPT,
|
|
80
|
+
tool_filter=_plan_tool_filter,
|
|
81
|
+
tools_description="All tools except Agent/Edit/Write/NotebookEdit",
|
|
82
|
+
default_max_steps=None,
|
|
83
|
+
allow_async=False,
|
|
84
|
+
tags={"readonly", "planning"},
|
|
85
|
+
)
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
def register(registry: SubagentRegistry) -> None:
|
|
89
|
+
registry.register(PLAN_AGENT)
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
"""
|
|
2
|
+
tools/agent/built_in/statusline_setup.py — statusline-setup 内置类型
|
|
3
|
+
|
|
4
|
+
职责:定义状态栏配置型 subagent,专门处理 Claude Code `statusLine` 配置迁移与维护。
|
|
5
|
+
在整体链路中的位置:builtin_subagent_loader 在 CLI + BUILTIN_STATUSLINE 时调用 register()。
|
|
6
|
+
CC 对照:src/tools/AgentTool/built-in/statuslineSetup.ts。
|
|
7
|
+
当前裁剪范围:v3 对齐垂直场景职责,限定工具仅 Read/Edit。
|
|
8
|
+
|
|
9
|
+
典型使用场景:
|
|
10
|
+
1) 用户要求“配置/修改 Claude Code 状态栏”;
|
|
11
|
+
2) 用户要求“把 shell PS1 迁移到 statusLine.command”;
|
|
12
|
+
3) 用户要求显示模型名、当前目录、context 剩余、订阅限额等状态信息。
|
|
13
|
+
"""
|
|
14
|
+
|
|
15
|
+
from __future__ import annotations
|
|
16
|
+
|
|
17
|
+
from ..registry.config import SubagentConfig
|
|
18
|
+
from ..registry.registry import SubagentRegistry
|
|
19
|
+
|
|
20
|
+
_ALLOWED = frozenset({"Read", "Edit"})
|
|
21
|
+
|
|
22
|
+
_SYSTEM_PROMPT = """You are a statusline-setup specialist for Claude Code.
|
|
23
|
+
|
|
24
|
+
Your job is to configure or update the user's Claude Code status line setting.
|
|
25
|
+
|
|
26
|
+
Core responsibilities:
|
|
27
|
+
1. Read user shell config files (prefer: ~/.zshrc, ~/.bashrc, ~/.bash_profile, ~/.profile).
|
|
28
|
+
2. If asked to migrate PS1, extract PS1 and convert it to a statusLine command style.
|
|
29
|
+
3. Update ~/.claude/settings.json (if it is a symlink, update the target file).
|
|
30
|
+
4. For long commands, you may recommend storing command logic in ~/.claude/statusline-command.sh.
|
|
31
|
+
5. Summarize what was configured and remind the caller that future status line changes
|
|
32
|
+
should continue using this statusline-setup agent.
|
|
33
|
+
|
|
34
|
+
Expected output behavior:
|
|
35
|
+
- Return a concise configuration summary.
|
|
36
|
+
- Include the exact statusLine command/script path that was set.
|
|
37
|
+
- Mention any assumptions or missing inputs that block completion.
|
|
38
|
+
"""
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
def _statusline_tool_filter(all_tools: list) -> list:
|
|
42
|
+
return [t for t in all_tools if getattr(t, "name", "") in _ALLOWED]
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
STATUSLINE_SETUP_AGENT = SubagentConfig(
|
|
46
|
+
name="statusline-setup",
|
|
47
|
+
description=(
|
|
48
|
+
"Specialized subagent for Claude Code statusLine setup/migration "
|
|
49
|
+
"(PS1 -> statusLine.command) and settings update."
|
|
50
|
+
),
|
|
51
|
+
when_to_use=(
|
|
52
|
+
"Use this agent to configure or update the user's Claude Code status line setting. "
|
|
53
|
+
"Handles PS1 migration to statusLine.command and ~/.claude/settings.json updates."
|
|
54
|
+
),
|
|
55
|
+
system_prompt_factory=lambda: _SYSTEM_PROMPT,
|
|
56
|
+
tool_filter=_statusline_tool_filter,
|
|
57
|
+
tools_description="Read, Edit",
|
|
58
|
+
default_max_steps=None,
|
|
59
|
+
allow_async=False,
|
|
60
|
+
tags={"cli", "statusline"},
|
|
61
|
+
)
|
|
62
|
+
|
|
63
|
+
def register(registry: SubagentRegistry) -> None:
|
|
64
|
+
registry.register(STATUSLINE_SETUP_AGENT)
|