@octopi-agent/engine 0.70.7 → 0.90.11
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.
- package/LICENSE +201 -201
- package/NOTICE +7 -7
- package/README.md +64 -26
- package/dist/config-schema/agent.d.ts +89 -1
- package/dist/config-schema/agent.js +81 -5
- package/dist/config-schema/context.d.ts +24 -5
- package/dist/config-schema/context.js +28 -1
- package/dist/config-schema/engine.d.ts +205 -13
- package/dist/config-schema/engine.js +31 -2
- package/dist/config-schema/governance.d.ts +95 -0
- package/dist/config-schema/governance.js +93 -1
- package/dist/config-schema/models.d.ts +3 -3
- package/dist/config-schema/observability.d.ts +6 -0
- package/dist/config-schema/observability.js +16 -0
- package/dist/config-schema/run.d.ts +10 -0
- package/dist/config-schema/run.js +18 -0
- package/dist/config-schema/shared.d.ts +13 -0
- package/dist/config-schema/shared.js +22 -0
- package/dist/config-schema/substrate.d.ts +2 -2
- package/dist/config-schema/subsystems.d.ts +1 -1
- package/dist/config-schema/subsystems.js +2 -1
- package/dist/config.d.ts +201 -8
- package/dist/config.js +105 -3
- package/dist/harness/activation/compiler.js +3 -0
- package/dist/harness/activation/runtime.d.ts +7 -0
- package/dist/harness/activation/runtime.js +60 -2
- package/dist/harness/activation/sources/agent-signal.d.ts +11 -0
- package/dist/harness/activation/sources/agent-signal.js +33 -0
- package/dist/harness/activation/types.d.ts +6 -1
- package/dist/harness/agent/builder.d.ts +50 -5
- package/dist/harness/agent/builder.js +189 -59
- package/dist/harness/agent/config-bridge.d.ts +33 -25
- package/dist/harness/agent/config-bridge.js +84 -291
- package/dist/harness/agent/index.d.ts +3 -1
- package/dist/harness/agent/index.js +2 -1
- package/dist/harness/agent/tool-purpose.d.ts +46 -0
- package/dist/harness/agent/tool-purpose.js +127 -0
- package/dist/harness/agent/wire-agent-builder.d.ts +133 -0
- package/dist/harness/agent/wire-agent-builder.js +370 -0
- package/dist/harness/collaboration/autonomous-subsystem/boundary/validator.d.ts +11 -1
- package/dist/harness/collaboration/autonomous-subsystem/boundary/validator.js +11 -1
- package/dist/harness/collaboration/autonomous-subsystem/loader.d.ts +13 -0
- package/dist/harness/collaboration/autonomous-subsystem/loader.js +16 -1
- package/dist/harness/collaboration/autonomous-subsystem/runtime.d.ts +8 -1
- package/dist/harness/collaboration/autonomous-subsystem/runtime.js +17 -9
- package/dist/harness/collaboration/autonomous-subsystem/sense/metrics.d.ts +12 -0
- package/dist/harness/collaboration/autonomous-subsystem/sense/metrics.js +19 -0
- package/dist/harness/collaboration/autonomous-subsystem/sense/session-lifecycle-bridge.d.ts +6 -0
- package/dist/harness/collaboration/autonomous-subsystem/sense/session-lifecycle-bridge.js +24 -7
- package/dist/harness/collaboration/autonomous-subsystem/think/executor.d.ts +5 -2
- package/dist/harness/collaboration/autonomous-subsystem/think/executor.js +11 -3
- package/dist/harness/collaboration/autonomous-subsystem/think/index.d.ts +1 -1
- package/dist/harness/collaboration/autonomous-subsystem/think/index.js +1 -1
- package/dist/harness/collaboration/autonomous-subsystem/think/llm-port.d.ts +7 -4
- package/dist/harness/collaboration/autonomous-subsystem/think/llm-port.js +8 -9
- package/dist/harness/collaboration/autonomous-subsystem/think/model-resolver.d.ts +36 -10
- package/dist/harness/collaboration/autonomous-subsystem/think/model-resolver.js +60 -7
- package/dist/harness/collaboration/delegation/child-run.d.ts +144 -0
- package/dist/harness/collaboration/delegation/child-run.js +241 -0
- package/dist/harness/collaboration/delegation/index.d.ts +26 -0
- package/dist/harness/collaboration/delegation/index.js +25 -0
- package/dist/harness/collaboration/delegation/notifier.d.ts +46 -0
- package/dist/harness/collaboration/delegation/notifier.js +84 -0
- package/dist/harness/collaboration/delegation/registry-types.d.ts +200 -0
- package/dist/harness/collaboration/delegation/registry-types.js +61 -0
- package/dist/harness/collaboration/delegation/registry.d.ts +110 -0
- package/dist/harness/collaboration/delegation/registry.js +220 -0
- package/dist/harness/collaboration/delegation/service.d.ts +249 -0
- package/dist/harness/collaboration/delegation/service.js +499 -0
- package/dist/harness/collaboration/delegation/store.d.ts +155 -0
- package/dist/harness/collaboration/delegation/store.js +271 -0
- package/dist/harness/collaboration/delegation/transport.d.ts +73 -0
- package/dist/harness/collaboration/delegation/transport.js +61 -0
- package/dist/harness/collaboration/delegation/types.d.ts +231 -0
- package/dist/harness/collaboration/delegation/types.js +70 -0
- package/dist/harness/collaboration/delegation/wiring.d.ts +111 -0
- package/dist/harness/collaboration/delegation/wiring.js +145 -0
- package/dist/harness/collaboration/orchestration/index.d.ts +11 -13
- package/dist/harness/collaboration/orchestration/index.js +11 -11
- package/dist/harness/context/assembler.d.ts +2 -2
- package/dist/harness/context/assembler.js +12 -7
- package/dist/harness/context/capabilities/compact/engine.js +80 -38
- package/dist/harness/context/capabilities/compact/types.d.ts +12 -1
- package/dist/harness/context/capabilities/summary/registry.js +10 -0
- package/dist/harness/context/constitution/default-agents.md +230 -228
- package/dist/harness/context/default-context-engine.d.ts +101 -23
- package/dist/harness/context/default-context-engine.js +483 -172
- package/dist/harness/context/hybrid-compressor.d.ts +3 -3
- package/dist/harness/context/hybrid-compressor.js +18 -23
- package/dist/harness/context/index.d.ts +5 -1
- package/dist/harness/context/index.js +2 -0
- package/dist/harness/context/layer-snapshot.d.ts +4 -0
- package/dist/harness/context/layer-snapshot.js +30 -18
- package/dist/harness/context/layer-types.d.ts +85 -1
- package/dist/harness/context/layer-types.js +110 -4
- package/dist/harness/context/layers.d.ts +5 -2
- package/dist/harness/context/layers.js +11 -5
- package/dist/harness/context/llm-summarizer.d.ts +15 -1
- package/dist/harness/context/llm-summarizer.js +107 -56
- package/dist/harness/context/message-selector.js +6 -2
- package/dist/harness/context/root-instructions.d.ts +72 -0
- package/dist/harness/context/root-instructions.js +227 -0
- package/dist/harness/context/runtime-datetime.d.ts +34 -7
- package/dist/harness/context/runtime-datetime.js +66 -10
- package/dist/harness/context/smart-router.d.ts +1 -1
- package/dist/harness/context/smart-router.js +1 -1
- package/dist/harness/context/system-prompt-assembler.d.ts +30 -0
- package/dist/harness/context/system-prompt-assembler.js +73 -6
- package/dist/harness/context/token-constants.d.ts +2 -2
- package/dist/harness/context/token-constants.js +2 -2
- package/dist/harness/context/token-estimate-fns.d.ts +1 -3
- package/dist/harness/context/token-estimate-fns.js +2 -4
- package/dist/harness/context/token-estimator.d.ts +1 -1
- package/dist/harness/context/token-estimator.js +14 -6
- package/dist/harness/context/tool-result-aging.d.ts +140 -0
- package/dist/harness/context/tool-result-aging.js +331 -0
- package/dist/harness/context/tool-result-body.d.ts +10 -0
- package/dist/harness/context/tool-result-body.js +27 -0
- package/dist/harness/context/turn-envelope.d.ts +123 -0
- package/dist/harness/context/turn-envelope.js +188 -0
- package/dist/harness/context/types.d.ts +35 -47
- package/dist/harness/extension/execution-environment/effect-policy.d.ts +258 -0
- package/dist/harness/extension/execution-environment/effect-policy.js +358 -0
- package/dist/harness/extension/execution-environment/index.d.ts +18 -2
- package/dist/harness/extension/execution-environment/index.js +11 -2
- package/dist/harness/extension/execution-environment/isolation.js +5 -1
- package/dist/harness/extension/execution-environment/memory-undo.d.ts +101 -0
- package/dist/harness/extension/execution-environment/memory-undo.js +192 -0
- package/dist/harness/extension/execution-environment/process-isolation.d.ts +84 -0
- package/dist/harness/extension/execution-environment/process-isolation.js +315 -0
- package/dist/harness/extension/execution-environment/resource-limits.d.ts +36 -0
- package/dist/harness/extension/execution-environment/resource-limits.js +84 -0
- package/dist/harness/extension/execution-environment/sandbox.d.ts +125 -4
- package/dist/harness/extension/execution-environment/sandbox.js +521 -51
- package/dist/harness/extension/execution-environment/shell-journal.d.ts +100 -0
- package/dist/harness/extension/execution-environment/shell-journal.js +299 -0
- package/dist/harness/extension/execution-environment/tool-capabilities.d.ts +45 -0
- package/dist/harness/extension/execution-environment/tool-capabilities.js +126 -0
- package/dist/harness/extension/execution-environment/types.d.ts +67 -39
- package/dist/harness/extension/execution-environment/types.js +2 -2
- package/dist/harness/extension/execution-environment/undo-log.d.ts +203 -0
- package/dist/harness/extension/execution-environment/undo-log.js +627 -0
- package/dist/harness/extension/execution-environment/undo-merge.d.ts +40 -0
- package/dist/harness/extension/execution-environment/undo-merge.js +167 -0
- package/dist/harness/extension/plugin-ecosystem/client-tools/index.d.ts +1 -1
- package/dist/harness/extension/plugin-ecosystem/client-tools/types.d.ts +9 -0
- package/dist/harness/extension/plugin-ecosystem/mcp/bridge.js +2 -0
- package/dist/harness/extension/plugin-ecosystem/plugins/api.d.ts +1 -6
- package/dist/harness/extension/plugin-ecosystem/plugins/api.js +3 -8
- package/dist/harness/extension/plugin-ecosystem/plugins/capability.d.ts +0 -3
- package/dist/harness/extension/plugin-ecosystem/plugins/capability.js +0 -3
- package/dist/harness/extension/plugin-ecosystem/plugins/entry.d.ts +2 -10
- package/dist/harness/extension/plugin-ecosystem/plugins/entry.js +2 -9
- package/dist/harness/extension/plugin-ecosystem/plugins/index.d.ts +1 -3
- package/dist/harness/extension/plugin-ecosystem/plugins/index.js +1 -3
- package/dist/harness/extension/plugin-ecosystem/plugins/loader.d.ts +2 -4
- package/dist/harness/extension/plugin-ecosystem/plugins/loader.js +4 -21
- package/dist/harness/extension/plugin-ecosystem/plugins/manager.d.ts +3 -9
- package/dist/harness/extension/plugin-ecosystem/plugins/manager.js +4 -8
- package/dist/harness/extension/plugin-ecosystem/plugins/manifest.d.ts +1 -4
- package/dist/harness/extension/plugin-ecosystem/plugins/manifest.js +1 -3
- package/dist/harness/extension/plugin-ecosystem/skills/manager.d.ts +1 -1
- package/dist/harness/extension/plugin-ecosystem/skills/manager.js +1 -1
- package/dist/harness/extension/plugin-ecosystem/tools/allowlisted-run.d.ts +51 -0
- package/dist/harness/extension/plugin-ecosystem/tools/allowlisted-run.js +153 -0
- package/dist/harness/extension/plugin-ecosystem/tools/ask-user.js +1 -0
- package/dist/harness/extension/plugin-ecosystem/tools/builtin.d.ts +18 -3
- package/dist/harness/extension/plugin-ecosystem/tools/builtin.js +277 -81
- package/dist/harness/extension/plugin-ecosystem/tools/delegation.d.ts +31 -0
- package/dist/harness/extension/plugin-ecosystem/tools/delegation.js +291 -0
- package/dist/harness/extension/plugin-ecosystem/tools/document-tools.js +10 -2
- package/dist/harness/extension/plugin-ecosystem/tools/env-info.js +1 -0
- package/dist/harness/extension/plugin-ecosystem/tools/eol.d.ts +35 -0
- package/dist/harness/extension/plugin-ecosystem/tools/eol.js +43 -0
- package/dist/harness/extension/plugin-ecosystem/tools/file-edit.js +40 -9
- package/dist/harness/extension/plugin-ecosystem/tools/file-ops.d.ts +33 -0
- package/dist/harness/extension/plugin-ecosystem/tools/file-ops.js +376 -0
- package/dist/harness/extension/plugin-ecosystem/tools/file-search.d.ts +12 -2
- package/dist/harness/extension/plugin-ecosystem/tools/file-search.js +241 -70
- package/dist/harness/extension/plugin-ecosystem/tools/git-runner.d.ts +31 -0
- package/dist/harness/extension/plugin-ecosystem/tools/git-runner.js +104 -0
- package/dist/harness/extension/plugin-ecosystem/tools/git-status-snapshot.d.ts +111 -0
- package/dist/harness/extension/plugin-ecosystem/tools/git-status-snapshot.js +197 -0
- package/dist/harness/extension/plugin-ecosystem/tools/git-tools.d.ts +27 -0
- package/dist/harness/extension/plugin-ecosystem/tools/git-tools.js +463 -0
- package/dist/harness/extension/plugin-ecosystem/tools/http.d.ts +10 -6
- package/dist/harness/extension/plugin-ecosystem/tools/http.js +41 -47
- package/dist/harness/extension/plugin-ecosystem/tools/index.d.ts +6 -0
- package/dist/harness/extension/plugin-ecosystem/tools/index.js +4 -0
- package/dist/harness/extension/plugin-ecosystem/tools/knowledge.js +4 -0
- package/dist/harness/extension/plugin-ecosystem/tools/memory.js +25 -1
- package/dist/harness/extension/plugin-ecosystem/tools/package-tools.d.ts +13 -0
- package/dist/harness/extension/plugin-ecosystem/tools/package-tools.js +391 -0
- package/dist/harness/extension/plugin-ecosystem/tools/platform.d.ts +51 -2
- package/dist/harness/extension/plugin-ecosystem/tools/platform.js +151 -12
- package/dist/harness/extension/plugin-ecosystem/tools/session-history.js +2 -0
- package/dist/harness/extension/plugin-ecosystem/tools/tool-bus.d.ts +10 -1
- package/dist/harness/extension/plugin-ecosystem/tools/tool-bus.js +35 -19
- package/dist/harness/extension/plugin-ecosystem/tools/tool-set.d.ts +8 -0
- package/dist/harness/extension/plugin-ecosystem/tools/tool-set.js +5 -0
- package/dist/harness/extension/plugin-ecosystem/tools/web-search.js +1 -0
- package/dist/harness/governance/credentials/index.d.ts +1 -1
- package/dist/harness/governance/credentials/store.d.ts +16 -4
- package/dist/harness/governance/credentials/store.js +33 -6
- package/dist/harness/governance/credentials/types.d.ts +11 -0
- package/dist/harness/governance/human-in-the-loop/decision-cache.d.ts +105 -0
- package/dist/harness/governance/human-in-the-loop/decision-cache.js +184 -0
- package/dist/harness/governance/human-in-the-loop/index.d.ts +5 -5
- package/dist/harness/governance/human-in-the-loop/index.js +3 -3
- package/dist/harness/governance/human-in-the-loop/types.d.ts +7 -62
- package/dist/harness/governance/human-in-the-loop/types.js +6 -2
- package/dist/harness/governance/security/capability-enforcer.d.ts +9 -1
- package/dist/harness/governance/security/capability-enforcer.js +31 -8
- package/dist/harness/governance/security/degradation.js +5 -7
- package/dist/harness/governance/security/risk-evaluator.d.ts +1 -1
- package/dist/harness/governance/security/risk-evaluator.js +4 -82
- package/dist/harness/governance/security/temp-path.d.ts +41 -0
- package/dist/harness/governance/security/temp-path.js +117 -0
- package/dist/harness/governance/session-acl/index.d.ts +1 -0
- package/dist/harness/governance/session-acl/index.js +1 -0
- package/dist/harness/governance/session-acl/rights.d.ts +12 -0
- package/dist/harness/governance/session-acl/rights.js +89 -7
- package/dist/harness/governance/session-acl/seed-roles.js +9 -1
- package/dist/harness/governance/session-acl/service.js +21 -29
- package/dist/harness/governance/session-acl/tool-rights.d.ts +81 -0
- package/dist/harness/governance/session-acl/tool-rights.js +238 -0
- package/dist/harness/governance/session-acl/types.d.ts +22 -0
- package/dist/harness/index.d.ts +16 -12
- package/dist/harness/index.js +10 -6
- package/dist/harness/knowledge/file-identity.d.ts +8 -0
- package/dist/harness/knowledge/file-identity.js +26 -1
- package/dist/harness/knowledge/file-index-store.js +11 -11
- package/dist/harness/knowledge/grounding.d.ts +2 -1
- package/dist/harness/knowledge/grounding.js +8 -5
- package/dist/harness/knowledge/index-store.d.ts +31 -4
- package/dist/harness/knowledge/index-store.js +121 -39
- package/dist/harness/knowledge/index.d.ts +2 -2
- package/dist/harness/knowledge/index.js +1 -1
- package/dist/harness/knowledge/ingest.d.ts +115 -115
- package/dist/harness/knowledge/ingest.js +154 -151
- package/dist/harness/knowledge/job-control-state.js +4 -4
- package/dist/harness/knowledge/job-control.js +11 -11
- package/dist/harness/knowledge/knowledge-serve-child.js +1 -1
- package/dist/harness/knowledge/membership-store.js +11 -11
- package/dist/harness/knowledge/network-guard.d.ts +61 -4
- package/dist/harness/knowledge/network-guard.js +390 -113
- package/dist/harness/knowledge/purge.js +4 -1
- package/dist/harness/knowledge/query-service.js +3 -3
- package/dist/harness/knowledge/writer-service.d.ts +2 -0
- package/dist/harness/knowledge/writer-service.js +14 -13
- package/dist/harness/memory/backfill-coverage.js +3 -1
- package/dist/harness/memory/backfill-trigger.d.ts +2 -2
- package/dist/harness/memory/backfill-trigger.js +4 -4
- package/dist/harness/memory/index.d.ts +1 -0
- package/dist/harness/memory/index.js +1 -0
- package/dist/harness/memory/sqlite/agent-db.js +2 -0
- package/dist/harness/memory/sqlite/memory-store.d.ts +1 -0
- package/dist/harness/memory/sqlite/memory-store.js +14 -4
- package/dist/harness/memory/sqlite/wisdom-store.js +9 -9
- package/dist/harness/memory/store.d.ts +1 -0
- package/dist/harness/memory/store.js +3 -0
- package/dist/harness/memory/time-format.d.ts +28 -0
- package/dist/harness/memory/time-format.js +52 -0
- package/dist/harness/memory/types.d.ts +12 -0
- package/dist/harness/observability/observer/hub.js +53 -2
- package/dist/harness/observability/observer/index.d.ts +2 -2
- package/dist/harness/observability/observer/index.js +1 -1
- package/dist/harness/observability/observer/types.d.ts +80 -0
- package/dist/harness/observability/observer/types.js +118 -9
- package/dist/harness/run/agent/agent.d.ts +18 -0
- package/dist/harness/run/agent/agent.js +26 -0
- package/dist/harness/run/concurrency/tool-loop-detection-core.d.ts +1 -1
- package/dist/harness/run/concurrency/tool-loop-detection-core.js +1 -1
- package/dist/harness/run/reliability/harness-events.d.ts +4 -0
- package/dist/harness/run/reliability/run-agent.js +110 -18
- package/dist/harness/run/reliability/run-metrics-collector.d.ts +28 -2
- package/dist/harness/run/reliability/run-metrics-collector.js +92 -2
- package/dist/harness/run/run-guard/default-run-guard.d.ts +0 -5
- package/dist/harness/run/run-guard/default-run-guard.js +104 -44
- package/dist/harness/run/run-scope.d.ts +52 -0
- package/dist/harness/run/runner.d.ts +117 -16
- package/dist/harness/run/runner.js +668 -157
- package/dist/harness/session/attachments/llm-intent.js +17 -17
- package/dist/harness/session/history/port.js +16 -5
- package/dist/harness/session/in-memory-store.d.ts +6 -0
- package/dist/harness/session/in-memory-store.js +55 -3
- package/dist/harness/session/schedules/index.d.ts +10 -0
- package/dist/harness/session/schedules/index.js +10 -0
- package/dist/harness/session/schedules/render.d.ts +13 -0
- package/dist/harness/session/schedules/render.js +63 -0
- package/dist/harness/session/schedules/service.d.ts +179 -0
- package/dist/harness/session/schedules/service.js +695 -0
- package/dist/harness/session/schedules/store.d.ts +119 -0
- package/dist/harness/session/schedules/store.js +323 -0
- package/dist/harness/session/schedules/tools.d.ts +39 -0
- package/dist/harness/session/schedules/tools.js +442 -0
- package/dist/harness/session/schedules/types.d.ts +104 -0
- package/dist/harness/session/schedules/types.js +97 -0
- package/dist/harness/session/tasks/tools.js +22 -0
- package/dist/harness/session/title.js +25 -9
- package/dist/harness/session/types.d.ts +35 -0
- package/dist/harness/shared/events/agent-event-map.d.ts +39 -0
- package/dist/harness/shared/events/agent-event-map.js +2 -0
- package/dist/harness/shared/types/agent-definition.d.ts +23 -0
- package/dist/index.d.ts +25 -9
- package/dist/index.js +11 -2
- package/dist/integration/observability/run-telemetry.d.ts +8 -0
- package/dist/integration/observability/run-telemetry.js +31 -8
- package/dist/integration/observability/trace-collector.js +26 -4
- package/dist/integration/observability/trace-events.d.ts +1 -0
- package/dist/integration/observability/trace-events.js +2 -0
- package/dist/integration/observability/trace-logger.js +27 -17
- package/dist/integration/providers/anthropic.d.ts +10 -0
- package/dist/integration/providers/anthropic.js +44 -1
- package/dist/integration/providers/openai.d.ts +10 -0
- package/dist/integration/providers/openai.js +58 -2
- package/dist/integration/providers/wire-dump-diff.d.ts +191 -0
- package/dist/integration/providers/wire-dump-diff.js +351 -0
- package/dist/integration/providers/wire-dump.d.ts +178 -0
- package/dist/integration/providers/wire-dump.js +396 -0
- package/dist/integration/storage/jsonl.d.ts +29 -0
- package/dist/integration/storage/jsonl.js +243 -41
- package/dist/integration/storage/session-index.js +63 -8
- package/dist/paths.d.ts +19 -0
- package/dist/paths.js +38 -1
- package/dist/subsystems/cognition-steward/conceptualize/SUBSYSTEM.md +43 -43
- package/dist/subsystems/cognition-steward/conceptualize/config.yaml +50 -50
- package/dist/subsystems/cognition-steward/consolidate/SUBSYSTEM.md +6 -6
- package/dist/subsystems/cognition-steward/consolidate/config.yaml +54 -54
- package/dist/subsystems/memory-steward/backfill/handler.js +9 -0
- package/dist/subsystems/safety-guard/config.yaml +3 -1
- package/dist/subsystems/wisdom-steward/evaluate/config.yaml +50 -50
- package/dist/subsystems/wisdom-steward/formation/SUBSYSTEM.md +42 -42
- package/dist/subsystems/wisdom-steward/formation/config.yaml +54 -54
- package/dist/subsystems/wisdom-steward/govern/config.yaml +55 -55
- package/package.json +115 -115
- package/dist/harness/collaboration/multi-agent/agent-registry-types.d.ts +0 -144
- package/dist/harness/collaboration/multi-agent/agent-registry-types.js +0 -25
- package/dist/harness/collaboration/multi-agent/index.d.ts +0 -17
- package/dist/harness/collaboration/multi-agent/index.js +0 -15
- package/dist/harness/collaboration/multi-agent/process.d.ts +0 -167
- package/dist/harness/collaboration/multi-agent/process.js +0 -256
- package/dist/harness/collaboration/multi-agent/registry.d.ts +0 -36
- package/dist/harness/collaboration/multi-agent/registry.js +0 -137
- package/dist/harness/collaboration/multi-agent/swarm.d.ts +0 -135
- package/dist/harness/collaboration/multi-agent/swarm.js +0 -317
- package/dist/harness/collaboration/multi-agent/types.d.ts +0 -66
- package/dist/harness/collaboration/multi-agent/types.js +0 -15
- package/dist/harness/collaboration/orchestration/async-task-store.d.ts +0 -107
- package/dist/harness/collaboration/orchestration/async-task-store.js +0 -12
- package/dist/harness/collaboration/orchestration/async-task.d.ts +0 -156
- package/dist/harness/collaboration/orchestration/async-task.js +0 -359
- package/dist/harness/collaboration/orchestration/planner/hybrid-planner.d.ts +0 -47
- package/dist/harness/collaboration/orchestration/planner/hybrid-planner.js +0 -61
- package/dist/harness/collaboration/orchestration/planner/index.d.ts +0 -9
- package/dist/harness/collaboration/orchestration/planner/index.js +0 -6
- package/dist/harness/collaboration/orchestration/planner/llm-planner.d.ts +0 -54
- package/dist/harness/collaboration/orchestration/planner/llm-planner.js +0 -167
- package/dist/harness/collaboration/orchestration/planner/rule-planner.d.ts +0 -85
- package/dist/harness/collaboration/orchestration/planner/rule-planner.js +0 -175
- package/dist/harness/collaboration/orchestration/quality/classifier.d.ts +0 -21
- package/dist/harness/collaboration/orchestration/quality/classifier.js +0 -235
- package/dist/harness/collaboration/orchestration/quality/gate.d.ts +0 -29
- package/dist/harness/collaboration/orchestration/quality/gate.js +0 -409
- package/dist/harness/collaboration/orchestration/quality/index.d.ts +0 -9
- package/dist/harness/collaboration/orchestration/quality/index.js +0 -8
- package/dist/harness/collaboration/orchestration/quality/types.d.ts +0 -159
- package/dist/harness/collaboration/orchestration/quality/types.js +0 -33
- package/dist/harness/collaboration/orchestration/scheduler/index.d.ts +0 -5
- package/dist/harness/collaboration/orchestration/scheduler/index.js +0 -4
- package/dist/harness/collaboration/orchestration/scheduler/task-scheduler.d.ts +0 -143
- package/dist/harness/collaboration/orchestration/scheduler/task-scheduler.js +0 -297
- package/dist/harness/collaboration/orchestration/strategy/classifier.d.ts +0 -12
- package/dist/harness/collaboration/orchestration/strategy/classifier.js +0 -81
- package/dist/harness/collaboration/orchestration/strategy/index.d.ts +0 -3
- package/dist/harness/collaboration/orchestration/strategy/index.js +0 -2
- package/dist/harness/collaboration/orchestration/strategy/router.d.ts +0 -28
- package/dist/harness/collaboration/orchestration/strategy/router.js +0 -105
- package/dist/harness/collaboration/orchestration/strategy/types.d.ts +0 -49
- package/dist/harness/collaboration/orchestration/strategy/types.js +0 -4
- package/dist/harness/collaboration/orchestration/workflow/engine.d.ts +0 -86
- package/dist/harness/collaboration/orchestration/workflow/engine.js +0 -298
- package/dist/harness/collaboration/orchestration/workflow/index.d.ts +0 -9
- package/dist/harness/collaboration/orchestration/workflow/index.js +0 -7
- package/dist/harness/collaboration/orchestration/workflow/types.d.ts +0 -143
- package/dist/harness/collaboration/orchestration/workflow/types.js +0 -7
- package/dist/harness/governance/human-in-the-loop/approval-manager.d.ts +0 -32
- package/dist/harness/governance/human-in-the-loop/approval-manager.js +0 -93
- /package/dist/harness/collaboration/{multi-agent → delegation}/message-channel-types.d.ts +0 -0
- /package/dist/harness/collaboration/{multi-agent → delegation}/message-channel-types.js +0 -0
|
@@ -1,359 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* AsyncTask — 异步任务单元(Harness / orchestration)
|
|
3
|
-
*
|
|
4
|
-
* 调度与后台工作单元:超时、取消、重试、可选持久化。
|
|
5
|
-
* **不是 Kernel**:Loop 与裸 Agent.run 不依赖;主消费方 TaskScheduler。
|
|
6
|
-
*
|
|
7
|
-
* 边界说明:
|
|
8
|
-
* - `priority` 仅元数据;调度策略在 TaskScheduler
|
|
9
|
-
* - 重试无退避(退避是策略)
|
|
10
|
-
* - 持久化失败不阻塞执行,但会串行化
|
|
11
|
-
*/
|
|
12
|
-
import { randomUUID } from 'node:crypto';
|
|
13
|
-
// ── 任务状态机 ──
|
|
14
|
-
/** AsyncTask 事件 */
|
|
15
|
-
export const TaskEvents = {
|
|
16
|
-
CREATED: 'task.created',
|
|
17
|
-
STARTED: 'task.started',
|
|
18
|
-
COMPLETED: 'task.completed',
|
|
19
|
-
FAILED: 'task.failed',
|
|
20
|
-
CANCELLED: 'task.cancelled',
|
|
21
|
-
TIMEOUT: 'task.timeout',
|
|
22
|
-
RETRYING: 'task.retrying',
|
|
23
|
-
CHILD_SPAWNED: 'task.child.spawned',
|
|
24
|
-
};
|
|
25
|
-
// ── AsyncTask ──
|
|
26
|
-
/**
|
|
27
|
-
* AsyncTask — 异步任务
|
|
28
|
-
*
|
|
29
|
-
* 封装一个异步执行单元,提供生命周期管理。
|
|
30
|
-
*/
|
|
31
|
-
export class AsyncTask {
|
|
32
|
-
id;
|
|
33
|
-
type;
|
|
34
|
-
priority;
|
|
35
|
-
parentId;
|
|
36
|
-
agentId;
|
|
37
|
-
sessionId;
|
|
38
|
-
createdAt;
|
|
39
|
-
_status = 'pending';
|
|
40
|
-
_output;
|
|
41
|
-
_error;
|
|
42
|
-
_startedAt;
|
|
43
|
-
_completedAt;
|
|
44
|
-
_retryCount = 0;
|
|
45
|
-
_maxRetries;
|
|
46
|
-
_timeoutMs;
|
|
47
|
-
_metadata;
|
|
48
|
-
_input;
|
|
49
|
-
_abortController;
|
|
50
|
-
_resolvePromise;
|
|
51
|
-
_rejectPromise;
|
|
52
|
-
_promise;
|
|
53
|
-
_timeoutHandle;
|
|
54
|
-
// 外部依赖
|
|
55
|
-
_events;
|
|
56
|
-
_store;
|
|
57
|
-
_settled = false;
|
|
58
|
-
/** 串行化持久化,避免 create/update 乱序 */
|
|
59
|
-
_persistChain = Promise.resolve();
|
|
60
|
-
constructor(options, events, store) {
|
|
61
|
-
this.id = randomUUID();
|
|
62
|
-
this.type = options.type;
|
|
63
|
-
this.priority = options.priority ?? 'normal';
|
|
64
|
-
this.parentId = options.parentId;
|
|
65
|
-
this.agentId = options.agentId;
|
|
66
|
-
this.sessionId = options.sessionId;
|
|
67
|
-
this.createdAt = Date.now();
|
|
68
|
-
this._input = options.input;
|
|
69
|
-
this._maxRetries = options.maxRetries ?? 0;
|
|
70
|
-
this._timeoutMs = options.timeoutMs;
|
|
71
|
-
this._metadata = options.metadata;
|
|
72
|
-
this._abortController = new AbortController();
|
|
73
|
-
this._events = events;
|
|
74
|
-
this._store = store;
|
|
75
|
-
this._promise = new Promise((resolve, reject) => {
|
|
76
|
-
this._resolvePromise = resolve;
|
|
77
|
-
this._rejectPromise = reject;
|
|
78
|
-
});
|
|
79
|
-
// 不静默吞掉 unhandled rejection。
|
|
80
|
-
// 调用方应通过 task.promise.catch()、task.wait() 或 spawnTask() 处理错误。
|
|
81
|
-
// 持久化创建事件(fire-and-forget,经 _persistChain 串行)
|
|
82
|
-
this._persistAndEmit(TaskEvents.CREATED);
|
|
83
|
-
}
|
|
84
|
-
// ── 状态访问器 ──
|
|
85
|
-
/** 当前状态 */
|
|
86
|
-
get status() { return this._status; }
|
|
87
|
-
/** 任务输出(完成后有值) */
|
|
88
|
-
get output() { return this._output; }
|
|
89
|
-
/** 错误信息(失败时有值) */
|
|
90
|
-
get error() { return this._error; }
|
|
91
|
-
/** 重试次数 */
|
|
92
|
-
get retryCount() { return this._retryCount; }
|
|
93
|
-
/** 是否已完成(成功、失败或取消) */
|
|
94
|
-
get isDone() {
|
|
95
|
-
return this._status === 'completed'
|
|
96
|
-
|| this._status === 'failed'
|
|
97
|
-
|| this._status === 'cancelled';
|
|
98
|
-
}
|
|
99
|
-
/** AbortSignal,用于取消传递 */
|
|
100
|
-
get signal() { return this._abortController.signal; }
|
|
101
|
-
/** 等待结果的 Promise */
|
|
102
|
-
get promise() { return this._promise; }
|
|
103
|
-
// ── 生命周期方法 ──
|
|
104
|
-
/**
|
|
105
|
-
* 启动任务执行
|
|
106
|
-
*
|
|
107
|
-
* @param executor - 任务执行函数
|
|
108
|
-
* @returns 任务结果
|
|
109
|
-
*
|
|
110
|
-
* 内部方法,由 TaskRunner 或直接调用方触发。
|
|
111
|
-
* 重试为迭代实现,避免深递归;无退避(策略在外层)。
|
|
112
|
-
*/
|
|
113
|
-
async run(executor) {
|
|
114
|
-
if (this._status !== 'pending') {
|
|
115
|
-
throw new Error(`Task ${this.id} is not pending (status: ${this._status})`);
|
|
116
|
-
}
|
|
117
|
-
// 迭代重试:首次 + maxRetries
|
|
118
|
-
while (true) {
|
|
119
|
-
this._status = 'running';
|
|
120
|
-
this._startedAt = Date.now();
|
|
121
|
-
this._persistAndEmit(TaskEvents.STARTED);
|
|
122
|
-
if (this._timeoutMs && this._timeoutMs > 0) {
|
|
123
|
-
this._timeoutHandle = setTimeout(() => {
|
|
124
|
-
if (this._status === 'running') {
|
|
125
|
-
this._handleTimeout();
|
|
126
|
-
}
|
|
127
|
-
}, this._timeoutMs);
|
|
128
|
-
}
|
|
129
|
-
try {
|
|
130
|
-
const result = await executor(this._input, this._abortController.signal);
|
|
131
|
-
// 已经被 timeout/cancel 处理过了,抛出原错误让调用方感知
|
|
132
|
-
if (this._settled) {
|
|
133
|
-
throw this._settledError();
|
|
134
|
-
}
|
|
135
|
-
this._complete(result);
|
|
136
|
-
return result;
|
|
137
|
-
}
|
|
138
|
-
catch (err) {
|
|
139
|
-
// 已经被 timeout/cancel 处理过了,直接抛出原错误
|
|
140
|
-
if (this._settled)
|
|
141
|
-
throw err;
|
|
142
|
-
const error = err instanceof Error ? err : new Error(String(err));
|
|
143
|
-
// cancel() 会 abort signal,此时不重试
|
|
144
|
-
if (this._abortController.signal.aborted) {
|
|
145
|
-
this._fail(error.message);
|
|
146
|
-
throw error;
|
|
147
|
-
}
|
|
148
|
-
// 重试
|
|
149
|
-
if (this._retryCount < this._maxRetries) {
|
|
150
|
-
this._retryCount++;
|
|
151
|
-
this._abortController = new AbortController();
|
|
152
|
-
this._status = 'pending';
|
|
153
|
-
this._persistAndEmit(TaskEvents.RETRYING, {
|
|
154
|
-
retryCount: this._retryCount,
|
|
155
|
-
maxRetries: this._maxRetries,
|
|
156
|
-
lastError: error.message,
|
|
157
|
-
});
|
|
158
|
-
continue;
|
|
159
|
-
}
|
|
160
|
-
this._fail(error.message);
|
|
161
|
-
throw error;
|
|
162
|
-
}
|
|
163
|
-
finally {
|
|
164
|
-
if (this._timeoutHandle) {
|
|
165
|
-
clearTimeout(this._timeoutHandle);
|
|
166
|
-
this._timeoutHandle = undefined;
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
}
|
|
170
|
-
}
|
|
171
|
-
/**
|
|
172
|
-
* 取消任务
|
|
173
|
-
*
|
|
174
|
-
* @param reason - 取消原因
|
|
175
|
-
*/
|
|
176
|
-
cancel(reason) {
|
|
177
|
-
if (this.isDone || this._settled)
|
|
178
|
-
return;
|
|
179
|
-
this._settled = true;
|
|
180
|
-
this._status = 'cancelled';
|
|
181
|
-
this._completedAt = Date.now();
|
|
182
|
-
this._error = reason ?? 'cancelled';
|
|
183
|
-
this._abortController.abort();
|
|
184
|
-
this._persistAndEmit(TaskEvents.CANCELLED);
|
|
185
|
-
this._rejectPromise(new TaskCancelledError(this.id, reason));
|
|
186
|
-
}
|
|
187
|
-
/**
|
|
188
|
-
* 等待任务完成(带超时)
|
|
189
|
-
*
|
|
190
|
-
* @param timeoutMs - 超时时间(毫秒),不传则无限等待
|
|
191
|
-
* @returns 任务结果
|
|
192
|
-
* @throws TaskTimeoutError | TaskCancelledError | Error
|
|
193
|
-
*
|
|
194
|
-
* 调用方超时不会改变任务本身状态;任务超时用 TaskOptions.timeoutMs。
|
|
195
|
-
*/
|
|
196
|
-
async wait(timeoutMs) {
|
|
197
|
-
if (this.isDone) {
|
|
198
|
-
if (this._status === 'cancelled')
|
|
199
|
-
throw new TaskCancelledError(this.id, this._error);
|
|
200
|
-
if (this._status === 'failed')
|
|
201
|
-
throw new Error(this._error ?? 'Task failed');
|
|
202
|
-
return this._output;
|
|
203
|
-
}
|
|
204
|
-
if (timeoutMs === undefined)
|
|
205
|
-
return this._promise;
|
|
206
|
-
let timer;
|
|
207
|
-
try {
|
|
208
|
-
return await Promise.race([
|
|
209
|
-
this._promise,
|
|
210
|
-
new Promise((_, reject) => {
|
|
211
|
-
timer = setTimeout(() => {
|
|
212
|
-
reject(new TaskTimeoutError(this.id, timeoutMs));
|
|
213
|
-
}, timeoutMs);
|
|
214
|
-
}),
|
|
215
|
-
]);
|
|
216
|
-
}
|
|
217
|
-
finally {
|
|
218
|
-
if (timer !== undefined)
|
|
219
|
-
clearTimeout(timer);
|
|
220
|
-
}
|
|
221
|
-
}
|
|
222
|
-
/**
|
|
223
|
-
* 等待所有已排队的持久化完成(测试/优雅退出用)
|
|
224
|
-
*/
|
|
225
|
-
async flushPersist() {
|
|
226
|
-
await this._persistChain;
|
|
227
|
-
}
|
|
228
|
-
// ── 内部方法 ──
|
|
229
|
-
_settledError() {
|
|
230
|
-
const settledStatus = this._status;
|
|
231
|
-
if (settledStatus === 'failed' && this._error?.includes('timed out')) {
|
|
232
|
-
return new TaskTimeoutError(this.id, this._timeoutMs);
|
|
233
|
-
}
|
|
234
|
-
if (settledStatus === 'cancelled') {
|
|
235
|
-
return new TaskCancelledError(this.id, this._error);
|
|
236
|
-
}
|
|
237
|
-
return new Error(this._error ?? 'Task was settled externally');
|
|
238
|
-
}
|
|
239
|
-
_complete(output) {
|
|
240
|
-
this._status = 'completed';
|
|
241
|
-
this._output = output;
|
|
242
|
-
this._completedAt = Date.now();
|
|
243
|
-
this._persistAndEmit(TaskEvents.COMPLETED);
|
|
244
|
-
this._resolvePromise(output);
|
|
245
|
-
}
|
|
246
|
-
_fail(error) {
|
|
247
|
-
this._status = 'failed';
|
|
248
|
-
this._error = error;
|
|
249
|
-
this._completedAt = Date.now();
|
|
250
|
-
this._persistAndEmit(TaskEvents.FAILED);
|
|
251
|
-
this._rejectPromise(new Error(error));
|
|
252
|
-
}
|
|
253
|
-
_handleTimeout() {
|
|
254
|
-
if (this._settled)
|
|
255
|
-
return;
|
|
256
|
-
this._settled = true;
|
|
257
|
-
this._status = 'failed';
|
|
258
|
-
this._error = `Task timed out after ${this._timeoutMs}ms`;
|
|
259
|
-
this._completedAt = Date.now();
|
|
260
|
-
this._abortController.abort();
|
|
261
|
-
this._persistAndEmit(TaskEvents.TIMEOUT);
|
|
262
|
-
this._rejectPromise(new TaskTimeoutError(this.id, this._timeoutMs));
|
|
263
|
-
}
|
|
264
|
-
_persistAndEmit(eventType, extraData) {
|
|
265
|
-
// 事件同步发射:订阅方在状态变更同帧收到,保持原语可观测时序
|
|
266
|
-
if (this._events) {
|
|
267
|
-
const event = {
|
|
268
|
-
type: eventType,
|
|
269
|
-
timestamp: Date.now(),
|
|
270
|
-
agentId: this.agentId,
|
|
271
|
-
sessionId: this.sessionId,
|
|
272
|
-
data: {
|
|
273
|
-
taskId: this.id,
|
|
274
|
-
taskType: this.type,
|
|
275
|
-
status: this._status,
|
|
276
|
-
...extraData,
|
|
277
|
-
},
|
|
278
|
-
};
|
|
279
|
-
this._events.emit(event);
|
|
280
|
-
}
|
|
281
|
-
// 持久化串行化:后一次等前一次结束,保证 store 终态正确
|
|
282
|
-
const record = this.toRecord();
|
|
283
|
-
this._persistChain = this._persistChain.then(async () => {
|
|
284
|
-
if (!this._store)
|
|
285
|
-
return;
|
|
286
|
-
try {
|
|
287
|
-
if (eventType === TaskEvents.CREATED) {
|
|
288
|
-
await this._store.create(record);
|
|
289
|
-
}
|
|
290
|
-
else {
|
|
291
|
-
await this._store.update(this.id, record);
|
|
292
|
-
}
|
|
293
|
-
}
|
|
294
|
-
catch {
|
|
295
|
-
// 持久化失败不应阻塞任务执行
|
|
296
|
-
}
|
|
297
|
-
});
|
|
298
|
-
}
|
|
299
|
-
// ── 序列化 ──
|
|
300
|
-
/** 转换为 AsyncTaskRecord(用于快照/调试/持久化) */
|
|
301
|
-
toRecord() {
|
|
302
|
-
return {
|
|
303
|
-
id: this.id,
|
|
304
|
-
agentId: this.agentId ?? 'unknown',
|
|
305
|
-
sessionId: this.sessionId,
|
|
306
|
-
type: this.type,
|
|
307
|
-
status: this._status,
|
|
308
|
-
priority: this.priority,
|
|
309
|
-
input: this._input,
|
|
310
|
-
output: this._output,
|
|
311
|
-
error: this._error,
|
|
312
|
-
createdAt: this.createdAt,
|
|
313
|
-
startedAt: this._startedAt,
|
|
314
|
-
completedAt: this._completedAt,
|
|
315
|
-
retryCount: this._retryCount,
|
|
316
|
-
maxRetries: this._maxRetries,
|
|
317
|
-
timeoutMs: this._timeoutMs,
|
|
318
|
-
parentId: this.parentId,
|
|
319
|
-
metadata: this._metadata,
|
|
320
|
-
};
|
|
321
|
-
}
|
|
322
|
-
}
|
|
323
|
-
// ── 错误类型 ──
|
|
324
|
-
/** 任务超时错误 */
|
|
325
|
-
export class TaskTimeoutError extends Error {
|
|
326
|
-
taskId;
|
|
327
|
-
timeoutMs;
|
|
328
|
-
constructor(taskId, timeoutMs) {
|
|
329
|
-
super(`Task ${taskId} timed out after ${timeoutMs}ms`);
|
|
330
|
-
this.taskId = taskId;
|
|
331
|
-
this.timeoutMs = timeoutMs;
|
|
332
|
-
this.name = 'TaskTimeoutError';
|
|
333
|
-
}
|
|
334
|
-
}
|
|
335
|
-
/** 任务取消错误 */
|
|
336
|
-
export class TaskCancelledError extends Error {
|
|
337
|
-
taskId;
|
|
338
|
-
reason;
|
|
339
|
-
constructor(taskId, reason) {
|
|
340
|
-
super(`Task ${taskId} was cancelled${reason ? `: ${reason}` : ''}`);
|
|
341
|
-
this.taskId = taskId;
|
|
342
|
-
this.reason = reason;
|
|
343
|
-
this.name = 'TaskCancelledError';
|
|
344
|
-
}
|
|
345
|
-
}
|
|
346
|
-
// ── 工具函数 ──
|
|
347
|
-
/**
|
|
348
|
-
* 创建并立即启动一个 AsyncTask
|
|
349
|
-
*
|
|
350
|
-
* 便捷方法,适用于"发射后不管"的场景。
|
|
351
|
-
* 错误通过 task.promise 和 EventBus 传播,不会被静默吞掉。
|
|
352
|
-
*/
|
|
353
|
-
export function spawnTask(options, executor, events, store) {
|
|
354
|
-
const task = new AsyncTask(options, events, store);
|
|
355
|
-
// fire-and-forget:错误在 task 内部处理(状态更新 + 事件发射)
|
|
356
|
-
// 调用方应通过 task.wait() 或 task.promise 获取结果/错误
|
|
357
|
-
task.run(executor).catch(() => { });
|
|
358
|
-
return task;
|
|
359
|
-
}
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* HybridPlanner — 混合规划器
|
|
3
|
-
*
|
|
4
|
-
* 规则优先,LLM fallback。
|
|
5
|
-
* 常见事件用规则快速处理,复杂情况交给 LLM。
|
|
6
|
-
*
|
|
7
|
-
* 策略:
|
|
8
|
-
* 1. 先用 RulePlanner 匹配
|
|
9
|
-
* 2. 如果规则匹配且生成了步骤 → 直接使用
|
|
10
|
-
* 3. 如果没有匹配的规则 → fallback 到 LLMPlanner
|
|
11
|
-
*/
|
|
12
|
-
import type { Planner, Plan, AgentState } from '../cognitive-loop.js';
|
|
13
|
-
import type { EventBusAgentEvent as AgentEvent } from '@octopi-agent/core/index.js';
|
|
14
|
-
import type { LLMPlannerConfig } from './llm-planner.js';
|
|
15
|
-
import type { Rule } from './rule-planner.js';
|
|
16
|
-
export interface HybridPlannerConfig {
|
|
17
|
-
/** LLM 配置(fallback 用) */
|
|
18
|
-
llm: LLMPlannerConfig;
|
|
19
|
-
/** 规则集(默认使用内置规则) */
|
|
20
|
-
rules?: Rule[];
|
|
21
|
-
/** 是否启用 LLM fallback(默认 true) */
|
|
22
|
-
enableLLMFallback?: boolean;
|
|
23
|
-
}
|
|
24
|
-
/**
|
|
25
|
-
* 混合规划器
|
|
26
|
-
*
|
|
27
|
-
* 规则优先,LLM 兜底。
|
|
28
|
-
*/
|
|
29
|
-
export declare class HybridPlanner implements Planner {
|
|
30
|
-
readonly name = "hybrid-planner";
|
|
31
|
-
private _rulePlanner;
|
|
32
|
-
private _llmPlanner;
|
|
33
|
-
private _enableFallback;
|
|
34
|
-
constructor(config: HybridPlannerConfig);
|
|
35
|
-
/**
|
|
36
|
-
* 添加规则
|
|
37
|
-
*/
|
|
38
|
-
addRule(rule: Rule): void;
|
|
39
|
-
/**
|
|
40
|
-
* 分析事件:规则优先,LLM fallback
|
|
41
|
-
*/
|
|
42
|
-
decide(events: AgentEvent[], state: AgentState): Promise<Plan>;
|
|
43
|
-
/**
|
|
44
|
-
* 目标分解:直接用 LLM(规则不擅长分解)
|
|
45
|
-
*/
|
|
46
|
-
decompose(goal: string, state: AgentState): Promise<Plan>;
|
|
47
|
-
}
|
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* HybridPlanner — 混合规划器
|
|
3
|
-
*
|
|
4
|
-
* 规则优先,LLM fallback。
|
|
5
|
-
* 常见事件用规则快速处理,复杂情况交给 LLM。
|
|
6
|
-
*
|
|
7
|
-
* 策略:
|
|
8
|
-
* 1. 先用 RulePlanner 匹配
|
|
9
|
-
* 2. 如果规则匹配且生成了步骤 → 直接使用
|
|
10
|
-
* 3. 如果没有匹配的规则 → fallback 到 LLMPlanner
|
|
11
|
-
*/
|
|
12
|
-
import { RulePlanner } from './rule-planner.js';
|
|
13
|
-
import { LLMPlanner } from './llm-planner.js';
|
|
14
|
-
import { getDefaultRules } from './rule-planner.js';
|
|
15
|
-
// ── HybridPlanner ──
|
|
16
|
-
/**
|
|
17
|
-
* 混合规划器
|
|
18
|
-
*
|
|
19
|
-
* 规则优先,LLM 兜底。
|
|
20
|
-
*/
|
|
21
|
-
export class HybridPlanner {
|
|
22
|
-
name = 'hybrid-planner';
|
|
23
|
-
_rulePlanner;
|
|
24
|
-
_llmPlanner;
|
|
25
|
-
_enableFallback;
|
|
26
|
-
constructor(config) {
|
|
27
|
-
const rules = config.rules ?? getDefaultRules();
|
|
28
|
-
this._rulePlanner = new RulePlanner(rules);
|
|
29
|
-
this._llmPlanner = new LLMPlanner(config.llm);
|
|
30
|
-
this._enableFallback = config.enableLLMFallback ?? true;
|
|
31
|
-
}
|
|
32
|
-
/**
|
|
33
|
-
* 添加规则
|
|
34
|
-
*/
|
|
35
|
-
addRule(rule) {
|
|
36
|
-
this._rulePlanner.addRule(rule);
|
|
37
|
-
}
|
|
38
|
-
/**
|
|
39
|
-
* 分析事件:规则优先,LLM fallback
|
|
40
|
-
*/
|
|
41
|
-
async decide(events, state) {
|
|
42
|
-
// 1. 先用规则匹配
|
|
43
|
-
const rulePlan = await this._rulePlanner.decide(events, state);
|
|
44
|
-
// 2. 如果规则匹配到了步骤,直接使用
|
|
45
|
-
if (rulePlan.steps.length > 0) {
|
|
46
|
-
return rulePlan;
|
|
47
|
-
}
|
|
48
|
-
// 3. 没有匹配的规则,fallback 到 LLM
|
|
49
|
-
if (this._enableFallback) {
|
|
50
|
-
return this._llmPlanner.decide(events, state);
|
|
51
|
-
}
|
|
52
|
-
// 4. 未启用 fallback,返回空计划
|
|
53
|
-
return rulePlan;
|
|
54
|
-
}
|
|
55
|
-
/**
|
|
56
|
-
* 目标分解:直接用 LLM(规则不擅长分解)
|
|
57
|
-
*/
|
|
58
|
-
async decompose(goal, state) {
|
|
59
|
-
return this._llmPlanner.decompose(goal, state);
|
|
60
|
-
}
|
|
61
|
-
}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Planner 模块统一导出
|
|
3
|
-
*/
|
|
4
|
-
export { RulePlanner, USER_MESSAGE_RULE, SECURITY_EVENT_RULE, IDLE_RULE, getDefaultRules } from './rule-planner.js';
|
|
5
|
-
export type { Rule, RuleCondition, RuleAction } from './rule-planner.js';
|
|
6
|
-
export { LLMPlanner } from './llm-planner.js';
|
|
7
|
-
export type { LLMPlannerConfig } from './llm-planner.js';
|
|
8
|
-
export { HybridPlanner } from './hybrid-planner.js';
|
|
9
|
-
export type { HybridPlannerConfig } from './hybrid-planner.js';
|
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* LLMPlanner — LLM 驱动的规划器
|
|
3
|
-
*
|
|
4
|
-
* 用 LLM 分析事件和状态,决定下一步行动。
|
|
5
|
-
* 比规则驱动更灵活,但更慢、更贵。
|
|
6
|
-
*
|
|
7
|
-
* 适用场景:
|
|
8
|
-
* - 复杂的用户请求(需要理解意图)
|
|
9
|
-
* - 目标分解(大任务拆成小步骤)
|
|
10
|
-
* - 异常情况处理(规则没覆盖的场景)
|
|
11
|
-
*/
|
|
12
|
-
import type { Planner, Plan, AgentState } from '../cognitive-loop.js';
|
|
13
|
-
import type { EventBusAgentEvent as AgentEvent } from '@octopi-agent/core/index.js';
|
|
14
|
-
import type { ModelProvider } from '@octopi-agent/core/interfaces/model-provider.js';
|
|
15
|
-
export interface LLMPlannerConfig {
|
|
16
|
-
/** ModelProvider 实例 */
|
|
17
|
-
model: ModelProvider;
|
|
18
|
-
/** 使用的模型名 */
|
|
19
|
-
modelName?: string;
|
|
20
|
-
/** 系统提示词 */
|
|
21
|
-
systemPrompt?: string;
|
|
22
|
-
/** 温度 */
|
|
23
|
-
temperature?: number;
|
|
24
|
-
/** 最大 token */
|
|
25
|
-
maxTokens?: number;
|
|
26
|
-
}
|
|
27
|
-
/**
|
|
28
|
-
* LLM 驱动的规划器
|
|
29
|
-
*
|
|
30
|
-
* 将事件和状态序列化为 prompt,让 LLM 返回结构化的计划。
|
|
31
|
-
*/
|
|
32
|
-
export declare class LLMPlanner implements Planner {
|
|
33
|
-
readonly name = "llm-planner";
|
|
34
|
-
private _model;
|
|
35
|
-
private _modelName?;
|
|
36
|
-
private _systemPrompt;
|
|
37
|
-
private _temperature;
|
|
38
|
-
private _maxTokens;
|
|
39
|
-
constructor(config: LLMPlannerConfig);
|
|
40
|
-
/**
|
|
41
|
-
* 分析事件,让 LLM 决定下一步
|
|
42
|
-
*/
|
|
43
|
-
decide(events: AgentEvent[], state: AgentState): Promise<Plan>;
|
|
44
|
-
/**
|
|
45
|
-
* 将目标分解为可执行步骤
|
|
46
|
-
*/
|
|
47
|
-
decompose(goal: string, state: AgentState): Promise<Plan>;
|
|
48
|
-
private _buildDecidePrompt;
|
|
49
|
-
private _buildDecomposePrompt;
|
|
50
|
-
private _callLLM;
|
|
51
|
-
private _parsePlan;
|
|
52
|
-
private _validateStepType;
|
|
53
|
-
private _emptyPlan;
|
|
54
|
-
}
|