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,278 @@
|
|
|
1
|
+
"""
|
|
2
|
+
runtime/observability.py — 运行时可观测性总线与回放存储
|
|
3
|
+
|
|
4
|
+
职责:
|
|
5
|
+
定义跨工具统一的可观测契约与存储策略,包括:
|
|
6
|
+
- schema 常量与归因字典(reason/layer)
|
|
7
|
+
- 分级脱敏与采样策略
|
|
8
|
+
- tool_call 级回放索引(内存 + 日期分片 JSONL)
|
|
9
|
+
- 历史分片 gzip 归档、TTL 与容量清理
|
|
10
|
+
- 查询过滤(tool_name/status/time range)
|
|
11
|
+
|
|
12
|
+
OOP 边界:
|
|
13
|
+
- `ObservabilityTraceStore` 作为状态封装对象,负责持久化与查询;
|
|
14
|
+
- 顶层函数(sanitize/sample)保持纯函数,作为策略协作者供 store/adapter 复用;
|
|
15
|
+
- adapter/pipeline 只调用公共接口,不直接操作底层文件格式。
|
|
16
|
+
|
|
17
|
+
与 CC 对比:
|
|
18
|
+
CC 有更完整的 tracing/decision 链路。本实现在 Runtime 层建立统一总线,
|
|
19
|
+
让不同工具共享同一观测模型,避免“每个工具各自打点”。
|
|
20
|
+
"""
|
|
21
|
+
|
|
22
|
+
from __future__ import annotations
|
|
23
|
+
|
|
24
|
+
import json
|
|
25
|
+
import os
|
|
26
|
+
import time
|
|
27
|
+
import gzip
|
|
28
|
+
from dataclasses import dataclass
|
|
29
|
+
from datetime import datetime, timezone
|
|
30
|
+
from pathlib import Path
|
|
31
|
+
from typing import Any
|
|
32
|
+
|
|
33
|
+
from langchain_agentx.workspace import resolve_agent_workspace_config
|
|
34
|
+
|
|
35
|
+
OBS_SCHEMA_VERSION = "runtime-observability/v1"
|
|
36
|
+
|
|
37
|
+
REASON_CODES = frozenset(
|
|
38
|
+
{
|
|
39
|
+
"long_timeout_policy",
|
|
40
|
+
"explicit_request",
|
|
41
|
+
"sandbox_not_requested",
|
|
42
|
+
"excluded_command",
|
|
43
|
+
"permission_denied",
|
|
44
|
+
"manual_approval_required",
|
|
45
|
+
}
|
|
46
|
+
)
|
|
47
|
+
|
|
48
|
+
DECISION_LAYERS = frozenset(
|
|
49
|
+
{
|
|
50
|
+
"mode_preflight",
|
|
51
|
+
"hardening_command",
|
|
52
|
+
"ast_guard",
|
|
53
|
+
"segment",
|
|
54
|
+
"mode_finalize",
|
|
55
|
+
"segment_single",
|
|
56
|
+
}
|
|
57
|
+
)
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
def _compile_extra_keywords() -> tuple[str, ...]:
|
|
61
|
+
base = ["token", "password", "secret", "key=", "authorization", "cookie", "sessionid"]
|
|
62
|
+
path = os.getenv("AGENTX_OBSERVABILITY_REDACTION_RULES_FILE")
|
|
63
|
+
if not path:
|
|
64
|
+
return tuple(base)
|
|
65
|
+
try:
|
|
66
|
+
with open(os.path.expanduser(path), encoding="utf-8") as f:
|
|
67
|
+
payload = json.load(f)
|
|
68
|
+
except Exception:
|
|
69
|
+
return tuple(base)
|
|
70
|
+
extra = payload.get("keywords", []) if isinstance(payload, dict) else []
|
|
71
|
+
for kw in extra:
|
|
72
|
+
if isinstance(kw, str) and kw:
|
|
73
|
+
base.append(kw.lower())
|
|
74
|
+
return tuple(dict.fromkeys(base))
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
_REDACTION_KEYWORDS = _compile_extra_keywords()
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
def sanitize_value(value: Any, *, level: str = "standard") -> Any:
|
|
81
|
+
"""
|
|
82
|
+
level:
|
|
83
|
+
- strict: 对字符串更激进裁剪与脱敏
|
|
84
|
+
- standard: 默认
|
|
85
|
+
- dev: 仅截断,不脱敏(便于本地排障)
|
|
86
|
+
"""
|
|
87
|
+
if isinstance(value, str):
|
|
88
|
+
lowered = value.lower()
|
|
89
|
+
if level != "dev" and any(k in lowered for k in _REDACTION_KEYWORDS):
|
|
90
|
+
return "<redacted>"
|
|
91
|
+
max_len = 120 if level == "strict" else 180
|
|
92
|
+
if len(value) > max_len:
|
|
93
|
+
return value[:max_len] + "...(truncated)"
|
|
94
|
+
if isinstance(value, dict):
|
|
95
|
+
return {k: sanitize_value(v, level=level) for k, v in value.items()}
|
|
96
|
+
if isinstance(value, list):
|
|
97
|
+
return [sanitize_value(v, level=level) for v in value]
|
|
98
|
+
return value
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
def sample_events(events: list[dict[str, Any]], *, limit: int = 200) -> list[dict[str, Any]]:
|
|
102
|
+
if limit <= 0 or len(events) <= limit:
|
|
103
|
+
return events
|
|
104
|
+
head = max(1, limit // 2)
|
|
105
|
+
tail = max(1, limit - head)
|
|
106
|
+
sampled = events[:head] + events[-tail:]
|
|
107
|
+
sampled.insert(
|
|
108
|
+
head,
|
|
109
|
+
{"event": "events_sampled", "dropped_count": len(events) - len(sampled)},
|
|
110
|
+
)
|
|
111
|
+
return sampled
|
|
112
|
+
|
|
113
|
+
|
|
114
|
+
@dataclass
|
|
115
|
+
class ObservabilityTraceStore:
|
|
116
|
+
_records: dict[str, dict[str, Any]]
|
|
117
|
+
|
|
118
|
+
def __init__(self) -> None:
|
|
119
|
+
self._records = {}
|
|
120
|
+
workspace_cfg = resolve_agent_workspace_config()
|
|
121
|
+
self._root_dir = Path(
|
|
122
|
+
os.path.expanduser(
|
|
123
|
+
os.getenv(
|
|
124
|
+
"AGENTX_OBSERVABILITY_ROOT",
|
|
125
|
+
str(workspace_cfg.data_dir / "observability"),
|
|
126
|
+
)
|
|
127
|
+
)
|
|
128
|
+
)
|
|
129
|
+
self._max_records = int(os.getenv("AGENTX_OBSERVABILITY_MAX_RECORDS", "2000"))
|
|
130
|
+
self._ttl_sec = int(os.getenv("AGENTX_OBSERVABILITY_TTL_SEC", "86400"))
|
|
131
|
+
self._redaction_level = os.getenv("AGENTX_OBSERVABILITY_REDACTION_LEVEL", "standard")
|
|
132
|
+
self._archive_after_days = int(os.getenv("AGENTX_OBSERVABILITY_ARCHIVE_AFTER_DAYS", "3"))
|
|
133
|
+
self._root_dir.mkdir(parents=True, exist_ok=True)
|
|
134
|
+
|
|
135
|
+
def put(self, tool_call_id: str | None, record: dict[str, Any]) -> None:
|
|
136
|
+
if not tool_call_id:
|
|
137
|
+
return
|
|
138
|
+
now_ts = int(time.time())
|
|
139
|
+
safe_record = sanitize_value(
|
|
140
|
+
{
|
|
141
|
+
"saved_at_ts": now_ts,
|
|
142
|
+
**record,
|
|
143
|
+
},
|
|
144
|
+
level=self._redaction_level,
|
|
145
|
+
)
|
|
146
|
+
self._records[tool_call_id] = safe_record
|
|
147
|
+
self._append_sharded_jsonl(tool_call_id, safe_record)
|
|
148
|
+
self._prune()
|
|
149
|
+
self._archive_old_shards()
|
|
150
|
+
|
|
151
|
+
def get(self, tool_call_id: str) -> dict[str, Any] | None:
|
|
152
|
+
return self._records.get(tool_call_id)
|
|
153
|
+
|
|
154
|
+
def all_keys(self) -> list[str]:
|
|
155
|
+
return list(self._records.keys())
|
|
156
|
+
|
|
157
|
+
def tail_events(self, tool_call_id: str, offset: int = 0) -> tuple[list[dict[str, Any]], int]:
|
|
158
|
+
record = self._records.get(tool_call_id) or self._load_last_from_jsonl(tool_call_id)
|
|
159
|
+
if not record:
|
|
160
|
+
return [], offset
|
|
161
|
+
events = (((record.get("observability") or {}).get("events")) or [])
|
|
162
|
+
if not isinstance(events, list):
|
|
163
|
+
return [], offset
|
|
164
|
+
safe_offset = max(0, offset)
|
|
165
|
+
chunk = events[safe_offset:]
|
|
166
|
+
return chunk, safe_offset + len(chunk)
|
|
167
|
+
|
|
168
|
+
def query(
|
|
169
|
+
self,
|
|
170
|
+
*,
|
|
171
|
+
tool_name: str | None = None,
|
|
172
|
+
status: str | None = None,
|
|
173
|
+
start_ts: int | None = None,
|
|
174
|
+
end_ts: int | None = None,
|
|
175
|
+
limit: int = 200,
|
|
176
|
+
) -> list[dict[str, Any]]:
|
|
177
|
+
rows = list(self._records.values())
|
|
178
|
+
rows.sort(key=lambda r: int(r.get("saved_at_ts", 0)), reverse=True)
|
|
179
|
+
out: list[dict[str, Any]] = []
|
|
180
|
+
for r in rows:
|
|
181
|
+
ts = int(r.get("saved_at_ts", 0))
|
|
182
|
+
if tool_name and r.get("tool_name") != tool_name:
|
|
183
|
+
continue
|
|
184
|
+
if status and r.get("status") != status:
|
|
185
|
+
continue
|
|
186
|
+
if start_ts is not None and ts < start_ts:
|
|
187
|
+
continue
|
|
188
|
+
if end_ts is not None and ts > end_ts:
|
|
189
|
+
continue
|
|
190
|
+
out.append(r)
|
|
191
|
+
if len(out) >= limit:
|
|
192
|
+
break
|
|
193
|
+
return out
|
|
194
|
+
|
|
195
|
+
def _current_shard_path(self) -> Path:
|
|
196
|
+
day = datetime.now(timezone.utc).strftime("%Y-%m-%d")
|
|
197
|
+
return self._root_dir / f"replay-{day}.jsonl"
|
|
198
|
+
|
|
199
|
+
def _append_sharded_jsonl(self, tool_call_id: str, record: dict[str, Any]) -> None:
|
|
200
|
+
path = self._current_shard_path()
|
|
201
|
+
line = json.dumps(
|
|
202
|
+
{"tool_call_id": tool_call_id, "record": record},
|
|
203
|
+
ensure_ascii=False,
|
|
204
|
+
)
|
|
205
|
+
with open(path, "a", encoding="utf-8") as f:
|
|
206
|
+
f.write(line + "\n")
|
|
207
|
+
|
|
208
|
+
def _load_last_from_jsonl(self, tool_call_id: str) -> dict[str, Any] | None:
|
|
209
|
+
last: dict[str, Any] | None = None
|
|
210
|
+
for path in sorted(self._root_dir.glob("replay-*.jsonl")):
|
|
211
|
+
with open(path, encoding="utf-8") as f:
|
|
212
|
+
for line in f:
|
|
213
|
+
line = line.strip()
|
|
214
|
+
if not line:
|
|
215
|
+
continue
|
|
216
|
+
try:
|
|
217
|
+
data = json.loads(line)
|
|
218
|
+
except json.JSONDecodeError:
|
|
219
|
+
continue
|
|
220
|
+
if data.get("tool_call_id") == tool_call_id:
|
|
221
|
+
rec = data.get("record")
|
|
222
|
+
if isinstance(rec, dict):
|
|
223
|
+
last = rec
|
|
224
|
+
return last
|
|
225
|
+
|
|
226
|
+
def _prune(self) -> None:
|
|
227
|
+
if not self._records:
|
|
228
|
+
return
|
|
229
|
+
now_ts = int(time.time())
|
|
230
|
+
keys = list(self._records.keys())
|
|
231
|
+
for k in keys:
|
|
232
|
+
ts = int(self._records[k].get("saved_at_ts", now_ts))
|
|
233
|
+
if now_ts - ts > self._ttl_sec:
|
|
234
|
+
self._records.pop(k, None)
|
|
235
|
+
if len(self._records) <= self._max_records:
|
|
236
|
+
return
|
|
237
|
+
ordered = sorted(
|
|
238
|
+
self._records.items(),
|
|
239
|
+
key=lambda kv: int((kv[1] or {}).get("saved_at_ts", 0)),
|
|
240
|
+
)
|
|
241
|
+
drop_n = max(0, len(ordered) - self._max_records)
|
|
242
|
+
for i in range(drop_n):
|
|
243
|
+
self._records.pop(ordered[i][0], None)
|
|
244
|
+
|
|
245
|
+
def _archive_old_shards(self) -> None:
|
|
246
|
+
cutoff_days = self._archive_after_days
|
|
247
|
+
if cutoff_days <= 0:
|
|
248
|
+
return
|
|
249
|
+
now = datetime.now(timezone.utc).date()
|
|
250
|
+
for path in self._root_dir.glob("replay-*.jsonl"):
|
|
251
|
+
name = path.name.replace("replay-", "").replace(".jsonl", "")
|
|
252
|
+
try:
|
|
253
|
+
shard_day = datetime.strptime(name, "%Y-%m-%d").date()
|
|
254
|
+
except ValueError:
|
|
255
|
+
continue
|
|
256
|
+
if (now - shard_day).days < cutoff_days:
|
|
257
|
+
continue
|
|
258
|
+
gz_path = path.with_suffix(".jsonl.gz")
|
|
259
|
+
if gz_path.exists():
|
|
260
|
+
try:
|
|
261
|
+
path.unlink()
|
|
262
|
+
except OSError:
|
|
263
|
+
pass
|
|
264
|
+
continue
|
|
265
|
+
try:
|
|
266
|
+
with open(path, "rb") as src, gzip.open(gz_path, "wb") as dst:
|
|
267
|
+
dst.write(src.read())
|
|
268
|
+
path.unlink()
|
|
269
|
+
except OSError:
|
|
270
|
+
continue
|
|
271
|
+
|
|
272
|
+
|
|
273
|
+
_GLOBAL_TRACE_STORE = ObservabilityTraceStore()
|
|
274
|
+
|
|
275
|
+
|
|
276
|
+
def get_global_trace_store() -> ObservabilityTraceStore:
|
|
277
|
+
return _GLOBAL_TRACE_STORE
|
|
278
|
+
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"""
|
|
2
|
+
runtime/observability_ui.py — 可观测性 UI 投影适配器
|
|
3
|
+
|
|
4
|
+
职责:
|
|
5
|
+
将 replay 记录映射为前端可渲染的时间线结构(decision + event),
|
|
6
|
+
作为 UI 层与 runtime 观测数据之间的协议转换层。
|
|
7
|
+
|
|
8
|
+
OOP 边界:
|
|
9
|
+
- 该模块只做数据投影,不参与存储与查询;
|
|
10
|
+
- 输入为 replay record,输出为 UI timeline DTO;
|
|
11
|
+
- 可被 Web/桌面/CLI TUI 多端复用。
|
|
12
|
+
|
|
13
|
+
与 CC 对比:
|
|
14
|
+
对齐 CC 中“执行轨迹 + 决策归因”的可视化呈现方向,
|
|
15
|
+
保持视图层与存储层解耦。
|
|
16
|
+
"""
|
|
17
|
+
|
|
18
|
+
from __future__ import annotations
|
|
19
|
+
|
|
20
|
+
from typing import Any
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
def to_ui_timeline(record: dict[str, Any] | None) -> list[dict[str, Any]]:
|
|
24
|
+
if not record:
|
|
25
|
+
return []
|
|
26
|
+
items: list[dict[str, Any]] = []
|
|
27
|
+
for d in record.get("decision_trace", []):
|
|
28
|
+
items.append(
|
|
29
|
+
{
|
|
30
|
+
"kind": "decision",
|
|
31
|
+
"title": f"{d.get('layer')} -> {d.get('behavior')}",
|
|
32
|
+
"policy_id": d.get("policy_id"),
|
|
33
|
+
"command": d.get("command"),
|
|
34
|
+
}
|
|
35
|
+
)
|
|
36
|
+
events = (((record.get("observability") or {}).get("events")) or [])
|
|
37
|
+
for ev in events:
|
|
38
|
+
items.append(
|
|
39
|
+
{
|
|
40
|
+
"kind": "event",
|
|
41
|
+
"title": ev.get("event"),
|
|
42
|
+
"seq": ev.get("seq"),
|
|
43
|
+
"payload": {k: v for k, v in ev.items() if k not in {"seq", "event"}},
|
|
44
|
+
}
|
|
45
|
+
)
|
|
46
|
+
return items
|
|
47
|
+
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Trace 系统:全链路可观测性。
|
|
3
|
+
|
|
4
|
+
核心组件:
|
|
5
|
+
- TraceCollector: 采集 + 查询
|
|
6
|
+
- TraceLifecycleCollector / TraceCallbackHandler: 生命周期与 LLM/Tool 采集
|
|
7
|
+
- SqliteTraceStore: 持久化存储
|
|
8
|
+
"""
|
|
9
|
+
|
|
10
|
+
from .models import TraceSession, TraceSpan
|
|
11
|
+
from .collector import TraceCollector
|
|
12
|
+
from .sqlite_store import SqliteTraceStore
|
|
13
|
+
from .trace_lifecycle_collector import TraceLifecycleCollector
|
|
14
|
+
from .trace_callback import TraceCallbackHandler
|
|
15
|
+
from .hook_event_emitter import HookEventEmitter
|
|
16
|
+
|
|
17
|
+
__all__ = [
|
|
18
|
+
"TraceSession",
|
|
19
|
+
"TraceSpan",
|
|
20
|
+
"TraceCollector",
|
|
21
|
+
"SqliteTraceStore",
|
|
22
|
+
"TraceLifecycleCollector",
|
|
23
|
+
"TraceCallbackHandler",
|
|
24
|
+
"HookEventEmitter",
|
|
25
|
+
]
|