@octopi-agent/engine 0.70.7 → 0.86.38
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 +69 -0
- package/dist/config-schema/context.d.ts +23 -4
- package/dist/config-schema/context.js +28 -1
- package/dist/config-schema/engine.d.ts +201 -9
- package/dist/config-schema/engine.js +31 -2
- package/dist/config-schema/governance.d.ts +95 -0
- package/dist/config-schema/governance.js +91 -0
- package/dist/config-schema/models.d.ts +1 -1
- 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 +10 -0
- package/dist/config-schema/shared.js +10 -0
- package/dist/config-schema/substrate.d.ts +1 -1
- package/dist/config-schema/subsystems.d.ts +1 -1
- package/dist/config-schema/subsystems.js +2 -1
- package/dist/config.d.ts +178 -7
- package/dist/config.js +113 -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 +47 -3
- package/dist/harness/agent/builder.js +180 -54
- package/dist/harness/agent/config-bridge.d.ts +33 -25
- package/dist/harness/agent/config-bridge.js +81 -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 +38 -0
- package/dist/harness/agent/tool-purpose.js +118 -0
- package/dist/harness/agent/wire-agent-builder.d.ts +133 -0
- package/dist/harness/agent/wire-agent-builder.js +363 -0
- package/dist/harness/collaboration/autonomous-subsystem/runtime.d.ts +4 -1
- package/dist/harness/collaboration/autonomous-subsystem/runtime.js +14 -8
- 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 +49 -1
- package/dist/harness/context/layer-types.js +72 -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 +67 -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 +248 -0
- package/dist/harness/extension/execution-environment/effect-policy.js +334 -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/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 +493 -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 +45 -0
- package/dist/harness/extension/plugin-ecosystem/tools/allowlisted-run.js +136 -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 +239 -61
- package/dist/harness/extension/plugin-ecosystem/tools/git-tools.d.ts +27 -0
- package/dist/harness/extension/plugin-ecosystem/tools/git-tools.js +554 -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 +2 -0
- package/dist/harness/extension/plugin-ecosystem/tools/index.js +2 -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 +14 -12
- package/dist/harness/index.js +9 -6
- 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 +6 -3
- package/dist/harness/knowledge/index.d.ts +2 -2
- package/dist/harness/knowledge/index.js +1 -1
- package/dist/harness/knowledge/ingest.js +4 -1
- package/dist/harness/knowledge/job-control-state.js +4 -4
- package/dist/harness/knowledge/job-control.js +11 -11
- 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/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-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 +23 -1
- 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 +57 -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 +101 -16
- package/dist/harness/run/runner.js +556 -158
- package/dist/harness/session/attachments/llm-intent.js +17 -17
- package/dist/harness/session/history/port.js +1 -0
- package/dist/harness/session/in-memory-store.d.ts +1 -0
- package/dist/harness/session/in-memory-store.js +22 -1
- 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/types.d.ts +35 -0
- package/dist/harness/shared/events/agent-event-map.d.ts +13 -0
- package/dist/harness/shared/types/agent-definition.d.ts +23 -0
- package/dist/index.d.ts +23 -9
- package/dist/index.js +10 -2
- 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 +11 -0
- package/dist/integration/storage/jsonl.js +148 -39
- package/dist/integration/storage/session-index.js +63 -8
- 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/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,137 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* DefaultAgentRegistry — Agent 注册与发现的默认实现
|
|
3
|
-
*
|
|
4
|
-
* Harness 层组件。实现本域 `agent-registry-types.ts` 的 AgentRegistry。
|
|
5
|
-
* 基于内存存储,支持按能力发现、状态管理、关系管理。
|
|
6
|
-
*
|
|
7
|
-
* 设计原则:
|
|
8
|
-
* - 不依赖外部存储
|
|
9
|
-
* - 事件驱动:所有变更通过 EventBus 通知
|
|
10
|
-
* - 线程安全:操作是同步的,适合单进程场景
|
|
11
|
-
*/
|
|
12
|
-
import { AgentRegistryEvents } from './agent-registry-types.js';
|
|
13
|
-
/**
|
|
14
|
-
* DefaultAgentRegistry
|
|
15
|
-
*
|
|
16
|
-
* 基于内存的 Agent 注册表实现。
|
|
17
|
-
*/
|
|
18
|
-
export class DefaultAgentRegistry {
|
|
19
|
-
_agents = new Map();
|
|
20
|
-
_relations = [];
|
|
21
|
-
_events;
|
|
22
|
-
constructor(events) {
|
|
23
|
-
this._events = events;
|
|
24
|
-
}
|
|
25
|
-
// ── 注册 / 注销 ──
|
|
26
|
-
register(info) {
|
|
27
|
-
const now = Date.now();
|
|
28
|
-
const agentInfo = {
|
|
29
|
-
...info,
|
|
30
|
-
registeredAt: now,
|
|
31
|
-
lastActiveAt: now,
|
|
32
|
-
};
|
|
33
|
-
this._agents.set(info.id, agentInfo);
|
|
34
|
-
this._emit(AgentRegistryEvents.AGENT_REGISTERED, {
|
|
35
|
-
agentId: info.id,
|
|
36
|
-
name: info.name,
|
|
37
|
-
capabilities: info.capabilities,
|
|
38
|
-
});
|
|
39
|
-
}
|
|
40
|
-
unregister(agentId) {
|
|
41
|
-
const existed = this._agents.delete(agentId);
|
|
42
|
-
if (existed) {
|
|
43
|
-
// 清理相关关系
|
|
44
|
-
this._relations = this._relations.filter(r => r.from !== agentId && r.to !== agentId);
|
|
45
|
-
this._emit(AgentRegistryEvents.AGENT_UNREGISTERED, { agentId });
|
|
46
|
-
}
|
|
47
|
-
return existed;
|
|
48
|
-
}
|
|
49
|
-
// ── 查询 ──
|
|
50
|
-
get(agentId) {
|
|
51
|
-
return this._agents.get(agentId);
|
|
52
|
-
}
|
|
53
|
-
query(query) {
|
|
54
|
-
let results = Array.from(this._agents.values());
|
|
55
|
-
if (query.capabilities && query.capabilities.length > 0) {
|
|
56
|
-
results = results.filter(agent => query.capabilities.some(cap => agent.capabilities.includes(cap)));
|
|
57
|
-
}
|
|
58
|
-
if (query.status) {
|
|
59
|
-
results = results.filter(agent => agent.status === query.status);
|
|
60
|
-
}
|
|
61
|
-
if (query.metadata) {
|
|
62
|
-
results = results.filter(agent => {
|
|
63
|
-
if (!agent.metadata)
|
|
64
|
-
return false;
|
|
65
|
-
return Object.entries(query.metadata).every(([key, value]) => agent.metadata[key] === value);
|
|
66
|
-
});
|
|
67
|
-
}
|
|
68
|
-
return results;
|
|
69
|
-
}
|
|
70
|
-
list() {
|
|
71
|
-
return Array.from(this._agents.values());
|
|
72
|
-
}
|
|
73
|
-
findByCapability(capability) {
|
|
74
|
-
return Array.from(this._agents.values()).filter(agent => agent.capabilities.includes(capability));
|
|
75
|
-
}
|
|
76
|
-
// ── 状态管理 ──
|
|
77
|
-
updateStatus(agentId, status) {
|
|
78
|
-
const agent = this._agents.get(agentId);
|
|
79
|
-
if (!agent)
|
|
80
|
-
return;
|
|
81
|
-
const oldStatus = agent.status;
|
|
82
|
-
agent.status = status;
|
|
83
|
-
agent.lastActiveAt = Date.now();
|
|
84
|
-
if (oldStatus !== status) {
|
|
85
|
-
this._emit(AgentRegistryEvents.AGENT_STATUS_CHANGED, {
|
|
86
|
-
agentId,
|
|
87
|
-
oldStatus,
|
|
88
|
-
newStatus: status,
|
|
89
|
-
});
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
touch(agentId) {
|
|
93
|
-
const agent = this._agents.get(agentId);
|
|
94
|
-
if (agent) {
|
|
95
|
-
agent.lastActiveAt = Date.now();
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
// ── 关系管理 ──
|
|
99
|
-
addRelation(relation) {
|
|
100
|
-
// 去重
|
|
101
|
-
const exists = this._relations.some(r => r.from === relation.from && r.to === relation.to && r.type === relation.type);
|
|
102
|
-
if (exists)
|
|
103
|
-
return;
|
|
104
|
-
this._relations.push(relation);
|
|
105
|
-
this._emit(AgentRegistryEvents.RELATION_ADDED, {
|
|
106
|
-
from: relation.from,
|
|
107
|
-
to: relation.to,
|
|
108
|
-
type: relation.type,
|
|
109
|
-
});
|
|
110
|
-
}
|
|
111
|
-
removeRelation(from, to, type) {
|
|
112
|
-
const before = this._relations.length;
|
|
113
|
-
this._relations = this._relations.filter(r => {
|
|
114
|
-
if (r.from !== from || r.to !== to)
|
|
115
|
-
return true;
|
|
116
|
-
if (type && r.type !== type)
|
|
117
|
-
return true;
|
|
118
|
-
return false;
|
|
119
|
-
});
|
|
120
|
-
if (this._relations.length < before) {
|
|
121
|
-
this._emit(AgentRegistryEvents.RELATION_REMOVED, { from, to, type });
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
getRelations(agentId) {
|
|
125
|
-
return this._relations.filter(r => r.from === agentId || r.to === agentId);
|
|
126
|
-
}
|
|
127
|
-
// ── 内部方法 ──
|
|
128
|
-
_emit(type, data) {
|
|
129
|
-
if (this._events) {
|
|
130
|
-
this._events.emit({
|
|
131
|
-
type,
|
|
132
|
-
timestamp: Date.now(),
|
|
133
|
-
data,
|
|
134
|
-
});
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
}
|
|
@@ -1,135 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* AgentSwarm — 多 Agent 编排器
|
|
3
|
-
*
|
|
4
|
-
* Harness 层组件。管理多个 Agent 的协作。
|
|
5
|
-
*
|
|
6
|
-
* 支持的拓扑:
|
|
7
|
-
* - hierarchical: 协调者分配任务给工作者 Agent
|
|
8
|
-
* - peer-to-peer: Agent 之间直接通信
|
|
9
|
-
* - pipeline: Agent 按顺序处理(前一个的输出是后一个的输入)
|
|
10
|
-
* - broadcast: 一个 Agent 的输出广播给所有其他 Agent
|
|
11
|
-
*
|
|
12
|
-
* 设计原则:
|
|
13
|
-
* - 基于 AgentRegistry 发现和管理 Agent
|
|
14
|
-
* - 基于 EventBus 进行事件驱动通信
|
|
15
|
-
* - 每个 Agent 有独立的运行时作用域
|
|
16
|
-
* - 编排是策略,不是机制 — 可替换的编排逻辑
|
|
17
|
-
*/
|
|
18
|
-
import type { EventBus } from '@octopi-agent/core/primitives/event-bus.js';
|
|
19
|
-
import type { AgentRegistry } from './agent-registry-types.js';
|
|
20
|
-
import type { SwarmConfig, SwarmAgent, SwarmTask } from './types.js';
|
|
21
|
-
/**
|
|
22
|
-
* 编排策略
|
|
23
|
-
*
|
|
24
|
-
* 决定如何将任务分配给 Agent。
|
|
25
|
-
* 不同的拓扑有不同的策略实现。
|
|
26
|
-
*/
|
|
27
|
-
export interface OrchestrationStrategy {
|
|
28
|
-
/** 策略名称 */
|
|
29
|
-
readonly name: string;
|
|
30
|
-
/**
|
|
31
|
-
* 选择执行任务的 Agent
|
|
32
|
-
*
|
|
33
|
-
* @param task - 待执行的任务
|
|
34
|
-
* @param agents - 可用的 Agent 列表
|
|
35
|
-
* @param registry - Agent 注册表
|
|
36
|
-
* @returns 选中的 Agent ID,null 表示没有合适的 Agent
|
|
37
|
-
*/
|
|
38
|
-
selectAgent(task: SwarmTask, agents: Map<string, SwarmAgent>, registry: AgentRegistry): string | null;
|
|
39
|
-
/**
|
|
40
|
-
* 处理任务结果
|
|
41
|
-
*
|
|
42
|
-
* @param task - 已完成的任务
|
|
43
|
-
* @param result - 任务结果
|
|
44
|
-
* @param agents - 所有 Agent
|
|
45
|
-
* @returns 后续任务列表(可选)
|
|
46
|
-
*/
|
|
47
|
-
onTaskComplete?(task: SwarmTask, result: string, agents: Map<string, SwarmAgent>): SwarmTask[];
|
|
48
|
-
}
|
|
49
|
-
/** 轮询策略:依次分配给可用 Agent */
|
|
50
|
-
export declare class RoundRobinStrategy implements OrchestrationStrategy {
|
|
51
|
-
readonly name = "round-robin";
|
|
52
|
-
private _index;
|
|
53
|
-
selectAgent(_task: SwarmTask, agents: Map<string, SwarmAgent>): string | null;
|
|
54
|
-
}
|
|
55
|
-
/** 能力匹配策略:根据任务描述匹配 Agent 能力 */
|
|
56
|
-
export declare class CapabilityStrategy implements OrchestrationStrategy {
|
|
57
|
-
readonly name = "capability-match";
|
|
58
|
-
selectAgent(task: SwarmTask, agents: Map<string, SwarmAgent>, registry: AgentRegistry): string | null;
|
|
59
|
-
}
|
|
60
|
-
/** 流水线策略:按注册顺序依次传递 */
|
|
61
|
-
export declare class PipelineStrategy implements OrchestrationStrategy {
|
|
62
|
-
readonly name = "pipeline";
|
|
63
|
-
private _agentOrder;
|
|
64
|
-
constructor(agentOrder?: string[]);
|
|
65
|
-
setOrder(agentIds: string[]): void;
|
|
66
|
-
selectAgent(task: SwarmTask, agents: Map<string, SwarmAgent>): string | null;
|
|
67
|
-
onTaskComplete(task: SwarmTask, result: string, agents: Map<string, SwarmAgent>): SwarmTask[];
|
|
68
|
-
}
|
|
69
|
-
/**
|
|
70
|
-
* AgentSwarm — 多 Agent 编排器
|
|
71
|
-
*
|
|
72
|
-
* 管理多个 Agent 的生命周期和任务分配。
|
|
73
|
-
*/
|
|
74
|
-
export declare class AgentSwarm {
|
|
75
|
-
readonly id: string;
|
|
76
|
-
readonly name: string;
|
|
77
|
-
readonly topology: SwarmConfig['topology'];
|
|
78
|
-
private _agents;
|
|
79
|
-
private _tasks;
|
|
80
|
-
private _strategy;
|
|
81
|
-
private _registry;
|
|
82
|
-
private _events;
|
|
83
|
-
private _maxConcurrency;
|
|
84
|
-
private _taskTimeoutMs;
|
|
85
|
-
private _running;
|
|
86
|
-
constructor(config: SwarmConfig, registry: AgentRegistry, events: EventBus, strategy?: OrchestrationStrategy);
|
|
87
|
-
/**
|
|
88
|
-
* 添加 Agent 到 Swarm
|
|
89
|
-
*/
|
|
90
|
-
addAgent(agent: SwarmAgent): void;
|
|
91
|
-
/**
|
|
92
|
-
* 从 Swarm 移除 Agent
|
|
93
|
-
*/
|
|
94
|
-
removeAgent(agentId: string): void;
|
|
95
|
-
/**
|
|
96
|
-
* 获取 Agent
|
|
97
|
-
*/
|
|
98
|
-
getAgent(agentId: string): SwarmAgent | undefined;
|
|
99
|
-
/**
|
|
100
|
-
* 列出所有 Agent
|
|
101
|
-
*/
|
|
102
|
-
listAgents(): SwarmAgent[];
|
|
103
|
-
/**
|
|
104
|
-
* 提交任务
|
|
105
|
-
*/
|
|
106
|
-
submitTask(description: string, input: string): SwarmTask;
|
|
107
|
-
/**
|
|
108
|
-
* 执行任务
|
|
109
|
-
*
|
|
110
|
-
* 根据编排策略选择 Agent 并执行任务。
|
|
111
|
-
*/
|
|
112
|
-
executeTask(task: SwarmTask): Promise<SwarmTask>;
|
|
113
|
-
/**
|
|
114
|
-
* 广播任务给所有 Agent
|
|
115
|
-
*/
|
|
116
|
-
broadcastTask(description: string, input: string): Promise<SwarmTask[]>;
|
|
117
|
-
/**
|
|
118
|
-
* 获取任务
|
|
119
|
-
*/
|
|
120
|
-
getTask(taskId: string): SwarmTask | undefined;
|
|
121
|
-
/**
|
|
122
|
-
* 列出所有任务
|
|
123
|
-
*/
|
|
124
|
-
listTasks(): SwarmTask[];
|
|
125
|
-
/**
|
|
126
|
-
* 设置编排策略
|
|
127
|
-
*/
|
|
128
|
-
setStrategy(strategy: OrchestrationStrategy): void;
|
|
129
|
-
/**
|
|
130
|
-
* 获取当前策略
|
|
131
|
-
*/
|
|
132
|
-
getStrategy(): OrchestrationStrategy;
|
|
133
|
-
private _createDefaultStrategy;
|
|
134
|
-
private _emit;
|
|
135
|
-
}
|
|
@@ -1,317 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* AgentSwarm — 多 Agent 编排器
|
|
3
|
-
*
|
|
4
|
-
* Harness 层组件。管理多个 Agent 的协作。
|
|
5
|
-
*
|
|
6
|
-
* 支持的拓扑:
|
|
7
|
-
* - hierarchical: 协调者分配任务给工作者 Agent
|
|
8
|
-
* - peer-to-peer: Agent 之间直接通信
|
|
9
|
-
* - pipeline: Agent 按顺序处理(前一个的输出是后一个的输入)
|
|
10
|
-
* - broadcast: 一个 Agent 的输出广播给所有其他 Agent
|
|
11
|
-
*
|
|
12
|
-
* 设计原则:
|
|
13
|
-
* - 基于 AgentRegistry 发现和管理 Agent
|
|
14
|
-
* - 基于 EventBus 进行事件驱动通信
|
|
15
|
-
* - 每个 Agent 有独立的运行时作用域
|
|
16
|
-
* - 编排是策略,不是机制 — 可替换的编排逻辑
|
|
17
|
-
*/
|
|
18
|
-
import { randomUUID } from 'node:crypto';
|
|
19
|
-
import { SwarmEvents } from './types.js';
|
|
20
|
-
// ── 内置策略 ──
|
|
21
|
-
/** 轮询策略:依次分配给可用 Agent */
|
|
22
|
-
export class RoundRobinStrategy {
|
|
23
|
-
name = 'round-robin';
|
|
24
|
-
_index = 0;
|
|
25
|
-
selectAgent(_task, agents) {
|
|
26
|
-
const agentIds = Array.from(agents.keys()).filter(id => {
|
|
27
|
-
const agent = agents.get(id);
|
|
28
|
-
return agent?.info.status === 'active' || agent?.info.status === 'idle';
|
|
29
|
-
});
|
|
30
|
-
if (agentIds.length === 0)
|
|
31
|
-
return null;
|
|
32
|
-
const selected = agentIds[this._index % agentIds.length];
|
|
33
|
-
this._index++;
|
|
34
|
-
return selected;
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
/** 能力匹配策略:根据任务描述匹配 Agent 能力 */
|
|
38
|
-
export class CapabilityStrategy {
|
|
39
|
-
name = 'capability-match';
|
|
40
|
-
selectAgent(task, agents, registry) {
|
|
41
|
-
// 从任务描述中提取关键词作为能力需求
|
|
42
|
-
const keywords = task.description.toLowerCase().split(/\s+/);
|
|
43
|
-
let bestAgent = null;
|
|
44
|
-
let bestScore = 0;
|
|
45
|
-
for (const [id, agent] of agents) {
|
|
46
|
-
if (agent.info.status !== 'active' && agent.info.status !== 'idle')
|
|
47
|
-
continue;
|
|
48
|
-
// 计算能力匹配分数
|
|
49
|
-
const score = agent.info.capabilities.reduce((acc, cap) => {
|
|
50
|
-
const capLower = cap.toLowerCase();
|
|
51
|
-
return acc + keywords.filter(kw => capLower.includes(kw) || kw.includes(capLower)).length;
|
|
52
|
-
}, 0);
|
|
53
|
-
if (score > bestScore) {
|
|
54
|
-
bestScore = score;
|
|
55
|
-
bestAgent = id;
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
// 没有匹配时回退到轮询
|
|
59
|
-
if (bestAgent === null) {
|
|
60
|
-
const activeAgents = Array.from(agents.entries()).filter(([, a]) => a.info.status === 'active' || a.info.status === 'idle');
|
|
61
|
-
if (activeAgents.length > 0) {
|
|
62
|
-
bestAgent = activeAgents[0][0];
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
return bestAgent;
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
/** 流水线策略:按注册顺序依次传递 */
|
|
69
|
-
export class PipelineStrategy {
|
|
70
|
-
name = 'pipeline';
|
|
71
|
-
_agentOrder = [];
|
|
72
|
-
constructor(agentOrder) {
|
|
73
|
-
this._agentOrder = agentOrder ?? [];
|
|
74
|
-
}
|
|
75
|
-
setOrder(agentIds) {
|
|
76
|
-
this._agentOrder = [...agentIds];
|
|
77
|
-
}
|
|
78
|
-
selectAgent(task, agents) {
|
|
79
|
-
// 如果任务还没有分配过,分配给第一个 Agent
|
|
80
|
-
if (!task.assignedTo) {
|
|
81
|
-
return this._agentOrder[0] ?? null;
|
|
82
|
-
}
|
|
83
|
-
// 否则分配给下一个
|
|
84
|
-
const currentIndex = this._agentOrder.indexOf(task.assignedTo);
|
|
85
|
-
if (currentIndex < 0 || currentIndex >= this._agentOrder.length - 1)
|
|
86
|
-
return null;
|
|
87
|
-
return this._agentOrder[currentIndex + 1];
|
|
88
|
-
}
|
|
89
|
-
onTaskComplete(task, result, agents) {
|
|
90
|
-
// 检查是否还有下一个 Agent
|
|
91
|
-
const currentIndex = this._agentOrder.indexOf(task.assignedTo);
|
|
92
|
-
if (currentIndex < 0 || currentIndex >= this._agentOrder.length - 1)
|
|
93
|
-
return [];
|
|
94
|
-
// 创建传递给下一个 Agent 的任务
|
|
95
|
-
return [{
|
|
96
|
-
id: `task-${randomUUID().slice(0, 8)}`,
|
|
97
|
-
description: task.description,
|
|
98
|
-
input: result,
|
|
99
|
-
assignedTo: this._agentOrder[currentIndex + 1],
|
|
100
|
-
status: 'pending',
|
|
101
|
-
createdAt: Date.now(),
|
|
102
|
-
}];
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
// ── AgentSwarm ──
|
|
106
|
-
/**
|
|
107
|
-
* AgentSwarm — 多 Agent 编排器
|
|
108
|
-
*
|
|
109
|
-
* 管理多个 Agent 的生命周期和任务分配。
|
|
110
|
-
*/
|
|
111
|
-
export class AgentSwarm {
|
|
112
|
-
id;
|
|
113
|
-
name;
|
|
114
|
-
topology;
|
|
115
|
-
_agents = new Map();
|
|
116
|
-
_tasks = new Map();
|
|
117
|
-
_strategy;
|
|
118
|
-
_registry;
|
|
119
|
-
_events;
|
|
120
|
-
_maxConcurrency;
|
|
121
|
-
_taskTimeoutMs;
|
|
122
|
-
_running = false;
|
|
123
|
-
constructor(config, registry, events, strategy) {
|
|
124
|
-
this.id = `swarm-${randomUUID().slice(0, 8)}`;
|
|
125
|
-
this.name = config.name;
|
|
126
|
-
this.topology = config.topology;
|
|
127
|
-
this._registry = registry;
|
|
128
|
-
this._events = events;
|
|
129
|
-
this._maxConcurrency = config.maxConcurrency ?? 5;
|
|
130
|
-
this._taskTimeoutMs = config.taskTimeoutMs ?? 60_000;
|
|
131
|
-
this._strategy = strategy ?? this._createDefaultStrategy(config);
|
|
132
|
-
}
|
|
133
|
-
// ── Agent 管理 ──
|
|
134
|
-
/**
|
|
135
|
-
* 添加 Agent 到 Swarm
|
|
136
|
-
*/
|
|
137
|
-
addAgent(agent) {
|
|
138
|
-
this._agents.set(agent.info.id, agent);
|
|
139
|
-
this._registry.register(agent.info);
|
|
140
|
-
this._emit(SwarmEvents.AGENT_ADDED, {
|
|
141
|
-
agentId: agent.info.id,
|
|
142
|
-
name: agent.info.name,
|
|
143
|
-
capabilities: agent.info.capabilities,
|
|
144
|
-
});
|
|
145
|
-
}
|
|
146
|
-
/**
|
|
147
|
-
* 从 Swarm 移除 Agent
|
|
148
|
-
*/
|
|
149
|
-
removeAgent(agentId) {
|
|
150
|
-
this._agents.delete(agentId);
|
|
151
|
-
this._registry.unregister(agentId);
|
|
152
|
-
this._emit(SwarmEvents.AGENT_REMOVED, { agentId });
|
|
153
|
-
}
|
|
154
|
-
/**
|
|
155
|
-
* 获取 Agent
|
|
156
|
-
*/
|
|
157
|
-
getAgent(agentId) {
|
|
158
|
-
return this._agents.get(agentId);
|
|
159
|
-
}
|
|
160
|
-
/**
|
|
161
|
-
* 列出所有 Agent
|
|
162
|
-
*/
|
|
163
|
-
listAgents() {
|
|
164
|
-
return Array.from(this._agents.values());
|
|
165
|
-
}
|
|
166
|
-
// ── 任务管理 ──
|
|
167
|
-
/**
|
|
168
|
-
* 提交任务
|
|
169
|
-
*/
|
|
170
|
-
submitTask(description, input) {
|
|
171
|
-
const task = {
|
|
172
|
-
id: `task-${randomUUID().slice(0, 8)}`,
|
|
173
|
-
description,
|
|
174
|
-
input,
|
|
175
|
-
status: 'pending',
|
|
176
|
-
createdAt: Date.now(),
|
|
177
|
-
};
|
|
178
|
-
this._tasks.set(task.id, task);
|
|
179
|
-
this._emit(SwarmEvents.TASK_CREATED, { taskId: task.id, description });
|
|
180
|
-
return task;
|
|
181
|
-
}
|
|
182
|
-
/**
|
|
183
|
-
* 执行任务
|
|
184
|
-
*
|
|
185
|
-
* 根据编排策略选择 Agent 并执行任务。
|
|
186
|
-
*/
|
|
187
|
-
async executeTask(task) {
|
|
188
|
-
// 选择 Agent
|
|
189
|
-
const agentId = this._strategy.selectAgent(task, this._agents, this._registry);
|
|
190
|
-
if (!agentId) {
|
|
191
|
-
task.status = 'failed';
|
|
192
|
-
task.error = 'No suitable agent found';
|
|
193
|
-
task.completedAt = Date.now();
|
|
194
|
-
this._emit(SwarmEvents.TASK_FAILED, { taskId: task.id, error: task.error });
|
|
195
|
-
return task;
|
|
196
|
-
}
|
|
197
|
-
const agent = this._agents.get(agentId);
|
|
198
|
-
if (!agent) {
|
|
199
|
-
task.status = 'failed';
|
|
200
|
-
task.error = `Agent ${agentId} not found in swarm`;
|
|
201
|
-
task.completedAt = Date.now();
|
|
202
|
-
return task;
|
|
203
|
-
}
|
|
204
|
-
// 分配任务
|
|
205
|
-
task.assignedTo = agentId;
|
|
206
|
-
task.status = 'assigned';
|
|
207
|
-
this._emit(SwarmEvents.TASK_ASSIGNED, { taskId: task.id, agentId });
|
|
208
|
-
// 更新 Agent 状态
|
|
209
|
-
this._registry.updateStatus(agentId, 'busy');
|
|
210
|
-
try {
|
|
211
|
-
// 执行任务
|
|
212
|
-
task.status = 'running';
|
|
213
|
-
const messages = [{
|
|
214
|
-
role: 'user',
|
|
215
|
-
content: task.input,
|
|
216
|
-
timestamp: Date.now(),
|
|
217
|
-
}];
|
|
218
|
-
const systemPrompt = `You are agent "${agent.info.name}" in a multi-agent swarm. Your capabilities: ${agent.info.capabilities.join(', ')}. Execute the following task:\n\n${task.description}`;
|
|
219
|
-
// 同步 systemPrompt 到 Agent 上下文
|
|
220
|
-
agent.agent.context.systemPrompt = systemPrompt;
|
|
221
|
-
agent.agent.context.messages = messages;
|
|
222
|
-
let result = '';
|
|
223
|
-
for await (const event of agent.agent.run(undefined, agent.harness)) {
|
|
224
|
-
if (event.type === 'assistant_message') {
|
|
225
|
-
result = typeof event.message.content === 'string' ? event.message.content : '';
|
|
226
|
-
}
|
|
227
|
-
}
|
|
228
|
-
task.result = result;
|
|
229
|
-
task.status = 'completed';
|
|
230
|
-
task.completedAt = Date.now();
|
|
231
|
-
this._emit(SwarmEvents.TASK_COMPLETED, { taskId: task.id, agentId, result });
|
|
232
|
-
// 处理后续任务(如流水线)
|
|
233
|
-
if (this._strategy.onTaskComplete) {
|
|
234
|
-
const followUpTasks = this._strategy.onTaskComplete(task, result, this._agents);
|
|
235
|
-
for (const followUp of followUpTasks) {
|
|
236
|
-
this._tasks.set(followUp.id, followUp);
|
|
237
|
-
// 递归执行后续任务
|
|
238
|
-
await this.executeTask(followUp);
|
|
239
|
-
}
|
|
240
|
-
}
|
|
241
|
-
// 恢复 Agent 状态
|
|
242
|
-
this._registry.updateStatus(agentId, 'idle');
|
|
243
|
-
return task;
|
|
244
|
-
}
|
|
245
|
-
catch (err) {
|
|
246
|
-
task.status = 'failed';
|
|
247
|
-
task.error = err instanceof Error ? err.message : String(err);
|
|
248
|
-
task.completedAt = Date.now();
|
|
249
|
-
this._emit(SwarmEvents.TASK_FAILED, { taskId: task.id, agentId, error: task.error });
|
|
250
|
-
this._registry.updateStatus(agentId, 'idle');
|
|
251
|
-
return task;
|
|
252
|
-
}
|
|
253
|
-
}
|
|
254
|
-
/**
|
|
255
|
-
* 广播任务给所有 Agent
|
|
256
|
-
*/
|
|
257
|
-
async broadcastTask(description, input) {
|
|
258
|
-
const tasks = [];
|
|
259
|
-
for (const [agentId, agent] of this._agents) {
|
|
260
|
-
if (agent.info.status !== 'active' && agent.info.status !== 'idle')
|
|
261
|
-
continue;
|
|
262
|
-
const task = this.submitTask(description, input);
|
|
263
|
-
task.assignedTo = agentId;
|
|
264
|
-
tasks.push(task);
|
|
265
|
-
}
|
|
266
|
-
// 并发执行所有任务
|
|
267
|
-
const results = await Promise.all(tasks.map(task => this.executeTask(task)));
|
|
268
|
-
return results;
|
|
269
|
-
}
|
|
270
|
-
/**
|
|
271
|
-
* 获取任务
|
|
272
|
-
*/
|
|
273
|
-
getTask(taskId) {
|
|
274
|
-
return this._tasks.get(taskId);
|
|
275
|
-
}
|
|
276
|
-
/**
|
|
277
|
-
* 列出所有任务
|
|
278
|
-
*/
|
|
279
|
-
listTasks() {
|
|
280
|
-
return Array.from(this._tasks.values());
|
|
281
|
-
}
|
|
282
|
-
// ── 策略管理 ──
|
|
283
|
-
/**
|
|
284
|
-
* 设置编排策略
|
|
285
|
-
*/
|
|
286
|
-
setStrategy(strategy) {
|
|
287
|
-
this._strategy = strategy;
|
|
288
|
-
}
|
|
289
|
-
/**
|
|
290
|
-
* 获取当前策略
|
|
291
|
-
*/
|
|
292
|
-
getStrategy() {
|
|
293
|
-
return this._strategy;
|
|
294
|
-
}
|
|
295
|
-
// ── 内部方法 ──
|
|
296
|
-
_createDefaultStrategy(config) {
|
|
297
|
-
switch (config.topology) {
|
|
298
|
-
case 'hierarchical':
|
|
299
|
-
return new CapabilityStrategy();
|
|
300
|
-
case 'pipeline':
|
|
301
|
-
return new PipelineStrategy();
|
|
302
|
-
case 'broadcast':
|
|
303
|
-
return new RoundRobinStrategy();
|
|
304
|
-
case 'peer-to-peer':
|
|
305
|
-
return new CapabilityStrategy();
|
|
306
|
-
default:
|
|
307
|
-
return new RoundRobinStrategy();
|
|
308
|
-
}
|
|
309
|
-
}
|
|
310
|
-
_emit(type, data) {
|
|
311
|
-
this._events.emit({
|
|
312
|
-
type,
|
|
313
|
-
timestamp: Date.now(),
|
|
314
|
-
data,
|
|
315
|
-
});
|
|
316
|
-
}
|
|
317
|
-
}
|
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Multi-Agent 系统类型定义
|
|
3
|
-
*
|
|
4
|
-
* Harness 层的多 Agent 编排类型。
|
|
5
|
-
*/
|
|
6
|
-
import type { Agent } from '../../run/agent/index.js';
|
|
7
|
-
import type { ReliabilityHarness } from '../../run/reliability/index.js';
|
|
8
|
-
import type { AgentInfo } from './agent-registry-types.js';
|
|
9
|
-
import type { SessionAwareRunner } from '../../run/runner.js';
|
|
10
|
-
/** Swarm 拓扑类型 */
|
|
11
|
-
export type SwarmTopology = 'hierarchical' | 'peer-to-peer' | 'pipeline' | 'broadcast';
|
|
12
|
-
/** Swarm 配置 */
|
|
13
|
-
export interface SwarmConfig {
|
|
14
|
-
/** Swarm 名称 */
|
|
15
|
-
name: string;
|
|
16
|
-
/** 拓扑类型 */
|
|
17
|
-
topology: SwarmTopology;
|
|
18
|
-
/** 协调者 Agent ID(hierarchical 模式必需) */
|
|
19
|
-
coordinatorId?: string;
|
|
20
|
-
/** 最大并发 Agent 数 */
|
|
21
|
-
maxConcurrency?: number;
|
|
22
|
-
/** 任务超时(毫秒) */
|
|
23
|
-
taskTimeoutMs?: number;
|
|
24
|
-
}
|
|
25
|
-
/** Swarm 中的 Agent 节点 */
|
|
26
|
-
export interface SwarmAgent {
|
|
27
|
-
/** Agent 注册信息 */
|
|
28
|
-
info: AgentInfo;
|
|
29
|
-
/** Agent 实例 */
|
|
30
|
-
agent: Agent;
|
|
31
|
-
/** 可靠性 Harness */
|
|
32
|
-
harness: ReliabilityHarness;
|
|
33
|
-
/** Session 运行器(可选) */
|
|
34
|
-
runner?: SessionAwareRunner;
|
|
35
|
-
}
|
|
36
|
-
/** Swarm 任务 */
|
|
37
|
-
export interface SwarmTask {
|
|
38
|
-
/** 任务 ID */
|
|
39
|
-
id: string;
|
|
40
|
-
/** 任务描述 */
|
|
41
|
-
description: string;
|
|
42
|
-
/** 任务输入 */
|
|
43
|
-
input: string;
|
|
44
|
-
/** 分配给的 Agent ID */
|
|
45
|
-
assignedTo?: string;
|
|
46
|
-
/** 任务状态 */
|
|
47
|
-
status: 'pending' | 'assigned' | 'running' | 'completed' | 'failed';
|
|
48
|
-
/** 任务结果 */
|
|
49
|
-
result?: string;
|
|
50
|
-
/** 错误信息 */
|
|
51
|
-
error?: string;
|
|
52
|
-
/** 创建时间 */
|
|
53
|
-
createdAt: number;
|
|
54
|
-
/** 完成时间 */
|
|
55
|
-
completedAt?: number;
|
|
56
|
-
}
|
|
57
|
-
/** Swarm 事件 */
|
|
58
|
-
export declare const SwarmEvents: {
|
|
59
|
-
readonly AGENT_ADDED: "swarm.agent.added";
|
|
60
|
-
readonly AGENT_REMOVED: "swarm.agent.removed";
|
|
61
|
-
readonly TASK_CREATED: "swarm.task.created";
|
|
62
|
-
readonly TASK_ASSIGNED: "swarm.task.assigned";
|
|
63
|
-
readonly TASK_COMPLETED: "swarm.task.completed";
|
|
64
|
-
readonly TASK_FAILED: "swarm.task.failed";
|
|
65
|
-
readonly TOPOLOGY_CHANGED: "swarm.topology.changed";
|
|
66
|
-
};
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Multi-Agent 系统类型定义
|
|
3
|
-
*
|
|
4
|
-
* Harness 层的多 Agent 编排类型。
|
|
5
|
-
*/
|
|
6
|
-
/** Swarm 事件 */
|
|
7
|
-
export const SwarmEvents = {
|
|
8
|
-
AGENT_ADDED: 'swarm.agent.added',
|
|
9
|
-
AGENT_REMOVED: 'swarm.agent.removed',
|
|
10
|
-
TASK_CREATED: 'swarm.task.created',
|
|
11
|
-
TASK_ASSIGNED: 'swarm.task.assigned',
|
|
12
|
-
TASK_COMPLETED: 'swarm.task.completed',
|
|
13
|
-
TASK_FAILED: 'swarm.task.failed',
|
|
14
|
-
TOPOLOGY_CHANGED: 'swarm.topology.changed',
|
|
15
|
-
};
|