@roarpeng/graphflow 1.0.9 → 1.2.0
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/README.md +9 -1
- package/dist/agents/insight.js +1 -1
- package/dist/agents/insight.js.map +1 -1
- package/dist/config/defaults.d.ts.map +1 -1
- package/dist/config/defaults.js +1 -0
- package/dist/config/defaults.js.map +1 -1
- package/dist/config/embedding-factory.d.ts.map +1 -1
- package/dist/config/embedding-factory.js +23 -12
- package/dist/config/embedding-factory.js.map +1 -1
- package/dist/config/loader.d.ts +11 -0
- package/dist/config/loader.d.ts.map +1 -1
- package/dist/config/loader.js +103 -0
- package/dist/config/loader.js.map +1 -1
- package/dist/core/agent-assignment.d.ts +39 -0
- package/dist/core/agent-assignment.d.ts.map +1 -0
- package/dist/core/agent-assignment.js +73 -0
- package/dist/core/agent-assignment.js.map +1 -0
- package/dist/core/dag-checkpoint.d.ts +83 -0
- package/dist/core/dag-checkpoint.d.ts.map +1 -0
- package/dist/core/dag-checkpoint.js +164 -0
- package/dist/core/dag-checkpoint.js.map +1 -0
- package/dist/core/dag-engine.d.ts +9 -0
- package/dist/core/dag-engine.d.ts.map +1 -1
- package/dist/core/dag-engine.js +42 -0
- package/dist/core/dag-engine.js.map +1 -1
- package/dist/core/orchestrator-context.d.ts +10 -0
- package/dist/core/orchestrator-context.d.ts.map +1 -0
- package/dist/core/orchestrator-context.js +112 -0
- package/dist/core/orchestrator-context.js.map +1 -0
- package/dist/core/orchestrator-episode.d.ts +13 -0
- package/dist/core/orchestrator-episode.d.ts.map +1 -0
- package/dist/core/orchestrator-episode.js +128 -0
- package/dist/core/orchestrator-episode.js.map +1 -0
- package/dist/core/orchestrator-route.d.ts +20 -0
- package/dist/core/orchestrator-route.d.ts.map +1 -0
- package/dist/core/orchestrator-route.js +51 -0
- package/dist/core/orchestrator-route.js.map +1 -0
- package/dist/core/orchestrator.d.ts +2 -38
- package/dist/core/orchestrator.d.ts.map +1 -1
- package/dist/core/orchestrator.js +97 -286
- package/dist/core/orchestrator.js.map +1 -1
- package/dist/core/triage.d.ts +21 -0
- package/dist/core/triage.d.ts.map +1 -1
- package/dist/core/triage.js +25 -6
- package/dist/core/triage.js.map +1 -1
- package/dist/core/types.d.ts +53 -0
- package/dist/core/types.d.ts.map +1 -1
- package/dist/graph/context-slicer-types.d.ts +62 -0
- package/dist/graph/context-slicer-types.d.ts.map +1 -0
- package/dist/graph/context-slicer-types.js +13 -0
- package/dist/graph/context-slicer-types.js.map +1 -0
- package/dist/graph/context-slicer-utils.d.ts +24 -0
- package/dist/graph/context-slicer-utils.d.ts.map +1 -0
- package/dist/graph/context-slicer-utils.js +118 -0
- package/dist/graph/context-slicer-utils.js.map +1 -0
- package/dist/graph/context-slicer.d.ts +6 -61
- package/dist/graph/context-slicer.d.ts.map +1 -1
- package/dist/graph/context-slicer.js +73 -170
- package/dist/graph/context-slicer.js.map +1 -1
- package/dist/graph/file-indexer-cache.d.ts +34 -0
- package/dist/graph/file-indexer-cache.d.ts.map +1 -0
- package/dist/graph/file-indexer-cache.js +105 -0
- package/dist/graph/file-indexer-cache.js.map +1 -0
- package/dist/graph/file-indexer-edges.d.ts +55 -0
- package/dist/graph/file-indexer-edges.d.ts.map +1 -0
- package/dist/graph/file-indexer-edges.js +258 -0
- package/dist/graph/file-indexer-edges.js.map +1 -0
- package/dist/graph/file-indexer-nodes.d.ts +43 -0
- package/dist/graph/file-indexer-nodes.d.ts.map +1 -0
- package/dist/graph/file-indexer-nodes.js +137 -0
- package/dist/graph/file-indexer-nodes.js.map +1 -0
- package/dist/graph/file-indexer-walker.d.ts +35 -0
- package/dist/graph/file-indexer-walker.d.ts.map +1 -0
- package/dist/graph/file-indexer-walker.js +80 -0
- package/dist/graph/file-indexer-walker.js.map +1 -0
- package/dist/graph/file-indexer.d.ts +13 -39
- package/dist/graph/file-indexer.d.ts.map +1 -1
- package/dist/graph/file-indexer.js +167 -600
- package/dist/graph/file-indexer.js.map +1 -1
- package/dist/graph/graphify-file-client.d.ts.map +1 -1
- package/dist/graph/graphify-file-client.js +16 -6
- package/dist/graph/graphify-file-client.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -1
- package/dist/index.js.map +1 -1
- package/dist/integrations/agent-mcp-installer.d.ts +25 -1
- package/dist/integrations/agent-mcp-installer.d.ts.map +1 -1
- package/dist/integrations/agent-mcp-installer.js +189 -9
- package/dist/integrations/agent-mcp-installer.js.map +1 -1
- package/dist/integrations/skill-installer.d.ts +50 -0
- package/dist/integrations/skill-installer.d.ts.map +1 -0
- package/dist/integrations/skill-installer.js +373 -0
- package/dist/integrations/skill-installer.js.map +1 -0
- package/dist/learning/embeddings.d.ts +11 -0
- package/dist/learning/embeddings.d.ts.map +1 -1
- package/dist/learning/embeddings.js +24 -0
- package/dist/learning/embeddings.js.map +1 -1
- package/dist/learning/episodic-memory.d.ts +3 -2
- package/dist/learning/episodic-memory.d.ts.map +1 -1
- package/dist/learning/episodic-memory.js +105 -10
- package/dist/learning/episodic-memory.js.map +1 -1
- package/dist/learning/local-embedding.d.ts.map +1 -1
- package/dist/learning/local-embedding.js +16 -0
- package/dist/learning/local-embedding.js.map +1 -1
- package/dist/learning/seed-skills.d.ts +21 -0
- package/dist/learning/seed-skills.d.ts.map +1 -0
- package/dist/learning/seed-skills.js +113 -0
- package/dist/learning/seed-skills.js.map +1 -0
- package/dist/learning/skill-evolution.d.ts +1 -1
- package/dist/learning/skill-evolution.d.ts.map +1 -1
- package/dist/learning/skill-evolution.js +1 -1
- package/dist/learning/skill-evolution.js.map +1 -1
- package/dist/learning/skill-package.d.ts +55 -0
- package/dist/learning/skill-package.d.ts.map +1 -0
- package/dist/learning/skill-package.js +115 -0
- package/dist/learning/skill-package.js.map +1 -0
- package/dist/learning/triage-telemetry.d.ts +43 -0
- package/dist/learning/triage-telemetry.d.ts.map +1 -0
- package/dist/learning/triage-telemetry.js +114 -0
- package/dist/learning/triage-telemetry.js.map +1 -0
- package/dist/surfaces/cli/index.js +65 -0
- package/dist/surfaces/cli/index.js.map +1 -1
- package/dist/surfaces/cli/init.d.ts +17 -1
- package/dist/surfaces/cli/init.d.ts.map +1 -1
- package/dist/surfaces/cli/init.js +254 -25
- package/dist/surfaces/cli/init.js.map +1 -1
- package/dist/surfaces/cli/output.d.ts.map +1 -1
- package/dist/surfaces/cli/output.js +5 -0
- package/dist/surfaces/cli/output.js.map +1 -1
- package/dist/surfaces/cli/runtime/graph.d.ts +23 -0
- package/dist/surfaces/cli/runtime/graph.d.ts.map +1 -1
- package/dist/surfaces/cli/runtime/graph.js +40 -0
- package/dist/surfaces/cli/runtime/graph.js.map +1 -1
- package/dist/surfaces/cli/runtime/routing.d.ts.map +1 -1
- package/dist/surfaces/cli/runtime/routing.js +8 -1
- package/dist/surfaces/cli/runtime/routing.js.map +1 -1
- package/dist/surfaces/cli/runtime.d.ts +1 -1
- package/dist/surfaces/cli/runtime.d.ts.map +1 -1
- package/dist/surfaces/cli/runtime.js +4 -1
- package/dist/surfaces/cli/runtime.js.map +1 -1
- package/dist/surfaces/cursor-rules/graphflow.mdc +131 -0
- package/dist/surfaces/mcp/tool-definitions.js +20 -20
- package/dist/surfaces/mcp/tool-definitions.js.map +1 -1
- package/package.json +4 -3
- package/scripts/safe-postinstall.cjs +323 -5
- package/src/surfaces/cursor-rules/graphflow.mdc +131 -0
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.buildRouteDecisions = buildRouteDecisions;
|
|
4
|
+
exports.decisionToSelection = decisionToSelection;
|
|
5
|
+
exports.selectionIfHealthy = selectionIfHealthy;
|
|
6
|
+
exports.appendRouteFeedback = appendRouteFeedback;
|
|
7
|
+
const model_router_js_1 = require("../routing/model-router.js");
|
|
8
|
+
function buildRouteDecisions(providerHealth, providerFallbackChain, configPath) {
|
|
9
|
+
const resolve = (role) => providerHealth
|
|
10
|
+
? (0, model_router_js_1.resolveModelWithFallback)(role, providerHealth, providerFallbackChain, configPath)
|
|
11
|
+
: (0, model_router_js_1.resolveModelForRole)(role, configPath);
|
|
12
|
+
return {
|
|
13
|
+
planner: selectionToDecision("planner", resolve("planner")),
|
|
14
|
+
worker: selectionToDecision("worker", resolve("worker")),
|
|
15
|
+
validator: selectionToDecision("validator", resolve("validator")),
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
function selectionToDecision(role, selection) {
|
|
19
|
+
return {
|
|
20
|
+
role,
|
|
21
|
+
provider: selection.provider,
|
|
22
|
+
model: selection.model,
|
|
23
|
+
tier: selection.tier,
|
|
24
|
+
fallbackApplied: selection.fallbackApplied,
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
function decisionToSelection(decision) {
|
|
28
|
+
return {
|
|
29
|
+
provider: decision.provider,
|
|
30
|
+
model: decision.model,
|
|
31
|
+
tier: decision.tier,
|
|
32
|
+
fallbackApplied: decision.fallbackApplied,
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
function selectionIfHealthy(selection, providerHealth) {
|
|
36
|
+
if (!providerHealth) {
|
|
37
|
+
return selection;
|
|
38
|
+
}
|
|
39
|
+
return providerHealth[selection.provider] ? selection : undefined;
|
|
40
|
+
}
|
|
41
|
+
function appendRouteFeedback(run, routeDecisions, skillHints) {
|
|
42
|
+
return {
|
|
43
|
+
...run,
|
|
44
|
+
routeDecisions: [routeDecisions.planner, routeDecisions.worker, routeDecisions.validator],
|
|
45
|
+
feedback: `${run.feedback}; routes(planner=${routeDecisions.planner.provider}/${routeDecisions.planner.model}` +
|
|
46
|
+
`,worker=${routeDecisions.worker.provider}/${routeDecisions.worker.model}` +
|
|
47
|
+
`,validator=${routeDecisions.validator.provider}/${routeDecisions.validator.model})` +
|
|
48
|
+
`${skillHints.length > 0 ? `; skills(hints=${skillHints.join("|")})` : ""}`,
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
//# sourceMappingURL=orchestrator-route.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"orchestrator-route.js","sourceRoot":"","sources":["../../src/core/orchestrator-route.ts"],"names":[],"mappings":";;AAQA,kDAmBC;AAiBD,kDAYC;AAED,gDAQC;AAED,kDAcC;AAlFD,gEAKoC;AAGpC,SAAgB,mBAAmB,CACjC,cAAkC,EAClC,qBAAsC,EACtC,UAAmB;IAMnB,MAAM,OAAO,GAAG,CAAC,IAAwC,EAAE,EAAE,CAC3D,cAAc;QACZ,CAAC,CAAC,IAAA,0CAAwB,EAAC,IAAI,EAAE,cAAc,EAAE,qBAAqB,EAAE,UAAU,CAAC;QACnF,CAAC,CAAC,IAAA,qCAAmB,EAAC,IAAI,EAAE,UAAU,CAAC,CAAC;IAE5C,OAAO;QACL,OAAO,EAAE,mBAAmB,CAAC,SAAS,EAAE,OAAO,CAAC,SAAS,CAAC,CAAC;QAC3D,MAAM,EAAE,mBAAmB,CAAC,QAAQ,EAAE,OAAO,CAAC,QAAQ,CAAC,CAAC;QACxD,SAAS,EAAE,mBAAmB,CAAC,WAAW,EAAE,OAAO,CAAC,WAAW,CAAC,CAAC;KAClE,CAAC;AACJ,CAAC;AAED,SAAS,mBAAmB,CAAC,IAAwC,EAAE,SAKtE;IACC,OAAO;QACL,IAAI;QACJ,QAAQ,EAAE,SAAS,CAAC,QAAQ;QAC5B,KAAK,EAAE,SAAS,CAAC,KAAK;QACtB,IAAI,EAAE,SAAS,CAAC,IAAI;QACpB,eAAe,EAAE,SAAS,CAAC,eAAe;KAC3C,CAAC;AACJ,CAAC;AAED,SAAgB,mBAAmB,CAAC,QAAuB;IAMzD,OAAO;QACL,QAAQ,EAAE,QAAQ,CAAC,QAAyD;QAC5E,KAAK,EAAE,QAAQ,CAAC,KAAK;QACrB,IAAI,EAAE,QAAQ,CAAC,IAAI;QACnB,eAAe,EAAE,QAAQ,CAAC,eAAe;KAC1C,CAAC;AACJ,CAAC;AAED,SAAgB,kBAAkB,CAChC,SAAiD,EACjD,cAAkC;IAElC,IAAI,CAAC,cAAc,EAAE,CAAC;QACpB,OAAO,SAAS,CAAC;IACnB,CAAC;IACD,OAAO,cAAc,CAAC,SAAS,CAAC,QAAwB,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC;AACpF,CAAC;AAED,SAAgB,mBAAmB,CACjC,GAAkB,EAClB,cAA2F,EAC3F,UAAoB;IAEpB,OAAO;QACL,GAAG,GAAG;QACN,cAAc,EAAE,CAAC,cAAc,CAAC,OAAO,EAAE,cAAc,CAAC,MAAM,EAAE,cAAc,CAAC,SAAS,CAAC;QACzF,QAAQ,EACN,GAAG,GAAG,CAAC,QAAQ,oBAAoB,cAAc,CAAC,OAAO,CAAC,QAAQ,IAAI,cAAc,CAAC,OAAO,CAAC,KAAK,EAAE;YACpG,WAAW,cAAc,CAAC,MAAM,CAAC,QAAQ,IAAI,cAAc,CAAC,MAAM,CAAC,KAAK,EAAE;YAC1E,cAAc,cAAc,CAAC,SAAS,CAAC,QAAQ,IAAI,cAAc,CAAC,SAAS,CAAC,KAAK,GAAG;YACpF,GAAG,UAAU,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,kBAAkB,UAAU,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE;KAC9E,CAAC;AACJ,CAAC"}
|
|
@@ -1,40 +1,4 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
|
|
3
|
-
import { type ProviderName, type ProviderHealthMap } from "../routing/model-router";
|
|
4
|
-
import type { OrchestrationInput, TaskRunResult } from "./types";
|
|
5
|
-
export interface OrchestrateOptions {
|
|
6
|
-
graphClient?: GraphClient;
|
|
7
|
-
enableAutoGraphSync?: boolean;
|
|
8
|
-
enableNearLosslessMode?: boolean;
|
|
9
|
-
nearLosslessQuery?: string;
|
|
10
|
-
maxContextTokens?: number;
|
|
11
|
-
layerQuota?: {
|
|
12
|
-
l1: number;
|
|
13
|
-
l2: number;
|
|
14
|
-
l3: number;
|
|
15
|
-
};
|
|
16
|
-
onContextPackage?: (pkg: LayeredContextPackage) => void;
|
|
17
|
-
providerHealth?: ProviderHealthMap;
|
|
18
|
-
providerFallbackChain?: ProviderName[];
|
|
19
|
-
enableSkillFlywheel?: boolean;
|
|
20
|
-
skillHintsLimit?: number;
|
|
21
|
-
enableLlmAgents?: boolean;
|
|
22
|
-
enableDriftReplan?: boolean;
|
|
23
|
-
maxReplanRounds?: number;
|
|
24
|
-
enableGraphContextInPrompt?: boolean;
|
|
25
|
-
enableEpisodicMemory?: boolean;
|
|
26
|
-
enableLlmTriage?: boolean;
|
|
27
|
-
embeddingProvider?: import("../learning/embeddings").EmbeddingProvider;
|
|
28
|
-
configPath?: string;
|
|
29
|
-
executionMode?: "bridge" | "llm";
|
|
30
|
-
/** Enable zero-cost graph-structure compression (edge weights + PageRank). Default true. */
|
|
31
|
-
enableGraphCompression?: boolean;
|
|
32
|
-
/** Adaptively size the context token budget from task complexity. Auto-enabled for complex tasks unless false. */
|
|
33
|
-
enableAdaptiveBudget?: boolean;
|
|
34
|
-
/** Return module-level RepoMap overview when budget is tight. Default false. */
|
|
35
|
-
enableRepoMapFallback?: boolean;
|
|
36
|
-
/** Run Six Hats plan_insight before complex DAG planning. Default true for complex tasks. */
|
|
37
|
-
enablePlanInsight?: boolean;
|
|
38
|
-
}
|
|
1
|
+
import type { OrchestrationInput, TaskRunResult, OrchestrateOptions } from "./types.js";
|
|
2
|
+
export type { OrchestrateOptions } from "./types.js";
|
|
39
3
|
export declare function orchestrate(input: OrchestrationInput, options?: OrchestrateOptions): Promise<TaskRunResult>;
|
|
40
4
|
//# sourceMappingURL=orchestrator.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"orchestrator.d.ts","sourceRoot":"","sources":["../../src/core/orchestrator.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"orchestrator.d.ts","sourceRoot":"","sources":["../../src/core/orchestrator.ts"],"names":[],"mappings":"AAgBA,OAAO,KAAK,EAAE,kBAAkB,EAAE,aAAa,EAAY,kBAAkB,EAAE,MAAM,YAAY,CAAC;AAGlG,YAAY,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAC;AA4BrD,wBAAsB,WAAW,CAC/B,KAAK,EAAE,kBAAkB,EACzB,OAAO,CAAC,EAAE,kBAAkB,GAC3B,OAAO,CAAC,aAAa,CAAC,CAcxB"}
|
|
@@ -1,22 +1,25 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.orchestrate = orchestrate;
|
|
4
|
-
const
|
|
5
|
-
const
|
|
6
|
-
const
|
|
7
|
-
const
|
|
8
|
-
const
|
|
9
|
-
const
|
|
10
|
-
const
|
|
11
|
-
const
|
|
12
|
-
const
|
|
13
|
-
const
|
|
14
|
-
const
|
|
15
|
-
const
|
|
16
|
-
const
|
|
17
|
-
|
|
18
|
-
const
|
|
19
|
-
|
|
4
|
+
const planner_js_1 = require("../agents/planner.js");
|
|
5
|
+
const brainstormer_js_1 = require("../agents/brainstormer.js");
|
|
6
|
+
const resolve_js_1 = require("../config/resolve.js");
|
|
7
|
+
const llm_availability_js_1 = require("../config/llm-availability.js");
|
|
8
|
+
const logger_js_1 = require("../utils/logger.js");
|
|
9
|
+
const episodic_memory_js_1 = require("../learning/episodic-memory.js");
|
|
10
|
+
const provider_executor_js_1 = require("../routing/provider-executor.js");
|
|
11
|
+
const dag_engine_js_1 = require("./dag-engine.js");
|
|
12
|
+
const agent_delegation_js_1 = require("./agent-delegation.js");
|
|
13
|
+
const state_machine_js_1 = require("./state-machine.js");
|
|
14
|
+
const triage_js_1 = require("./triage.js");
|
|
15
|
+
const triage_telemetry_js_1 = require("../learning/triage-telemetry.js");
|
|
16
|
+
const agent_assignment_js_1 = require("./agent-assignment.js");
|
|
17
|
+
// Context module
|
|
18
|
+
const orchestrator_context_js_1 = require("./orchestrator-context.js");
|
|
19
|
+
// Episode module
|
|
20
|
+
const orchestrator_episode_js_1 = require("./orchestrator-episode.js");
|
|
21
|
+
// Route module
|
|
22
|
+
const orchestrator_route_js_1 = require("./orchestrator-route.js");
|
|
20
23
|
async function orchestrate(input, options) {
|
|
21
24
|
try {
|
|
22
25
|
return await runOrchestration(input, options);
|
|
@@ -25,7 +28,7 @@ async function orchestrate(input, options) {
|
|
|
25
28
|
// 顶层错误边界:任何来自上下文构建/DAG 执行/图同步的未捕获异常
|
|
26
29
|
// 都收敛为结构化的 HUMAN_REVIEW_REQUIRED 结果,而不是裸抛给调用方。
|
|
27
30
|
const message = error instanceof Error ? error.message : String(error);
|
|
28
|
-
|
|
31
|
+
logger_js_1.logger.error({ error, task: input.task }, "Orchestration failed with unhandled error");
|
|
29
32
|
return {
|
|
30
33
|
status: "HUMAN_REVIEW_REQUIRED",
|
|
31
34
|
attempts: 0,
|
|
@@ -34,24 +37,42 @@ async function orchestrate(input, options) {
|
|
|
34
37
|
}
|
|
35
38
|
}
|
|
36
39
|
async function runOrchestration(input, options) {
|
|
37
|
-
|
|
40
|
+
logger_js_1.logger.info({ task: input.task }, "Orchestration task started");
|
|
41
|
+
// 预置种子技能(幂等):在技能飞轮启用时为图写入常见工程技能基线,
|
|
42
|
+
// 须在构建技能提示之前执行,确保种子技能可被 suggestSkillHints 命中。
|
|
43
|
+
await (0, orchestrator_episode_js_1.maybeSeedInitialSkills)(options);
|
|
38
44
|
const retryOptions = input.maxRetries !== undefined ? { maxRetries: input.maxRetries } : {};
|
|
39
|
-
const contextPackage = await maybeBuildNearLosslessContext(input, options);
|
|
40
|
-
const routeDecisions = buildRouteDecisions(options?.providerHealth, options?.providerFallbackChain, options?.configPath);
|
|
41
|
-
const skillHints = await maybeBuildSkillHints(input.task, options);
|
|
42
|
-
const similarEpisodes = await maybeFindSimilarEpisodes(input.task, options);
|
|
43
|
-
const episodeSummaries = similarEpisodes.map((ep) => (0,
|
|
44
|
-
const promptContext = buildPromptContext(contextPackage, skillHints, episodeSummaries, options);
|
|
45
|
+
const contextPackage = await (0, orchestrator_context_js_1.maybeBuildNearLosslessContext)(input, options);
|
|
46
|
+
const routeDecisions = (0, orchestrator_route_js_1.buildRouteDecisions)(options?.providerHealth, options?.providerFallbackChain, options?.configPath);
|
|
47
|
+
const skillHints = await (0, orchestrator_context_js_1.maybeBuildSkillHints)(input.task, options);
|
|
48
|
+
const similarEpisodes = await (0, orchestrator_episode_js_1.maybeFindSimilarEpisodes)(input.task, options);
|
|
49
|
+
const episodeSummaries = similarEpisodes.map((ep) => (0, episodic_memory_js_1.summarizeEpisodeForPrompt)(ep));
|
|
50
|
+
const promptContext = (0, orchestrator_context_js_1.buildPromptContext)(contextPackage, skillHints, episodeSummaries, options);
|
|
45
51
|
const promptContextLines = promptContext?.summaryChannel?.length ?? 0;
|
|
46
|
-
let
|
|
52
|
+
let triageExplanation = (0, triage_js_1.triageTaskExplain)(input.task);
|
|
53
|
+
let mode = triageExplanation.decision;
|
|
47
54
|
if (options?.enableLlmTriage) {
|
|
48
|
-
|
|
55
|
+
const llmDecision = await (0, triage_js_1.triageTaskLlm)(input.task, (0, orchestrator_route_js_1.decisionToSelection)(routeDecisions.planner), promptContext);
|
|
56
|
+
mode = llmDecision;
|
|
57
|
+
// LLM triage 路径:保留启发式原因,并标记为 llmBased,用于准确率数据收集
|
|
58
|
+
triageExplanation = { decision: llmDecision, reason: { ...triageExplanation.reason, llmBased: true } };
|
|
59
|
+
}
|
|
60
|
+
// 记录 triage 决策 learning event(任务描述、决策、原因、时间戳),用于后续准确率分析。
|
|
61
|
+
// 仅在图客户端可用时记录;失败不阻断主流程。
|
|
62
|
+
let triageId;
|
|
63
|
+
if (options?.graphClient) {
|
|
64
|
+
try {
|
|
65
|
+
triageId = await (0, triage_telemetry_js_1.recordTriageDecision)(options.graphClient, input.task, mode, triageExplanation.reason);
|
|
66
|
+
}
|
|
67
|
+
catch (error) {
|
|
68
|
+
logger_js_1.logger.warn({ error }, "Triage telemetry recording failed");
|
|
69
|
+
}
|
|
49
70
|
}
|
|
50
71
|
let currentPlan = [];
|
|
51
72
|
if (mode === "simple") {
|
|
52
|
-
const workerSelection = selectionIfHealthy(decisionToSelection(routeDecisions.worker), options?.providerHealth);
|
|
53
|
-
const validatorSelection = selectionIfHealthy(decisionToSelection(routeDecisions.validator), options?.providerHealth);
|
|
54
|
-
const run = await (0,
|
|
73
|
+
const workerSelection = (0, orchestrator_route_js_1.selectionIfHealthy)((0, orchestrator_route_js_1.decisionToSelection)(routeDecisions.worker), options?.providerHealth);
|
|
74
|
+
const validatorSelection = (0, orchestrator_route_js_1.selectionIfHealthy)((0, orchestrator_route_js_1.decisionToSelection)(routeDecisions.validator), options?.providerHealth);
|
|
75
|
+
const run = await (0, state_machine_js_1.runSimpleTask)({
|
|
55
76
|
task: input.task,
|
|
56
77
|
...retryOptions,
|
|
57
78
|
...(workerSelection ? { workerSelection } : {}),
|
|
@@ -59,32 +80,32 @@ async function runOrchestration(input, options) {
|
|
|
59
80
|
...(promptContext ? { workerContext: promptContext, validatorContext: promptContext } : {}),
|
|
60
81
|
...(options?.executionMode ? { executionMode: options.executionMode } : {}),
|
|
61
82
|
});
|
|
62
|
-
const finalRun = appendContextFeedback(run, contextPackage, promptContextLines, options);
|
|
63
|
-
const withRoute = appendRouteFeedback(finalRun, routeDecisions, skillHints);
|
|
64
|
-
await maybeSyncGraph(input.task, withRoute, options);
|
|
65
|
-
await maybeSyncSkillGraph(input.task, withRoute, options);
|
|
66
|
-
|
|
67
|
-
return finalizeEpisode(input.task, currentPlan, withRoute, similarEpisodes, skillHints, options);
|
|
68
|
-
}
|
|
69
|
-
const plannerSelection = decisionToSelection(routeDecisions.planner);
|
|
83
|
+
const finalRun = (0, orchestrator_context_js_1.appendContextFeedback)(run, contextPackage, promptContextLines, options);
|
|
84
|
+
const withRoute = (0, orchestrator_route_js_1.appendRouteFeedback)(finalRun, routeDecisions, skillHints);
|
|
85
|
+
await (0, orchestrator_episode_js_1.maybeSyncGraph)(input.task, withRoute, options);
|
|
86
|
+
await (0, orchestrator_episode_js_1.maybeSyncSkillGraph)(input.task, withRoute, options);
|
|
87
|
+
logger_js_1.logger.info({ status: withRoute.status, task: input.task }, "Orchestration task finished (simple mode)");
|
|
88
|
+
return (0, orchestrator_episode_js_1.finalizeEpisode)(input.task, currentPlan, withRoute, similarEpisodes, skillHints, options, triageId);
|
|
89
|
+
}
|
|
90
|
+
const plannerSelection = (0, orchestrator_route_js_1.decisionToSelection)(routeDecisions.planner);
|
|
70
91
|
let brainstormIdeas;
|
|
71
92
|
let plan;
|
|
72
93
|
let planInsightBundle;
|
|
73
|
-
const insightConfig = (0,
|
|
94
|
+
const insightConfig = (0, resolve_js_1.resolveConfig)(options?.configPath);
|
|
74
95
|
const autoPlanInsight = options?.enablePlanInsight === true ||
|
|
75
96
|
(options?.enablePlanInsight !== false &&
|
|
76
|
-
!(0,
|
|
97
|
+
!(0, llm_availability_js_1.hasUsableLlmProvider)(insightConfig) &&
|
|
77
98
|
options?.enableLlmAgents !== true &&
|
|
78
99
|
(options?.executionMode === "bridge" || options?.executionMode === undefined));
|
|
79
100
|
if (autoPlanInsight) {
|
|
80
|
-
planInsightBundle = await maybeRunPlanInsightForComplex(input.task, options);
|
|
101
|
+
planInsightBundle = await (0, orchestrator_context_js_1.maybeRunPlanInsightForComplex)(input.task, options);
|
|
81
102
|
}
|
|
82
103
|
if (planInsightBundle) {
|
|
83
104
|
plan = planInsightBundle.plan;
|
|
84
105
|
}
|
|
85
106
|
else if (options?.enableLlmAgents) {
|
|
86
|
-
brainstormIdeas = await (0,
|
|
87
|
-
plan = await (0,
|
|
107
|
+
brainstormIdeas = await (0, brainstormer_js_1.brainstormTaskLlm)(input.task, plannerSelection, promptContext);
|
|
108
|
+
plan = await (0, planner_js_1.planTasksLlm)(input.task, {
|
|
88
109
|
selection: plannerSelection,
|
|
89
110
|
skillHints,
|
|
90
111
|
brainstormIdeas,
|
|
@@ -92,18 +113,22 @@ async function runOrchestration(input, options) {
|
|
|
92
113
|
});
|
|
93
114
|
}
|
|
94
115
|
else {
|
|
95
|
-
plan = (0,
|
|
116
|
+
plan = (0, planner_js_1.planTasks)(input.task, skillHints);
|
|
96
117
|
}
|
|
97
118
|
currentPlan = plan;
|
|
98
119
|
const plannerDraft = planInsightBundle
|
|
99
|
-
? `[plan-insight:${planInsightBundle.mode}] ${(0,
|
|
100
|
-
: await (0,
|
|
120
|
+
? `[plan-insight:${planInsightBundle.mode}] ${(0, agent_delegation_js_1.summarizeInsightForContext)(planInsightBundle.insight)}`
|
|
121
|
+
: await (0, provider_executor_js_1.executeRolePrompt)("planner", `plan task: ${input.task}`, plannerSelection, promptContext);
|
|
101
122
|
// Bridge mode: package the planned DAG for external agent execution instead of running it
|
|
102
123
|
if (options?.executionMode === "bridge") {
|
|
103
|
-
|
|
124
|
+
// 多 Agent 协作编排:为每个任务节点标注建议的 agent 专业领域
|
|
125
|
+
const assignedPlan = (0, agent_assignment_js_1.assignAgentsToTasks)(plan);
|
|
126
|
+
const agentAssignments = (0, agent_assignment_js_1.buildAgentAssignments)(assignedPlan);
|
|
127
|
+
const planProjection = assignedPlan.map((node) => ({
|
|
104
128
|
id: node.id,
|
|
105
129
|
description: node.description,
|
|
106
130
|
dependencies: node.dependencies,
|
|
131
|
+
...(node.assignedAgent ? { assignedAgent: node.assignedAgent } : {}),
|
|
107
132
|
}));
|
|
108
133
|
const contextStr = promptContext
|
|
109
134
|
? Object.entries(promptContext)
|
|
@@ -111,7 +136,7 @@ async function runOrchestration(input, options) {
|
|
|
111
136
|
.join("; ")
|
|
112
137
|
: "";
|
|
113
138
|
const insightSummary = planInsightBundle
|
|
114
|
-
? (0,
|
|
139
|
+
? (0, agent_delegation_js_1.summarizeInsightForContext)(planInsightBundle.insight)
|
|
115
140
|
: undefined;
|
|
116
141
|
const delegatedExtras = planInsightBundle?.mode === "agent-delegated" && planInsightBundle.agentWorkItems
|
|
117
142
|
? {
|
|
@@ -134,20 +159,21 @@ async function runOrchestration(input, options) {
|
|
|
134
159
|
task: input.task,
|
|
135
160
|
context: `plan=${JSON.stringify(planProjection)}${insightSummary ? `; insight=${insightSummary}` : ""}${contextStr ? `; ${contextStr}` : ""}`,
|
|
136
161
|
retryHints: [],
|
|
162
|
+
...(agentAssignments.length > 0 ? { agentAssignments } : {}),
|
|
137
163
|
...delegatedExtras,
|
|
138
164
|
},
|
|
139
165
|
};
|
|
140
|
-
const finalRun = appendContextFeedback(bridgeRun, contextPackage, promptContextLines, options);
|
|
141
|
-
const withRoute = appendRouteFeedback(finalRun, routeDecisions, skillHints);
|
|
142
|
-
await maybeSyncSkillGraph(input.task, withRoute, options);
|
|
143
|
-
|
|
144
|
-
return finalizeEpisode(input.task, currentPlan, withRoute, similarEpisodes, skillHints, options);
|
|
166
|
+
const finalRun = (0, orchestrator_context_js_1.appendContextFeedback)(bridgeRun, contextPackage, promptContextLines, options);
|
|
167
|
+
const withRoute = (0, orchestrator_route_js_1.appendRouteFeedback)(finalRun, routeDecisions, skillHints);
|
|
168
|
+
await (0, orchestrator_episode_js_1.maybeSyncSkillGraph)(input.task, withRoute, options);
|
|
169
|
+
logger_js_1.logger.info({ status: withRoute.status, task: input.task }, "Orchestration task delegated (bridge mode)");
|
|
170
|
+
return (0, orchestrator_episode_js_1.finalizeEpisode)(input.task, currentPlan, withRoute, similarEpisodes, skillHints, options, triageId);
|
|
145
171
|
}
|
|
146
172
|
const runner = async (node) => {
|
|
147
|
-
|
|
148
|
-
const workerSelection = selectionIfHealthy(decisionToSelection(routeDecisions.worker), options?.providerHealth);
|
|
149
|
-
const validatorSelection = selectionIfHealthy(decisionToSelection(routeDecisions.validator), options?.providerHealth);
|
|
150
|
-
const run = await (0,
|
|
173
|
+
logger_js_1.logger.info({ nodeId: node.id, description: node.description }, "Executing task node");
|
|
174
|
+
const workerSelection = (0, orchestrator_route_js_1.selectionIfHealthy)((0, orchestrator_route_js_1.decisionToSelection)(routeDecisions.worker), options?.providerHealth);
|
|
175
|
+
const validatorSelection = (0, orchestrator_route_js_1.selectionIfHealthy)((0, orchestrator_route_js_1.decisionToSelection)(routeDecisions.validator), options?.providerHealth);
|
|
176
|
+
const run = await (0, state_machine_js_1.runSimpleTask)({
|
|
151
177
|
task: node.description,
|
|
152
178
|
...retryOptions,
|
|
153
179
|
...(workerSelection ? { workerSelection } : {}),
|
|
@@ -156,7 +182,7 @@ async function runOrchestration(input, options) {
|
|
|
156
182
|
});
|
|
157
183
|
return run.status === "COMPLETED";
|
|
158
184
|
};
|
|
159
|
-
let result = await (0,
|
|
185
|
+
let result = await (0, dag_engine_js_1.executeDag)(plan, runner);
|
|
160
186
|
let replanRounds = 0;
|
|
161
187
|
const maxReplanRounds = options?.maxReplanRounds ?? 1;
|
|
162
188
|
const canReplan = options?.enableDriftReplan === true && options.enableLlmAgents === true;
|
|
@@ -169,7 +195,7 @@ async function runOrchestration(input, options) {
|
|
|
169
195
|
return `${id}: ${failedNode?.description ?? ""}`;
|
|
170
196
|
})
|
|
171
197
|
.join("; ");
|
|
172
|
-
const newPlan = await (0,
|
|
198
|
+
const newPlan = await (0, planner_js_1.planTasksLlm)(input.task, {
|
|
173
199
|
selection: plannerSelection,
|
|
174
200
|
skillHints,
|
|
175
201
|
previousPlan: plan,
|
|
@@ -183,7 +209,7 @@ async function runOrchestration(input, options) {
|
|
|
183
209
|
replanRounds += 1;
|
|
184
210
|
plan = newPlan;
|
|
185
211
|
currentPlan = plan;
|
|
186
|
-
result = await (0,
|
|
212
|
+
result = await (0, dag_engine_js_1.executeDag)(plan, runner);
|
|
187
213
|
}
|
|
188
214
|
if (result.failed.length > 0) {
|
|
189
215
|
const run = {
|
|
@@ -194,12 +220,12 @@ async function runOrchestration(input, options) {
|
|
|
194
220
|
replanRounds,
|
|
195
221
|
...(brainstormIdeas ? { brainstormIdeas } : {}),
|
|
196
222
|
};
|
|
197
|
-
const finalRun = appendContextFeedback(run, contextPackage, promptContextLines, options);
|
|
198
|
-
const withRoute = appendRouteFeedback(finalRun, routeDecisions, skillHints);
|
|
199
|
-
await maybeSyncGraph(input.task, withRoute, options);
|
|
200
|
-
await maybeSyncSkillGraph(input.task, withRoute, options);
|
|
201
|
-
|
|
202
|
-
return finalizeEpisode(input.task, currentPlan, withRoute, similarEpisodes, skillHints, options);
|
|
223
|
+
const finalRun = (0, orchestrator_context_js_1.appendContextFeedback)(run, contextPackage, promptContextLines, options);
|
|
224
|
+
const withRoute = (0, orchestrator_route_js_1.appendRouteFeedback)(finalRun, routeDecisions, skillHints);
|
|
225
|
+
await (0, orchestrator_episode_js_1.maybeSyncGraph)(input.task, withRoute, options);
|
|
226
|
+
await (0, orchestrator_episode_js_1.maybeSyncSkillGraph)(input.task, withRoute, options);
|
|
227
|
+
logger_js_1.logger.error({ status: withRoute.status, failed: result.failed }, "Orchestration task failed or needs human review");
|
|
228
|
+
return (0, orchestrator_episode_js_1.finalizeEpisode)(input.task, currentPlan, withRoute, similarEpisodes, skillHints, options);
|
|
203
229
|
}
|
|
204
230
|
const run = {
|
|
205
231
|
status: "COMPLETED",
|
|
@@ -209,12 +235,12 @@ async function runOrchestration(input, options) {
|
|
|
209
235
|
replanRounds,
|
|
210
236
|
...(brainstormIdeas ? { brainstormIdeas } : {}),
|
|
211
237
|
};
|
|
212
|
-
const finalRun = appendContextFeedback(run, contextPackage, promptContextLines, options);
|
|
213
|
-
const withRoute = appendRouteFeedback(finalRun, routeDecisions, skillHints);
|
|
214
|
-
await maybeSyncGraph(input.task, withRoute, options);
|
|
215
|
-
await maybeSyncSkillGraph(input.task, withRoute, options);
|
|
216
|
-
|
|
217
|
-
return finalizeEpisode(input.task, currentPlan, withRoute, similarEpisodes, skillHints, options);
|
|
238
|
+
const finalRun = (0, orchestrator_context_js_1.appendContextFeedback)(run, contextPackage, promptContextLines, options);
|
|
239
|
+
const withRoute = (0, orchestrator_route_js_1.appendRouteFeedback)(finalRun, routeDecisions, skillHints);
|
|
240
|
+
await (0, orchestrator_episode_js_1.maybeSyncGraph)(input.task, withRoute, options);
|
|
241
|
+
await (0, orchestrator_episode_js_1.maybeSyncSkillGraph)(input.task, withRoute, options);
|
|
242
|
+
logger_js_1.logger.info({ status: withRoute.status, task: input.task, rounds: result.rounds }, "Orchestration task completed successfully");
|
|
243
|
+
return (0, orchestrator_episode_js_1.finalizeEpisode)(input.task, currentPlan, withRoute, similarEpisodes, skillHints, options, triageId);
|
|
218
244
|
}
|
|
219
245
|
function projectPlan(plan) {
|
|
220
246
|
return JSON.stringify(plan.map((node) => ({
|
|
@@ -223,225 +249,10 @@ function projectPlan(plan) {
|
|
|
223
249
|
dependencies: node.dependencies,
|
|
224
250
|
})));
|
|
225
251
|
}
|
|
226
|
-
async function maybeBuildNearLosslessContext(input, options) {
|
|
227
|
-
if (!options?.enableNearLosslessMode || !options.graphClient) {
|
|
228
|
-
return undefined;
|
|
229
|
-
}
|
|
230
|
-
const query = options.nearLosslessQuery ?? input.task;
|
|
231
|
-
const maxTokens = options.maxContextTokens ?? 1200;
|
|
232
|
-
const packageOptions = {
|
|
233
|
-
...(options.layerQuota ? { layerQuota: options.layerQuota } : {}),
|
|
234
|
-
...(options.embeddingProvider ? { embeddingProvider: options.embeddingProvider, enableVectorRecall: true } : {}),
|
|
235
|
-
// Graph-structure compression is zero-cost; enable by default unless explicitly disabled.
|
|
236
|
-
enableGraphCompression: options.enableGraphCompression !== false,
|
|
237
|
-
};
|
|
238
|
-
// Adaptive budget: derive task complexity from triage and let the package
|
|
239
|
-
// estimator resize the token budget. Auto-enable for complex tasks unless
|
|
240
|
-
// explicitly disabled via enableAdaptiveBudget: false.
|
|
241
|
-
const taskMode = (0, triage_1.triageTask)(input.task);
|
|
242
|
-
const enableAdaptiveBudget = options.enableAdaptiveBudget !== false &&
|
|
243
|
-
(options.enableAdaptiveBudget === true || taskMode === "complex");
|
|
244
|
-
if (enableAdaptiveBudget) {
|
|
245
|
-
packageOptions.taskMode = taskMode;
|
|
246
|
-
}
|
|
247
|
-
// RepoMap overview fallback for tight budgets (opt-in).
|
|
248
|
-
if (options.enableRepoMapFallback) {
|
|
249
|
-
packageOptions.enableRepoMapFallback = true;
|
|
250
|
-
}
|
|
251
|
-
const { buildEnhancedContextPackage } = await import("../graph/context-slicer.js");
|
|
252
|
-
const pkg = await buildEnhancedContextPackage(options.graphClient, query, input.task, maxTokens, packageOptions);
|
|
253
|
-
options.onContextPackage?.(pkg);
|
|
254
|
-
return pkg;
|
|
255
|
-
}
|
|
256
|
-
function appendContextFeedback(run, contextPackage, promptContextLines = 0, options) {
|
|
257
|
-
let next = run;
|
|
258
|
-
if (contextPackage) {
|
|
259
|
-
next = {
|
|
260
|
-
...next,
|
|
261
|
-
feedback: `${next.feedback}; context(summary=${contextPackage.summaryChannel.length}, ` +
|
|
262
|
-
`anchors=${contextPackage.anchorChannel.length}, tokens=${contextPackage.tokenEstimate})`,
|
|
263
|
-
};
|
|
264
|
-
}
|
|
265
|
-
if (options?.enableGraphContextInPrompt) {
|
|
266
|
-
next = {
|
|
267
|
-
...next,
|
|
268
|
-
feedback: `${next.feedback}; promptCtx(lines=${promptContextLines})`,
|
|
269
|
-
promptContextLines,
|
|
270
|
-
};
|
|
271
|
-
}
|
|
272
|
-
return next;
|
|
273
|
-
}
|
|
274
|
-
function buildPromptContext(contextPackage, skillHints, episodeSummaries, options) {
|
|
275
|
-
const includeGraph = options?.enableGraphContextInPrompt === true && contextPackage !== undefined;
|
|
276
|
-
const includeEpisodes = options?.enableEpisodicMemory === true && episodeSummaries.length > 0;
|
|
277
|
-
if (!includeGraph && !includeEpisodes) {
|
|
278
|
-
return undefined;
|
|
279
|
-
}
|
|
280
|
-
const ctx = {};
|
|
281
|
-
if (includeGraph && contextPackage && contextPackage.summaryChannel.length > 0) {
|
|
282
|
-
ctx.summaryChannel = contextPackage.summaryChannel;
|
|
283
|
-
}
|
|
284
|
-
if (includeGraph && skillHints.length > 0) {
|
|
285
|
-
ctx.skillHints = skillHints;
|
|
286
|
-
}
|
|
287
|
-
if (includeEpisodes) {
|
|
288
|
-
ctx.extraInstructions = [...episodeSummaries];
|
|
289
|
-
}
|
|
290
|
-
if (!ctx.summaryChannel && !ctx.skillHints && !ctx.extraInstructions) {
|
|
291
|
-
return undefined;
|
|
292
|
-
}
|
|
293
|
-
return ctx;
|
|
294
|
-
}
|
|
295
|
-
function appendRouteFeedback(run, routeDecisions, skillHints) {
|
|
296
|
-
return {
|
|
297
|
-
...run,
|
|
298
|
-
routeDecisions: [routeDecisions.planner, routeDecisions.worker, routeDecisions.validator],
|
|
299
|
-
feedback: `${run.feedback}; routes(planner=${routeDecisions.planner.provider}/${routeDecisions.planner.model}` +
|
|
300
|
-
`,worker=${routeDecisions.worker.provider}/${routeDecisions.worker.model}` +
|
|
301
|
-
`,validator=${routeDecisions.validator.provider}/${routeDecisions.validator.model})` +
|
|
302
|
-
`${skillHints.length > 0 ? `; skills(hints=${skillHints.join("|")})` : ""}`,
|
|
303
|
-
};
|
|
304
|
-
}
|
|
305
|
-
function selectionIfHealthy(selection, providerHealth) {
|
|
306
|
-
if (!providerHealth) {
|
|
307
|
-
return selection;
|
|
308
|
-
}
|
|
309
|
-
return providerHealth[selection.provider] ? selection : undefined;
|
|
310
|
-
}
|
|
311
|
-
function buildRouteDecisions(providerHealth, providerFallbackChain, configPath) {
|
|
312
|
-
const resolve = (role) => providerHealth
|
|
313
|
-
? (0, model_router_1.resolveModelWithFallback)(role, providerHealth, providerFallbackChain, configPath)
|
|
314
|
-
: (0, model_router_1.resolveModelForRole)(role, configPath);
|
|
315
|
-
return {
|
|
316
|
-
planner: selectionToDecision("planner", resolve("planner")),
|
|
317
|
-
worker: selectionToDecision("worker", resolve("worker")),
|
|
318
|
-
validator: selectionToDecision("validator", resolve("validator")),
|
|
319
|
-
};
|
|
320
|
-
}
|
|
321
|
-
function selectionToDecision(role, selection) {
|
|
322
|
-
return {
|
|
323
|
-
role,
|
|
324
|
-
provider: selection.provider,
|
|
325
|
-
model: selection.model,
|
|
326
|
-
tier: selection.tier,
|
|
327
|
-
fallbackApplied: selection.fallbackApplied,
|
|
328
|
-
};
|
|
329
|
-
}
|
|
330
|
-
function decisionToSelection(decision) {
|
|
331
|
-
return {
|
|
332
|
-
provider: decision.provider,
|
|
333
|
-
model: decision.model,
|
|
334
|
-
tier: decision.tier,
|
|
335
|
-
fallbackApplied: decision.fallbackApplied,
|
|
336
|
-
};
|
|
337
|
-
}
|
|
338
252
|
function shorten(text) {
|
|
339
253
|
if (text.length <= 60) {
|
|
340
254
|
return text;
|
|
341
255
|
}
|
|
342
256
|
return `${text.slice(0, 57)}...`;
|
|
343
257
|
}
|
|
344
|
-
async function maybeSyncGraph(task, run, options) {
|
|
345
|
-
if (!options?.graphClient || !options.enableAutoGraphSync) {
|
|
346
|
-
return;
|
|
347
|
-
}
|
|
348
|
-
if (run.status !== "COMPLETED") {
|
|
349
|
-
return;
|
|
350
|
-
}
|
|
351
|
-
await (0, post_run_sync_1.syncGraphAfterRun)(options.graphClient, [
|
|
352
|
-
{
|
|
353
|
-
filePath: "runtime:task",
|
|
354
|
-
summary: `Task completed: ${task}`,
|
|
355
|
-
},
|
|
356
|
-
], options.configPath);
|
|
357
|
-
}
|
|
358
|
-
async function maybeBuildSkillHints(task, options) {
|
|
359
|
-
if (!options?.enableSkillFlywheel || !options.graphClient) {
|
|
360
|
-
return [];
|
|
361
|
-
}
|
|
362
|
-
return (0, skill_flywheel_1.suggestSkillHints)(options.graphClient, task, options.skillHintsLimit ?? 3);
|
|
363
|
-
}
|
|
364
|
-
async function maybeSyncSkillGraph(task, run, options) {
|
|
365
|
-
if (!options?.enableSkillFlywheel || !options.graphClient) {
|
|
366
|
-
return;
|
|
367
|
-
}
|
|
368
|
-
// Bridge mode: task is delegated to an external agent whose outcome is unknown.
|
|
369
|
-
// Skip skill score updates until the external agent reports back via
|
|
370
|
-
// updateEpisodeOutcome + applySkillLearning. Otherwise every delegated task
|
|
371
|
-
// would be counted as a failure, permanently sinking skill scores to -20.
|
|
372
|
-
if (run.status === "DELEGATED") {
|
|
373
|
-
return;
|
|
374
|
-
}
|
|
375
|
-
await (0, skill_flywheel_1.applySkillLearning)(options.graphClient, task, run);
|
|
376
|
-
}
|
|
377
|
-
async function maybeFindSimilarEpisodes(task, options) {
|
|
378
|
-
if (!options?.enableEpisodicMemory || !options.graphClient) {
|
|
379
|
-
return [];
|
|
380
|
-
}
|
|
381
|
-
return (0, episodic_memory_1.findSimilarEpisodes)(options.graphClient, task, 3);
|
|
382
|
-
}
|
|
383
|
-
function statusToOutcome(status) {
|
|
384
|
-
if (status === "COMPLETED")
|
|
385
|
-
return "pass";
|
|
386
|
-
if (status === "HUMAN_REVIEW_REQUIRED")
|
|
387
|
-
return "human_review";
|
|
388
|
-
if (status === "DELEGATED")
|
|
389
|
-
return "pending";
|
|
390
|
-
return "fail";
|
|
391
|
-
}
|
|
392
|
-
async function finalizeEpisode(task, plan, run, similar, skillHints, options) {
|
|
393
|
-
if (!options?.enableEpisodicMemory || !options.graphClient) {
|
|
394
|
-
return run;
|
|
395
|
-
}
|
|
396
|
-
const decisions = [];
|
|
397
|
-
for (const rd of run.routeDecisions ?? []) {
|
|
398
|
-
decisions.push(`route ${rd.role}: ${rd.provider}/${rd.model}`);
|
|
399
|
-
}
|
|
400
|
-
for (const hint of skillHints.slice(0, 3)) {
|
|
401
|
-
decisions.push(`skill: ${hint}`);
|
|
402
|
-
}
|
|
403
|
-
const dedupedDecisions = Array.from(new Set(decisions)).slice(0, 6);
|
|
404
|
-
const planProjection = plan.map((node) => ({ id: node.id, description: node.description }));
|
|
405
|
-
const recordInput = {
|
|
406
|
-
task,
|
|
407
|
-
plan: planProjection,
|
|
408
|
-
outcome: statusToOutcome(run.status),
|
|
409
|
-
keyDecisions: dedupedDecisions,
|
|
410
|
-
lessons: [],
|
|
411
|
-
attempts: run.attempts,
|
|
412
|
-
...(run.executionRounds ? { executionRounds: run.executionRounds } : {}),
|
|
413
|
-
...(run.feedback !== undefined ? { runFeedback: run.feedback } : {}),
|
|
414
|
-
};
|
|
415
|
-
const episode = await (0, episodic_memory_1.recordEpisode)(options.graphClient, recordInput);
|
|
416
|
-
const similarSummaries = similar.map((ep) => ({
|
|
417
|
-
id: ep.id,
|
|
418
|
-
task: ep.task,
|
|
419
|
-
score: ep.outcome === "pass" ? 1 : ep.outcome === "fail" ? -1 : 0,
|
|
420
|
-
}));
|
|
421
|
-
return {
|
|
422
|
-
...run,
|
|
423
|
-
episodeId: episode.id,
|
|
424
|
-
similarEpisodes: similarSummaries,
|
|
425
|
-
};
|
|
426
|
-
}
|
|
427
|
-
async function maybeRunPlanInsightForComplex(task, options) {
|
|
428
|
-
try {
|
|
429
|
-
const config = (0, resolve_1.resolveConfig)(options?.configPath);
|
|
430
|
-
if (!(0, llm_availability_1.hasUsableLlmProvider)(config)) {
|
|
431
|
-
return (0, agent_delegation_1.buildAgentDelegatedPlanInsight)(task);
|
|
432
|
-
}
|
|
433
|
-
(0, env_1.applyOpenBmbRuntimeEnv)(config);
|
|
434
|
-
const selection = (0, model_router_1.resolveModelForRole)("planner");
|
|
435
|
-
const { insight, plan } = await (0, insight_1.planInsight)(task, { selection });
|
|
436
|
-
return {
|
|
437
|
-
mode: "llm",
|
|
438
|
-
insight,
|
|
439
|
-
plan,
|
|
440
|
-
};
|
|
441
|
-
}
|
|
442
|
-
catch (error) {
|
|
443
|
-
logger_1.logger.warn({ error, task }, "Plan insight failed, using agent-delegated heuristic");
|
|
444
|
-
return (0, agent_delegation_1.buildAgentDelegatedPlanInsight)(task);
|
|
445
|
-
}
|
|
446
|
-
}
|
|
447
258
|
//# sourceMappingURL=orchestrator.js.map
|