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,258 @@
|
|
|
1
|
+
"""
|
|
2
|
+
evaluation/store.py — EvaluationStore,评估结果持久化。
|
|
3
|
+
|
|
4
|
+
职责:
|
|
5
|
+
使用独立 SQLite 存储评估结果与诊断报告。
|
|
6
|
+
|
|
7
|
+
链路位置:
|
|
8
|
+
由 EvaluationService 写入,供查询与诊断调度读取。
|
|
9
|
+
"""
|
|
10
|
+
|
|
11
|
+
from __future__ import annotations
|
|
12
|
+
|
|
13
|
+
import json
|
|
14
|
+
import sqlite3
|
|
15
|
+
import time
|
|
16
|
+
import os
|
|
17
|
+
from contextlib import contextmanager
|
|
18
|
+
from dataclasses import dataclass, field
|
|
19
|
+
from pathlib import Path
|
|
20
|
+
from typing import Any
|
|
21
|
+
|
|
22
|
+
from langchain_agentx.workspace import resolve_agent_workspace_config
|
|
23
|
+
from .checkers.base import CheckResult
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
@dataclass
|
|
27
|
+
class DiagnosticReport:
|
|
28
|
+
session_id: str
|
|
29
|
+
checker_names: list[str]
|
|
30
|
+
report: str
|
|
31
|
+
model: str
|
|
32
|
+
created_at: float = field(default_factory=time.time)
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
class EvaluationStore:
|
|
36
|
+
"""评估结果 SQLite 存储。独立于 TraceStore。"""
|
|
37
|
+
|
|
38
|
+
def __init__(self, db_path: str | Path) -> None:
|
|
39
|
+
self.db_path = str(db_path)
|
|
40
|
+
self._init_db()
|
|
41
|
+
|
|
42
|
+
@classmethod
|
|
43
|
+
def from_env(cls) -> "EvaluationStore":
|
|
44
|
+
"""从环境变量或 workspace 默认路径创建 EvaluationStore。"""
|
|
45
|
+
db_path = os.getenv("AGENTX_EVAL_DB_PATH")
|
|
46
|
+
if db_path:
|
|
47
|
+
return cls(db_path)
|
|
48
|
+
workspace_cfg = resolve_agent_workspace_config()
|
|
49
|
+
workspace_cfg.evaluation_db_path.parent.mkdir(parents=True, exist_ok=True)
|
|
50
|
+
return cls(workspace_cfg.evaluation_db_path)
|
|
51
|
+
|
|
52
|
+
@contextmanager
|
|
53
|
+
def _conn(self): # type: ignore[no-untyped-def]
|
|
54
|
+
conn = sqlite3.connect(self.db_path, check_same_thread=False)
|
|
55
|
+
conn.row_factory = sqlite3.Row
|
|
56
|
+
try:
|
|
57
|
+
yield conn
|
|
58
|
+
conn.commit()
|
|
59
|
+
finally:
|
|
60
|
+
conn.close()
|
|
61
|
+
|
|
62
|
+
def _init_db(self) -> None:
|
|
63
|
+
Path(self.db_path).parent.mkdir(parents=True, exist_ok=True)
|
|
64
|
+
with self._conn() as conn:
|
|
65
|
+
conn.execute("PRAGMA journal_mode=WAL")
|
|
66
|
+
conn.execute(
|
|
67
|
+
"""
|
|
68
|
+
CREATE TABLE IF NOT EXISTS evaluation_results (
|
|
69
|
+
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
70
|
+
session_id TEXT NOT NULL,
|
|
71
|
+
checker_name TEXT NOT NULL,
|
|
72
|
+
status TEXT NOT NULL,
|
|
73
|
+
message TEXT NOT NULL,
|
|
74
|
+
evidence TEXT,
|
|
75
|
+
created_at REAL NOT NULL
|
|
76
|
+
)
|
|
77
|
+
"""
|
|
78
|
+
)
|
|
79
|
+
conn.execute(
|
|
80
|
+
"""
|
|
81
|
+
CREATE TABLE IF NOT EXISTS diagnostic_reports (
|
|
82
|
+
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
83
|
+
session_id TEXT NOT NULL,
|
|
84
|
+
checker_names TEXT NOT NULL,
|
|
85
|
+
report TEXT NOT NULL,
|
|
86
|
+
model TEXT NOT NULL,
|
|
87
|
+
created_at REAL NOT NULL
|
|
88
|
+
)
|
|
89
|
+
"""
|
|
90
|
+
)
|
|
91
|
+
conn.execute("CREATE INDEX IF NOT EXISTS idx_eval_session ON evaluation_results(session_id)")
|
|
92
|
+
conn.execute("CREATE INDEX IF NOT EXISTS idx_eval_status ON evaluation_results(status)")
|
|
93
|
+
conn.execute("CREATE INDEX IF NOT EXISTS idx_diag_session ON diagnostic_reports(session_id)")
|
|
94
|
+
|
|
95
|
+
def save_results(self, session_id: str, results: list[CheckResult]) -> None:
|
|
96
|
+
now = time.time()
|
|
97
|
+
with self._conn() as conn:
|
|
98
|
+
conn.executemany(
|
|
99
|
+
(
|
|
100
|
+
"INSERT INTO evaluation_results("
|
|
101
|
+
"session_id,checker_name,status,message,evidence,created_at"
|
|
102
|
+
") VALUES(?,?,?,?,?,?)"
|
|
103
|
+
),
|
|
104
|
+
[
|
|
105
|
+
(
|
|
106
|
+
session_id,
|
|
107
|
+
result.checker_name,
|
|
108
|
+
result.status,
|
|
109
|
+
result.message,
|
|
110
|
+
json.dumps(result.evidence),
|
|
111
|
+
now,
|
|
112
|
+
)
|
|
113
|
+
for result in results
|
|
114
|
+
],
|
|
115
|
+
)
|
|
116
|
+
|
|
117
|
+
def save_diagnostic_report(self, report: DiagnosticReport) -> None:
|
|
118
|
+
with self._conn() as conn:
|
|
119
|
+
conn.execute(
|
|
120
|
+
(
|
|
121
|
+
"INSERT INTO diagnostic_reports("
|
|
122
|
+
"session_id,checker_names,report,model,created_at"
|
|
123
|
+
") VALUES(?,?,?,?,?)"
|
|
124
|
+
),
|
|
125
|
+
(
|
|
126
|
+
report.session_id,
|
|
127
|
+
json.dumps(report.checker_names),
|
|
128
|
+
report.report,
|
|
129
|
+
report.model,
|
|
130
|
+
report.created_at,
|
|
131
|
+
),
|
|
132
|
+
)
|
|
133
|
+
|
|
134
|
+
def get_results(self, session_id: str) -> list[CheckResult]:
|
|
135
|
+
with self._conn() as conn:
|
|
136
|
+
rows = conn.execute(
|
|
137
|
+
(
|
|
138
|
+
"SELECT checker_name,status,message,evidence "
|
|
139
|
+
"FROM evaluation_results WHERE session_id=? ORDER BY id"
|
|
140
|
+
),
|
|
141
|
+
(session_id,),
|
|
142
|
+
).fetchall()
|
|
143
|
+
return [
|
|
144
|
+
CheckResult(
|
|
145
|
+
checker_name=row["checker_name"],
|
|
146
|
+
status=row["status"],
|
|
147
|
+
message=row["message"],
|
|
148
|
+
evidence=json.loads(row["evidence"] or "{}"),
|
|
149
|
+
)
|
|
150
|
+
for row in rows
|
|
151
|
+
]
|
|
152
|
+
|
|
153
|
+
def get_recent_failures(self, limit: int = 20) -> list[dict[str, Any]]:
|
|
154
|
+
with self._conn() as conn:
|
|
155
|
+
rows = conn.execute(
|
|
156
|
+
(
|
|
157
|
+
"SELECT session_id,checker_name,message,evidence,created_at "
|
|
158
|
+
"FROM evaluation_results WHERE status='fail' "
|
|
159
|
+
"ORDER BY created_at DESC LIMIT ?"
|
|
160
|
+
),
|
|
161
|
+
(limit,),
|
|
162
|
+
).fetchall()
|
|
163
|
+
return [dict(row) for row in rows]
|
|
164
|
+
|
|
165
|
+
def get_failure_sessions(self, limit: int = 20) -> list[dict[str, Any]]:
|
|
166
|
+
"""按 session 聚合返回失败会话摘要。"""
|
|
167
|
+
with self._conn() as conn:
|
|
168
|
+
rows = conn.execute(
|
|
169
|
+
"""
|
|
170
|
+
SELECT
|
|
171
|
+
e.session_id AS session_id,
|
|
172
|
+
COUNT(*) AS fail_count,
|
|
173
|
+
MIN(e.created_at) AS first_failed_at,
|
|
174
|
+
MAX(e.created_at) AS last_failed_at,
|
|
175
|
+
GROUP_CONCAT(DISTINCT e.checker_name) AS checker_names
|
|
176
|
+
FROM evaluation_results e
|
|
177
|
+
WHERE e.status='fail'
|
|
178
|
+
GROUP BY e.session_id
|
|
179
|
+
ORDER BY last_failed_at DESC
|
|
180
|
+
LIMIT ?
|
|
181
|
+
""",
|
|
182
|
+
(limit,),
|
|
183
|
+
).fetchall()
|
|
184
|
+
items: list[dict[str, Any]] = []
|
|
185
|
+
for row in rows:
|
|
186
|
+
checker_names = str(row["checker_names"] or "")
|
|
187
|
+
items.append(
|
|
188
|
+
{
|
|
189
|
+
"session_id": row["session_id"],
|
|
190
|
+
"fail_count": int(row["fail_count"] or 0),
|
|
191
|
+
"first_failed_at": row["first_failed_at"],
|
|
192
|
+
"last_failed_at": row["last_failed_at"],
|
|
193
|
+
"checker_names": [name for name in checker_names.split(",") if name],
|
|
194
|
+
}
|
|
195
|
+
)
|
|
196
|
+
return items
|
|
197
|
+
|
|
198
|
+
def get_diagnostic_report(self, session_id: str) -> DiagnosticReport | None:
|
|
199
|
+
with self._conn() as conn:
|
|
200
|
+
row = conn.execute(
|
|
201
|
+
"SELECT * FROM diagnostic_reports WHERE session_id=? ORDER BY created_at DESC LIMIT 1",
|
|
202
|
+
(session_id,),
|
|
203
|
+
).fetchone()
|
|
204
|
+
if row is None:
|
|
205
|
+
return None
|
|
206
|
+
return DiagnosticReport(
|
|
207
|
+
session_id=row["session_id"],
|
|
208
|
+
checker_names=json.loads(row["checker_names"]),
|
|
209
|
+
report=row["report"],
|
|
210
|
+
model=row["model"],
|
|
211
|
+
created_at=row["created_at"],
|
|
212
|
+
)
|
|
213
|
+
|
|
214
|
+
def has_unanalyzed_failures(self, session_id: str) -> bool:
|
|
215
|
+
"""判断指定 session 是否有 fail 且尚无诊断报告。"""
|
|
216
|
+
with self._conn() as conn:
|
|
217
|
+
fail_count = conn.execute(
|
|
218
|
+
"SELECT COUNT(*) FROM evaluation_results WHERE session_id=? AND status='fail'",
|
|
219
|
+
(session_id,),
|
|
220
|
+
).fetchone()[0]
|
|
221
|
+
if fail_count == 0:
|
|
222
|
+
return False
|
|
223
|
+
report_count = conn.execute(
|
|
224
|
+
"SELECT COUNT(*) FROM diagnostic_reports WHERE session_id=?",
|
|
225
|
+
(session_id,),
|
|
226
|
+
).fetchone()[0]
|
|
227
|
+
return report_count == 0
|
|
228
|
+
|
|
229
|
+
def get_sessions_needing_analysis(self, limit: int = 50) -> list[str]:
|
|
230
|
+
"""返回有 fail 但无诊断报告的 session_id 列表。"""
|
|
231
|
+
with self._conn() as conn:
|
|
232
|
+
rows = conn.execute(
|
|
233
|
+
"""
|
|
234
|
+
SELECT DISTINCT e.session_id
|
|
235
|
+
FROM evaluation_results e
|
|
236
|
+
WHERE e.status = 'fail'
|
|
237
|
+
AND NOT EXISTS (
|
|
238
|
+
SELECT 1 FROM diagnostic_reports d WHERE d.session_id = e.session_id
|
|
239
|
+
)
|
|
240
|
+
ORDER BY e.created_at DESC
|
|
241
|
+
LIMIT ?
|
|
242
|
+
""",
|
|
243
|
+
(limit,),
|
|
244
|
+
).fetchall()
|
|
245
|
+
return [row["session_id"] for row in rows]
|
|
246
|
+
|
|
247
|
+
def cleanup_old_reports(self, *, days: int = 180) -> int:
|
|
248
|
+
"""按 ``created_at``(REAL,Unix 秒)删除早于 ``days`` 天的 ``diagnostic_reports`` 行。"""
|
|
249
|
+
cutoff = time.time() - float(days) * 24.0 * 3600.0
|
|
250
|
+
with self._conn() as conn:
|
|
251
|
+
cur = conn.execute(
|
|
252
|
+
"DELETE FROM diagnostic_reports WHERE created_at < ?",
|
|
253
|
+
(cutoff,),
|
|
254
|
+
)
|
|
255
|
+
return int(cur.rowcount or 0)
|
|
256
|
+
|
|
257
|
+
|
|
258
|
+
__all__ = ["EvaluationStore", "DiagnosticReport"]
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"""Agent utilities for LangChain AgentX."""
|
|
2
|
+
|
|
3
|
+
from .langchain_agentx_event_adapter import (
|
|
4
|
+
LangchainAgentEventType,
|
|
5
|
+
LangchainAgentEvent,
|
|
6
|
+
EventAdapterState,
|
|
7
|
+
LangGraphToLangchainAgentEventAdapter,
|
|
8
|
+
)
|
|
9
|
+
|
|
10
|
+
__all__ = [
|
|
11
|
+
"LangchainAgentEventType",
|
|
12
|
+
"LangchainAgentEvent",
|
|
13
|
+
"EventAdapterState",
|
|
14
|
+
"LangGraphToLangchainAgentEventAdapter",
|
|
15
|
+
]
|