@mcp-abap-adt/llm-agent-server-libs 33.1.0 → 34.0.1
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/factories/controller-factory.d.ts +2 -2
- package/dist/generated/version.d.ts +1 -1
- package/dist/generated/version.js +1 -1
- package/dist/pipelines/controller.d.ts +3 -1
- package/dist/pipelines/controller.d.ts.map +1 -1
- package/dist/pipelines/controller.js +53 -67
- package/dist/pipelines/controller.js.map +1 -1
- package/dist/smart-agent/config-reload-watcher.d.ts +1 -0
- package/dist/smart-agent/config-reload-watcher.d.ts.map +1 -1
- package/dist/smart-agent/config-reload-watcher.js +1 -0
- package/dist/smart-agent/config-reload-watcher.js.map +1 -1
- package/dist/smart-agent/controller/board.d.ts +10 -27
- package/dist/smart-agent/controller/board.d.ts.map +1 -1
- package/dist/smart-agent/controller/board.js +11 -66
- package/dist/smart-agent/controller/board.js.map +1 -1
- package/dist/smart-agent/controller/caller-scoped-backend.d.ts +9 -0
- package/dist/smart-agent/controller/caller-scoped-backend.d.ts.map +1 -0
- package/dist/smart-agent/controller/caller-scoped-backend.js +27 -0
- package/dist/smart-agent/controller/caller-scoped-backend.js.map +1 -0
- package/dist/smart-agent/controller/control-history.d.ts +20 -0
- package/dist/smart-agent/controller/control-history.d.ts.map +1 -0
- package/dist/smart-agent/controller/control-history.js +57 -0
- package/dist/smart-agent/controller/control-history.js.map +1 -0
- package/dist/smart-agent/controller/controller-coordinator-handler.d.ts +1 -0
- package/dist/smart-agent/controller/controller-coordinator-handler.d.ts.map +1 -1
- package/dist/smart-agent/controller/controller-coordinator-handler.js +123 -115
- package/dist/smart-agent/controller/controller-coordinator-handler.js.map +1 -1
- package/dist/smart-agent/controller/finalizer.d.ts +7 -19
- package/dist/smart-agent/controller/finalizer.d.ts.map +1 -1
- package/dist/smart-agent/controller/finalizer.js +9 -93
- package/dist/smart-agent/controller/finalizer.js.map +1 -1
- package/dist/smart-agent/controller/reviewer.d.ts +1 -1
- package/dist/smart-agent/controller/reviewer.d.ts.map +1 -1
- package/dist/smart-agent/controller/reviewer.js +4 -4
- package/dist/smart-agent/controller/reviewer.js.map +1 -1
- package/dist/smart-agent/controller/subagent-client.d.ts.map +1 -1
- package/dist/smart-agent/controller/subagent-client.js +11 -2
- package/dist/smart-agent/controller/subagent-client.js.map +1 -1
- package/dist/smart-agent/controller/types.d.ts +8 -1
- package/dist/smart-agent/controller/types.d.ts.map +1 -1
- package/dist/smart-agent/controller/types.js.map +1 -1
- package/dist/smart-agent/http/adapter-route-handler.js +2 -2
- package/dist/smart-agent/http/adapter-route-handler.js.map +1 -1
- package/dist/smart-agent/http/config-route-handler.d.ts.map +1 -1
- package/dist/smart-agent/http/config-route-handler.js +1 -0
- package/dist/smart-agent/http/config-route-handler.js.map +1 -1
- package/dist/smart-agent/http/sessions-route-handler.d.ts.map +1 -1
- package/dist/smart-agent/http/sessions-route-handler.js +4 -0
- package/dist/smart-agent/http/sessions-route-handler.js.map +1 -1
- package/dist/smart-agent/resolve-config-sections.d.ts.map +1 -1
- package/dist/smart-agent/resolve-config-sections.js +1 -0
- package/dist/smart-agent/resolve-config-sections.js.map +1 -1
- package/dist/smart-agent/smart-server.d.ts +3 -0
- package/dist/smart-agent/smart-server.d.ts.map +1 -1
- package/dist/smart-agent/smart-server.js +6 -16
- package/dist/smart-agent/smart-server.js.map +1 -1
- package/dist/smart-agent/yaml-loader.d.ts +1 -1
- package/dist/smart-agent/yaml-loader.d.ts.map +1 -1
- package/dist/smart-agent/yaml-loader.js +5 -4
- package/dist/smart-agent/yaml-loader.js.map +1 -1
- package/package.json +4 -4
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/** Keep durable corrections between the same tool rounds across resumes. */
|
|
2
|
+
export class ControllerControlHistory {
|
|
3
|
+
messages;
|
|
4
|
+
anchors;
|
|
5
|
+
prefixLength;
|
|
6
|
+
constructor(messages, anchors, prefixLength) {
|
|
7
|
+
this.messages = messages;
|
|
8
|
+
this.anchors = anchors;
|
|
9
|
+
this.prefixLength = prefixLength;
|
|
10
|
+
}
|
|
11
|
+
append(preceding, message) {
|
|
12
|
+
this.anchors.push(this.anchor(preceding));
|
|
13
|
+
this.messages.push(message);
|
|
14
|
+
}
|
|
15
|
+
record(messages) {
|
|
16
|
+
for (const anchor of this.anchors) {
|
|
17
|
+
if (!anchor)
|
|
18
|
+
continue;
|
|
19
|
+
anchor.following += messages.filter((message) => JSON.stringify(message) === anchor.key).length;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
/** Old bundles stored only a tail. Anchor it before recording newer rounds. */
|
|
23
|
+
migrate(formed) {
|
|
24
|
+
const preceding = [...formed];
|
|
25
|
+
for (const [index, message] of this.messages.entries()) {
|
|
26
|
+
if (index >= this.anchors.length)
|
|
27
|
+
this.anchors.push(this.anchor(preceding));
|
|
28
|
+
preceding.push(message);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
restore(formed) {
|
|
32
|
+
const out = [...formed];
|
|
33
|
+
let earliest = this.prefixLength;
|
|
34
|
+
for (const [index, message] of this.messages.entries()) {
|
|
35
|
+
const anchor = this.anchors[index];
|
|
36
|
+
let insertAt = earliest;
|
|
37
|
+
if (anchor) {
|
|
38
|
+
const matches = out.flatMap((candidate, position) => JSON.stringify(candidate) === anchor.key ? [position] : []);
|
|
39
|
+
const position = matches[matches.length - anchor.following - 1];
|
|
40
|
+
if (position !== undefined)
|
|
41
|
+
insertAt = Math.max(earliest, position + 1);
|
|
42
|
+
}
|
|
43
|
+
// An explicitly selected strategy may omit the predecessor. Keep the
|
|
44
|
+
// correction before its newer retained rounds and after earlier corrections.
|
|
45
|
+
out.splice(insertAt, 0, message);
|
|
46
|
+
earliest = insertAt + 1;
|
|
47
|
+
}
|
|
48
|
+
return out;
|
|
49
|
+
}
|
|
50
|
+
anchor(preceding) {
|
|
51
|
+
if (preceding.length <= this.prefixLength)
|
|
52
|
+
return null;
|
|
53
|
+
const key = JSON.stringify(preceding[preceding.length - 1]);
|
|
54
|
+
return { key, following: 0 };
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
//# sourceMappingURL=control-history.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"control-history.js","sourceRoot":"","sources":["../../../src/smart-agent/controller/control-history.ts"],"names":[],"mappings":"AAQA,4EAA4E;AAC5E,MAAM,OAAO,wBAAwB;IAEhB;IACA;IACA;IAHnB,YACmB,QAAmB,EACnB,OAA2C,EAC3C,YAAoB;QAFpB,aAAQ,GAAR,QAAQ,CAAW;QACnB,YAAO,GAAP,OAAO,CAAoC;QAC3C,iBAAY,GAAZ,YAAY,CAAQ;IACpC,CAAC;IAEJ,MAAM,CAAC,SAAoB,EAAE,OAAgB;QAC3C,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC,CAAC;QAC1C,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IAC9B,CAAC;IAED,MAAM,CAAC,QAAmB;QACxB,KAAK,MAAM,MAAM,IAAI,IAAI,CAAC,OAAO,EAAE,CAAC;YAClC,IAAI,CAAC,MAAM;gBAAE,SAAS;YACtB,MAAM,CAAC,SAAS,IAAI,QAAQ,CAAC,MAAM,CACjC,CAAC,OAAO,EAAE,EAAE,CAAC,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,KAAK,MAAM,CAAC,GAAG,CACpD,CAAC,MAAM,CAAC;QACX,CAAC;IACH,CAAC;IAED,+EAA+E;IAC/E,OAAO,CAAC,MAAiB;QACvB,MAAM,SAAS,GAAG,CAAC,GAAG,MAAM,CAAC,CAAC;QAC9B,KAAK,MAAM,CAAC,KAAK,EAAE,OAAO,CAAC,IAAI,IAAI,CAAC,QAAQ,CAAC,OAAO,EAAE,EAAE,CAAC;YACvD,IAAI,KAAK,IAAI,IAAI,CAAC,OAAO,CAAC,MAAM;gBAC9B,IAAI,CAAC,OAAO,CAA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,YAAY;YAAE,OAAO,IAAI,CAAC;QACvD,MAAM,GAAG,GAAG,IAAI,CAAC,SAAS,CAAC,SAAS,CAAC,SAAS,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC;QAC5D,OAAO,EAAE,GAAG,EAAE,SAAS,EAAE,CAAC,EAAE,CAAC;IAC/B,CAAC;CACF"}
|
|
@@ -136,6 +136,7 @@ export declare class ControllerCoordinatorHandler implements IStageHandler {
|
|
|
136
136
|
private readonly deps;
|
|
137
137
|
constructor(deps: ControllerHandlerDeps);
|
|
138
138
|
execute(ctx: PipelineContext, _config: Record<string, unknown>, _span: unknown): Promise<boolean>;
|
|
139
|
+
private executeScoped;
|
|
139
140
|
/** Returns 'advanced' (step succeeded — continue loop), 'failed' (retries/
|
|
140
141
|
* tool-call budget OR reviewer-unverifiable budget exhausted; the failure note
|
|
141
142
|
* is in plannerPrivate so the planner can replan), 'partial' (reviewer approved
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"controller-coordinator-handler.d.ts","sourceRoot":"","sources":["../../../src/smart-agent/controller/controller-coordinator-handler.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,WAAW,EAGhB,KAAK,mBAAmB,EACxB,KAAK,kBAAkB,EACvB,KAAK,oBAAoB,EACzB,KAAK,aAAa,EAClB,KAAK,qBAAqB,EAE1B,KAAK,aAAa,EAElB,KAAK,OAAO,EAEZ,KAAK,QAAQ,EACb,KAAK,aAAa,EAGlB,KAAK,eAAe,EAGpB,KAAK,8BAA8B,EAEpC,MAAM,yBAAyB,CAAC;AACjC,OAAO,EACL,KAAK,gBAAgB,EAGrB,KAAK,eAAe,
|
|
1
|
+
{"version":3,"file":"controller-coordinator-handler.d.ts","sourceRoot":"","sources":["../../../src/smart-agent/controller/controller-coordinator-handler.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,WAAW,EAGhB,KAAK,mBAAmB,EACxB,KAAK,kBAAkB,EACvB,KAAK,oBAAoB,EACzB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AAM,YAAY,CAAC;AAC7C,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,EAAE,eAAe,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAC/D,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAElD,yEAAyE;AACzE,eAAO,MAAM,iBAAiB,qCAAqC,CAAC;AAEpE;;;;;;GAMG;AACH,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,aAAa,GAAG,MAAM,GAAG,SAAS,CAS7E;AAED;yDACyD;AACzD,wBAAgB,YAAY,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAEpD;AAMD;;;;;;;;;;;;;;;;;;;GAmBG;AACH,qBAAa,4BAA6B,YAAW,aAAa;IACpD,OAAO,CAAC,QAAQ,CAAC,IAAI;gBAAJ,IAAI,EAAE,qBAAqB;IAElD,OAAO,CACX,GAAG,EAAE,eAAe,EACpB,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAChC,KAAK,EAAE,OAAO,GACb,OAAO,CAAC,OAAO,CAAC;YAcL,aAAa;IA+uB3B;;;;;;yCAMqC;YACvB,OAAO;IAmwBrB;;;;;;;gFAO4E;YAC9D,aAAa;IAwF3B;;;mEAG+D;YACjD,iBAAiB;YAqCjB,QAAQ;IAatB;;wFAEoF;YACtE,aAAa;YAyBb,QAAQ;IAmKtB;+EAC2E;YAC7D,qBAAqB;IAwCnC,OAAO,CAAC,cAAc;IAetB,OAAO,CAAC,YAAY;IAepB,OAAO,CAAC,eAAe;CAexB"}
|
|
@@ -1,7 +1,9 @@
|
|
|
1
|
-
import { DefaultWaitStrategy, externalToolCallId, McpError, mergeOfferedTools, } from '@mcp-abap-adt/llm-agent';
|
|
2
|
-
import { LegacyAccumulateContextStrategy, LegacyTranscriptContextStrategy, summaryToUsage, } from '@mcp-abap-adt/llm-agent-libs';
|
|
1
|
+
import { DefaultWaitStrategy, externalToolCallId, McpError, mergeOfferedTools, toToolCallDelta, } from '@mcp-abap-adt/llm-agent';
|
|
2
|
+
import { LegacyAccumulateContextStrategy, LegacyTranscriptContextStrategy, summaryToUsage, ToolResponseRound, } from '@mcp-abap-adt/llm-agent-libs';
|
|
3
3
|
import { writePlanDecision } from './artifacts.js';
|
|
4
4
|
import { BoardOverBudgetError, renderLiveBoard, } from './board.js';
|
|
5
|
+
import { callerScopedBackend } from './caller-scoped-backend.js';
|
|
6
|
+
import { ControllerControlHistory } from './control-history.js';
|
|
5
7
|
import { DefaultStepExecutionControl } from './default-step-execution-control.js';
|
|
6
8
|
import { writeArtifact } from './memorizer.js';
|
|
7
9
|
import { resolveByPrecedence } from './outcome.js';
|
|
@@ -94,6 +96,15 @@ export class ControllerCoordinatorHandler {
|
|
|
94
96
|
this.deps = deps;
|
|
95
97
|
}
|
|
96
98
|
async execute(ctx, _config, _span) {
|
|
99
|
+
const scoped = callerScopedBackend(this.deps.backend, ctx.options, ctx.sessionId);
|
|
100
|
+
const handler = new ControllerCoordinatorHandler({
|
|
101
|
+
...this.deps,
|
|
102
|
+
backend: scoped.backend,
|
|
103
|
+
knowledgeRagFor: () => this.deps.knowledgeRagFor(scoped.storageKey),
|
|
104
|
+
});
|
|
105
|
+
return handler.executeScoped(ctx);
|
|
106
|
+
}
|
|
107
|
+
async executeScoped(ctx) {
|
|
97
108
|
const deps = this.deps;
|
|
98
109
|
// Seams resolved once per execute(); consumed by Task 11+ (reviewer/finalizer/run-scope).
|
|
99
110
|
const now = deps.now ?? (() => new Date().toISOString());
|
|
@@ -279,19 +290,28 @@ export class ControllerCoordinatorHandler {
|
|
|
279
290
|
runId: bundle.runId,
|
|
280
291
|
seq: bundle.inFlightStep?.seq,
|
|
281
292
|
attempt: bundle.inFlightStep?.attempt,
|
|
282
|
-
//
|
|
283
|
-
// duplicate fetches of the same object across attempts.
|
|
293
|
+
// The result belongs to this pending suspension only.
|
|
284
294
|
identityKey: extId,
|
|
285
295
|
writeOrdinal: bundle.writeOrdinal,
|
|
286
296
|
content: result,
|
|
287
297
|
}, ctx.options);
|
|
288
298
|
if (bundle.inFlightStep) {
|
|
299
|
+
// Separate pre-release history from this new continuation so legacy
|
|
300
|
+
// corrections can be anchored before the external exchange is recorded.
|
|
301
|
+
if (bundle.inFlightStep.contextStrategyState === undefined &&
|
|
302
|
+
bundle.inFlightStep.transcript.length > 0) {
|
|
303
|
+
bundle.inFlightStep.contextStrategyState =
|
|
304
|
+
new LegacyTranscriptContextStrategy({
|
|
305
|
+
rawMessages: bundle.inFlightStep.transcript,
|
|
306
|
+
}).snapshot();
|
|
307
|
+
bundle.inFlightStep.transcript.length = 0;
|
|
308
|
+
}
|
|
289
309
|
// External CONTINUATION: inject the tool result into the durable
|
|
290
310
|
// transcript so the loop RE-RUNS the in-flight step (the executor
|
|
291
311
|
// continues from its own tool call). Bounded by toolCallCount, NOT a
|
|
292
312
|
// crash-replay — externalContinuation tells block (A) not to charge
|
|
293
313
|
// resumeCount when it re-runs the step this invocation.
|
|
294
|
-
bundle.inFlightStep.transcript.push({
|
|
314
|
+
bundle.inFlightStep.transcript.push(bundle.pending.assistantMessage ?? {
|
|
295
315
|
role: 'assistant',
|
|
296
316
|
content: null,
|
|
297
317
|
tool_calls: [
|
|
@@ -304,7 +324,11 @@ export class ControllerCoordinatorHandler {
|
|
|
304
324
|
},
|
|
305
325
|
},
|
|
306
326
|
],
|
|
307
|
-
}, {
|
|
327
|
+
}, {
|
|
328
|
+
role: 'tool',
|
|
329
|
+
tool_call_id: extId,
|
|
330
|
+
content: result,
|
|
331
|
+
}, ...(bundle.pending.siblingResults ?? []));
|
|
308
332
|
bundle.pending = undefined;
|
|
309
333
|
bundle.runState = 'active';
|
|
310
334
|
externalContinuation = true;
|
|
@@ -790,16 +814,15 @@ export class ControllerCoordinatorHandler {
|
|
|
790
814
|
else {
|
|
791
815
|
strategy = makeStrategy(); // fresh step
|
|
792
816
|
}
|
|
793
|
-
// Durable, bounded control-message tail (retries only). Aliased IN PLACE so
|
|
794
|
-
// push/prune mutate the persisted field; a legacy call with no inFlightStep gets
|
|
795
|
-
// an ephemeral local (no durable tail to persist).
|
|
796
|
-
let controlTail;
|
|
797
817
|
if (inFlight) {
|
|
798
|
-
inFlight.controlTail
|
|
799
|
-
|
|
818
|
+
inFlight.controlTail ??= [];
|
|
819
|
+
inFlight.controlTailAnchors ??= [];
|
|
800
820
|
}
|
|
801
|
-
|
|
802
|
-
|
|
821
|
+
const controlTail = inFlight?.controlTail ?? [];
|
|
822
|
+
const controlAnchors = inFlight?.controlTailAnchors ?? [];
|
|
823
|
+
const controlHistory = new ControllerControlHistory(controlTail, controlAnchors, staticPrefix.length);
|
|
824
|
+
if (controlAnchors.length < controlTail.length) {
|
|
825
|
+
controlHistory.migrate(await strategy.form({ prefix: staticPrefix, queryText: step.instructions }, ctx.options));
|
|
803
826
|
}
|
|
804
827
|
// External CONTINUATION bridge: the resume preamble APPENDS the freshly
|
|
805
828
|
// resolved external assistant/tool pair(s) to inFlight.transcript. Record them
|
|
@@ -820,8 +843,18 @@ export class ControllerCoordinatorHandler {
|
|
|
820
843
|
results.push(t[i]);
|
|
821
844
|
i++;
|
|
822
845
|
}
|
|
823
|
-
if (assistant)
|
|
824
|
-
|
|
846
|
+
if (assistant) {
|
|
847
|
+
// This exchange was recorded before suspension. Preserve its IDs;
|
|
848
|
+
// only a new model response creates a new ToolResponseRound.
|
|
849
|
+
const calls = assistant.tool_calls ?? [];
|
|
850
|
+
if (calls.length !== results.length ||
|
|
851
|
+
calls.some((call, index) => call.id !== results[index].tool_call_id)) {
|
|
852
|
+
throw new Error('A recorded tool call must have exactly one result');
|
|
853
|
+
}
|
|
854
|
+
const round = { assistant, results };
|
|
855
|
+
await strategy.record(round, ctx.options);
|
|
856
|
+
controlHistory.record([round.assistant, ...round.results]);
|
|
857
|
+
}
|
|
825
858
|
}
|
|
826
859
|
inFlight.transcript.length = 0;
|
|
827
860
|
}
|
|
@@ -894,7 +927,7 @@ export class ControllerCoordinatorHandler {
|
|
|
894
927
|
note: reason,
|
|
895
928
|
remainder: '',
|
|
896
929
|
stepId: step.stepId,
|
|
897
|
-
digest: reason
|
|
930
|
+
digest: reason,
|
|
898
931
|
writeOrdinal: bundle.writeOrdinal,
|
|
899
932
|
// NEVER empty: an empty `content` is handed to the RAG's embedder,
|
|
900
933
|
// and a real embedder (e.g. SAP AI Core) rejects empty text with an
|
|
@@ -936,9 +969,8 @@ export class ControllerCoordinatorHandler {
|
|
|
936
969
|
const rc = budget.shouldContinueRound(state());
|
|
937
970
|
if (!rc.continue)
|
|
938
971
|
return cutControlFailure(rc.reason);
|
|
939
|
-
//
|
|
940
|
-
|
|
941
|
-
const messages = (await strategy.form({ prefix: staticPrefix, queryText: step.instructions }, ctx.options)).concat(controlTail);
|
|
972
|
+
// Restore corrections at their chronological positions between rounds.
|
|
973
|
+
const messages = controlHistory.restore(await strategy.form({ prefix: staticPrefix, queryText: step.instructions }, ctx.options));
|
|
942
974
|
// Merged signal into the executor call. A reject WHILE the step budget is
|
|
943
975
|
// aborted is a step-timeout cut (NOT the executor-error retry); a normal
|
|
944
976
|
// return after the budget fired is ALSO a step-timeout cut.
|
|
@@ -975,7 +1007,7 @@ export class ControllerCoordinatorHandler {
|
|
|
975
1007
|
approved: res.content,
|
|
976
1008
|
remainder: '',
|
|
977
1009
|
note: '',
|
|
978
|
-
digest: res.content
|
|
1010
|
+
digest: res.content,
|
|
979
1011
|
},
|
|
980
1012
|
};
|
|
981
1013
|
// Judge failure (provider error / malformed / contradictory ok-with-empty)
|
|
@@ -1046,7 +1078,7 @@ export class ControllerCoordinatorHandler {
|
|
|
1046
1078
|
if (res.kind === 'error') {
|
|
1047
1079
|
retries++;
|
|
1048
1080
|
if (retries <= cfg.maxRetries) {
|
|
1049
|
-
|
|
1081
|
+
controlHistory.append(messages, {
|
|
1050
1082
|
role: 'user',
|
|
1051
1083
|
content: `The previous attempt failed: ${res.error}. Retry the step.`,
|
|
1052
1084
|
});
|
|
@@ -1062,12 +1094,15 @@ export class ControllerCoordinatorHandler {
|
|
|
1062
1094
|
return settle('failed', executorErrorReason);
|
|
1063
1095
|
}
|
|
1064
1096
|
// res.kind === 'tool_call' → route the FIRST tool call.
|
|
1065
|
-
|
|
1066
|
-
|
|
1097
|
+
if (res.toolCalls.length === 0) {
|
|
1098
|
+
const round = new ToolResponseRound(res.content ?? null, []).finish();
|
|
1099
|
+
const assistant = round.assistant;
|
|
1100
|
+
await strategy.record(round, ctx.options);
|
|
1101
|
+
controlHistory.record([assistant]);
|
|
1067
1102
|
// Empty tool-call array → treat as an executor error (retry/replan).
|
|
1068
1103
|
retries++;
|
|
1069
1104
|
if (retries <= cfg.maxRetries) {
|
|
1070
|
-
|
|
1105
|
+
controlHistory.append([...messages, assistant], {
|
|
1071
1106
|
role: 'user',
|
|
1072
1107
|
content: 'The previous attempt produced an empty tool call. Retry the step.',
|
|
1073
1108
|
});
|
|
@@ -1079,32 +1114,54 @@ export class ControllerCoordinatorHandler {
|
|
|
1079
1114
|
bundle.plannerPrivate += `\n[step ${step.name} failed] empty tool call`;
|
|
1080
1115
|
return settle('failed', `step "${step.name}" produced an empty tool call`);
|
|
1081
1116
|
}
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1117
|
+
const responseRound = new ToolResponseRound(res.content ?? null, res.toolCalls.map((raw, index) => {
|
|
1118
|
+
const call = toToolCallDelta(raw, index);
|
|
1119
|
+
return {
|
|
1120
|
+
name: call.name ?? '',
|
|
1121
|
+
arguments: typeof raw.arguments === 'string'
|
|
1122
|
+
? raw.arguments
|
|
1123
|
+
: (call.arguments ?? ''),
|
|
1124
|
+
};
|
|
1125
|
+
}), isExternalTool);
|
|
1126
|
+
const calls = responseRound.executableCalls();
|
|
1127
|
+
if (calls.length === 0 || calls[0].id !== responseRound.calls[0].id) {
|
|
1128
|
+
for (const sibling of calls) {
|
|
1129
|
+
responseRound.resolve(sibling, 'Error: not executed: the controller accepts one tool call per response.', true);
|
|
1090
1130
|
}
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1131
|
+
const round = responseRound.finish();
|
|
1132
|
+
await strategy.record(round, ctx.options);
|
|
1133
|
+
controlHistory.record([round.assistant, ...round.results]);
|
|
1134
|
+
await persistExchange();
|
|
1135
|
+
continue;
|
|
1136
|
+
}
|
|
1137
|
+
const call = calls[0];
|
|
1138
|
+
const assistant = responseRound.assistant;
|
|
1139
|
+
const siblingResults = calls.slice(1).map((item) => ({
|
|
1140
|
+
role: 'tool',
|
|
1141
|
+
tool_call_id: item.id,
|
|
1142
|
+
content: `Error: not executed: the controller accepts one tool call per response. Request "${item.name}" again after the preceding result.`,
|
|
1143
|
+
}));
|
|
1144
|
+
// Content identities below belong to context metadata, never resume matching.
|
|
1145
|
+
siblingResults.forEach((message, index) => {
|
|
1146
|
+
responseRound.add(message, {
|
|
1147
|
+
identityKey: externalToolCallId(calls[index + 1].name, calls[index + 1].arguments),
|
|
1148
|
+
isError: true,
|
|
1149
|
+
});
|
|
1150
|
+
});
|
|
1151
|
+
const recordResponse = async (text, isError = false) => {
|
|
1152
|
+
bundle.writeOrdinal = (bundle.writeOrdinal ?? 0) + 1;
|
|
1153
|
+
responseRound.add({ role: 'tool', tool_call_id: call.id, content: text }, {
|
|
1154
|
+
identityKey: externalToolCallId(call.name, call.arguments),
|
|
1155
|
+
isError,
|
|
1156
|
+
});
|
|
1157
|
+
const round = {
|
|
1158
|
+
...responseRound.finish(),
|
|
1159
|
+
ordinal: bundle.writeOrdinal,
|
|
1160
|
+
};
|
|
1161
|
+
await strategy.record(round, ctx.options);
|
|
1162
|
+
controlHistory.record([round.assistant, ...round.results]);
|
|
1163
|
+
await persistExchange();
|
|
1164
|
+
};
|
|
1108
1165
|
const name = call.name;
|
|
1109
1166
|
const args = call.arguments;
|
|
1110
1167
|
if (isExternalTool(name)) {
|
|
@@ -1112,13 +1169,15 @@ export class ControllerCoordinatorHandler {
|
|
|
1112
1169
|
// prospective count gate is consulted BEFORE the increment so an external
|
|
1113
1170
|
// tool cannot exceed the cap. Cut → control-failed replan at the same seq.
|
|
1114
1171
|
const g = budget.canExecuteTool(state());
|
|
1115
|
-
if (!g.continue)
|
|
1172
|
+
if (!g.continue) {
|
|
1173
|
+
await recordResponse(`Error: not executed: ${g.reason}`, true);
|
|
1116
1174
|
return cutControlFailure(g.reason);
|
|
1175
|
+
}
|
|
1117
1176
|
// Snapshot the strategy state SO FAR before we suspend (the resume injection
|
|
1118
1177
|
// appends the external assistant/tool pair, recorded on the next invocation).
|
|
1119
1178
|
if (inFlight)
|
|
1120
1179
|
inFlight.contextStrategyState = strategy.snapshot();
|
|
1121
|
-
const extId =
|
|
1180
|
+
const extId = call.id;
|
|
1122
1181
|
if (inFlight)
|
|
1123
1182
|
inFlight.toolCallCount += 1;
|
|
1124
1183
|
// The new marker REPLACES any prior pending (a fresh extId).
|
|
@@ -1128,6 +1187,8 @@ export class ControllerCoordinatorHandler {
|
|
|
1128
1187
|
toolName: name,
|
|
1129
1188
|
args,
|
|
1130
1189
|
position: step.name,
|
|
1190
|
+
assistantMessage: assistant,
|
|
1191
|
+
siblingResults: responseRound.resolved(),
|
|
1131
1192
|
};
|
|
1132
1193
|
bundle.runState = 'suspended';
|
|
1133
1194
|
await persistBundle(deps.backend, sessionId, bundle);
|
|
@@ -1139,9 +1200,11 @@ export class ControllerCoordinatorHandler {
|
|
|
1139
1200
|
// stale / out-of-scope) is rejected — NOT executed — and fed back as a
|
|
1140
1201
|
// tool-not-available error so the executor retries with an offered tool.
|
|
1141
1202
|
if (!offeredInternalNames.has(name)) {
|
|
1203
|
+
await recordResponse(`Error: Tool "${name}" is not available for this step.`, true);
|
|
1142
1204
|
retries++;
|
|
1143
1205
|
if (retries <= cfg.maxRetries) {
|
|
1144
|
-
|
|
1206
|
+
const preceding = await strategy.form({ prefix: staticPrefix, queryText: step.instructions }, ctx.options);
|
|
1207
|
+
controlHistory.append(controlHistory.restore(preceding), {
|
|
1145
1208
|
role: 'user',
|
|
1146
1209
|
content: `Tool "${name}" is not available for this step. Use only the tools provided to you.`,
|
|
1147
1210
|
});
|
|
@@ -1157,8 +1220,10 @@ export class ControllerCoordinatorHandler {
|
|
|
1157
1220
|
// Prospective count gate BEFORE the increment (the before-increment model:
|
|
1158
1221
|
// the increment happens only after canExecuteTool allows the call).
|
|
1159
1222
|
const g = budget.canExecuteTool(state());
|
|
1160
|
-
if (!g.continue)
|
|
1223
|
+
if (!g.continue) {
|
|
1224
|
+
await recordResponse(`Error: not executed: ${g.reason}`, true);
|
|
1161
1225
|
return cutControlFailure(g.reason);
|
|
1226
|
+
}
|
|
1162
1227
|
// Durable round-trip count: ++ and persist BEFORE surfacing so it survives a
|
|
1163
1228
|
// resume (never a per-resume local).
|
|
1164
1229
|
if (inFlight) {
|
|
@@ -1195,6 +1260,7 @@ export class ControllerCoordinatorHandler {
|
|
|
1195
1260
|
// Map that to a step-timeout control-failure BEFORE the McpError escalate so
|
|
1196
1261
|
// it is NOT mis-classified as MCP-unavailable (20.4.0 escalate order is
|
|
1197
1262
|
// otherwise unchanged).
|
|
1263
|
+
await recordResponse(`Error: ${mcpErr instanceof Error ? mcpErr.message : String(mcpErr)}`, true);
|
|
1198
1264
|
if (budget.signal.aborted)
|
|
1199
1265
|
return cutControlFailure('step-timeout');
|
|
1200
1266
|
if (mcpErr instanceof McpError) {
|
|
@@ -1215,67 +1281,9 @@ export class ControllerCoordinatorHandler {
|
|
|
1215
1281
|
isError: result.isError,
|
|
1216
1282
|
durationMs: Date.now() - mcpCallStartedAt,
|
|
1217
1283
|
}, 'mcp');
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
// reviewer for this step); reuse cutControlFailure so the step settles
|
|
1221
|
-
// 'failed' with the tool's error text and the planner replans / surfaces
|
|
1222
|
-
// it. Read result.isError directly here — BEFORE the round reaches the
|
|
1223
|
-
// context strategy — so no Message/meta replay is needed. The durable
|
|
1224
|
-
// failed step-result + plannerPrivate note (written by cutControlFailure)
|
|
1225
|
-
// ARE the resume carrier; the mcp-result artifact is intentionally not
|
|
1226
|
-
// relied on (the cut may never call strategy.record).
|
|
1227
|
-
if (result.isError) {
|
|
1284
|
+
await recordResponse(result.text, result.isError);
|
|
1285
|
+
if (result.isError)
|
|
1228
1286
|
return cutControlFailure(result.text);
|
|
1229
|
-
}
|
|
1230
|
-
// Record this exchange as a coherent assistant→tool ROUND (OpenAI protocol)
|
|
1231
|
-
// via the context strategy so the executor LLM continues from its own tool
|
|
1232
|
-
// call. The strategy owns the per-round context (Window keeps a bounded
|
|
1233
|
-
// buffer; RagRecall (Task 13) persists the mcp-result + recalls it) — the
|
|
1234
|
-
// handler no longer writes the mcp-result artifact or grows a raw transcript.
|
|
1235
|
-
// Durable monotonic write ordinal for this mcp-result write. RagRecall's
|
|
1236
|
-
// run-scoped dedup (isBetterMcp) tie-breaks on writeOrdinal FIRST (then
|
|
1237
|
-
// createdAt); since all mcp-result writes in a step share createdAt, a later
|
|
1238
|
-
// same-identityKey fetch only wins with a strictly-higher ordinal. Increment
|
|
1239
|
-
// BEFORE building the round so the value rides on it into strategy.record.
|
|
1240
|
-
bundle.writeOrdinal = (bundle.writeOrdinal ?? 0) + 1;
|
|
1241
|
-
const round = {
|
|
1242
|
-
assistant: {
|
|
1243
|
-
role: 'assistant',
|
|
1244
|
-
content: null,
|
|
1245
|
-
tool_calls: [
|
|
1246
|
-
{
|
|
1247
|
-
id: call.id,
|
|
1248
|
-
type: 'function',
|
|
1249
|
-
function: { name, arguments: JSON.stringify(args) },
|
|
1250
|
-
},
|
|
1251
|
-
],
|
|
1252
|
-
},
|
|
1253
|
-
results: [
|
|
1254
|
-
{
|
|
1255
|
-
role: 'tool',
|
|
1256
|
-
tool_call_id: call.id,
|
|
1257
|
-
content: result.text,
|
|
1258
|
-
},
|
|
1259
|
-
],
|
|
1260
|
-
// Stable fetch identity (tool+args) for run-scoped recall dedup, plus
|
|
1261
|
-
// the tool-level isError threaded from the bridge (#213). An unavailable
|
|
1262
|
-
// MCP server still aborts BEFORE record; a returned result carries its
|
|
1263
|
-
// real isError so the executor sees a failed call as failed, not as a
|
|
1264
|
-
// delivered success it retries forever.
|
|
1265
|
-
meta: [
|
|
1266
|
-
{
|
|
1267
|
-
identityKey: externalToolCallId(name, args),
|
|
1268
|
-
isError: result.isError,
|
|
1269
|
-
},
|
|
1270
|
-
],
|
|
1271
|
-
ordinal: bundle.writeOrdinal,
|
|
1272
|
-
roundId: undefined,
|
|
1273
|
-
};
|
|
1274
|
-
await strategy.record(round, ctx.options);
|
|
1275
|
-
// A recorded round supersedes any pending control retry → prune the tail.
|
|
1276
|
-
controlTail.length = 0;
|
|
1277
|
-
// The executor saw this round → make the strategy state durable before next.
|
|
1278
|
-
await persistExchange();
|
|
1279
1287
|
}
|
|
1280
1288
|
}
|
|
1281
1289
|
finally {
|
|
@@ -1367,7 +1375,7 @@ export class ControllerCoordinatorHandler {
|
|
|
1367
1375
|
note,
|
|
1368
1376
|
remainder: '',
|
|
1369
1377
|
stepId: step.stepId,
|
|
1370
|
-
digest: text
|
|
1378
|
+
digest: text,
|
|
1371
1379
|
writeOrdinal: bundle.writeOrdinal,
|
|
1372
1380
|
content: text,
|
|
1373
1381
|
}, args.ctx.options);
|