@octopi-agent/engine 0.90.11 → 0.98.4
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/dist/config-admin/agent-presets.d.ts +70 -0
- package/dist/config-admin/agent-presets.js +243 -0
- package/dist/config-admin/discover.d.ts +30 -0
- package/dist/config-admin/discover.js +48 -0
- package/dist/config-admin/env.d.ts +22 -0
- package/dist/config-admin/env.js +41 -0
- package/dist/config-admin/index.d.ts +20 -0
- package/dist/config-admin/index.js +15 -0
- package/dist/config-admin/model-presets.d.ts +75 -0
- package/dist/config-admin/model-presets.js +249 -0
- package/dist/config-admin/name-guard.d.ts +14 -0
- package/dist/config-admin/name-guard.js +24 -0
- package/dist/config-admin/patch.d.ts +56 -0
- package/dist/config-admin/patch.js +201 -0
- package/dist/config-admin/port.d.ts +68 -0
- package/dist/config-admin/port.js +21 -0
- package/dist/config-admin/redact.d.ts +39 -0
- package/dist/config-admin/redact.js +42 -0
- package/dist/config-schema/agent.d.ts +45 -1
- package/dist/config-schema/context.d.ts +6 -1
- package/dist/config-schema/context.js +8 -0
- package/dist/config-schema/engine.d.ts +110 -4
- package/dist/config-schema/governance.d.ts +45 -1
- package/dist/config-schema/governance.js +187 -0
- package/dist/config-schema/models.d.ts +5 -2
- package/dist/config-schema/models.js +4 -1
- package/dist/config-schema/observability.d.ts +9 -0
- package/dist/config-schema/observability.js +29 -0
- package/dist/config-schema/run.d.ts +3 -0
- package/dist/config-schema/run.js +14 -0
- package/dist/config.d.ts +29 -4
- package/dist/config.js +15 -4
- package/dist/harness/activation/dispatcher.d.ts +8 -2
- package/dist/harness/activation/dispatcher.js +33 -5
- package/dist/harness/activation/inbox.d.ts +87 -0
- package/dist/harness/activation/inbox.js +169 -0
- package/dist/harness/activation/runtime.d.ts +9 -8
- package/dist/harness/activation/runtime.js +100 -8
- package/dist/harness/activation/types.d.ts +19 -0
- package/dist/harness/activation/types.js +2 -0
- package/dist/harness/agent/builder.d.ts +26 -1
- package/dist/harness/agent/builder.js +85 -37
- package/dist/harness/agent/config-bridge.d.ts +5 -0
- package/dist/harness/agent/config-bridge.js +3 -0
- package/dist/harness/agent/config-integrity.d.ts +138 -0
- package/dist/harness/agent/config-integrity.js +235 -0
- package/dist/harness/agent/wire-agent-builder.js +7 -1
- package/dist/harness/collaboration/autonomous-subsystem/index.d.ts +2 -2
- package/dist/harness/collaboration/autonomous-subsystem/index.js +1 -1
- package/dist/harness/collaboration/autonomous-subsystem/loader.js +3 -0
- package/dist/harness/collaboration/autonomous-subsystem/sense/engine.js +19 -2
- package/dist/harness/collaboration/autonomous-subsystem/think/completion-guard.d.ts +40 -0
- package/dist/harness/collaboration/autonomous-subsystem/think/completion-guard.js +59 -0
- package/dist/harness/collaboration/autonomous-subsystem/think/executor.js +3 -1
- package/dist/harness/collaboration/autonomous-subsystem/think/index.d.ts +2 -0
- package/dist/harness/collaboration/autonomous-subsystem/think/index.js +1 -0
- package/dist/harness/collaboration/autonomous-subsystem/think/model-resolver.js +1 -1
- package/dist/harness/collaboration/autonomous-subsystem/types.d.ts +9 -0
- package/dist/harness/collaboration/delegation/child-run.js +21 -5
- package/dist/harness/collaboration/delegation/notifier.js +4 -3
- package/dist/harness/collaboration/delegation/service.js +2 -3
- package/dist/harness/collaboration/delegation/wiring.js +6 -5
- package/dist/harness/collaboration/orchestration/reflector/llm-reflector.d.ts +1 -1
- package/dist/harness/collaboration/orchestration/reflector/llm-reflector.js +1 -1
- package/dist/harness/context/capabilities/compact/engine.d.ts +30 -0
- package/dist/harness/context/capabilities/compact/engine.js +198 -46
- package/dist/harness/context/capabilities/compact/handover.d.ts +78 -0
- package/dist/harness/context/capabilities/compact/handover.js +107 -0
- package/dist/harness/context/capabilities/compact/index.d.ts +3 -1
- package/dist/harness/context/capabilities/compact/index.js +2 -1
- package/dist/harness/context/capabilities/compact/types.d.ts +30 -1
- package/dist/harness/context/capabilities/summary/executor.js +2 -1
- package/dist/harness/context/capabilities/summary/policies.js +8 -5
- package/dist/harness/context/capabilities/summary/resolver.d.ts +1 -1
- package/dist/harness/context/capabilities/summary/resolver.js +4 -4
- package/dist/harness/context/capabilities/summary/types.d.ts +2 -2
- package/dist/harness/context/constitution/default-agents.md +11 -10
- package/dist/harness/context/default-context-engine.d.ts +34 -4
- package/dist/harness/context/default-context-engine.js +194 -49
- package/dist/harness/context/hybrid-compressor.js +6 -0
- package/dist/harness/context/layers.d.ts +2 -4
- package/dist/harness/context/layers.js +9 -11
- package/dist/harness/context/llm-summarizer.d.ts +2 -8
- package/dist/harness/context/llm-summarizer.js +69 -91
- package/dist/harness/context/message-selector.js +4 -3
- package/dist/harness/context/summarize.d.ts +3 -1
- package/dist/harness/context/summarize.js +9 -4
- package/dist/harness/context/system-prompt-assembler.d.ts +2 -0
- package/dist/harness/context/system-prompt-assembler.js +1 -0
- package/dist/harness/context/truncate-compressor.js +7 -0
- package/dist/harness/context/turn-envelope.d.ts +3 -2
- package/dist/harness/context/turn-envelope.js +3 -2
- package/dist/harness/context/types.d.ts +33 -1
- package/dist/harness/extension/execution-environment/dangerous-commands.d.ts +28 -0
- package/dist/harness/extension/execution-environment/dangerous-commands.js +129 -0
- package/dist/harness/extension/execution-environment/effect-policy.d.ts +149 -8
- package/dist/harness/extension/execution-environment/effect-policy.js +274 -19
- package/dist/harness/extension/execution-environment/index.d.ts +4 -2
- package/dist/harness/extension/execution-environment/index.js +2 -1
- package/dist/harness/extension/execution-environment/kill-switch.d.ts +34 -0
- package/dist/harness/extension/execution-environment/kill-switch.js +46 -0
- package/dist/harness/extension/execution-environment/ops-audit.d.ts +204 -0
- package/dist/harness/extension/execution-environment/ops-audit.js +337 -0
- package/dist/harness/extension/execution-environment/privileged-exec.d.ts +158 -0
- package/dist/harness/extension/execution-environment/privileged-exec.js +418 -0
- package/dist/harness/extension/execution-environment/process-info.d.ts +180 -0
- package/dist/harness/extension/execution-environment/process-info.js +466 -0
- package/dist/harness/extension/execution-environment/process-isolation.d.ts +7 -0
- package/dist/harness/extension/execution-environment/process-isolation.js +9 -0
- package/dist/harness/extension/execution-environment/sandbox.d.ts +109 -0
- package/dist/harness/extension/execution-environment/sandbox.js +228 -21
- package/dist/harness/extension/execution-environment/tool-capabilities.d.ts +1 -1
- package/dist/harness/extension/execution-environment/tool-capabilities.js +6 -0
- package/dist/harness/extension/execution-environment/types.d.ts +19 -0
- package/dist/harness/extension/execution-environment/undo-log.d.ts +6 -2
- package/dist/harness/extension/execution-environment/undo-log.js +31 -10
- package/dist/harness/extension/plugin-ecosystem/channel-types.d.ts +5 -0
- package/dist/harness/extension/plugin-ecosystem/tools/allowlisted-run.js +33 -0
- package/dist/harness/extension/plugin-ecosystem/tools/ask-user.d.ts +4 -5
- package/dist/harness/extension/plugin-ecosystem/tools/ask-user.js +5 -15
- package/dist/harness/extension/plugin-ecosystem/tools/builtin.d.ts +3 -0
- package/dist/harness/extension/plugin-ecosystem/tools/builtin.js +70 -26
- package/dist/harness/extension/plugin-ecosystem/tools/document-tools.js +3 -9
- package/dist/harness/extension/plugin-ecosystem/tools/file-edit.js +3 -6
- package/dist/harness/extension/plugin-ecosystem/tools/file-ops.js +9 -5
- package/dist/harness/extension/plugin-ecosystem/tools/file-search.js +9 -130
- package/dist/harness/extension/plugin-ecosystem/tools/git-tools.js +122 -14
- 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/package-tools.js +4 -13
- package/dist/harness/extension/plugin-ecosystem/tools/platform.d.ts +25 -11
- package/dist/harness/extension/plugin-ecosystem/tools/platform.js +168 -62
- package/dist/harness/extension/plugin-ecosystem/tools/privileged-tool.d.ts +43 -0
- package/dist/harness/extension/plugin-ecosystem/tools/privileged-tool.js +350 -0
- package/dist/harness/extension/plugin-ecosystem/tools/process-tools.d.ts +30 -0
- package/dist/harness/extension/plugin-ecosystem/tools/process-tools.js +137 -0
- package/dist/harness/governance/human-in-the-loop/decision-cache.d.ts +54 -4
- package/dist/harness/governance/human-in-the-loop/decision-cache.js +42 -16
- package/dist/harness/governance/security/default-risk-policy.d.ts +1 -0
- package/dist/harness/governance/security/default-risk-policy.js +1 -0
- package/dist/harness/governance/security/default-security-guard.js +9 -0
- package/dist/harness/governance/security/index.d.ts +1 -0
- package/dist/harness/governance/security/index.js +2 -0
- package/dist/harness/governance/security/risk-evaluator.js +13 -0
- package/dist/harness/governance/security/risk-types.d.ts +12 -0
- package/dist/harness/governance/security/shell-parser-fallback.d.ts +29 -0
- package/dist/harness/governance/security/shell-parser-fallback.js +410 -0
- package/dist/harness/governance/security/shell-parser-shared.d.ts +83 -0
- package/dist/harness/governance/security/shell-parser-shared.js +188 -0
- package/dist/harness/governance/security/shell-parser-treesitter.d.ts +52 -0
- package/dist/harness/governance/security/shell-parser-treesitter.js +370 -0
- package/dist/harness/governance/security/shell-parser.d.ts +23 -10
- package/dist/harness/governance/security/shell-parser.js +37 -496
- package/dist/harness/governance/security/temp-path.d.ts +9 -0
- package/dist/harness/governance/security/temp-path.js +13 -2
- package/dist/harness/governance/security/vendor/README.md +24 -0
- package/dist/harness/governance/security/vendor/tree-sitter-bash.LICENSE.txt +21 -0
- package/dist/harness/governance/security/vendor/tree-sitter-bash.wasm +0 -0
- package/dist/harness/governance/session-acl/seed-roles.js +14 -0
- package/dist/harness/index.d.ts +2 -0
- package/dist/harness/index.js +2 -0
- package/dist/harness/knowledge/fts.js +1 -2
- package/dist/harness/knowledge/index-store.js +59 -9
- package/dist/harness/memory/index.d.ts +6 -2
- package/dist/harness/memory/index.js +4 -1
- package/dist/harness/memory/memory-events.d.ts +25 -0
- package/dist/harness/memory/memory-events.js +38 -0
- package/dist/harness/memory/sqlite/agent-db.js +15 -0
- package/dist/harness/memory/sqlite/keyword-search.d.ts +1 -0
- package/dist/harness/memory/sqlite/keyword-search.js +4 -3
- package/dist/harness/memory/sqlite/wisdom-store.d.ts +7 -2
- package/dist/harness/memory/sqlite/wisdom-store.js +51 -2
- package/dist/harness/memory/steward-policy.d.ts +3 -0
- package/dist/harness/memory/steward-policy.js +1 -1
- package/dist/harness/memory/types.d.ts +41 -3
- package/dist/harness/memory/wisdom-attribution.d.ts +136 -0
- package/dist/harness/memory/wisdom-attribution.js +287 -0
- package/dist/harness/memory/wisdom-events.d.ts +37 -0
- package/dist/harness/memory/wisdom-events.js +61 -0
- package/dist/harness/memory/wisdom-formation.d.ts +20 -1
- package/dist/harness/memory/wisdom-formation.js +55 -21
- package/dist/harness/memory/wisdom.d.ts +7 -2
- package/dist/harness/memory/wisdom.js +40 -2
- package/dist/harness/observability/observer/hub.js +8 -0
- package/dist/harness/observability/observer/run-snapshot.js +1 -0
- package/dist/harness/observability/observer/types.d.ts +4 -0
- package/dist/harness/run/agent/agent.d.ts +7 -0
- package/dist/harness/run/agent/agent.js +23 -1
- package/dist/harness/run/reliability/fallback-provider.d.ts +117 -5
- package/dist/harness/run/reliability/fallback-provider.js +262 -22
- package/dist/harness/run/reliability/harness-events.d.ts +24 -1
- package/dist/harness/run/reliability/model-error-policy.d.ts +32 -0
- package/dist/harness/run/reliability/model-error-policy.js +42 -0
- package/dist/harness/run/reliability/provider-wrapper.js +29 -2
- package/dist/harness/run/reliability/refusal-guard.d.ts +20 -0
- package/dist/harness/run/reliability/refusal-guard.js +102 -0
- package/dist/harness/run/reliability/run-agent.js +231 -33
- package/dist/harness/run/run-guard/default-run-guard.js +1 -1
- package/dist/harness/run/run-scope.d.ts +35 -0
- package/dist/harness/run/runner.d.ts +141 -2
- package/dist/harness/run/runner.js +592 -42
- package/dist/harness/session/attachments/llm-intent.js +2 -1
- package/dist/harness/session/tasks/render.d.ts +4 -1
- package/dist/harness/session/tasks/render.js +10 -7
- package/dist/harness/shared/events/agent-event-map.d.ts +66 -0
- package/dist/harness/shared/events/agent-event-map.js +5 -0
- package/dist/harness/shared/paths/glob.d.ts +52 -0
- package/dist/harness/shared/paths/glob.js +218 -0
- package/dist/harness/shared/paths/index.d.ts +84 -0
- package/dist/harness/shared/paths/index.js +179 -0
- package/dist/index.d.ts +3 -3
- package/dist/index.js +2 -2
- package/dist/integration/agent-runtime/channel-message-source.js +19 -1
- package/dist/integration/index.d.ts +2 -0
- package/dist/integration/index.js +1 -0
- package/dist/integration/observability/loop-watchdog.d.ts +56 -0
- package/dist/integration/observability/loop-watchdog.js +177 -0
- package/dist/integration/observability/metrics.d.ts +3 -0
- package/dist/integration/observability/metrics.js +18 -7
- package/dist/integration/providers/anthropic.d.ts +23 -0
- package/dist/integration/providers/anthropic.js +97 -12
- package/dist/integration/providers/fetch-timeout.d.ts +42 -0
- package/dist/integration/providers/fetch-timeout.js +51 -0
- package/dist/integration/providers/openai.d.ts +10 -0
- package/dist/integration/providers/openai.js +58 -11
- package/dist/integration/providers/provider-diagnostics.d.ts +80 -0
- package/dist/integration/providers/provider-diagnostics.js +89 -0
- package/dist/integration/providers/timeout-coherence.d.ts +52 -0
- package/dist/integration/providers/timeout-coherence.js +68 -0
- package/dist/integration/providers/wire-dump.d.ts +62 -0
- package/dist/integration/providers/wire-dump.js +111 -2
- package/dist/integration/storage/jsonl.js +4 -1
- package/dist/subsystems/cognition-steward/conceptualize/config.yaml +4 -2
- package/dist/subsystems/cognition-steward/conceptualize/handler.js +12 -20
- package/dist/subsystems/memory-steward/backfill/config.yaml +4 -2
- package/dist/subsystems/memory-steward/backfill/handler.js +44 -52
- package/dist/subsystems/wisdom-steward/attribute/SUBSYSTEM.md +24 -0
- package/dist/subsystems/wisdom-steward/attribute/config.yaml +60 -0
- package/dist/subsystems/wisdom-steward/attribute/handler.d.ts +23 -0
- package/dist/subsystems/wisdom-steward/attribute/handler.js +167 -0
- package/dist/subsystems/wisdom-steward/evaluate/handler.js +3 -1
- package/dist/subsystems/wisdom-steward/formation/config.yaml +12 -5
- package/dist/subsystems/wisdom-steward/formation/handler.js +12 -18
- package/dist/subsystems/wisdom-steward/govern/config.yaml +1 -1
- package/dist/subsystems/wisdom-steward/govern/handler.js +4 -0
- package/package.json +8 -2
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
* 设计:arch/agent-runtime.md
|
|
8
8
|
*/
|
|
9
9
|
import { CoalesceBuffer } from './coalesce.js';
|
|
10
|
-
import { buildRunRequest, resolveSessionId } from './compiler.js';
|
|
10
|
+
import { buildRunRequest, compileMessages, resolveSessionId } from './compiler.js';
|
|
11
11
|
import { ExplicitRouter } from './router.js';
|
|
12
12
|
import { RuntimeEvents } from './types.js';
|
|
13
13
|
/**
|
|
@@ -156,8 +156,9 @@ export class AgentRuntime {
|
|
|
156
156
|
return results;
|
|
157
157
|
}
|
|
158
158
|
/**
|
|
159
|
-
* 模型 A:await 至 Run 结束(或 skipped / failed)
|
|
159
|
+
* 模型 A:await 至 Run 结束(或 skipped / failed / accepted)
|
|
160
160
|
* @param options.onEvent - 转发 Run 事件流(Gateway 流式广播);不变量 #6
|
|
161
|
+
* @param options.onDelivery - 活跃 Run 接收即回执(早于 Run 结束)
|
|
161
162
|
*/
|
|
162
163
|
async dispatch(trigger, options) {
|
|
163
164
|
if (!this.started) {
|
|
@@ -183,8 +184,22 @@ export class AgentRuntime {
|
|
|
183
184
|
});
|
|
184
185
|
return { status: 'skipped', reason: 'no_agent' };
|
|
185
186
|
}
|
|
187
|
+
// 回执恒发一次:fan-out 多 target 时首个去向生效,其余静默
|
|
188
|
+
//(每 target 一帧 accepted 会与 channel/web 的「一次受理」契约冲突)
|
|
189
|
+
let deliveryFired = false;
|
|
190
|
+
const deliveryOptions = options
|
|
191
|
+
? {
|
|
192
|
+
...options,
|
|
193
|
+
onDelivery: (delivery) => {
|
|
194
|
+
if (deliveryFired)
|
|
195
|
+
return;
|
|
196
|
+
deliveryFired = true;
|
|
197
|
+
options.onDelivery?.(delivery);
|
|
198
|
+
},
|
|
199
|
+
}
|
|
200
|
+
: undefined;
|
|
186
201
|
if (targets.length === 1) {
|
|
187
|
-
const result = await this.dispatchToTarget(trigger, targets[0],
|
|
202
|
+
const result = await this.dispatchToTarget(trigger, targets[0], deliveryOptions);
|
|
188
203
|
// 单目标丢弃也必须留下 TRIGGER_DROPPED(与 fan-out 对称):
|
|
189
204
|
// 「trigger 未被受理必有 dropped 事件」是委派送达回执(delegation §7.1)
|
|
190
205
|
// 依赖的不变量,缺事件 = 送达回执无法证伪。受理后 run 失败走 RUN_FAILED
|
|
@@ -201,11 +216,11 @@ export class AgentRuntime {
|
|
|
201
216
|
// fan-out:串行;聚合为 FanoutDispatchResult(ran/aborted/failed 均不静默丢弃)
|
|
202
217
|
const results = [];
|
|
203
218
|
for (const target of targets) {
|
|
204
|
-
const result = await this.dispatchToTarget(trigger, target,
|
|
219
|
+
const result = await this.dispatchToTarget(trigger, target, deliveryOptions);
|
|
205
220
|
results.push({ agentId: target.agentId, result });
|
|
206
221
|
}
|
|
207
222
|
const anyFailed = results.some((r) => r.result.status === 'failed');
|
|
208
|
-
const anyRan = results.some((r) => r.result.status === 'ran');
|
|
223
|
+
const anyRan = results.some((r) => r.result.status === 'ran' || r.result.status === 'accepted');
|
|
209
224
|
const allSkipped = results.every((r) => r.result.status === 'skipped');
|
|
210
225
|
if (anyFailed) {
|
|
211
226
|
this.emitRuntime(RuntimeEvents.TRIGGER_DROPPED, {
|
|
@@ -234,6 +249,40 @@ export class AgentRuntime {
|
|
|
234
249
|
}
|
|
235
250
|
return { status: 'skipped', reason: 'no_agent' };
|
|
236
251
|
}
|
|
252
|
+
/**
|
|
253
|
+
* 路由目标的活跃 inbox 接收(human 与 delegation signal 共用)。
|
|
254
|
+
* 仅 message / agent_signal 可接续;其余类型与带附件/换模型输入走完整新 Run。
|
|
255
|
+
*/
|
|
256
|
+
offerToTarget(trigger, target, sessionId, onEvent) {
|
|
257
|
+
if (!target.dispatcher.inbox)
|
|
258
|
+
return 'dispatched';
|
|
259
|
+
if (trigger.type !== 'message' && trigger.type !== 'agent_signal')
|
|
260
|
+
return 'dispatched';
|
|
261
|
+
const [compiledMessage] = compileMessages([trigger]);
|
|
262
|
+
const human = trigger.type === 'message' && trigger.payload.kind === 'user_message';
|
|
263
|
+
const delegationId = trigger.metadata?.delegationId;
|
|
264
|
+
return target.dispatcher.inbox.offer({
|
|
265
|
+
agentId: target.agentId,
|
|
266
|
+
sessionId,
|
|
267
|
+
entryId: delegationId ?? trigger.id,
|
|
268
|
+
triggerType: trigger.type,
|
|
269
|
+
human,
|
|
270
|
+
modelOverride: trigger.metadata?.modelOverride,
|
|
271
|
+
modelProvider: trigger.metadata?.modelProvider,
|
|
272
|
+
trigger,
|
|
273
|
+
onEvent,
|
|
274
|
+
message: compiledMessage,
|
|
275
|
+
onAdmitted: (delivery) => {
|
|
276
|
+
this.emitRuntime(RuntimeEvents.INBOX_ADMITTED, {
|
|
277
|
+
triggerId: trigger.id,
|
|
278
|
+
agentId: target.agentId,
|
|
279
|
+
sessionId,
|
|
280
|
+
delegationId,
|
|
281
|
+
delivery,
|
|
282
|
+
});
|
|
283
|
+
},
|
|
284
|
+
});
|
|
285
|
+
}
|
|
237
286
|
async dispatchToTarget(trigger, target, options) {
|
|
238
287
|
const agent = this.agents.get(target.agentId);
|
|
239
288
|
if (!agent) {
|
|
@@ -243,6 +292,14 @@ export class AgentRuntime {
|
|
|
243
292
|
...trigger,
|
|
244
293
|
sessionId: target.sessionId ?? trigger.sessionId,
|
|
245
294
|
});
|
|
295
|
+
// 单一 offer 点:活跃 Run 接收 = 不再开新 Run(原 Trigger 不 dispatch,
|
|
296
|
+
// Run 关闭未消费时由 inbox 按原 Trigger 重投)
|
|
297
|
+
const offerResult = this.offerToTarget(trigger, agent, sessionId, options?.onEvent);
|
|
298
|
+
if (offerResult === 'steered' || offerResult === 'duplicate') {
|
|
299
|
+
options?.onDelivery?.('steered');
|
|
300
|
+
return { status: 'accepted', agentId: agent.agentId, sessionId, delivery: 'steered' };
|
|
301
|
+
}
|
|
302
|
+
options?.onDelivery?.('run');
|
|
246
303
|
if (trigger.coalesceKey) {
|
|
247
304
|
this.emitRuntime(RuntimeEvents.RUN_SCHEDULED, {
|
|
248
305
|
triggerId: trigger.id,
|
|
@@ -291,15 +348,46 @@ export class AgentRuntime {
|
|
|
291
348
|
triggerType: triggers[0]?.type,
|
|
292
349
|
});
|
|
293
350
|
try {
|
|
351
|
+
// loop 终态如实镜像到 RUN_ENDED / DispatchResult:LLM 彻底失败以
|
|
352
|
+
// engine.error 事件收尾(不 throw),不得记成 completed——否则事故在
|
|
353
|
+
// 监控与 dispatch 结果里隐身(10-27 事故同族问题)
|
|
354
|
+
let endReason;
|
|
355
|
+
let endError;
|
|
294
356
|
for await (const event of agent.dispatcher.execute(request, controller.signal)) {
|
|
357
|
+
// 所有 Trigger(含后台 signal)共用一个 run-event 出口;调用方的
|
|
358
|
+
// onEvent 只承担该次 dispatch 的业务收尾,不再是后台 Run 的唯一可见通道。
|
|
359
|
+
this.emitRuntime(RuntimeEvents.RUN_EVENT, {
|
|
360
|
+
requestId: request.requestId,
|
|
361
|
+
triggerId: triggers[0]?.id,
|
|
362
|
+
triggerType: triggers[0]?.type,
|
|
363
|
+
// 路由键必带:gateway 按 sessionId 扇出 WS(缺则整条流式/终态链路静默落空)
|
|
364
|
+
agentId: agent.agentId,
|
|
365
|
+
sessionId,
|
|
366
|
+
event,
|
|
367
|
+
});
|
|
368
|
+
if (event.type === 'engine.end') {
|
|
369
|
+
const reason = event.data?.reason;
|
|
370
|
+
if (endReason !== 'error') {
|
|
371
|
+
// error 粘滞:合批(coalesce)里前一条 entry 失败、后一条成功时
|
|
372
|
+
// 不得被翻回 completed——任一 entry 失败即整体失败
|
|
373
|
+
endReason = reason === 'should_stop' || reason === 'aborted' ? reason : 'completed';
|
|
374
|
+
}
|
|
375
|
+
}
|
|
376
|
+
else if (event.type === 'engine.error') {
|
|
377
|
+
endReason = 'error';
|
|
378
|
+
const rawError = event.data?.error;
|
|
379
|
+
// 与 runner 同口径取 message(自定义 dispatcher 直传 Error 时不留 "Error: " 前缀)
|
|
380
|
+
endError = rawError instanceof Error ? rawError.message : String(rawError ?? 'Unknown error');
|
|
381
|
+
}
|
|
295
382
|
try {
|
|
296
383
|
onEvent?.(event);
|
|
297
384
|
}
|
|
298
385
|
catch {
|
|
299
|
-
//
|
|
386
|
+
// 消费者(频道最终回复等)异常不中断 Run
|
|
300
387
|
}
|
|
301
388
|
}
|
|
302
|
-
|
|
389
|
+
// error 优先于 aborted:失败与中止同刻到达时,失败不得在监控里消失
|
|
390
|
+
if (controller.signal.aborted && endReason !== 'error') {
|
|
303
391
|
this.emitRuntime(RuntimeEvents.RUN_ENDED, {
|
|
304
392
|
requestId: request.requestId,
|
|
305
393
|
agentId: agent.agentId,
|
|
@@ -312,8 +400,12 @@ export class AgentRuntime {
|
|
|
312
400
|
requestId: request.requestId,
|
|
313
401
|
agentId: agent.agentId,
|
|
314
402
|
sessionId,
|
|
315
|
-
reason: 'completed',
|
|
403
|
+
reason: endReason ?? 'completed',
|
|
404
|
+
...(endError ? { error: endError } : {}),
|
|
316
405
|
});
|
|
406
|
+
if (endReason === 'error') {
|
|
407
|
+
return { status: 'failed', error: endError ?? 'unknown' };
|
|
408
|
+
}
|
|
317
409
|
return {
|
|
318
410
|
status: 'ran',
|
|
319
411
|
requestId: request.requestId,
|
|
@@ -95,6 +95,17 @@ export interface RunAuditRecord {
|
|
|
95
95
|
}
|
|
96
96
|
export interface RunDispatcher {
|
|
97
97
|
execute(req: RunRequest, signal?: AbortSignal): AsyncIterable<AgentEvent>;
|
|
98
|
+
/** 可选:活跃 Run 接续;缺省保持原 Trigger 排队语义。 */
|
|
99
|
+
inbox?: {
|
|
100
|
+
offer(signal: import('./inbox.js').SessionInboxSignal): import('./inbox.js').InboxOfferResult;
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
/** dispatch 调用方选项 */
|
|
104
|
+
export interface DispatchOptions {
|
|
105
|
+
/** Run 事件流转发(频道回复捕获等);不变量 #6 */
|
|
106
|
+
onEvent?: (event: AgentEvent) => void;
|
|
107
|
+
/** 活跃 Run 接收即回执(早于 Run 结束);run = 走新 Run。 */
|
|
108
|
+
onDelivery?: (delivery: 'steered' | 'run') => void;
|
|
98
109
|
}
|
|
99
110
|
export interface RouteTarget {
|
|
100
111
|
agentId: string;
|
|
@@ -127,6 +138,12 @@ export type DispatchResult = {
|
|
|
127
138
|
requestId: string;
|
|
128
139
|
agentId: string;
|
|
129
140
|
sessionId: string;
|
|
141
|
+
} | {
|
|
142
|
+
/** 已交活跃 Run 在下一消息边界接续(不开新 Run)。 */
|
|
143
|
+
status: 'accepted';
|
|
144
|
+
agentId: string;
|
|
145
|
+
sessionId: string;
|
|
146
|
+
delivery: 'steered';
|
|
130
147
|
} | {
|
|
131
148
|
status: 'skipped';
|
|
132
149
|
reason: 'no_agent' | 'filtered' | 'runtime_stopped' | 'aborted';
|
|
@@ -159,6 +176,8 @@ export declare const RuntimeEvents: {
|
|
|
159
176
|
readonly RUN_FAILED: "runtime.run.failed";
|
|
160
177
|
readonly AGENT_SIGNAL_EMITTED: "runtime.agent_signal.emitted";
|
|
161
178
|
readonly TRIGGER_DROPPED: "runtime.trigger.dropped";
|
|
179
|
+
readonly RUN_EVENT: "runtime.run.event";
|
|
180
|
+
readonly INBOX_ADMITTED: "runtime.inbox.admitted";
|
|
162
181
|
};
|
|
163
182
|
export type RuntimeEventType = (typeof RuntimeEvents)[keyof typeof RuntimeEvents];
|
|
164
183
|
export interface RuntimeEvent {
|
|
@@ -18,7 +18,8 @@ import type { ModelProvider } from '@octopi-agent/core/interfaces/model-provider
|
|
|
18
18
|
import { Agent } from '../run/agent/index.js';
|
|
19
19
|
import type { ReliabilityConfig, ReliabilityHarness } from '../run/reliability/run-agent.js';
|
|
20
20
|
import type { ContextEngine, SummarizeFunction } from '../context/types.js';
|
|
21
|
-
import type { ErrorStrategy } from '@octopi-agent/core/interfaces/error-strategy.js';
|
|
21
|
+
import type { ErrorStrategy, ClassifiedError, ErrorAction, OverflowAction } from '@octopi-agent/core/interfaces/error-strategy.js';
|
|
22
|
+
import type { SecurityViolation, SecurityAction } from '@octopi-agent/core/security-guard.js';
|
|
22
23
|
import type { RunGuard } from '@octopi-agent/core/interfaces/run-guard.js';
|
|
23
24
|
import type { RunGuardConfig } from '../run/run-guard/default-run-guard.js';
|
|
24
25
|
import type { Observer } from '@octopi-agent/core/interfaces/observer.js';
|
|
@@ -31,6 +32,13 @@ import { SessionAwareRunner } from '../run/runner.js';
|
|
|
31
32
|
import type { SessionAwareRunnerConfig } from '../run/runner.js';
|
|
32
33
|
import type { McpClientFactory } from '../extension/plugin-ecosystem/mcp/manager.js';
|
|
33
34
|
import type { McpServerConfig, McpManager } from '../extension/plugin-ecosystem/mcp/types.js';
|
|
35
|
+
/** 默认错误策略(按原因分级重试 + 中止;上限见 MODEL_ERROR_MAX_ATTEMPTS) */
|
|
36
|
+
export declare class DefaultErrorStrategy implements ErrorStrategy {
|
|
37
|
+
onModelError(error: ClassifiedError, attempt: number): ErrorAction;
|
|
38
|
+
onToolError(error: ClassifiedError, _call: any): ErrorAction;
|
|
39
|
+
onContextOverflow(_tokenCount: number, _limit: number): OverflowAction;
|
|
40
|
+
onSecurityViolation(violation: SecurityViolation): SecurityAction;
|
|
41
|
+
}
|
|
34
42
|
/** 工具运行时上下文提供者 */
|
|
35
43
|
export interface ToolContextProvider {
|
|
36
44
|
get(): {
|
|
@@ -44,8 +52,17 @@ export interface ToolContextProvider {
|
|
|
44
52
|
memoryEffects: import('@octopi-agent/core/types/tools.js').MemoryEffectJournal;
|
|
45
53
|
pathRoots?: string[];
|
|
46
54
|
pathContainment?: 'strict' | 'soft' | 'none';
|
|
55
|
+
/** 拒绝最终组件为符号链接的文件读写(来自 effectPolicy.refuseFinalSymlink) */
|
|
56
|
+
refuseFinalSymlink?: boolean;
|
|
57
|
+
pathDenylist?: readonly string[];
|
|
47
58
|
confirmEffect?: import('@octopi-agent/core/types/tools.js').ToolExecutionContext['confirmEffect'];
|
|
48
59
|
effectChannel?: 'engine' | 'host-gate';
|
|
60
|
+
/** 提权策略(ops P3/P4,resolved;与 core ToolExecutionContext 同源) */
|
|
61
|
+
escalation?: import('@octopi-agent/core/types/tools.js').ToolExecutionContext['escalation'];
|
|
62
|
+
/** 危险命令减速带 resolved(§6;与 core ToolExecutionContext 同源) */
|
|
63
|
+
dangerousCommands?: import('@octopi-agent/core/types/tools.js').ToolExecutionContext['dangerousCommands'];
|
|
64
|
+
/** 参与者身份(SEC-2 / ops P5;与 core ToolExecutionContext 同源) */
|
|
65
|
+
sessionParticipants?: import('@octopi-agent/core/types/tools.js').ToolExecutionContext['sessionParticipants'];
|
|
49
66
|
processLimits?: boolean;
|
|
50
67
|
shellEscape?: 'deny' | 'confirm' | 'allow';
|
|
51
68
|
shellJournal?: 'snapshot' | 'off';
|
|
@@ -181,6 +198,8 @@ export declare class AgentBuilder {
|
|
|
181
198
|
private _knowledgeGrounding?;
|
|
182
199
|
/** 智慧(注入 system prompt WisdomLayer) */
|
|
183
200
|
private _wisdomStore?;
|
|
201
|
+
/** Wisdom 注入策略(wisdom.injection:core/scenario 上限 + trialVisible) */
|
|
202
|
+
private _wisdomInjection?;
|
|
184
203
|
/** 认知图谱(注入 system prompt CognitionLayer) */
|
|
185
204
|
private _cognitionStore?;
|
|
186
205
|
/** system prompt 装配器调参 */
|
|
@@ -337,6 +356,12 @@ export declare class AgentBuilder {
|
|
|
337
356
|
}): this;
|
|
338
357
|
/** 注入 WisdomStore(半静态思维范式,进 system prompt WisdomLayer) */
|
|
339
358
|
wisdomStore(store: import('../memory/types.js').WisdomStore): this;
|
|
359
|
+
/** 注入策略(wisdom.injection.*:coreMaxItems/scenarioMaxItems/trialVisible) */
|
|
360
|
+
wisdomInjection(cfg: {
|
|
361
|
+
coreMaxItems?: number;
|
|
362
|
+
scenarioMaxItems?: number;
|
|
363
|
+
trialVisible?: boolean;
|
|
364
|
+
}): this;
|
|
340
365
|
/** 注入 ConceptGraphStore(spreadingActivate 召回概念子图,进 system prompt CognitionLayer) */
|
|
341
366
|
cognitionStore(store: import('../memory/types.js').ConceptGraphStore): this;
|
|
342
367
|
/**
|
|
@@ -29,6 +29,7 @@ import { createSessionScheduleTools } from '../session/schedules/tools.js';
|
|
|
29
29
|
import { InMemorySessionStore } from '../session/in-memory-store.js';
|
|
30
30
|
import { DefaultEventBus, } from '@octopi-agent/core/primitives/event-bus.js';
|
|
31
31
|
import { DefaultSecurityGuard, } from '../governance/security/default-security-guard.js';
|
|
32
|
+
import { initShellParser } from '../governance/security/shell-parser.js';
|
|
32
33
|
import { BudgetPolicyEngine, } from '../run/budget/budget.js';
|
|
33
34
|
import { PersonaSource } from './persona.js';
|
|
34
35
|
import { getRunScope } from '../run/run-scope.js';
|
|
@@ -37,24 +38,30 @@ import { createProviderSummarize } from '../context/summarize.js';
|
|
|
37
38
|
import { createDefaultSystemPromptAssembler } from '../context/system-prompt-assembler.js';
|
|
38
39
|
import { SessionAwareRunner } from '../run/runner.js';
|
|
39
40
|
import { DefaultMcpManager } from '../extension/plugin-ecosystem/mcp/manager.js';
|
|
41
|
+
import { maxAttemptsFor } from '../run/reliability/model-error-policy.js';
|
|
40
42
|
// ── 默认实现 ──
|
|
41
|
-
/**
|
|
42
|
-
class DefaultErrorStrategy {
|
|
43
|
+
/** 默认错误策略(按原因分级重试 + 中止;上限见 MODEL_ERROR_MAX_ATTEMPTS) */
|
|
44
|
+
export class DefaultErrorStrategy {
|
|
43
45
|
onModelError(error, attempt) {
|
|
46
|
+
const maxAttempts = maxAttemptsFor(error.reason);
|
|
44
47
|
// ── 可重试错误:限流、超时、网络、服务端 ──
|
|
45
|
-
if (error.reason === 'rate_limit' && attempt <
|
|
48
|
+
if (error.reason === 'rate_limit' && attempt < maxAttempts) {
|
|
46
49
|
const delayMs = error.retryAfterMs ?? (attempt + 1) * 1000;
|
|
47
50
|
return { action: 'retry', delayMs };
|
|
48
51
|
}
|
|
49
|
-
if (error.reason === 'timeout' && attempt <
|
|
52
|
+
if (error.reason === 'timeout' && attempt < maxAttempts) {
|
|
50
53
|
return { action: 'retry', delayMs: (attempt + 1) * 1000 };
|
|
51
54
|
}
|
|
52
|
-
if (error.reason === 'network' && attempt <
|
|
55
|
+
if (error.reason === 'network' && attempt < maxAttempts) {
|
|
53
56
|
return { action: 'retry', delayMs: (attempt + 1) * 1500 };
|
|
54
57
|
}
|
|
55
|
-
if (error.reason === 'server' && attempt <
|
|
58
|
+
if (error.reason === 'server' && attempt < maxAttempts) {
|
|
56
59
|
return { action: 'retry', delayMs: (attempt + 1) * 2000 };
|
|
57
60
|
}
|
|
61
|
+
// ── content_filter:内容过滤拒答多为阈值型误杀,原样重试常过;不教模型换说法绕过 ──
|
|
62
|
+
if (error.reason === 'content_filter' && attempt < maxAttempts) {
|
|
63
|
+
return { action: 'retry', delayMs: (attempt + 1) * 1000 };
|
|
64
|
+
}
|
|
58
65
|
// ── context_length:由引擎尝试 compact,这里返回 abort 让引擎决定 ──
|
|
59
66
|
if (error.reason === 'context_length') {
|
|
60
67
|
return { action: 'abort', reason: `Context length exceeded: ${error.message}` };
|
|
@@ -102,29 +109,17 @@ class RuntimeToolContextProvider {
|
|
|
102
109
|
const unconfigured = createUnconfiguredFileEffects();
|
|
103
110
|
const unconfiguredMemory = createUnconfiguredMemoryEffects();
|
|
104
111
|
if (scope?.toolRuntime) {
|
|
112
|
+
// Spread rather than copy field by field: this list has already dropped a
|
|
113
|
+
// newly added security field twice (refuseFinalSymlink, and the gateway's
|
|
114
|
+
// sibling mapping dropped pathContainment/pathRoots). Enumerating is what
|
|
115
|
+
// makes that failure possible, and it fails silently because the field is
|
|
116
|
+
// optional. Everything on RunToolRuntime is context by construction.
|
|
105
117
|
return {
|
|
106
|
-
|
|
107
|
-
agentId: scope.toolRuntime.agentId,
|
|
118
|
+
...scope.toolRuntime,
|
|
108
119
|
runId: scope.runId,
|
|
109
|
-
messages: scope.toolRuntime.messages,
|
|
110
120
|
cwd: scope.toolRuntime.cwd ?? this.cwd,
|
|
111
|
-
attachmentRoots: scope.toolRuntime.attachmentRoots,
|
|
112
121
|
fileEffects: scope.toolRuntime.fileEffects ?? unconfigured,
|
|
113
122
|
memoryEffects: scope.toolRuntime.memoryEffects ?? unconfiguredMemory,
|
|
114
|
-
pathRoots: scope.toolRuntime.pathRoots,
|
|
115
|
-
undoRoots: scope.toolRuntime.undoRoots,
|
|
116
|
-
networkPolicy: scope.toolRuntime.networkPolicy,
|
|
117
|
-
requireCredentialBindings: scope.toolRuntime.requireCredentialBindings,
|
|
118
|
-
requireJail: scope.toolRuntime.requireJail,
|
|
119
|
-
homeWrite: scope.toolRuntime.homeWrite,
|
|
120
|
-
noteSecurityDegraded: scope.toolRuntime.noteSecurityDegraded,
|
|
121
|
-
pathContainment: scope.toolRuntime.pathContainment,
|
|
122
|
-
confirmEffect: scope.toolRuntime.confirmEffect,
|
|
123
|
-
effectChannel: scope.toolRuntime.effectChannel,
|
|
124
|
-
processLimits: scope.toolRuntime.processLimits,
|
|
125
|
-
shellEscape: scope.toolRuntime.shellEscape,
|
|
126
|
-
shellJournal: scope.toolRuntime.shellJournal,
|
|
127
|
-
shellJournalLimit: scope.toolRuntime.shellJournalLimit,
|
|
128
123
|
};
|
|
129
124
|
}
|
|
130
125
|
if (scope) {
|
|
@@ -165,7 +160,7 @@ function convertToAgentTool(tool, contextProvider) {
|
|
|
165
160
|
description: tool.definition.description,
|
|
166
161
|
executionMode: tool.executionMode,
|
|
167
162
|
parameters: buildToolLlmParameters(tool.definition.parameters),
|
|
168
|
-
execute: async (toolCallId, args, signal) => {
|
|
163
|
+
execute: async (toolCallId, args, signal, onUpdate) => {
|
|
169
164
|
const startTime = Date.now();
|
|
170
165
|
try {
|
|
171
166
|
const context = contextProvider.get();
|
|
@@ -176,7 +171,12 @@ function convertToAgentTool(tool, contextProvider) {
|
|
|
176
171
|
const handlerArgs = prepareHandlerArgs(rawArgs, tool.definition);
|
|
177
172
|
const { runWithToolLimits, resolveToolTimeoutMs } = await import('../extension/execution-environment/resource-limits.js');
|
|
178
173
|
const processLimitsEnabled = context.processLimits !== false;
|
|
179
|
-
const result = await runWithToolLimits((sig) => tool.handler(handlerArgs, {
|
|
174
|
+
const result = await runWithToolLimits((sig) => tool.handler(handlerArgs, {
|
|
175
|
+
...context,
|
|
176
|
+
abortSignal: sig,
|
|
177
|
+
// 工具部分输出通道(展示用途);无转发器时不给工具假通道
|
|
178
|
+
...(onUpdate ? { onUpdate } : {}),
|
|
179
|
+
}), {
|
|
180
180
|
timeoutMs: processLimitsEnabled
|
|
181
181
|
? resolveToolTimeoutMs(tool.definition)
|
|
182
182
|
: undefined,
|
|
@@ -376,6 +376,8 @@ export class AgentBuilder {
|
|
|
376
376
|
_knowledgeGrounding;
|
|
377
377
|
/** 智慧(注入 system prompt WisdomLayer) */
|
|
378
378
|
_wisdomStore;
|
|
379
|
+
/** Wisdom 注入策略(wisdom.injection:core/scenario 上限 + trialVisible) */
|
|
380
|
+
_wisdomInjection;
|
|
379
381
|
/** 认知图谱(注入 system prompt CognitionLayer) */
|
|
380
382
|
_cognitionStore;
|
|
381
383
|
/** system prompt 装配器调参 */
|
|
@@ -609,6 +611,11 @@ export class AgentBuilder {
|
|
|
609
611
|
this._wisdomStore = store;
|
|
610
612
|
return this;
|
|
611
613
|
}
|
|
614
|
+
/** 注入策略(wisdom.injection.*:coreMaxItems/scenarioMaxItems/trialVisible) */
|
|
615
|
+
wisdomInjection(cfg) {
|
|
616
|
+
this._wisdomInjection = cfg;
|
|
617
|
+
return this;
|
|
618
|
+
}
|
|
612
619
|
/** 注入 ConceptGraphStore(spreadingActivate 召回概念子图,进 system prompt CognitionLayer) */
|
|
613
620
|
cognitionStore(store) {
|
|
614
621
|
this._cognitionStore = store;
|
|
@@ -826,6 +833,8 @@ export class AgentBuilder {
|
|
|
826
833
|
const mode = options?.mode ?? 'full';
|
|
827
834
|
const events = this._events ?? new DefaultEventBus();
|
|
828
835
|
this._events = events;
|
|
836
|
+
// Shell 解析引擎(安全风险评估依赖;失败自动降级 legacy,不阻断构建)
|
|
837
|
+
await initShellParser();
|
|
829
838
|
// 并发控制:ProviderPool
|
|
830
839
|
if (this._concurrencyConfig?.providerPool && this._namedProviders.size > 0) {
|
|
831
840
|
const { ProviderPool } = await import('../run/concurrency/provider-pool.js');
|
|
@@ -887,17 +896,32 @@ export class AgentBuilder {
|
|
|
887
896
|
gates: memCfg?.gates?.maxLength
|
|
888
897
|
? { maxLength: memCfg.gates.maxLength }
|
|
889
898
|
: undefined,
|
|
890
|
-
onStored:
|
|
899
|
+
onStored: events
|
|
891
900
|
? (info) => {
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
901
|
+
// 概念化请求只在 cognitionStore 存在时发(否则 conceptualize handler 无 store 会抛错)
|
|
902
|
+
if (this._cognitionStore) {
|
|
903
|
+
void import('../memory/cognition-trigger.js')
|
|
904
|
+
.then(({ emitConceptualizeRequest }) => {
|
|
905
|
+
emitConceptualizeRequest(events, {
|
|
906
|
+
memoryId: info.id,
|
|
907
|
+
proposition: info.proposition,
|
|
908
|
+
evidence: info.evidence,
|
|
909
|
+
memoryType: info.type,
|
|
910
|
+
memoryStatus: info.status,
|
|
911
|
+
channel: info.channel,
|
|
912
|
+
sessionId: info.sessionId,
|
|
913
|
+
});
|
|
914
|
+
})
|
|
915
|
+
.catch(() => {
|
|
916
|
+
// 动态加载失败不阻断 memory 写
|
|
917
|
+
});
|
|
918
|
+
}
|
|
919
|
+
void import('../memory/memory-events.js')
|
|
920
|
+
.then(({ emitMemoryStored }) => {
|
|
921
|
+
emitMemoryStored(events, {
|
|
895
922
|
memoryId: info.id,
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
memoryType: info.type,
|
|
899
|
-
memoryStatus: info.status,
|
|
900
|
-
channel: info.channel,
|
|
923
|
+
type: info.type,
|
|
924
|
+
status: info.status,
|
|
901
925
|
sessionId: info.sessionId,
|
|
902
926
|
});
|
|
903
927
|
})
|
|
@@ -996,6 +1020,9 @@ export class AgentBuilder {
|
|
|
996
1020
|
knowledgeGroupByScope: this._knowledgeCatalogOpts?.groupByScope,
|
|
997
1021
|
knowledgeShowProgress: this._knowledgeCatalogOpts?.showProgress,
|
|
998
1022
|
wisdomStore,
|
|
1023
|
+
wisdomCoreMaxItems: this._wisdomInjection?.coreMaxItems,
|
|
1024
|
+
wisdomScenarioMaxItems: this._wisdomInjection?.scenarioMaxItems,
|
|
1025
|
+
wisdomIncludeTrial: this._wisdomInjection?.trialVisible,
|
|
999
1026
|
cognitionStore,
|
|
1000
1027
|
systemBudgetRatio: assemblerCfg?.systemBudgetRatio,
|
|
1001
1028
|
systemBudgetTokens: assemblerCfg?.systemBudgetTokens,
|
|
@@ -1009,6 +1036,18 @@ export class AgentBuilder {
|
|
|
1009
1036
|
},
|
|
1010
1037
|
});
|
|
1011
1038
|
runner.setSystemPromptAssembler((input) => systemPromptAssembler.assemble(input), (sid) => systemPromptAssembler.clearSession(sid));
|
|
1039
|
+
// Wisdom 归因窗口记账(学习环):run 收尾 → 窗口落库,待判官批量判决
|
|
1040
|
+
if (wisdomStore) {
|
|
1041
|
+
runner.setWisdomAttributionSink(async (info) => {
|
|
1042
|
+
try {
|
|
1043
|
+
const { recordWisdomRunWindow } = await import('../memory/wisdom-attribution.js');
|
|
1044
|
+
await recordWisdomRunWindow(wisdomStore, info);
|
|
1045
|
+
}
|
|
1046
|
+
catch {
|
|
1047
|
+
// 归因记账失败不得拖垮 run 收口
|
|
1048
|
+
}
|
|
1049
|
+
});
|
|
1050
|
+
}
|
|
1012
1051
|
// turn 级 Knowledge grounding(消息插槽 knowledgeGrounding;不进 system)
|
|
1013
1052
|
const groundingPort = this._knowledgeGroundingPort ?? this._knowledgeRetriever;
|
|
1014
1053
|
if (groundingPort) {
|
|
@@ -1120,6 +1159,10 @@ export class AgentBuilder {
|
|
|
1120
1159
|
if (this._cognitionStore) {
|
|
1121
1160
|
subsystemRuntime.registerDependency('conceptGraphStore', this._cognitionStore);
|
|
1122
1161
|
}
|
|
1162
|
+
{
|
|
1163
|
+
// eventBus 注入:steward handler 发 memory.stored 等信号用(可选依赖,缺失时静默跳过)
|
|
1164
|
+
subsystemRuntime.registerDependency('eventBus', events);
|
|
1165
|
+
}
|
|
1123
1166
|
{
|
|
1124
1167
|
const { InMemoryBackfillCoverageStore } = await import('../memory/backfill-coverage.js');
|
|
1125
1168
|
let coverage = this._backfillCoverage;
|
|
@@ -1334,7 +1377,11 @@ export class AgentBuilder {
|
|
|
1334
1377
|
const snap = getResolvedModel();
|
|
1335
1378
|
const provider = snap?.provider ?? this._model;
|
|
1336
1379
|
const model = snap?.modelName;
|
|
1337
|
-
return createProviderSummarize(provider, {
|
|
1380
|
+
return createProviderSummarize(provider, {
|
|
1381
|
+
model,
|
|
1382
|
+
// F8R-04:源头钳制与 gateway 对齐——自动路径同样受模型输出上限约束
|
|
1383
|
+
maxOutputTokens: snap?.maxOutputTokens,
|
|
1384
|
+
})(messages, opts);
|
|
1338
1385
|
}
|
|
1339
1386
|
: undefined);
|
|
1340
1387
|
agent.setConvertToLlm(async (messages) => {
|
|
@@ -1366,6 +1413,7 @@ export class AgentBuilder {
|
|
|
1366
1413
|
tools,
|
|
1367
1414
|
tokenBudget: contextWindow,
|
|
1368
1415
|
contextWindow,
|
|
1416
|
+
maxOutputTokens: snapshot?.maxOutputTokens,
|
|
1369
1417
|
compactTargetTokens: this._contextAssemblerConfig?.compactTargetTokens,
|
|
1370
1418
|
summarize: summarizeFn,
|
|
1371
1419
|
loadCompactState: () => agent.getSessionCompactState(sessionId, agentId),
|
|
@@ -1537,7 +1585,7 @@ export class AgentBuilder {
|
|
|
1537
1585
|
${toolList}
|
|
1538
1586
|
|
|
1539
1587
|
Tool selection (strict):
|
|
1540
|
-
1. Prefer a dedicated tool when one covers the job (file_read / file_list / file_write / file_edit / file_delete / file_mkdir / file_rename / file_copy / file_stat / file_rmdir / file_search / env_info, and any task-specific tool).
|
|
1588
|
+
1. Prefer a dedicated tool when one covers the job (file_read / file_list / file_write / file_edit / file_delete / file_mkdir / file_rename / file_copy / file_stat / file_rmdir / file_search / env_info / process_list, and any task-specific tool).
|
|
1541
1589
|
2. If a dedicated-tool call fails because your arguments were wrong (bad path, bad params), fix the call and retry that tool — do not switch to shell for a call you can fix.
|
|
1542
1590
|
3. Use shell only when: (a) no dedicated tool covers the operation, or (b) the dedicated tool is unavailable, or (c) it still fails after a correct retry and shell is the only remaining way to make progress.
|
|
1543
1591
|
4. Do not prefer shell over a working dedicated tool for the same job.
|
|
@@ -85,4 +85,9 @@ export interface BuildFromConfigOptions {
|
|
|
85
85
|
* 委派编排开关。缺省 = 只要有 agent 声明 `delegation` 策略就接线。
|
|
86
86
|
*/
|
|
87
87
|
delegation?: boolean;
|
|
88
|
+
/**
|
|
89
|
+
* 宿主注入的 Runner 附加配置(浅合并进每个 agent)。
|
|
90
|
+
* ops P2:`securityIntegrity`(安全配置漂移守卫)与 `opsAuditPath` 走此通道。
|
|
91
|
+
*/
|
|
92
|
+
runnerConfig?: import('../run/runner.js').SessionAwareRunnerConfig;
|
|
88
93
|
}
|
|
@@ -131,6 +131,7 @@ export async function buildFromConfig(config, options) {
|
|
|
131
131
|
modelCallConfig: config.modelCall,
|
|
132
132
|
concurrencyConfig: config.concurrency,
|
|
133
133
|
observabilityConfig: config.observability,
|
|
134
|
+
runnerConfig: options?.runnerConfig,
|
|
134
135
|
});
|
|
135
136
|
agents.set(agentConfig.id, built);
|
|
136
137
|
}
|
|
@@ -171,6 +172,8 @@ export async function buildFromConfig(config, options) {
|
|
|
171
172
|
*/
|
|
172
173
|
async function buildAgent(agentConfig, shared) {
|
|
173
174
|
const builder = new AgentBuilder();
|
|
175
|
+
if (shared.runnerConfig)
|
|
176
|
+
builder.runnerConfig(shared.runnerConfig);
|
|
174
177
|
// 解析主模型 provider(宿主可在此包装 circuit breaker;config-bridge 用原始 provider)
|
|
175
178
|
const resolvedModel = resolveModelConfig(agentConfig.model, shared.flatModels);
|
|
176
179
|
const provider = shared.providers.get(resolvedModel.provider);
|