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,183 @@
|
|
|
1
|
+
"""event_emitter.py — OOP 统一事件发射器。"""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from dataclasses import dataclass
|
|
6
|
+
from typing import TYPE_CHECKING, Any, Optional
|
|
7
|
+
|
|
8
|
+
if TYPE_CHECKING:
|
|
9
|
+
from .collector import TraceCollector
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
@dataclass
|
|
13
|
+
class TraceEventEmitter:
|
|
14
|
+
"""Loop 节点事件发射器(面向对象)。"""
|
|
15
|
+
|
|
16
|
+
collector: "TraceCollector"
|
|
17
|
+
session_id: str
|
|
18
|
+
|
|
19
|
+
def emit_loop_decision_event(
|
|
20
|
+
self,
|
|
21
|
+
*,
|
|
22
|
+
decision: str,
|
|
23
|
+
selected_edge: str,
|
|
24
|
+
reason_code: str,
|
|
25
|
+
evidence: dict[str, Any],
|
|
26
|
+
node: str = "loop_controller",
|
|
27
|
+
) -> str:
|
|
28
|
+
return self.collector.emit_event(
|
|
29
|
+
session_id=self.session_id,
|
|
30
|
+
event_type="loop.decision",
|
|
31
|
+
payload={
|
|
32
|
+
"node": node,
|
|
33
|
+
"decision": decision,
|
|
34
|
+
"selected_edge": selected_edge,
|
|
35
|
+
"reason_code": reason_code,
|
|
36
|
+
"reason_text": _reason_code_to_text(reason_code),
|
|
37
|
+
"evidence": evidence,
|
|
38
|
+
},
|
|
39
|
+
)
|
|
40
|
+
|
|
41
|
+
def emit_task_event(
|
|
42
|
+
self,
|
|
43
|
+
*,
|
|
44
|
+
event_type: str,
|
|
45
|
+
batch_id: str,
|
|
46
|
+
command_ids: list[str],
|
|
47
|
+
**kwargs: Any,
|
|
48
|
+
) -> str:
|
|
49
|
+
return self.collector.emit_event(
|
|
50
|
+
session_id=self.session_id,
|
|
51
|
+
event_type=event_type,
|
|
52
|
+
payload={
|
|
53
|
+
"batch_id": batch_id,
|
|
54
|
+
"command_ids": command_ids,
|
|
55
|
+
**kwargs,
|
|
56
|
+
},
|
|
57
|
+
)
|
|
58
|
+
|
|
59
|
+
@classmethod
|
|
60
|
+
def from_state(cls, state: dict[str, Any]) -> Optional["TraceEventEmitter"]:
|
|
61
|
+
collector = _get_collector_from_state(state)
|
|
62
|
+
session_id = state.get("_run_id")
|
|
63
|
+
if not collector or not session_id:
|
|
64
|
+
return None
|
|
65
|
+
return cls(collector=collector, session_id=session_id)
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
def emit_loop_decision_event(
|
|
69
|
+
state: dict[str, Any],
|
|
70
|
+
decision: str,
|
|
71
|
+
selected_edge: str,
|
|
72
|
+
reason_code: str,
|
|
73
|
+
evidence: dict[str, Any],
|
|
74
|
+
) -> None:
|
|
75
|
+
"""
|
|
76
|
+
采集 loop.decision 事件。
|
|
77
|
+
|
|
78
|
+
Args:
|
|
79
|
+
state: Agent state(需包含 _trace_collector 和 _run_id)
|
|
80
|
+
decision: 决策类型(continue/call_tools/terminal/task_reconcile)
|
|
81
|
+
selected_edge: 选中的下一跳节点名
|
|
82
|
+
reason_code: 机器可读原因码(枚举)
|
|
83
|
+
evidence: 决策依据(结构化字段)
|
|
84
|
+
|
|
85
|
+
Example:
|
|
86
|
+
>>> emit_loop_decision_event(
|
|
87
|
+
... state=state,
|
|
88
|
+
... decision="call_tools",
|
|
89
|
+
... selected_edge="tools",
|
|
90
|
+
... reason_code="pending_tool_calls",
|
|
91
|
+
... evidence={"pending_tool_calls": 2, "step": 4},
|
|
92
|
+
... )
|
|
93
|
+
"""
|
|
94
|
+
emitter = TraceEventEmitter.from_state(state)
|
|
95
|
+
if emitter is None:
|
|
96
|
+
return
|
|
97
|
+
emitter.emit_loop_decision_event(
|
|
98
|
+
decision=decision,
|
|
99
|
+
selected_edge=selected_edge,
|
|
100
|
+
reason_code=reason_code,
|
|
101
|
+
evidence=evidence,
|
|
102
|
+
)
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
def emit_task_event(
|
|
106
|
+
state: dict[str, Any],
|
|
107
|
+
event_type: str,
|
|
108
|
+
batch_id: str,
|
|
109
|
+
command_ids: list[str],
|
|
110
|
+
**kwargs: Any,
|
|
111
|
+
) -> None:
|
|
112
|
+
"""
|
|
113
|
+
采集 task.reserve/ack 事件。
|
|
114
|
+
|
|
115
|
+
Args:
|
|
116
|
+
state: Agent state
|
|
117
|
+
event_type: 事件类型(task.reserve / task.ack)
|
|
118
|
+
batch_id: 批次 ID
|
|
119
|
+
command_ids: 命令 ID 列表
|
|
120
|
+
**kwargs: 其他字段(如 attachment_count)
|
|
121
|
+
|
|
122
|
+
Example:
|
|
123
|
+
>>> emit_task_event(
|
|
124
|
+
... state=state,
|
|
125
|
+
... event_type="task.reserve",
|
|
126
|
+
... batch_id="batch-123",
|
|
127
|
+
... command_ids=["cmd-1", "cmd-2"],
|
|
128
|
+
... attachment_count=2,
|
|
129
|
+
... )
|
|
130
|
+
"""
|
|
131
|
+
emitter = TraceEventEmitter.from_state(state)
|
|
132
|
+
if emitter is None:
|
|
133
|
+
return
|
|
134
|
+
emitter.emit_task_event(
|
|
135
|
+
event_type=event_type,
|
|
136
|
+
batch_id=batch_id,
|
|
137
|
+
command_ids=command_ids,
|
|
138
|
+
**kwargs,
|
|
139
|
+
)
|
|
140
|
+
|
|
141
|
+
|
|
142
|
+
def _get_collector_from_state(state: dict[str, Any]) -> Optional["TraceCollector"]:
|
|
143
|
+
"""
|
|
144
|
+
从 state 获取 collector。
|
|
145
|
+
|
|
146
|
+
Args:
|
|
147
|
+
state: Agent state
|
|
148
|
+
|
|
149
|
+
Returns:
|
|
150
|
+
TraceCollector 实例,如果不存在则返回 None
|
|
151
|
+
|
|
152
|
+
Note:
|
|
153
|
+
优雅降级:collector 不存在时返回 None,调用方应检查并跳过采集。
|
|
154
|
+
"""
|
|
155
|
+
return state.get("_trace_collector")
|
|
156
|
+
|
|
157
|
+
|
|
158
|
+
def _reason_code_to_text(reason_code: str) -> str:
|
|
159
|
+
"""
|
|
160
|
+
将 reason_code 转换为人可读文本。
|
|
161
|
+
|
|
162
|
+
Args:
|
|
163
|
+
reason_code: 机器可读原因码
|
|
164
|
+
|
|
165
|
+
Returns:
|
|
166
|
+
人可读说明文本
|
|
167
|
+
"""
|
|
168
|
+
reason_text_map = {
|
|
169
|
+
"middleware_jump_to": "Middleware requested jump",
|
|
170
|
+
"max_steps_force_final": "Max steps reached, forcing final response",
|
|
171
|
+
"should_end_terminal": "Loop decided to terminate",
|
|
172
|
+
"pending_tool_calls": "Tool calls pending execution",
|
|
173
|
+
"pending_task_notifications": "Task notifications pending",
|
|
174
|
+
"no_tools_and_not_continue": "No tools to call and not continuing",
|
|
175
|
+
}
|
|
176
|
+
return reason_text_map.get(reason_code, reason_code)
|
|
177
|
+
|
|
178
|
+
|
|
179
|
+
__all__ = [
|
|
180
|
+
"TraceEventEmitter",
|
|
181
|
+
"emit_loop_decision_event",
|
|
182
|
+
"emit_task_event",
|
|
183
|
+
]
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
"""
|
|
2
|
+
hook_event_emitter.py — Hook 执行记录写入 TraceCollector(Phase 3)。
|
|
3
|
+
|
|
4
|
+
职责:
|
|
5
|
+
接收 HookExecutionRecord 并写入 collector,供后续查询 hook_id/skip_reason/snapshot_id。
|
|
6
|
+
|
|
7
|
+
链路位置:
|
|
8
|
+
HookEngine 执行后(或 HookGraphWiring)调用本发射器。
|
|
9
|
+
|
|
10
|
+
当前裁剪范围:
|
|
11
|
+
仅处理结构化 record,不负责 Hook 执行或策略决策。
|
|
12
|
+
"""
|
|
13
|
+
|
|
14
|
+
from __future__ import annotations
|
|
15
|
+
|
|
16
|
+
from dataclasses import dataclass
|
|
17
|
+
|
|
18
|
+
from langchain_agentx.loop.hook.types import HookExecutionRecord
|
|
19
|
+
|
|
20
|
+
from .collector import TraceCollector
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
@dataclass
|
|
24
|
+
class HookEventEmitter:
|
|
25
|
+
"""Hook 执行记录发射器。"""
|
|
26
|
+
|
|
27
|
+
collector: TraceCollector
|
|
28
|
+
|
|
29
|
+
def emit_record(self, session_id: str, record: HookExecutionRecord) -> str:
|
|
30
|
+
return self.collector.emit_event(
|
|
31
|
+
session_id=session_id,
|
|
32
|
+
event_type="hook.execution",
|
|
33
|
+
payload={
|
|
34
|
+
"hook_id": record.hook_id,
|
|
35
|
+
"hook_event": record.hook_event,
|
|
36
|
+
"hook_source": record.hook_source,
|
|
37
|
+
"matcher": record.matcher,
|
|
38
|
+
"matched": record.matched,
|
|
39
|
+
"skip_reason": record.skip_reason,
|
|
40
|
+
"snapshot_id": record.snapshot_id,
|
|
41
|
+
"policy_source": record.policy_source,
|
|
42
|
+
"outcome": record.outcome,
|
|
43
|
+
"prevent_continuation": record.prevent_continuation,
|
|
44
|
+
"duration_ms": record.duration_ms,
|
|
45
|
+
},
|
|
46
|
+
)
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
__all__ = ["HookEventEmitter"]
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Trace 数据模型。
|
|
3
|
+
|
|
4
|
+
职责:
|
|
5
|
+
- 定义 TraceSession(一次 Agent 运行)
|
|
6
|
+
- 定义 TraceSpan(一次操作)
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
from dataclasses import dataclass, field
|
|
10
|
+
from typing import Any, Dict, List, Optional
|
|
11
|
+
from enum import Enum
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
class SpanType(str, Enum):
|
|
15
|
+
"""Span 类型枚举"""
|
|
16
|
+
AGENT_RUN = "agent_run"
|
|
17
|
+
LOOP_STEP = "loop_step"
|
|
18
|
+
LLM_CALL = "llm_call"
|
|
19
|
+
TOOL_CALL = "tool_call"
|
|
20
|
+
HOOK_EXEC = "hook_exec"
|
|
21
|
+
EXIT_LOGIC = "exit_logic"
|
|
22
|
+
COMPACTION = "compaction"
|
|
23
|
+
LOOP_DECISION = "loop_decision"
|
|
24
|
+
TASK_EVENT = "task_event"
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
class SpanStatus(str, Enum):
|
|
28
|
+
"""Span 状态"""
|
|
29
|
+
RUNNING = "running"
|
|
30
|
+
COMPLETED = "completed"
|
|
31
|
+
FAILED = "failed"
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
@dataclass
|
|
35
|
+
class TraceSpan:
|
|
36
|
+
"""一次操作的 trace span"""
|
|
37
|
+
|
|
38
|
+
span_id: str
|
|
39
|
+
session_id: str
|
|
40
|
+
parent_span_id: Optional[str]
|
|
41
|
+
span_type: SpanType
|
|
42
|
+
name: str
|
|
43
|
+
start_time: float
|
|
44
|
+
end_time: Optional[float] = None
|
|
45
|
+
latency_ms: Optional[float] = None
|
|
46
|
+
status: SpanStatus = SpanStatus.RUNNING
|
|
47
|
+
input_data: Optional[Dict[str, Any]] = None
|
|
48
|
+
output_data: Optional[Dict[str, Any]] = None
|
|
49
|
+
error: Optional[str] = None
|
|
50
|
+
metadata: Dict[str, Any] = field(default_factory=dict)
|
|
51
|
+
|
|
52
|
+
def to_dict(self) -> Dict[str, Any]:
|
|
53
|
+
"""转换为字典(用于 JSON 序列化)"""
|
|
54
|
+
return {
|
|
55
|
+
"span_id": self.span_id,
|
|
56
|
+
"session_id": self.session_id,
|
|
57
|
+
"parent_span_id": self.parent_span_id,
|
|
58
|
+
"span_type": self.span_type.value if isinstance(self.span_type, SpanType) else self.span_type,
|
|
59
|
+
"name": self.name,
|
|
60
|
+
"start_time": self.start_time,
|
|
61
|
+
"end_time": self.end_time,
|
|
62
|
+
"latency_ms": self.latency_ms,
|
|
63
|
+
"status": self.status.value if isinstance(self.status, SpanStatus) else self.status,
|
|
64
|
+
"input_data": self.input_data,
|
|
65
|
+
"output_data": self.output_data,
|
|
66
|
+
"error": self.error,
|
|
67
|
+
"metadata": self.metadata,
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
@dataclass
|
|
72
|
+
class TraceSession:
|
|
73
|
+
"""一次 Agent 运行的 trace session"""
|
|
74
|
+
|
|
75
|
+
session_id: str
|
|
76
|
+
user_query: Optional[str]
|
|
77
|
+
graph_name: str
|
|
78
|
+
start_time: float
|
|
79
|
+
conversation_session_id: str = ""
|
|
80
|
+
parent_session_id: Optional[str] = None # 父 run 的 session_id(子 Agent 场景)
|
|
81
|
+
parent_tool_call_id: Optional[str] = None # 触发本子 Agent 的 tool_call_id
|
|
82
|
+
workflow_id: Optional[str] = None # Workflow 聚合标识
|
|
83
|
+
unit_type: str = "main_loop" # main_loop / subagent / background
|
|
84
|
+
container_type: str = "agent_session" # agent_session / conversation / workflow / background
|
|
85
|
+
origin: str = "user" # user / tool / system
|
|
86
|
+
visibility: str = "default" # default / hidden / summary_only
|
|
87
|
+
end_time: Optional[float] = None
|
|
88
|
+
status: str = "running"
|
|
89
|
+
finish_reason: Optional[str] = None
|
|
90
|
+
exit_code: Optional[str] = None
|
|
91
|
+
terminal_reason: Optional[str] = None
|
|
92
|
+
loop_count: int = 0
|
|
93
|
+
total_input_tokens: int = 0
|
|
94
|
+
total_output_tokens: int = 0
|
|
95
|
+
total_latency_ms: float = 0.0
|
|
96
|
+
metadata: Dict[str, Any] = field(default_factory=dict)
|
|
97
|
+
|
|
98
|
+
def to_dict(self) -> Dict[str, Any]:
|
|
99
|
+
"""转换为字典(用于 JSON 序列化)"""
|
|
100
|
+
return {
|
|
101
|
+
"session_id": self.session_id,
|
|
102
|
+
"conversation_session_id": self.conversation_session_id,
|
|
103
|
+
"parent_session_id": self.parent_session_id,
|
|
104
|
+
"parent_tool_call_id": self.parent_tool_call_id,
|
|
105
|
+
"workflow_id": self.workflow_id,
|
|
106
|
+
"unit_type": self.unit_type,
|
|
107
|
+
"container_type": self.container_type,
|
|
108
|
+
"origin": self.origin,
|
|
109
|
+
"visibility": self.visibility,
|
|
110
|
+
"user_query": self.user_query,
|
|
111
|
+
"graph_name": self.graph_name,
|
|
112
|
+
"start_time": self.start_time,
|
|
113
|
+
"end_time": self.end_time,
|
|
114
|
+
"status": self.status,
|
|
115
|
+
"finish_reason": self.finish_reason,
|
|
116
|
+
"exit_code": self.exit_code,
|
|
117
|
+
"terminal_reason": self.terminal_reason,
|
|
118
|
+
"loop_count": self.loop_count,
|
|
119
|
+
"total_input_tokens": self.total_input_tokens,
|
|
120
|
+
"total_output_tokens": self.total_output_tokens,
|
|
121
|
+
"total_latency_ms": self.total_latency_ms,
|
|
122
|
+
"metadata": self.metadata,
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
|
|
126
|
+
@dataclass
|
|
127
|
+
class SessionBuffer:
|
|
128
|
+
"""Session 的内存缓冲区(flush 前暂存)"""
|
|
129
|
+
|
|
130
|
+
session: TraceSession
|
|
131
|
+
spans: List[TraceSpan] = field(default_factory=list)
|
|
132
|
+
span_stack: List[str] = field(default_factory=list) # 用于追踪当前 span 栈
|
|
133
|
+
next_seq_no: int = 1 # run 内事件顺序号(单调递增)
|
|
134
|
+
|
|
135
|
+
def add_span(self, span: TraceSpan) -> None:
|
|
136
|
+
"""添加 span"""
|
|
137
|
+
self.spans.append(span)
|
|
138
|
+
|
|
139
|
+
def get_span(self, span_id: str) -> Optional[TraceSpan]:
|
|
140
|
+
"""根据 span_id 获取 span"""
|
|
141
|
+
for span in self.spans:
|
|
142
|
+
if span.span_id == span_id:
|
|
143
|
+
return span
|
|
144
|
+
return None
|