@mcp-abap-adt/llm-agent-libs 33.1.0 → 35.0.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 +72 -22
- package/dist/adapters/llm-adapter.d.ts +2 -2
- package/dist/adapters/llm-adapter.d.ts.map +1 -1
- package/dist/adapters/llm-adapter.js +51 -34
- package/dist/adapters/llm-adapter.js.map +1 -1
- package/dist/adapters/llm-provider-bridge.d.ts.map +1 -1
- package/dist/adapters/llm-provider-bridge.js +13 -20
- package/dist/adapters/llm-provider-bridge.js.map +1 -1
- package/dist/adapters/normalize-finish-reason.d.ts +3 -0
- package/dist/adapters/normalize-finish-reason.d.ts.map +1 -0
- package/dist/adapters/normalize-finish-reason.js +17 -0
- package/dist/adapters/normalize-finish-reason.js.map +1 -0
- package/dist/agent/rag-helpers.d.ts +4 -6
- package/dist/agent/rag-helpers.d.ts.map +1 -1
- package/dist/agent/rag-helpers.js +3 -43
- package/dist/agent/rag-helpers.js.map +1 -1
- package/dist/agent/rag-orchestrator-types.d.ts +3 -0
- package/dist/agent/rag-orchestrator-types.d.ts.map +1 -1
- package/dist/agent/rag-orchestrator.d.ts +0 -1
- package/dist/agent/rag-orchestrator.d.ts.map +1 -1
- package/dist/agent/rag-orchestrator.js +9 -29
- package/dist/agent/rag-orchestrator.js.map +1 -1
- package/dist/agent.d.ts +12 -3
- package/dist/agent.d.ts.map +1 -1
- package/dist/agent.js +178 -245
- package/dist/agent.js.map +1 -1
- package/dist/builder-types.d.ts +1 -1
- package/dist/builder-types.d.ts.map +1 -1
- package/dist/builder.d.ts +7 -7
- package/dist/builder.d.ts.map +1 -1
- package/dist/builder.js +16 -26
- package/dist/builder.js.map +1 -1
- package/dist/config/config-watcher.d.ts +3 -0
- package/dist/config/config-watcher.d.ts.map +1 -1
- package/dist/config/config-watcher.js +1 -0
- package/dist/config/config-watcher.js.map +1 -1
- package/dist/context/context-assembler.d.ts.map +1 -1
- package/dist/context/context-assembler.js +23 -23
- package/dist/context/context-assembler.js.map +1 -1
- package/dist/coordinator/adaptive/adaptive-interpreter.d.ts +2 -1
- package/dist/coordinator/adaptive/adaptive-interpreter.d.ts.map +1 -1
- package/dist/coordinator/adaptive/adaptive-interpreter.js +46 -22
- package/dist/coordinator/adaptive/adaptive-interpreter.js.map +1 -1
- package/dist/coordinator/adaptive/compose-step-input.d.ts +1 -5
- package/dist/coordinator/adaptive/compose-step-input.d.ts.map +1 -1
- package/dist/coordinator/adaptive/compose-step-input.js +6 -17
- package/dist/coordinator/adaptive/compose-step-input.js.map +1 -1
- package/dist/coordinator/adaptive/index.d.ts +2 -2
- package/dist/coordinator/adaptive/index.d.ts.map +1 -1
- package/dist/coordinator/adaptive/index.js +2 -2
- package/dist/coordinator/adaptive/index.js.map +1 -1
- package/dist/coordinator/adaptive/llm-adaptive-controller.d.ts.map +1 -1
- package/dist/coordinator/adaptive/llm-adaptive-controller.js +14 -20
- package/dist/coordinator/adaptive/llm-adaptive-controller.js.map +1 -1
- package/dist/coordinator/adaptive/parse-plan.d.ts +0 -2
- package/dist/coordinator/adaptive/parse-plan.d.ts.map +1 -1
- package/dist/coordinator/adaptive/parse-plan.js +4 -6
- package/dist/coordinator/adaptive/parse-plan.js.map +1 -1
- package/dist/coordinator/dag/dag-plan-interpreter.d.ts.map +1 -1
- package/dist/coordinator/dag/dag-plan-interpreter.js +7 -1
- package/dist/coordinator/dag/dag-plan-interpreter.js.map +1 -1
- package/dist/coordinator/dag/llm-finalizer.d.ts.map +1 -1
- package/dist/coordinator/dag/llm-finalizer.js +5 -2
- package/dist/coordinator/dag/llm-finalizer.js.map +1 -1
- package/dist/coordinator/dialogue/dialogue-session.d.ts +2 -3
- package/dist/coordinator/dialogue/dialogue-session.d.ts.map +1 -1
- package/dist/coordinator/dialogue/dialogue-session.js +103 -64
- package/dist/coordinator/dialogue/dialogue-session.js.map +1 -1
- package/dist/coordinator/dialogue/index.d.ts +2 -2
- package/dist/coordinator/dialogue/index.d.ts.map +1 -1
- package/dist/coordinator/dialogue/index.js +2 -2
- package/dist/coordinator/dialogue/index.js.map +1 -1
- package/dist/coordinator/dialogue/planner-context-builder.d.ts +2 -3
- package/dist/coordinator/dialogue/planner-context-builder.d.ts.map +1 -1
- package/dist/coordinator/dialogue/planner-context-builder.js +13 -73
- package/dist/coordinator/dialogue/planner-context-builder.js.map +1 -1
- package/dist/coordinator/dialogue/planner-retrieval.d.ts.map +1 -1
- package/dist/coordinator/dialogue/planner-retrieval.js +13 -4
- package/dist/coordinator/dialogue/planner-retrieval.js.map +1 -1
- package/dist/coordinator/dialogue/planner-scope.d.ts +4 -1
- package/dist/coordinator/dialogue/planner-scope.d.ts.map +1 -1
- package/dist/coordinator/dialogue/planner-scope.js.map +1 -1
- package/dist/coordinator/dialogue/planner-tools-client.d.ts.map +1 -1
- package/dist/coordinator/dialogue/planner-tools-client.js +47 -26
- package/dist/coordinator/dialogue/planner-tools-client.js.map +1 -1
- package/dist/coordinator/dialogue/profile-plan-author.d.ts.map +1 -1
- package/dist/coordinator/dialogue/profile-plan-author.js +5 -5
- package/dist/coordinator/dialogue/profile-plan-author.js.map +1 -1
- package/dist/coordinator/dialogue/profile-resolver.d.ts.map +1 -1
- package/dist/coordinator/dialogue/profile-resolver.js +8 -0
- package/dist/coordinator/dialogue/profile-resolver.js.map +1 -1
- package/dist/coordinator/dialogue/structured-plan.d.ts +1 -1
- package/dist/coordinator/dialogue/structured-plan.d.ts.map +1 -1
- package/dist/coordinator/dialogue/structured-plan.js +6 -7
- package/dist/coordinator/dialogue/structured-plan.js.map +1 -1
- package/dist/coordinator/dialogue/submit-report-tool.d.ts +1 -1
- package/dist/coordinator/dialogue/submit-report-tool.d.ts.map +1 -1
- package/dist/coordinator/dialogue/submit-report-tool.js +4 -17
- package/dist/coordinator/dialogue/submit-report-tool.js.map +1 -1
- package/dist/coordinator/dialogue/task-board.d.ts +11 -3
- package/dist/coordinator/dialogue/task-board.d.ts.map +1 -1
- package/dist/coordinator/dialogue/task-board.js +42 -12
- package/dist/coordinator/dialogue/task-board.js.map +1 -1
- package/dist/coordinator/dialogue/task-reference.d.ts +1 -3
- package/dist/coordinator/dialogue/task-reference.d.ts.map +1 -1
- package/dist/coordinator/dialogue/task-reference.js +3 -10
- package/dist/coordinator/dialogue/task-reference.js.map +1 -1
- package/dist/coordinator/dialogue/tool-trace-render.d.ts.map +1 -1
- package/dist/coordinator/dialogue/tool-trace-render.js +9 -29
- package/dist/coordinator/dialogue/tool-trace-render.js.map +1 -1
- package/dist/coordinator/dispatch/self.d.ts.map +1 -1
- package/dist/coordinator/dispatch/self.js +41 -26
- package/dist/coordinator/dispatch/self.js.map +1 -1
- package/dist/coordinator/dispatch/subagent.d.ts.map +1 -1
- package/dist/coordinator/dispatch/subagent.js +3 -0
- package/dist/coordinator/dispatch/subagent.js.map +1 -1
- package/dist/coordinator/llm-output-truncation.d.ts +3 -0
- package/dist/coordinator/llm-output-truncation.d.ts.map +1 -0
- package/dist/coordinator/llm-output-truncation.js +6 -0
- package/dist/coordinator/llm-output-truncation.js.map +1 -0
- package/dist/coordinator/planning/one-shot.d.ts.map +1 -1
- package/dist/coordinator/planning/one-shot.js +4 -0
- package/dist/coordinator/planning/one-shot.js.map +1 -1
- package/dist/coordinator/planning/replan-on-error.d.ts.map +1 -1
- package/dist/coordinator/planning/replan-on-error.js +5 -1
- package/dist/coordinator/planning/replan-on-error.js.map +1 -1
- package/dist/coordinator/stepper/cyclic-react-executor.d.ts.map +1 -1
- package/dist/coordinator/stepper/cyclic-react-executor.js +51 -37
- package/dist/coordinator/stepper/cyclic-react-executor.js.map +1 -1
- package/dist/coordinator/stepper/llm-evaluator.d.ts.map +1 -1
- package/dist/coordinator/stepper/llm-evaluator.js +12 -4
- package/dist/coordinator/stepper/llm-evaluator.js.map +1 -1
- package/dist/coordinator/stepper/llm-stepper-planner.d.ts.map +1 -1
- package/dist/coordinator/stepper/llm-stepper-planner.js +16 -5
- package/dist/coordinator/stepper/llm-stepper-planner.js.map +1 -1
- package/dist/coordinator/stepper/llm-task-formalizer.d.ts +2 -3
- package/dist/coordinator/stepper/llm-task-formalizer.d.ts.map +1 -1
- package/dist/coordinator/stepper/llm-task-formalizer.js +14 -8
- package/dist/coordinator/stepper/llm-task-formalizer.js.map +1 -1
- package/dist/coordinator/stepper/need-resolver.d.ts.map +1 -1
- package/dist/coordinator/stepper/need-resolver.js +10 -1
- package/dist/coordinator/stepper/need-resolver.js.map +1 -1
- package/dist/coordinator/stepper/root-finalizer.d.ts.map +1 -1
- package/dist/coordinator/stepper/root-finalizer.js +8 -3
- package/dist/coordinator/stepper/root-finalizer.js.map +1 -1
- package/dist/coordinator/stepper/stepper-interpreter.d.ts.map +1 -1
- package/dist/coordinator/stepper/stepper-interpreter.js +8 -19
- package/dist/coordinator/stepper/stepper-interpreter.js.map +1 -1
- package/dist/history/history-memory.d.ts +1 -0
- package/dist/history/history-memory.d.ts.map +1 -1
- package/dist/history/history-memory.js +5 -1
- package/dist/history/history-memory.js.map +1 -1
- package/dist/history/history-summarizer.js +1 -1
- package/dist/history/history-summarizer.js.map +1 -1
- package/dist/index.d.ts +4 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -1
- package/dist/index.js.map +1 -1
- package/dist/interfaces/pipeline.d.ts +1 -1
- package/dist/interfaces/pipeline.d.ts.map +1 -1
- package/dist/pipeline/context/tool-loop-context/window-context-strategy.d.ts +1 -1
- package/dist/pipeline/context/tool-loop-context/window-context-strategy.d.ts.map +1 -1
- package/dist/pipeline/context/tool-loop-context/window-context-strategy.js +6 -3
- package/dist/pipeline/context/tool-loop-context/window-context-strategy.js.map +1 -1
- package/dist/pipeline/context/tool-loop-control-history.d.ts +15 -0
- package/dist/pipeline/context/tool-loop-control-history.d.ts.map +1 -0
- package/dist/pipeline/context/tool-loop-control-history.js +72 -0
- package/dist/pipeline/context/tool-loop-control-history.js.map +1 -0
- package/dist/pipeline/context.d.ts +5 -2
- package/dist/pipeline/context.d.ts.map +1 -1
- package/dist/pipeline/default-pipeline.d.ts +2 -2
- package/dist/pipeline/default-pipeline.d.ts.map +1 -1
- package/dist/pipeline/default-pipeline.js +7 -7
- package/dist/pipeline/default-pipeline.js.map +1 -1
- package/dist/pipeline/executor.d.ts.map +1 -1
- package/dist/pipeline/executor.js +6 -0
- package/dist/pipeline/executor.js.map +1 -1
- package/dist/pipeline/handlers/adaptive-coordinator.d.ts +1 -1
- package/dist/pipeline/handlers/adaptive-coordinator.d.ts.map +1 -1
- package/dist/pipeline/handlers/adaptive-coordinator.js +42 -46
- package/dist/pipeline/handlers/adaptive-coordinator.js.map +1 -1
- package/dist/pipeline/handlers/assemble.d.ts +0 -9
- package/dist/pipeline/handlers/assemble.d.ts.map +1 -1
- package/dist/pipeline/handlers/assemble.js +7 -11
- package/dist/pipeline/handlers/assemble.js.map +1 -1
- package/dist/pipeline/handlers/coordinator.d.ts +1 -0
- package/dist/pipeline/handlers/coordinator.d.ts.map +1 -1
- package/dist/pipeline/handlers/coordinator.js +39 -7
- package/dist/pipeline/handlers/coordinator.js.map +1 -1
- package/dist/pipeline/handlers/dag-coordinator.d.ts.map +1 -1
- package/dist/pipeline/handlers/dag-coordinator.js +17 -13
- package/dist/pipeline/handlers/dag-coordinator.js.map +1 -1
- package/dist/pipeline/handlers/history-upsert.d.ts +2 -0
- package/dist/pipeline/handlers/history-upsert.d.ts.map +1 -1
- package/dist/pipeline/handlers/history-upsert.js +6 -1
- package/dist/pipeline/handlers/history-upsert.js.map +1 -1
- package/dist/pipeline/handlers/pass-through.d.ts +5 -3
- package/dist/pipeline/handlers/pass-through.d.ts.map +1 -1
- package/dist/pipeline/handlers/pass-through.js +165 -91
- package/dist/pipeline/handlers/pass-through.js.map +1 -1
- package/dist/pipeline/handlers/subagent.d.ts.map +1 -1
- package/dist/pipeline/handlers/subagent.js +4 -1
- package/dist/pipeline/handlers/subagent.js.map +1 -1
- package/dist/pipeline/handlers/summarize.d.ts +2 -12
- package/dist/pipeline/handlers/summarize.d.ts.map +1 -1
- package/dist/pipeline/handlers/summarize.js +2 -54
- package/dist/pipeline/handlers/summarize.js.map +1 -1
- package/dist/pipeline/handlers/tool-loop-core.d.ts +15 -9
- package/dist/pipeline/handlers/tool-loop-core.d.ts.map +1 -1
- package/dist/pipeline/handlers/tool-loop-core.js +128 -59
- package/dist/pipeline/handlers/tool-loop-core.js.map +1 -1
- package/dist/pipeline/handlers/tool-loop.d.ts.map +1 -1
- package/dist/pipeline/handlers/tool-loop.js +120 -298
- package/dist/pipeline/handlers/tool-loop.js.map +1 -1
- package/dist/pipeline/handlers/tool-response-round.d.ts +48 -0
- package/dist/pipeline/handlers/tool-response-round.d.ts.map +1 -0
- package/dist/pipeline/handlers/tool-response-round.js +104 -0
- package/dist/pipeline/handlers/tool-response-round.js.map +1 -0
- package/dist/pipeline/handlers/tool-select.d.ts.map +1 -1
- package/dist/pipeline/handlers/tool-select.js +5 -1
- package/dist/pipeline/handlers/tool-select.js.map +1 -1
- package/dist/pipeline/pipeline-to-stream.d.ts.map +1 -1
- package/dist/pipeline/pipeline-to-stream.js +13 -6
- package/dist/pipeline/pipeline-to-stream.js.map +1 -1
- package/dist/policy/caller-identity.d.ts +29 -0
- package/dist/policy/caller-identity.d.ts.map +1 -0
- package/dist/policy/caller-identity.js +79 -0
- package/dist/policy/caller-identity.js.map +1 -0
- package/dist/policy/mixed-tool-call-handler.d.ts +9 -3
- package/dist/policy/mixed-tool-call-handler.d.ts.map +1 -1
- package/dist/policy/mixed-tool-call-handler.js +29 -7
- package/dist/policy/mixed-tool-call-handler.js.map +1 -1
- package/dist/policy/pending-tool-results-registry.d.ts +46 -4
- package/dist/policy/pending-tool-results-registry.d.ts.map +1 -1
- package/dist/policy/pending-tool-results-registry.js +203 -18
- package/dist/policy/pending-tool-results-registry.js.map +1 -1
- package/dist/policy/tool-availability-registry.d.ts +6 -5
- package/dist/policy/tool-availability-registry.d.ts.map +1 -1
- package/dist/policy/tool-availability-registry.js +13 -2
- package/dist/policy/tool-availability-registry.js.map +1 -1
- package/dist/resilience/retry-llm.d.ts +7 -5
- package/dist/resilience/retry-llm.d.ts.map +1 -1
- package/dist/resilience/retry-llm.js +93 -58
- package/dist/resilience/retry-llm.js.map +1 -1
- package/dist/subagent/default-context-builder.d.ts.map +1 -1
- package/dist/subagent/default-context-builder.js +9 -2
- package/dist/subagent/default-context-builder.js.map +1 -1
- package/dist/subagent/direct-llm-subagent.d.ts +1 -1
- package/dist/subagent/direct-llm-subagent.d.ts.map +1 -1
- package/dist/subagent/direct-llm-subagent.js +12 -3
- package/dist/subagent/direct-llm-subagent.js.map +1 -1
- package/dist/subagent/smart-agent-subagent.d.ts.map +1 -1
- package/dist/subagent/smart-agent-subagent.js +8 -5
- package/dist/subagent/smart-agent-subagent.js.map +1 -1
- package/package.json +2 -2
|
@@ -1,13 +1,16 @@
|
|
|
1
|
-
import { addCacheTokenUsage,
|
|
1
|
+
import { addCacheTokenUsage, toModelToolMessages, } from '@mcp-abap-adt/llm-agent';
|
|
2
2
|
import { normalizeLoopLimit } from '../../config/normalize-max-iterations.js';
|
|
3
3
|
import { withSubmitReport } from '../../coordinator/dialogue/submit-report-tool.js';
|
|
4
4
|
import { denyRagAccess, ownerBoundQuery } from '../../rag/owner-bound-query.js';
|
|
5
|
-
import {
|
|
5
|
+
import { ToolResponseRound } from './tool-response-round.js';
|
|
6
|
+
import { buildNamespacedTools, defaultToolNamespace, mergeOfferedTools, scopedUsage, toolNameFromRecord, toToolCallDelta, } from '@mcp-abap-adt/llm-agent';
|
|
6
7
|
import { OrchestratorError } from '../../agent.js';
|
|
8
|
+
import { resolveCallerIdentity } from '../../policy/caller-identity.js';
|
|
7
9
|
import { fireInternalToolsAsync } from '../../policy/mixed-tool-call-handler.js';
|
|
8
10
|
import { LegacyAccumulateContextStrategy } from '../context/tool-loop-context/index.js';
|
|
11
|
+
import { ToolLoopControlHistory } from '../context/tool-loop-control-history.js';
|
|
9
12
|
import { normalizeHeartbeatMs } from './normalize-heartbeat-ms.js';
|
|
10
|
-
import {
|
|
13
|
+
import { classifyToolCalls, executeToolBatchWithHeartbeat, filterAvailableTools, guardToolRound, injectPendingResults, injectToolPriority, pendingSourceMessages, readTaskFinish, runOutputValidationReprompt, } from './tool-loop-core.js';
|
|
11
14
|
import { wrapFinalResponse } from './wrap-final-response.js';
|
|
12
15
|
function summarizeIterationMessages(messages) {
|
|
13
16
|
const totalChars = messages.reduce((sum, msg) => {
|
|
@@ -71,6 +74,7 @@ function describeCause(error) {
|
|
|
71
74
|
}
|
|
72
75
|
export class ToolLoopHandler {
|
|
73
76
|
async execute(ctx, config, parentSpan) {
|
|
77
|
+
const identity = ctx.callerResolution ?? resolveCallerIdentity(ctx.options, ctx.sessionId);
|
|
74
78
|
const maxIterations = normalizeLoopLimit('maxIterations' in config
|
|
75
79
|
? config.maxIterations
|
|
76
80
|
: ctx.config.maxIterations, 'maxIterations');
|
|
@@ -103,29 +107,19 @@ export class ToolLoopHandler {
|
|
|
103
107
|
const timingLog = [];
|
|
104
108
|
const loopStart = Date.now();
|
|
105
109
|
let currentTools = ctx.activeTools;
|
|
110
|
+
const localBlocks = new Set();
|
|
106
111
|
messages = injectToolPriority(messages, externalTools);
|
|
107
112
|
// staticPrefix is immutable across all iterations — re-emitted every round.
|
|
108
|
-
const staticPrefix = messages;
|
|
113
|
+
const staticPrefix = await injectPendingResults(messages, ctx.pendingToolResults, identity, ctx.options, ctx.externalResults, ctx.textOrMessages);
|
|
109
114
|
const strategy = (ctx.toolLoopContextStrategyFactory ??
|
|
110
115
|
(() => new LegacyAccumulateContextStrategy()))({ run: undefined });
|
|
111
|
-
//
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
const withPending = await injectPendingResults(messages, ctx.pendingToolResults, ctx.sessionId, ctx.options);
|
|
115
|
-
if (withPending.length > staticPrefix.length) {
|
|
116
|
-
// Injected pending results form an assistant+tool group → record as round.
|
|
117
|
-
const injected = withPending.slice(staticPrefix.length);
|
|
118
|
-
const pendingRound = {
|
|
119
|
-
assistant: injected[0],
|
|
120
|
-
results: injected.slice(1),
|
|
121
|
-
};
|
|
122
|
-
await strategy.record(pendingRound);
|
|
123
|
-
}
|
|
124
|
-
messages = (await strategy.form({
|
|
116
|
+
// Preserve validation exchanges between their original tool rounds.
|
|
117
|
+
const controlHistory = new ToolLoopControlHistory(staticPrefix.length);
|
|
118
|
+
messages = controlHistory.restore(await strategy.form({
|
|
125
119
|
prefix: staticPrefix,
|
|
126
120
|
toolTrust: ctx.config.toolTrust,
|
|
127
121
|
queryText: ctx.inputText,
|
|
128
|
-
}))
|
|
122
|
+
}));
|
|
129
123
|
const finalize = (content, finishReason) => {
|
|
130
124
|
ctx.assistantText = content;
|
|
131
125
|
const summary = ctx.requestLogger.getSummary();
|
|
@@ -355,7 +349,7 @@ export class ToolLoopHandler {
|
|
|
355
349
|
}
|
|
356
350
|
currentTools = await withSubmitReport(currentTools, ctx.toolClientMap, ctx.options, externalTools);
|
|
357
351
|
// Filter tools per iteration
|
|
358
|
-
currentTools = filterAvailableTools(ctx.toolAvailabilityRegistry,
|
|
352
|
+
currentTools = filterAvailableTools(ctx.toolAvailabilityRegistry, identity, currentTools, iteration, ctx.options, localBlocks);
|
|
359
353
|
if (maxToolCalls !== undefined && toolCallCount >= maxToolCalls) {
|
|
360
354
|
currentTools = [];
|
|
361
355
|
ctx.yield({
|
|
@@ -408,7 +402,6 @@ export class ToolLoopHandler {
|
|
|
408
402
|
const toolCallsMap = new Map();
|
|
409
403
|
// Track which streaming indices belong to external tools so that
|
|
410
404
|
// argument-only continuation deltas (no name field) are forwarded too.
|
|
411
|
-
const externalToolIndices = new Set();
|
|
412
405
|
const available = ctx.mcpTools.length + externalTools.length;
|
|
413
406
|
if (currentTools.length !== lastToolsSelected ||
|
|
414
407
|
available !== lastToolsAvailable) {
|
|
@@ -462,10 +455,8 @@ export class ToolLoopHandler {
|
|
|
462
455
|
finishReason,
|
|
463
456
|
chunksSeen,
|
|
464
457
|
}, 'llm');
|
|
465
|
-
ctx.
|
|
466
|
-
|
|
467
|
-
error: new OrchestratorError(chunkResult.error.message, 'LLM_ERROR'),
|
|
468
|
-
});
|
|
458
|
+
ctx.error = chunkResult.error;
|
|
459
|
+
ctx.yield(chunkResult);
|
|
469
460
|
return false;
|
|
470
461
|
}
|
|
471
462
|
chunksSeen += 1;
|
|
@@ -479,7 +470,6 @@ export class ToolLoopHandler {
|
|
|
479
470
|
ctx.onPartial?.({ kind: 'iteration-end', outcome: 'retry' });
|
|
480
471
|
content = '';
|
|
481
472
|
toolCallsMap.clear();
|
|
482
|
-
externalToolIndices.clear();
|
|
483
473
|
finishReason = undefined;
|
|
484
474
|
iterPromptTokens = 0;
|
|
485
475
|
iterCompletionTokens = 0;
|
|
@@ -502,18 +492,7 @@ export class ToolLoopHandler {
|
|
|
502
492
|
}
|
|
503
493
|
}
|
|
504
494
|
if (chunk.toolCalls) {
|
|
505
|
-
//
|
|
506
|
-
// tool-call deltas are BUFFERED (accumulated into toolCallsMap) and
|
|
507
|
-
// NOT yielded live: an external call is surfaced only AFTER the stream
|
|
508
|
-
// settles — and only if it has no resume result (miss). This avoids
|
|
509
|
-
// leaking a call we may instead resolve from `ctx.externalResults`.
|
|
510
|
-
for (const tc of chunk.toolCalls) {
|
|
511
|
-
const name = getStreamToolCallName(tc);
|
|
512
|
-
if (name && externalToolNames.has(name)) {
|
|
513
|
-
const delta = toToolCallDelta(tc, 0);
|
|
514
|
-
externalToolIndices.add(delta.index);
|
|
515
|
-
}
|
|
516
|
-
}
|
|
495
|
+
// Buffer calls until the complete response can be classified atomically.
|
|
517
496
|
for (const [fallbackIndex, rawToolCall,] of chunk.toolCalls.entries()) {
|
|
518
497
|
const tc = toToolCallDelta(rawToolCall, fallbackIndex);
|
|
519
498
|
if (!toolCallsMap.has(tc.index)) {
|
|
@@ -576,21 +555,19 @@ export class ToolLoopHandler {
|
|
|
576
555
|
durationMs: llmCallDuration,
|
|
577
556
|
requestId: ctx.options?.trace?.traceId,
|
|
578
557
|
});
|
|
579
|
-
const
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
ctx.options?.sessionLogger?.logStep(`llm_response_iter_${iteration + 1}`, { content, toolCalls, finishReason }, 'llm');
|
|
590
|
-
const val = finishReason === 'tool_calls' && toolCalls.length > 0
|
|
558
|
+
const hasToolCalls = finishReason === 'tool_calls' && toolCallsMap.size > 0;
|
|
559
|
+
const responseRound = new ToolResponseRound(content, toolCallsMap.values(), (name) => externalToolNames.has(name) && !ctx.toolClientMap.has(name));
|
|
560
|
+
const toolCalls = hasToolCalls ? responseRound.executableCalls() : [];
|
|
561
|
+
ctx.options?.sessionLogger?.logStep(`llm_response_iter_${iteration + 1}`, { content, ...responseRound.diagnostics(toolCalls), finishReason }, 'llm');
|
|
562
|
+
if (finishReason === 'length') {
|
|
563
|
+
ctx.error = new OrchestratorError('LLM response was truncated at a token limit.', 'LLM_OUTPUT_TRUNCATED');
|
|
564
|
+
ctx.yield({ ok: false, error: ctx.error });
|
|
565
|
+
return false;
|
|
566
|
+
}
|
|
567
|
+
const val = hasToolCalls
|
|
591
568
|
? { reprompt: false, messages }
|
|
592
569
|
: await runOutputValidationReprompt(ctx.outputValidator, content, messages, currentTools, ctx.options, ctx.config.toolTrust);
|
|
593
|
-
const iterationEnd =
|
|
570
|
+
const iterationEnd = hasToolCalls
|
|
594
571
|
? 'tool_calls'
|
|
595
572
|
: val.reprompt
|
|
596
573
|
? 'retry'
|
|
@@ -607,262 +584,117 @@ export class ToolLoopHandler {
|
|
|
607
584
|
ctx.yield({ ok: true, value: { content: '', iterationEnd } });
|
|
608
585
|
ctx.onPartial?.({ kind: 'iteration-end', outcome: iterationEnd });
|
|
609
586
|
// -- No tool calls: validate and finish --------------------------------
|
|
610
|
-
if (
|
|
587
|
+
if (!hasToolCalls) {
|
|
611
588
|
if (val.reprompt) {
|
|
612
|
-
//
|
|
613
|
-
// into the strategy — they are ephemeral and survive only until the
|
|
614
|
-
// next recorded tool round, at which point controlTail is pruned.
|
|
589
|
+
// Anchor the rejected reply and correction before any newer tool rounds.
|
|
615
590
|
const appended = val.messages.slice(messages.length);
|
|
616
|
-
|
|
617
|
-
messages = (await strategy.form({
|
|
591
|
+
controlHistory.append(appended);
|
|
592
|
+
messages = controlHistory.restore(await strategy.form({
|
|
618
593
|
prefix: staticPrefix,
|
|
619
594
|
toolTrust: ctx.config.toolTrust,
|
|
620
595
|
queryText: ctx.inputText,
|
|
621
|
-
}))
|
|
596
|
+
}));
|
|
622
597
|
continue;
|
|
623
598
|
}
|
|
624
599
|
return finalize(content, finishReason);
|
|
625
600
|
}
|
|
626
601
|
// -- Classify tool calls -----------------------------------------------
|
|
627
602
|
const roundRejections = guardToolRound(toolCalls, ctx.options) ?? new Map();
|
|
628
|
-
const { internalCalls, validExternalCalls, blockedCalls, hallucinations, } = classifyToolCalls(toolCalls, ctx.toolClientMap, externalToolNames, ctx.toolAvailabilityRegistry,
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
const rejectedExternal = validExternalCalls.filter((tc) => roundRejections.has(toolCalls.indexOf(tc)));
|
|
632
|
-
if (rejectedExternal.length > 0) {
|
|
633
|
-
await strategy.record({
|
|
634
|
-
assistant: {
|
|
635
|
-
role: 'assistant',
|
|
636
|
-
content: content || null,
|
|
637
|
-
tool_calls: rejectedExternal.map((tc) => ({
|
|
638
|
-
id: tc.id,
|
|
639
|
-
type: 'function',
|
|
640
|
-
function: {
|
|
641
|
-
name: tc.name,
|
|
642
|
-
arguments: JSON.stringify(tc.arguments),
|
|
643
|
-
},
|
|
644
|
-
})),
|
|
645
|
-
},
|
|
646
|
-
results: rejectedExternal.map((tc) => ({
|
|
647
|
-
role: 'tool',
|
|
648
|
-
tool_call_id: tc.id,
|
|
649
|
-
content: `Error: ${roundRejections.get(toolCalls.indexOf(tc))}`,
|
|
650
|
-
})),
|
|
651
|
-
meta: rejectedExternal.map(() => ({ isError: true })),
|
|
652
|
-
});
|
|
653
|
-
for (const tc of rejectedExternal) {
|
|
654
|
-
validExternalCalls.splice(validExternalCalls.indexOf(tc), 1);
|
|
655
|
-
}
|
|
656
|
-
controlTail.length = 0;
|
|
657
|
-
messages = (await strategy.form({
|
|
658
|
-
prefix: staticPrefix,
|
|
659
|
-
toolTrust: ctx.config.toolTrust,
|
|
660
|
-
queryText: ctx.inputText,
|
|
661
|
-
})).concat(controlTail);
|
|
662
|
-
if (validExternalCalls.length === 0 &&
|
|
663
|
-
internalCalls.length === 0 &&
|
|
664
|
-
blockedCalls.length === 0 &&
|
|
665
|
-
hallucinations.length === 0)
|
|
666
|
-
continue;
|
|
603
|
+
const { internalCalls, validExternalCalls, blockedCalls, hallucinations, } = classifyToolCalls(toolCalls, ctx.toolClientMap, externalToolNames, ctx.toolAvailabilityRegistry, identity, localBlocks);
|
|
604
|
+
for (const tc of blockedCalls) {
|
|
605
|
+
responseRound.resolve(tc, `Error: Tool "${tc.name}" is temporarily unavailable in this session.`, true);
|
|
667
606
|
}
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
await strategy.record({
|
|
671
|
-
assistant: group.assistant,
|
|
672
|
-
results: group.results,
|
|
673
|
-
});
|
|
674
|
-
controlTail.length = 0;
|
|
675
|
-
messages = (await strategy.form({
|
|
676
|
-
prefix: staticPrefix,
|
|
677
|
-
toolTrust: ctx.config.toolTrust,
|
|
678
|
-
queryText: ctx.inputText,
|
|
679
|
-
})).concat(controlTail);
|
|
680
|
-
continue;
|
|
607
|
+
for (const tc of hallucinations) {
|
|
608
|
+
responseRound.resolve(tc, `Error: Tool "${tc.name}" not found.`, true);
|
|
681
609
|
}
|
|
610
|
+
const externalCalls = validExternalCalls.filter((tc) => {
|
|
611
|
+
const rejection = roundRejections.get(toolCalls.indexOf(tc));
|
|
612
|
+
if (rejection === undefined)
|
|
613
|
+
return true;
|
|
614
|
+
responseRound.resolve(tc, `Error: ${rejection}`, true);
|
|
615
|
+
return false;
|
|
616
|
+
});
|
|
682
617
|
// Check tool call budget
|
|
683
618
|
const remaining = maxToolCalls !== undefined
|
|
684
619
|
? maxToolCalls - toolCallCount
|
|
685
620
|
: internalCalls.length;
|
|
686
621
|
const batch = internalCalls.slice(0, Math.max(0, remaining));
|
|
687
622
|
const skipped = internalCalls.slice(batch.length);
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
},
|
|
704
|
-
results: unknownCalls.map((tc) => ({
|
|
705
|
-
role: 'tool',
|
|
706
|
-
tool_call_id: tc.id,
|
|
707
|
-
content: `Error: Tool "${tc.name}" not found.`,
|
|
708
|
-
})),
|
|
709
|
-
meta: unknownCalls.map(() => ({ isError: true })),
|
|
623
|
+
if (externalCalls.length > 0) {
|
|
624
|
+
const pending = fireInternalToolsAsync(content, batch, ctx.pendingToolResults, identity, {
|
|
625
|
+
toolClientMap: ctx.toolClientMap,
|
|
626
|
+
toolCache: ctx.toolCache,
|
|
627
|
+
metrics: ctx.metrics,
|
|
628
|
+
options: ctx.options,
|
|
629
|
+
roundCalls: toolCalls,
|
|
630
|
+
roundRejections,
|
|
631
|
+
skippedCalls: skipped,
|
|
632
|
+
maxToolCalls: maxToolCalls,
|
|
633
|
+
assistantMessage: responseRound.assistant,
|
|
634
|
+
resolvedResults: responseRound.resolved(),
|
|
635
|
+
precedingMessages: messages,
|
|
636
|
+
sourceMessages: pendingSourceMessages(ctx.textOrMessages, staticPrefix, messages),
|
|
637
|
+
externalCalls,
|
|
710
638
|
});
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
queryText: ctx.inputText,
|
|
716
|
-
})).concat(controlTail);
|
|
717
|
-
}
|
|
718
|
-
// -- Handle external (client-provided) tool calls (spec D1) ------------
|
|
719
|
-
// Each external call is rewritten to a deterministic content-addressed id
|
|
720
|
-
// (`externalToolCallId`). Two paths:
|
|
721
|
-
// HIT — `ctx.externalResults` already has the result (stateless resume
|
|
722
|
-
// from the client's prior round-trip): inject a MATCHED
|
|
723
|
-
// assistant(tool_calls=[extId]) -> tool(tool_call_id=extId) pair
|
|
724
|
-
// and CONTINUE the loop (no re-surface).
|
|
725
|
-
// MISS — no result yet: surface the call (with extId) to the consumer
|
|
726
|
-
// and END the worker turn (`finish_reason: tool_calls`); never
|
|
727
|
-
// execute it server-side.
|
|
728
|
-
if (validExternalCalls.length > 0) {
|
|
729
|
-
const externalWithId = validExternalCalls.map((tc) => ({
|
|
730
|
-
...tc,
|
|
731
|
-
extId: externalToolCallId(tc.name, tc.arguments),
|
|
732
|
-
}));
|
|
733
|
-
const hits = externalWithId.filter((tc) => ctx.externalResults?.has(tc.extId));
|
|
734
|
-
const misses = externalWithId.filter((tc) => !ctx.externalResults?.has(tc.extId));
|
|
735
|
-
// HIT path: inject matched pairs (assistant tool_call + tool result),
|
|
736
|
-
// each correlated by the SAME extId, and resolve them in-conversation.
|
|
737
|
-
if (hits.length > 0) {
|
|
738
|
-
markExternalTraceUnavailable(ctx.options?.onToolTrace);
|
|
739
|
-
const hitAssistant = {
|
|
740
|
-
role: 'assistant',
|
|
741
|
-
content: null,
|
|
742
|
-
tool_calls: hits.map((tc) => ({
|
|
743
|
-
id: tc.extId,
|
|
744
|
-
type: 'function',
|
|
745
|
-
function: {
|
|
746
|
-
name: tc.name,
|
|
747
|
-
arguments: JSON.stringify(tc.arguments),
|
|
748
|
-
},
|
|
749
|
-
})),
|
|
750
|
-
};
|
|
751
|
-
const hitResults = hits.map((tc) => ({
|
|
752
|
-
role: 'tool',
|
|
753
|
-
content: ctx.externalResults?.get(tc.extId) ?? '',
|
|
754
|
-
tool_call_id: tc.extId,
|
|
755
|
-
}));
|
|
756
|
-
await strategy.record({
|
|
757
|
-
assistant: hitAssistant,
|
|
758
|
-
results: hitResults,
|
|
759
|
-
});
|
|
760
|
-
controlTail.length = 0;
|
|
761
|
-
messages = (await strategy.form({
|
|
762
|
-
prefix: staticPrefix,
|
|
763
|
-
toolTrust: ctx.config.toolTrust,
|
|
764
|
-
queryText: ctx.inputText,
|
|
765
|
-
})).concat(controlTail);
|
|
766
|
-
ctx.options?.sessionLogger?.logStep('external_results_resumed', {
|
|
767
|
-
extIds: hits.map((tc) => tc.extId),
|
|
768
|
-
toolNames: hits.map((tc) => tc.name),
|
|
769
|
-
});
|
|
770
|
-
}
|
|
771
|
-
// MISS path: surface the unresolved external call(s) and end the turn.
|
|
772
|
-
if (misses.length > 0) {
|
|
773
|
-
if (internalCalls.length > 0) {
|
|
774
|
-
fireInternalToolsAsync(content, batch, ctx.pendingToolResults, ctx.sessionId, {
|
|
775
|
-
toolClientMap: ctx.toolClientMap,
|
|
776
|
-
toolCache: ctx.toolCache,
|
|
777
|
-
metrics: ctx.metrics,
|
|
778
|
-
options: ctx.options,
|
|
779
|
-
roundCalls: toolCalls,
|
|
780
|
-
roundRejections,
|
|
781
|
-
skippedCalls: skipped,
|
|
782
|
-
maxToolCalls: maxToolCalls,
|
|
783
|
-
});
|
|
784
|
-
toolCallCount += batch.length;
|
|
785
|
-
if (batch.length > 0) {
|
|
786
|
-
try {
|
|
787
|
-
ctx.options?.onToolCallCount?.(toolCallCount, maxToolCalls);
|
|
788
|
-
}
|
|
789
|
-
catch {
|
|
790
|
-
/* Observers cannot affect execution. */
|
|
791
|
-
}
|
|
792
|
-
}
|
|
793
|
-
if (maxToolCalls !== undefined && toolCallCount >= maxToolCalls) {
|
|
794
|
-
ctx.yield({
|
|
795
|
-
ok: true,
|
|
796
|
-
value: {
|
|
797
|
-
content: '',
|
|
798
|
-
budgetExhausted: true,
|
|
799
|
-
toolCallCount,
|
|
800
|
-
maxToolCalls: maxToolCalls,
|
|
801
|
-
},
|
|
802
|
-
});
|
|
803
|
-
}
|
|
804
|
-
ctx.options?.sessionLogger?.logStep('mixed_tool_calls', {
|
|
805
|
-
internal: internalCalls.map((tc) => tc.name),
|
|
806
|
-
external: misses.map((tc) => tc.name),
|
|
807
|
-
});
|
|
639
|
+
toolCallCount += batch.length;
|
|
640
|
+
if (batch.length > 0) {
|
|
641
|
+
try {
|
|
642
|
+
ctx.options?.onToolCallCount?.(toolCallCount, maxToolCalls);
|
|
808
643
|
}
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
value: {
|
|
815
|
-
content: '',
|
|
816
|
-
toolCalls: misses.map((tc, index) => ({
|
|
817
|
-
index,
|
|
818
|
-
id: tc.extId,
|
|
819
|
-
name: tc.name,
|
|
820
|
-
arguments: JSON.stringify(tc.arguments),
|
|
821
|
-
})),
|
|
822
|
-
},
|
|
823
|
-
});
|
|
824
|
-
timingLog.push({ phase: 'total', duration: Date.now() - loopStart });
|
|
825
|
-
ctx.timing.push(...timingLog);
|
|
644
|
+
catch {
|
|
645
|
+
/* Observers cannot affect execution. */
|
|
646
|
+
}
|
|
647
|
+
}
|
|
648
|
+
if (maxToolCalls !== undefined && toolCallCount >= maxToolCalls) {
|
|
826
649
|
ctx.yield({
|
|
827
650
|
ok: true,
|
|
828
651
|
value: {
|
|
829
652
|
content: '',
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
models: ctx.requestLogger.getSummary().byModel,
|
|
834
|
-
components: ctx.requestLogger.getSummary().byComponent,
|
|
835
|
-
},
|
|
836
|
-
timing: timingLog,
|
|
653
|
+
budgetExhausted: true,
|
|
654
|
+
toolCallCount,
|
|
655
|
+
maxToolCalls: maxToolCalls,
|
|
837
656
|
},
|
|
838
657
|
});
|
|
839
|
-
return true;
|
|
840
|
-
}
|
|
841
|
-
// Only hits (no misses): if there are no internal calls to execute,
|
|
842
|
-
// continue the loop directly so the worker consumes the injected
|
|
843
|
-
// results. With internal calls present, fall through to execute them.
|
|
844
|
-
if (internalCalls.length === 0) {
|
|
845
|
-
continue;
|
|
846
658
|
}
|
|
659
|
+
ctx.options?.sessionLogger?.logStep('mixed_tool_calls', {
|
|
660
|
+
internal: internalCalls.map((tc) => tc.name),
|
|
661
|
+
external: externalCalls.map((tc) => tc.name),
|
|
662
|
+
});
|
|
663
|
+
// Return this suspension's unique IDs; keep model IDs internal.
|
|
664
|
+
emitProgressFallback();
|
|
665
|
+
ctx.yield({
|
|
666
|
+
ok: true,
|
|
667
|
+
value: {
|
|
668
|
+
content: '',
|
|
669
|
+
toolCalls: externalCalls.map((tc, index) => ({
|
|
670
|
+
index,
|
|
671
|
+
id: pending.externalCalls[index].returnedId,
|
|
672
|
+
name: tc.name,
|
|
673
|
+
arguments: JSON.stringify(tc.arguments),
|
|
674
|
+
})),
|
|
675
|
+
},
|
|
676
|
+
});
|
|
677
|
+
timingLog.push({ phase: 'total', duration: Date.now() - loopStart });
|
|
678
|
+
ctx.timing.push(...timingLog);
|
|
679
|
+
ctx.yield({
|
|
680
|
+
ok: true,
|
|
681
|
+
value: {
|
|
682
|
+
content: '',
|
|
683
|
+
finishReason: 'tool_calls',
|
|
684
|
+
usage: {
|
|
685
|
+
...usage,
|
|
686
|
+
models: ctx.requestLogger.getSummary().byModel,
|
|
687
|
+
components: ctx.requestLogger.getSummary().byComponent,
|
|
688
|
+
},
|
|
689
|
+
timing: timingLog,
|
|
690
|
+
},
|
|
691
|
+
});
|
|
692
|
+
return true;
|
|
847
693
|
}
|
|
848
694
|
// -- Execute internal MCP tool calls -----------------------------------
|
|
849
695
|
// Capture the assistant message now; record the full round (assistant +
|
|
850
696
|
// tool results) atomically after the batch completes so the strategy
|
|
851
697
|
// always sees a complete ToolRound.
|
|
852
|
-
const batchAssistantMsg = {
|
|
853
|
-
role: 'assistant',
|
|
854
|
-
content: content || null,
|
|
855
|
-
tool_calls: toolCalls
|
|
856
|
-
.filter((tc) => internalCalls.includes(tc) || hallucinations.includes(tc))
|
|
857
|
-
.map((tc) => ({
|
|
858
|
-
id: tc.id,
|
|
859
|
-
type: 'function',
|
|
860
|
-
function: {
|
|
861
|
-
name: tc.name,
|
|
862
|
-
arguments: JSON.stringify(tc.arguments),
|
|
863
|
-
},
|
|
864
|
-
})),
|
|
865
|
-
};
|
|
866
698
|
// Yield progress messages
|
|
867
699
|
for (const tc of batch) {
|
|
868
700
|
ctx.yield({
|
|
@@ -875,6 +707,8 @@ export class ToolLoopHandler {
|
|
|
875
707
|
}
|
|
876
708
|
// Execute tool calls concurrently with heartbeat (shared core).
|
|
877
709
|
const batchGen = executeToolBatchWithHeartbeat({
|
|
710
|
+
callerResolution: identity,
|
|
711
|
+
localBlocks,
|
|
878
712
|
batch,
|
|
879
713
|
roundCalls: toolCalls,
|
|
880
714
|
roundRejections,
|
|
@@ -891,6 +725,16 @@ export class ToolLoopHandler {
|
|
|
891
725
|
timingLog,
|
|
892
726
|
heartbeatMs,
|
|
893
727
|
options: ctx.options,
|
|
728
|
+
onBatchComplete: async (outcome) => {
|
|
729
|
+
outcome.toolMessages.forEach((message, index) => {
|
|
730
|
+
responseRound.add(message, outcome.resultMeta[index]);
|
|
731
|
+
});
|
|
732
|
+
for (const tc of skipped) {
|
|
733
|
+
responseRound.resolve(tc, `Error: not executed: tool-call budget of ${maxToolCalls} for this request is exhausted; return what you have and report what is missing`, true);
|
|
734
|
+
}
|
|
735
|
+
const batchRound = responseRound.finish();
|
|
736
|
+
await strategy.record(controlHistory.record(batchRound));
|
|
737
|
+
},
|
|
894
738
|
mcpFailureClassifier: ctx.mcpFailureClassifier,
|
|
895
739
|
maxToolCalls,
|
|
896
740
|
onToolExecuted: (r) => {
|
|
@@ -956,33 +800,11 @@ export class ToolLoopHandler {
|
|
|
956
800
|
},
|
|
957
801
|
});
|
|
958
802
|
}
|
|
959
|
-
|
|
960
|
-
assistant: batchAssistantMsg,
|
|
961
|
-
results: [
|
|
962
|
-
...outcome.toolMessages,
|
|
963
|
-
...hallucinations.map((tc) => ({
|
|
964
|
-
role: 'tool',
|
|
965
|
-
tool_call_id: tc.id,
|
|
966
|
-
content: `Error: Tool "${tc.name}" not found.`,
|
|
967
|
-
})),
|
|
968
|
-
...skipped.map((tc) => ({
|
|
969
|
-
role: 'tool',
|
|
970
|
-
tool_call_id: tc.id,
|
|
971
|
-
content: `Error: not executed: tool-call budget of ${maxToolCalls} for this request is exhausted; return what you have and report what is missing`,
|
|
972
|
-
})),
|
|
973
|
-
],
|
|
974
|
-
meta: [
|
|
975
|
-
...outcome.resultMeta,
|
|
976
|
-
...[...hallucinations, ...skipped].map(() => ({ isError: true })),
|
|
977
|
-
],
|
|
978
|
-
};
|
|
979
|
-
await strategy.record(batchRound);
|
|
980
|
-
controlTail.length = 0;
|
|
981
|
-
messages = (await strategy.form({
|
|
803
|
+
messages = controlHistory.restore(await strategy.form({
|
|
982
804
|
prefix: staticPrefix,
|
|
983
805
|
toolTrust: ctx.config.toolTrust,
|
|
984
806
|
queryText: ctx.inputText,
|
|
985
|
-
}))
|
|
807
|
+
}));
|
|
986
808
|
}
|
|
987
809
|
}
|
|
988
810
|
}
|