u-foo 3.1.7 → 4.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/OBSERVABILITY.md +65 -0
- package/README.md +238 -21
- package/README.zh-CN.md +165 -20
- package/SKILLS/ufoo/SKILL.md +40 -4
- package/SKILLS/ufoo-bus/SKILL.md +46 -3
- package/bin/uclaude.js +4 -0
- package/bin/ucodex.js +4 -0
- package/bin/ufoo.js +6 -4
- package/dist/tui/darwin-arm64/ufoo-tui +0 -0
- package/dist/tui/darwin-x64/ufoo-tui +0 -0
- package/dist/tui/linux-arm64/ufoo-tui +0 -0
- package/dist/tui/linux-x64/ufoo-tui +0 -0
- package/package.json +14 -7
- package/scripts/postinstall-skills.js +53 -0
- package/scripts/postinstall.js +11 -16
- package/scripts/smoke-native-messages.js +214 -0
- package/src/agents/activity/activityDetector.js +1 -1
- package/src/agents/activity/activityStateWriter.js +37 -38
- package/src/agents/capabilities/agentManagement/index.js +4 -0
- package/src/agents/capabilities/agentManagement/service.js +140 -0
- package/src/agents/capabilities/agentRouting/index.js +4 -0
- package/src/agents/capabilities/coding/index.js +32 -0
- package/src/agents/capabilities/coordination/index.js +37 -0
- package/src/agents/capabilities/globalRouting/index.js +5 -0
- package/src/agents/capabilities/groups/index.js +3 -0
- package/src/agents/capabilities/index.js +25 -0
- package/src/agents/capabilities/planning/index.js +123 -0
- package/src/agents/capabilities/planning/main.js +28 -0
- package/src/agents/capabilities/projectDiscovery/index.js +3 -0
- package/src/agents/capabilities/scheduling/index.js +3 -0
- package/src/agents/capabilities/sharedMemory/index.js +4 -0
- package/src/agents/capabilities/skills/index.js +12 -0
- package/src/agents/capabilities/taskExecution/index.js +3 -0
- package/src/agents/capabilities/taskReports/index.js +6 -0
- package/src/agents/controller/controllerToolExecutor.js +40 -22
- package/src/agents/controller/index.js +1 -6
- package/src/agents/internal/internalRunner.js +181 -76
- package/src/agents/launch/index.js +0 -1
- package/src/agents/launch/launcher.js +96 -14
- package/src/agents/launch/nativeCapabilities.js +40 -0
- package/src/agents/launch/nativeMessages.js +362 -0
- package/src/agents/launch/notifier.js +15 -20
- package/src/agents/launch/readyDetector.js +28 -14
- package/src/agents/profiles/coding.js +6 -0
- package/src/agents/profiles/globalRouter.js +2 -0
- package/src/agents/profiles/main.js +5 -0
- package/src/agents/prompts/cooperation.js +14 -0
- package/src/agents/prompts/defaultBootstrap.js +1 -1
- package/src/agents/prompts/groupBootstrap.js +32 -6
- package/src/agents/prompts/mainAgent.js +48 -0
- package/src/agents/prompts/native/system.js +4 -1
- package/src/agents/prompts/native/tasks.js +2 -2
- package/src/agents/prompts/native/ufoo.js +14 -3
- package/src/agents/prompts/promptProfiles.js +2 -0
- package/src/agents/prompts/reporting.js +16 -0
- package/src/agents/providers/claudeEventTranslator.js +9 -1
- package/src/agents/providers/claudeThreadProvider.js +47 -4
- package/src/agents/providers/clientIdentity.js +75 -0
- package/src/agents/providers/codexEventTranslator.js +68 -7
- package/src/agents/providers/codexThreadProvider.js +18 -8
- package/src/agents/providers/credentials/claude.js +10 -3
- package/src/agents/providers/credentials/index.js +2 -0
- package/src/agents/providers/directAuthStatus.js +1 -1
- package/src/agents/providers/index.js +1 -1
- package/src/agents/providers/modelSettings.js +34 -0
- package/src/agents/providers/modelsCatalog.js +379 -0
- package/src/agents/providers/nativeTransport.js +1146 -0
- package/src/agents/providers/runtimeConfig.js +188 -0
- package/src/agents/providers/thinkingLevels.js +106 -0
- package/src/agents/providers/transports/anthropicMessagesTransport.js +121 -0
- package/src/agents/providers/transports/index.js +10 -0
- package/src/agents/providers/transports/openaiChatTransport.js +117 -0
- package/src/agents/providers/transports/openaiResponsesTransport.js +120 -0
- package/src/agents/providers/transports/responsesProtocol.js +504 -0
- package/src/agents/providers/transports/systemBlocks.js +16 -0
- package/src/agents/providers/transports/transportContract.js +50 -0
- package/src/agents/providers/transports/visionBlocks.js +151 -0
- package/src/agents/providers/upstreamRuntime.js +135 -0
- package/src/agents/runtime/composeCapabilities.js +89 -0
- package/src/agents/runtime/context/checkpointStore.js +38 -0
- package/src/agents/runtime/context/commandStore.js +43 -0
- package/src/agents/runtime/context/compaction.js +151 -0
- package/src/agents/runtime/context/contextBudget.js +93 -0
- package/src/agents/runtime/context/contextWindow.js +119 -0
- package/src/agents/runtime/context/fileLock.js +36 -0
- package/src/agents/runtime/context/replayHistory.js +28 -0
- package/src/agents/runtime/context/runtimeStore.js +127 -0
- package/src/agents/runtime/context/sessionJournal.js +360 -0
- package/src/agents/runtime/context/sessionStore.js +57 -0
- package/src/agents/runtime/core/agentLoop.js +351 -0
- package/src/agents/runtime/core/executionBudget.js +36 -0
- package/src/agents/runtime/core/stableJson.js +29 -0
- package/src/agents/runtime/core/toolLoopGuard.js +55 -0
- package/src/agents/runtime/createAgentRuntime.js +259 -0
- package/src/agents/runtime/index.js +14 -0
- package/src/agents/runtime/prompts/responseLanguage.js +12 -0
- package/src/agents/runtime/protocol/faultHarness.js +90 -0
- package/src/agents/runtime/protocol/materialize.js +107 -0
- package/src/agents/runtime/protocol/runObservation.js +24 -0
- package/src/agents/runtime/protocol/toolCallLedger.js +221 -0
- package/src/agents/runtime/protocol/traceContext.js +9 -0
- package/src/agents/runtime/tasks/resourceLease.js +66 -0
- package/src/agents/runtime/tasks/scheduler.js +73 -0
- package/src/agents/runtime/tools/registry.js +57 -0
- package/src/app/chat/ChatController.js +29 -45
- package/src/app/chat/agentDirectory.js +9 -18
- package/src/app/chat/bootstrap.js +1 -2
- package/src/app/chat/commandExecutor.js +111 -313
- package/src/app/chat/commands.js +39 -45
- package/src/app/chat/daemonConnection.js +58 -5
- package/src/app/chat/daemonMessageRouter.js +61 -48
- package/src/app/chat/historyStore.js +12 -48
- package/src/app/chat/inputSubmitHandler.js +21 -35
- package/src/app/chat/internalAgentLogHistory.js +19 -60
- package/src/app/chat/launchRequestContext.js +42 -0
- package/src/app/chat/multiWindow/paneManager.js +91 -164
- package/src/app/chat/streamState.js +3 -7
- package/src/app/chat/transport.js +1 -1
- package/src/app/cli/busCoreCommands.js +9 -0
- package/src/app/cli/features/doctor.js +33 -0
- package/src/app/cli/features/init.js +5 -5
- package/src/app/cli/features/skills.js +16 -4
- package/src/app/cli/metricsCommands.js +68 -0
- package/src/app/cli/reportCoreCommands.js +37 -0
- package/src/app/cli/run.js +82 -42
- package/src/app/cli/traceCommands.js +36 -0
- package/src/code/agent.js +34 -17
- package/src/code/busConsumer.js +1 -3
- package/src/code/commands.js +1 -1
- package/src/code/context/artifacts.js +12 -11
- package/src/code/context/assembler.js +9 -9
- package/src/code/context/promptLayers.js +1 -13
- package/src/code/context/stableJson.js +2 -27
- package/src/code/context/stateCommit.js +2 -1
- package/src/code/contextWindow.js +2 -117
- package/src/code/conversation/sessionJournal.js +3 -349
- package/src/code/internalThread.js +107 -0
- package/src/code/launcher/ucode.js +1 -1
- package/src/code/launcher/ucodeBootstrap.js +1 -1
- package/src/code/modelCommand.js +11 -35
- package/src/code/nativeRunner.js +104 -2697
- package/src/code/protocol/faultHarness.js +2 -88
- package/src/code/protocol/materialize.js +2 -105
- package/src/code/protocol/toolCallLedger.js +5 -215
- package/src/code/providers/anthropicMessagesTransport.js +2 -118
- package/src/code/providers/modelsCatalog.js +1 -317
- package/src/code/providers/openaiChatTransport.js +2 -114
- package/src/code/providers/openaiResponsesTransport.js +2 -117
- package/src/code/providers/responsesProtocol.js +2 -497
- package/src/code/providers/transportContract.js +2 -48
- package/src/code/providers/visionBlocks.js +2 -149
- package/src/code/repl.js +2 -11
- package/src/code/sessionStore.js +27 -99
- package/src/code/taskDecomposer.js +18 -0
- package/src/code/thinkingLevels.js +1 -130
- package/src/code/toolBudget.js +1 -17
- package/src/code/toolLoopGuard.js +3 -49
- package/src/code/tools/artifactRead.js +1 -1
- package/src/code/tools/executor.js +373 -0
- package/src/code/tools/specs.js +312 -0
- package/src/config.js +95 -131
- package/src/coordination/bus/deliveryQueue.js +16 -2
- package/src/coordination/bus/index.js +14 -9
- package/src/coordination/bus/inject.js +15 -7
- package/src/coordination/bus/message.js +15 -1
- package/src/coordination/bus/nativeReceipts.js +100 -0
- package/src/coordination/bus/nickname.js +1 -1
- package/src/coordination/bus/queue.js +1 -3
- package/src/coordination/bus/subscriber.js +3 -2
- package/src/coordination/bus/utils.js +8 -4
- package/src/coordination/history/agentPerformance.js +279 -0
- package/src/coordination/history/agentSurface.js +142 -0
- package/src/coordination/history/agentTrace.js +249 -0
- package/src/coordination/memory/index.js +5 -21
- package/src/coordination/report/store.js +103 -83
- package/src/coordination/state/agentsStore.js +57 -3
- package/src/coordination/state/fileLock.js +2 -0
- package/src/coordination/state/workspaceAccess.js +36 -0
- package/src/orchestration/controller/index.js +1 -8
- package/src/orchestration/controller/launchRouting.js +1 -1
- package/src/orchestration/solo/commands.js +3 -1
- package/src/runtime/contracts/agentMode.js +26 -0
- package/src/runtime/contracts/eventContract.js +3 -0
- package/src/runtime/contracts/uiProtocol.js +20 -17
- package/src/runtime/daemon/agentHost.js +407 -0
- package/src/runtime/daemon/agentRecoveryGroups.js +70 -0
- package/src/runtime/daemon/busBridge.js +396 -0
- package/src/runtime/daemon/claudeChannel.js +159 -0
- package/src/runtime/daemon/controlPlaneService.js +28 -18
- package/src/runtime/daemon/cronOps.js +25 -17
- package/src/runtime/daemon/deliveryScheduler.js +32 -5
- package/src/runtime/daemon/globalDaemon.js +28 -1
- package/src/runtime/daemon/groupOrchestrator.js +21 -5
- package/src/runtime/daemon/groupStatus.js +20 -0
- package/src/runtime/daemon/index.js +120 -375
- package/src/runtime/daemon/ipcServer.js +32 -10
- package/src/runtime/daemon/mcpConfigure.js +113 -20
- package/src/runtime/daemon/mcpHttpServer.js +27 -5
- package/src/runtime/daemon/mcpServer.js +8 -5
- package/src/runtime/daemon/mcpStdioProxy.js +127 -10
- package/src/runtime/daemon/nicknameScope.js +1 -1
- package/src/runtime/daemon/ops.js +68 -40
- package/src/runtime/daemon/projectRuntimeGateway.js +2 -0
- package/src/runtime/daemon/promptRequest.js +92 -570
- package/src/runtime/daemon/providerSessions.js +67 -33
- package/src/runtime/daemon/reportControlBus.js +59 -25
- package/src/runtime/daemon/status.js +9 -6
- package/src/runtime/privacy/redactor.js +2 -2
- package/src/runtime/projects/identity.js +2 -1
- package/src/runtime/projects/registry.js +98 -38
- package/src/tools/controllerSchemas.js +28 -0
- package/src/tools/handlers/dispatchMessage.js +5 -2
- package/src/tools/handlers/listAgents.js +3 -1
- package/src/tools/handlers/readBusSummary.js +3 -1
- package/src/tools/handlers/readProjectRegistry.js +29 -2
- package/src/tools/handlers/routeAgent.js +35 -0
- package/src/tools/handlers/tier2.js +4 -2
- package/src/tools/index.js +1 -0
- package/src/tools/registry.js +6 -0
- package/src/tools/schemaFixtures.js +42 -5
- package/src/tools/tier0/readAgentMetrics.js +14 -0
- package/src/tools/tier0/readAgentTrace.js +12 -0
- package/src/tools/tier1/routeAgent.js +2 -2
- package/src/tools/tier2/runtimeCoordination.js +38 -0
- package/src/tools/types.js +2 -0
- package/src/ui/agentPresentation.js +109 -0
- package/src/ui/agentSettingsController.js +107 -0
- package/src/ui/agentSurface.js +270 -0
- package/src/ui/dashboardBridge.js +1 -1
- package/src/ui/format/banner.js +9 -15
- package/src/ui/format/index.js +14 -10
- package/src/ui/format/loopSummary.js +50 -0
- package/src/ui/format/markdownRenderer.js +3 -4
- package/src/ui/format/startupBanner.js +50 -0
- package/src/ui/multiPaneBusMirror.js +29 -3
- package/src/ui/rustChatHost.js +316 -599
- package/src/ui/rustMultiSession.js +288 -73
- package/src/ui/rustUcodeHost.js +21 -88
- package/src/ui/settingsBridge.js +34 -14
- package/src/ui/toolMergeBridge.js +0 -4
- package/src/ui/uiHostServer.js +5 -8
- package/src/agents/controller/loopObservability.js +0 -200
- package/src/agents/controller/loopRuntime.js +0 -472
- package/src/agents/controller/ufooAgent.js +0 -829
- package/src/agents/launch/ptyRunner.js +0 -1135
- package/src/agents/providers/upstreamTransport.js +0 -689
- package/src/app/chat/agentBar.js +0 -135
- package/src/app/chat/agentEnter.js +0 -70
- package/src/app/chat/agentSockets.js +0 -225
- package/src/app/chat/dashboardView.js +0 -405
- package/src/app/chat/multiWindow/index.js +0 -310
- package/src/app/chat/multiWindow/paneLayout.js +0 -84
- package/src/app/chat/multiWindow/renderer.js +0 -420
- package/src/app/chat/multiWindow/virtualTerminal.js +0 -327
- package/src/app/chat/multiWindow/vtFrame.js +0 -93
- package/src/app/chat/rawKeyMap.js +0 -42
- package/src/app/chat/settingsController.js +0 -111
- package/src/orchestration/controller/flags.js +0 -167
- package/src/orchestration/controller/gateRouter.js +0 -211
- package/src/orchestration/controller/routerFastPath.js +0 -22
- package/src/orchestration/controller/routerFinalize.js +0 -222
- package/src/orchestration/controller/shadowGuard.js +0 -280
- package/src/runtime/daemon/promptLoop.js +0 -136
- package/src/runtime/privacy/shadowDiff.js +0 -174
- package/src/ui/multiWindowHandoff.js +0 -232
- package/src/ui/ptyHandoff.js +0 -23
|
@@ -0,0 +1,351 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const { randomUUID } = require("crypto");
|
|
4
|
+
const ledgerApi = require("../protocol/toolCallLedger");
|
|
5
|
+
const { materializeResolvedToolResults } = require("../protocol/materialize");
|
|
6
|
+
const { withFaultPoint } = require("../protocol/faultHarness");
|
|
7
|
+
const { ToolLoopGuard } = require("./toolLoopGuard");
|
|
8
|
+
const { buildContextMeter, contextTokensFromUsage } = require("../context/contextWindow");
|
|
9
|
+
const { isContextOverflow } = require("../context/compaction");
|
|
10
|
+
const { buildRunObservation, observationFingerprint } = require("../protocol/runObservation");
|
|
11
|
+
|
|
12
|
+
const clone = (value) => JSON.parse(JSON.stringify(value));
|
|
13
|
+
const count = (value) => Number.isFinite(Number(value)) && Number(value) > 0 ? Math.floor(Number(value)) : 0;
|
|
14
|
+
|
|
15
|
+
function createExecutionGuards({ signal = null, timeoutMs = 43200000 } = {}) {
|
|
16
|
+
const started = Date.now();
|
|
17
|
+
return { ensureActive() {
|
|
18
|
+
if (signal && signal.aborted) throw Object.assign(new Error("agent cancelled"), { code: "cancelled" });
|
|
19
|
+
if (Date.now() - started > timeoutMs) throw Object.assign(new Error(`agent timeout (${timeoutMs}ms)`), { code: "timeout" });
|
|
20
|
+
} };
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/** Shared model/tool loop. All business policies and tools are injected. */
|
|
24
|
+
async function runAgentLoop({
|
|
25
|
+
transport, tools, policies = [], workspaceRoot = process.cwd(),
|
|
26
|
+
prompt = "", systemPrompt = "", systemBlocks = null, historyMessages = [],
|
|
27
|
+
model = "", baseUrl = "", apiKey = "", provider = "", accountId = "", requestHeaders = {}, requestProfile = "",
|
|
28
|
+
thinkingLevel = "", requestKind = "unknown",
|
|
29
|
+
timeoutMs = 43200000, onStreamDelta = null, onThinkingDelta = null,
|
|
30
|
+
onPhase = null, onToolEvent = null, onArtifactPersisted = null, onContextUsage = null,
|
|
31
|
+
sessionId = "", signal = null, guards = null, executionState: initialState = null,
|
|
32
|
+
resume = false, toolBudget = {}, maxAutoContinues = 24,
|
|
33
|
+
sanitizeMessages = (messages) => messages, retireImages = () => {},
|
|
34
|
+
providerTurnGate = null, maxRounds = Infinity, onEvent = null,
|
|
35
|
+
projectId = "", agentId = "", taskId = "", taskRunId = "", attemptId = "", requestId = "",
|
|
36
|
+
traceId = "", parentTaskRunId = "", parentSessionId = "",
|
|
37
|
+
artifactNamespace = "ucode",
|
|
38
|
+
contextManager = null, historyOffset: restoredHistoryOffset = null,
|
|
39
|
+
} = {}) {
|
|
40
|
+
const requestModel = String(model || "").trim();
|
|
41
|
+
if (!requestModel) throw new Error("agent model is not configured");
|
|
42
|
+
if (!tools || typeof tools.execute !== "function") throw new Error("agent tool registry is required");
|
|
43
|
+
const requestUrl = transport.resolveUrl(baseUrl);
|
|
44
|
+
if (!requestUrl) throw new Error("agent baseUrl is not configured");
|
|
45
|
+
const signalGuards = createExecutionGuards({ signal, timeoutMs });
|
|
46
|
+
const activeGuards = guards ? { ensureActive() { signalGuards.ensureActive(); guards.ensureActive(); } } : signalGuards;
|
|
47
|
+
const messages = sanitizeMessages(clone(historyMessages));
|
|
48
|
+
const historyOffset = restoredHistoryOffset ?? (resume ? 0 : messages.filter(message => message.role !== "system").length);
|
|
49
|
+
if (!resume) transport.prepareMessages({ messages, systemPrompt, prompt });
|
|
50
|
+
const outputStart = messages.length;
|
|
51
|
+
const currentTurnItems = () => clone(messages.slice(outputStart)).filter((message) => (
|
|
52
|
+
String(message.role || "").toLowerCase() !== "user" || Array.isArray(message.content)
|
|
53
|
+
&& message.content.some((block) => ["tool_result", "image", "image_url"].includes(block.type))
|
|
54
|
+
));
|
|
55
|
+
let executionState = initialState;
|
|
56
|
+
for (const policy of policies) if (policy.initializeState) executionState = policy.initializeState(executionState);
|
|
57
|
+
if (!executionState || typeof executionState !== "object") executionState = {};
|
|
58
|
+
const loopGuard = new ToolLoopGuard({ tightTools: tools.tightTools() });
|
|
59
|
+
const usage = { turns: 0, input: 0, output: 0, cacheRead: 0, cacheCreation: 0, lastContextTokens: 0 };
|
|
60
|
+
let aggregated = "";
|
|
61
|
+
let streamed = false;
|
|
62
|
+
let toolCallsExecuted = 0;
|
|
63
|
+
let toolErrors = 0;
|
|
64
|
+
let emptyRetries = 0;
|
|
65
|
+
let activeLedger = null;
|
|
66
|
+
let lastLedger = null;
|
|
67
|
+
let autoContinues = 0;
|
|
68
|
+
let lastContinueKey = "";
|
|
69
|
+
let emptyContinues = 0;
|
|
70
|
+
let providerMessages = messages;
|
|
71
|
+
let isolatedPrefix = 0;
|
|
72
|
+
let turnId = "";
|
|
73
|
+
let lastContextEstimate = 0;
|
|
74
|
+
let forceCompaction = false;
|
|
75
|
+
let contextRetry = false;
|
|
76
|
+
const context = () => ({ executionState, messages, loopGuard, usage, toolCallsExecuted, toolErrors, turnId });
|
|
77
|
+
const event = async (type, data = {}) => {
|
|
78
|
+
if (onEvent) await onEvent({ type, time: new Date().toISOString(), projectId, agentId, sessionId, taskId, taskRunId, attemptId, requestId, turnId,
|
|
79
|
+
traceId: traceId || taskId || taskRunId, parentTaskRunId, parentSessionId, ...data });
|
|
80
|
+
};
|
|
81
|
+
const policyStop = async (hook, extra = {}) => {
|
|
82
|
+
for (const policy of policies) {
|
|
83
|
+
const stop = policy[hook] && await policy[hook]({ ...context(), ...extra });
|
|
84
|
+
if (stop) return typeof stop === "string" ? { stopReason: stop } : stop;
|
|
85
|
+
}
|
|
86
|
+
return null;
|
|
87
|
+
};
|
|
88
|
+
const sanitizeResult = (result) => policies.reduce((value, policy) => policy.sanitizeResult ? policy.sanitizeResult(value) : value, result);
|
|
89
|
+
const callId = (call) => String(call.source && call.source.id || "");
|
|
90
|
+
const resolve = (call, result) => ledgerApi.resolveCall(activeLedger, callId(call), { result: sanitizeResult(result), isError: !result || result.ok === false });
|
|
91
|
+
const mirror = () => {
|
|
92
|
+
if (providerMessages === messages) return;
|
|
93
|
+
messages.push(...clone(providerMessages.slice(isolatedPrefix)));
|
|
94
|
+
isolatedPrefix = providerMessages.length;
|
|
95
|
+
};
|
|
96
|
+
const finish = (extra = {}) => ({
|
|
97
|
+
text: aggregated, finalText: "", streamed, toolCallsExecuted, messages,
|
|
98
|
+
turnItems: currentTurnItems(), usage, executionState,
|
|
99
|
+
protocolLedger: lastLedger || ledgerApi.snapshotLedger(activeLedger), historyOffset, ...extra,
|
|
100
|
+
});
|
|
101
|
+
const flush = (calls) => {
|
|
102
|
+
const pendingById = Object.fromEntries(calls.map((call) => [callId(call), call]));
|
|
103
|
+
materializeResolvedToolResults(activeLedger, { transport, messages: providerMessages, pendingById });
|
|
104
|
+
mirror();
|
|
105
|
+
lastLedger = ledgerApi.snapshotLedger(activeLedger);
|
|
106
|
+
};
|
|
107
|
+
const pendingInteraction = () => {
|
|
108
|
+
for (const policy of policies) {
|
|
109
|
+
const pending = policy.pendingInteraction && policy.pendingInteraction(executionState);
|
|
110
|
+
if (pending) return pending;
|
|
111
|
+
}
|
|
112
|
+
return null;
|
|
113
|
+
};
|
|
114
|
+
const toolContext = (extra = {}) => ({ workspaceRoot, onToolEvent: typeof onToolEvent === "function" ? event => onToolEvent({ ...event,
|
|
115
|
+
...(event.origin ? { parentToolCallId: extra.toolCallId } : { toolCallId: extra.toolCallId }) }) : null, sessionId, onArtifactPersisted, executionState, signal,
|
|
116
|
+
projectId, agentId, taskId, taskRunId, attemptId, requestId, turnId, traceId: traceId || taskId || taskRunId, parentTaskRunId, parentSessionId, artifactNamespace, ...extra });
|
|
117
|
+
if (onEvent) await event("run.config", { configuration: buildRunObservation({ provider, model: requestModel,
|
|
118
|
+
transport: transport.name || transport.id || "", thinkingLevel, systemPrompt, systemBlocks, prompt,
|
|
119
|
+
tools: tools.toOpenAiTools(), resume, requestKind, engineFingerprint: LOOP_IMPLEMENTATION_FINGERPRINT }) });
|
|
120
|
+
if (resume) await withFaultPoint("before_provider_resume", () => {});
|
|
121
|
+
|
|
122
|
+
while (true) {
|
|
123
|
+
activeGuards.ensureActive();
|
|
124
|
+
const turnStop = await policyStop("beforeTurn");
|
|
125
|
+
if (turnStop) return finish(turnStop);
|
|
126
|
+
if (usage.turns >= maxRounds) return finish({ stopReason: "budget_exceeded" });
|
|
127
|
+
turnId = `turn_${randomUUID()}`;
|
|
128
|
+
providerMessages = messages;
|
|
129
|
+
for (const policy of policies) {
|
|
130
|
+
if (policy.prepareTurn) providerMessages = await policy.prepareTurn({ ...context(), providerMessages }) || providerMessages;
|
|
131
|
+
}
|
|
132
|
+
isolatedPrefix = providerMessages.length;
|
|
133
|
+
if (activeLedger) {
|
|
134
|
+
if (providerTurnGate) providerTurnGate(activeLedger);
|
|
135
|
+
else if (ledgerApi.listUnresolved(activeLedger).length || ledgerApi.listDeferred(activeLedger).length) {
|
|
136
|
+
throw new Error("unresolved tool calls before provider turn");
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
const action = loopGuard.nextAction();
|
|
140
|
+
if (action) await event(`loop.${action.kind === "stop" ? "stopped" : "warning"}`, { code: "repeated_tool_calls", repeatedSteps: loopGuard.count, toolNames: loopGuard.names });
|
|
141
|
+
if (action && action.kind === "stop") return finish({ error: action.message, stopReason: "repeated_tool_calls" });
|
|
142
|
+
if (action && action.kind === "warn") providerMessages.push({ role: "user", content: action.message });
|
|
143
|
+
mirror();
|
|
144
|
+
|
|
145
|
+
let maxOutputTokens;
|
|
146
|
+
if (contextManager) {
|
|
147
|
+
let prepared;
|
|
148
|
+
try { prepared = await contextManager.prepare({ messages: providerMessages, model: requestModel, systemPrompt, systemBlocks,
|
|
149
|
+
tools: tools.toOpenAiTools(), transport, signal, onPhase, onEvent: event,
|
|
150
|
+
lastUsage: usage.lastContextTokens, lastEstimate: lastContextEstimate,
|
|
151
|
+
force: forceCompaction,
|
|
152
|
+
request: { url: requestUrl, apiKey, provider, accountId, requestHeaders, requestProfile, sessionId } }); }
|
|
153
|
+
catch (error) {
|
|
154
|
+
// Preflight runs only after tool results are paired. Keep this complete
|
|
155
|
+
// transcript even when compression is cancelled or storage is broken.
|
|
156
|
+
return finish({ error: error.message, stopReason: error.code || "context_compression_failed" });
|
|
157
|
+
}
|
|
158
|
+
providerMessages = prepared.messages;
|
|
159
|
+
lastContextEstimate = prepared.estimatedTokens;
|
|
160
|
+
maxOutputTokens = prepared.maxOutputTokens;
|
|
161
|
+
forceCompaction = false;
|
|
162
|
+
}
|
|
163
|
+
// Only newly generated messages are mirrored into the full transcript.
|
|
164
|
+
isolatedPrefix = providerMessages.length;
|
|
165
|
+
|
|
166
|
+
try { activeGuards.ensureActive(); }
|
|
167
|
+
catch (error) { return finish({ error: error.message, stopReason: error.code || "runtime_error" }); }
|
|
168
|
+
const modelStarted = Date.now();
|
|
169
|
+
await event("model.started", { provider, model: requestModel, transport: transport.name || transport.id || "", estimatedInputTokens: lastContextEstimate });
|
|
170
|
+
const streamEvents = [];
|
|
171
|
+
let streamEventError = null;
|
|
172
|
+
let turnResult;
|
|
173
|
+
let turnError = null;
|
|
174
|
+
const outputBeforeTurn = aggregated.length;
|
|
175
|
+
try { turnResult = await transport.runTurn({
|
|
176
|
+
url: requestUrl, apiKey, model: requestModel, provider, accountId, requestHeaders, requestProfile, thinkingLevel,
|
|
177
|
+
systemPrompt, systemBlocks, messages: providerMessages, tools: tools.toOpenAiTools(),
|
|
178
|
+
...(maxOutputTokens ? { maxOutputTokens } : {}),
|
|
179
|
+
sessionId, signal, timeoutMs,
|
|
180
|
+
onPhase(phase) {
|
|
181
|
+
streamEvents.push(event("model.phase", { phase }).catch(error => { streamEventError ||= error; }));
|
|
182
|
+
onPhase?.(phase);
|
|
183
|
+
},
|
|
184
|
+
onThinkingDelta(delta) {
|
|
185
|
+
streamEvents.push(event("thinking.delta", { text: String(delta || "") }).catch(error => { streamEventError ||= error; }));
|
|
186
|
+
onThinkingDelta?.(delta);
|
|
187
|
+
},
|
|
188
|
+
onTextDelta(chunk) {
|
|
189
|
+
const text = String(chunk || "");
|
|
190
|
+
if (!text) return;
|
|
191
|
+
aggregated += text;
|
|
192
|
+
if (onEvent) {
|
|
193
|
+
streamed = true;
|
|
194
|
+
streamEvents.push(event("message.delta", { text }).catch((error) => { streamEventError = streamEventError || error; }));
|
|
195
|
+
}
|
|
196
|
+
if (typeof onStreamDelta === "function") { streamed = true; onStreamDelta(text); }
|
|
197
|
+
},
|
|
198
|
+
}); } catch (error) { turnError = error; } finally {
|
|
199
|
+
await Promise.all(streamEvents);
|
|
200
|
+
if (streamEventError) throw streamEventError;
|
|
201
|
+
}
|
|
202
|
+
if (turnError) {
|
|
203
|
+
await event("model.failed", { error: turnError.message, code: turnError.code || "provider_error", durationMs: Date.now() - modelStarted });
|
|
204
|
+
if (!contextManager || !isContextOverflow(turnError)) throw turnError;
|
|
205
|
+
if (contextRetry || aggregated.length !== outputBeforeTurn) return finish({ error: turnError.message, stopReason: "context_budget_exceeded" });
|
|
206
|
+
contextRetry = true;
|
|
207
|
+
forceCompaction = true;
|
|
208
|
+
await event("model.retry", { code: "context_overflow", retry: 1 });
|
|
209
|
+
continue;
|
|
210
|
+
}
|
|
211
|
+
contextRetry = false;
|
|
212
|
+
activeGuards.ensureActive();
|
|
213
|
+
retireImages(providerMessages);
|
|
214
|
+
if (providerMessages !== messages) retireImages(messages);
|
|
215
|
+
usage.turns += 1;
|
|
216
|
+
for (const key of ["input", "output", "cacheRead", "cacheCreation"]) usage[key] += count(turnResult && turnResult.usage && turnResult.usage[key]);
|
|
217
|
+
usage.lastContextTokens = contextTokensFromUsage(turnResult && turnResult.usage);
|
|
218
|
+
await event("model.completed", { usage: turnResult && turnResult.usage || {}, durationMs: Date.now() - modelStarted });
|
|
219
|
+
if (typeof onContextUsage === "function") {
|
|
220
|
+
try { onContextUsage(buildContextMeter({ usedTokens: usage.lastContextTokens, model: requestModel })); } catch { /* observer only */ }
|
|
221
|
+
}
|
|
222
|
+
const calls = transport.getToolCalls(turnResult);
|
|
223
|
+
if (!calls.length) {
|
|
224
|
+
loopGuard.reset();
|
|
225
|
+
const text = String(turnResult.text || "").trim();
|
|
226
|
+
if (!text && toolCallsExecuted > 0) {
|
|
227
|
+
if (emptyRetries >= 2) throw new Error("model returned an empty response after tool execution");
|
|
228
|
+
emptyRetries += 1;
|
|
229
|
+
await event("model.retry", { code: "empty_response", retry: emptyRetries });
|
|
230
|
+
providerMessages.push({ role: "user", content: "Continue the current task after the tool results. Call any remaining tools, or provide a concrete final answer to the user. Do not end the turn with an empty response." });
|
|
231
|
+
mirror();
|
|
232
|
+
continue;
|
|
233
|
+
}
|
|
234
|
+
emptyRetries = 0;
|
|
235
|
+
let legacy = null;
|
|
236
|
+
for (const policy of policies) if (policy.legacyCommand) { legacy = policy.legacyCommand(text); if (legacy) break; }
|
|
237
|
+
transport.appendFinalAssistantMessage({ messages: providerMessages, turnResult });
|
|
238
|
+
if (legacy) {
|
|
239
|
+
activeGuards.ensureActive();
|
|
240
|
+
const result = await tools.execute(legacy.tool, legacy.args, toolContext({ origin: legacy.origin }));
|
|
241
|
+
activeGuards.ensureActive();
|
|
242
|
+
if (result && result.executionState) executionState = result.executionState;
|
|
243
|
+
providerMessages.push({ role: "user", content: JSON.stringify({ type: legacy.resultType, ...sanitizeResult(result && result.status ? result : { status: "rejected", ok: false, error: `${legacy.tool} failed` }) }) });
|
|
244
|
+
mirror();
|
|
245
|
+
continue;
|
|
246
|
+
}
|
|
247
|
+
mirror();
|
|
248
|
+
if (!aggregated.trim() && text) aggregated = text;
|
|
249
|
+
let continuation = false;
|
|
250
|
+
if (autoContinues < maxAutoContinues) {
|
|
251
|
+
for (const policy of policies) {
|
|
252
|
+
const key = policy.continuationKey ? policy.continuationKey(context()) : "continuation";
|
|
253
|
+
if (emptyContinues >= 2 && key && key === lastContinueKey) continue;
|
|
254
|
+
if (policy.continueAfterFinal && policy.continueAfterFinal(context())) {
|
|
255
|
+
autoContinues += 1; emptyContinues += 1; lastContinueKey = key; continuation = true; break;
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
if (continuation) {
|
|
260
|
+
await event("model.retry", { code: "auto_continue", retry: autoContinues });
|
|
261
|
+
continue;
|
|
262
|
+
}
|
|
263
|
+
return finish({ finalText: text });
|
|
264
|
+
}
|
|
265
|
+
emptyContinues = 0;
|
|
266
|
+
emptyRetries = 0;
|
|
267
|
+
const pending = transport.prepareToolCalls({ messages: providerMessages, turnResult, toolCalls: calls });
|
|
268
|
+
if (!pending) { mirror(); return finish(); }
|
|
269
|
+
loopGuard.observe(pending);
|
|
270
|
+
activeLedger = ledgerApi.createToolCallLedger({ provider, sessionId, deferableTools: tools.deferableTools() });
|
|
271
|
+
for (const call of pending) {
|
|
272
|
+
if (!call.source) call.source = {};
|
|
273
|
+
if (!call.source.id) call.source.id = `call_${randomUUID()}`;
|
|
274
|
+
}
|
|
275
|
+
if (new Set(pending.map(callId)).size !== pending.length) {
|
|
276
|
+
throw Object.assign(new Error("duplicate tool call IDs in provider turn"), { code: "duplicate_tool_call_id" });
|
|
277
|
+
}
|
|
278
|
+
ledgerApi.declareCalls(activeLedger, pending.map((call) => ({ callId: callId(call), name: String(call.name || "").toLowerCase(), args: call.args })));
|
|
279
|
+
lastLedger = ledgerApi.snapshotLedger(activeLedger);
|
|
280
|
+
await withFaultPoint("after_prepare_tool_calls", () => {});
|
|
281
|
+
await withFaultPoint("before_tool_exec", () => {});
|
|
282
|
+
let batchError = null;
|
|
283
|
+
for (const policy of policies) if (policy.validateBatch) { batchError = policy.validateBatch(pending); if (batchError) break; }
|
|
284
|
+
if (batchError) {
|
|
285
|
+
for (const call of pending) {
|
|
286
|
+
await event("tool.rejected", { toolCallId: callId(call), toolName: call.name, code: batchError.code || "invalid_batch", argumentFingerprint: observationFingerprint(call.args) });
|
|
287
|
+
resolve(call, batchError); toolCallsExecuted += 1; toolErrors += 1;
|
|
288
|
+
}
|
|
289
|
+
flush(pending);
|
|
290
|
+
continue;
|
|
291
|
+
}
|
|
292
|
+
let deferred = null;
|
|
293
|
+
let toolStop = null;
|
|
294
|
+
for (const call of pending) {
|
|
295
|
+
const name = String(call.name || "").trim().toLowerCase();
|
|
296
|
+
const before = toolStop || await policyStop("beforeTool", { call });
|
|
297
|
+
if (before) {
|
|
298
|
+
toolStop = before;
|
|
299
|
+
await event("tool.rejected", { toolCallId: callId(call), toolName: name, code: before.stopReason || "stopped", argumentFingerprint: observationFingerprint(call.args) });
|
|
300
|
+
resolve(call, { ok: false, code: before.stopReason || "stopped", error: "execution stopped before tool invocation" });
|
|
301
|
+
continue;
|
|
302
|
+
}
|
|
303
|
+
let blocked = null;
|
|
304
|
+
for (const policy of policies) if (policy.validateTool) { blocked = policy.validateTool(name, executionState); if (blocked) break; }
|
|
305
|
+
if (blocked) {
|
|
306
|
+
await event("tool.rejected", { toolCallId: callId(call), toolName: name, code: blocked.code || "tool_not_allowed", argumentFingerprint: observationFingerprint(call.args) });
|
|
307
|
+
toolCallsExecuted += 1; toolErrors += 1; resolve(call, blocked); continue;
|
|
308
|
+
}
|
|
309
|
+
const resumeCall = tools.deferableTools().includes(name) ? { toolCallId: callId(call), toolName: name, call: { name: call.name, args: call.args, source: call.source } } : null;
|
|
310
|
+
ledgerApi.markExecuting(activeLedger, callId(call));
|
|
311
|
+
activeGuards.ensureActive();
|
|
312
|
+
await event("tool.started", { toolCallId: callId(call), toolName: name, args: call.args, argumentFingerprint: observationFingerprint(call.args) });
|
|
313
|
+
const toolStarted = Date.now();
|
|
314
|
+
let result;
|
|
315
|
+
try { result = await tools.execute(name, call.args, toolContext({ resume: resumeCall, toolCallId: callId(call) })); }
|
|
316
|
+
catch (error) {
|
|
317
|
+
await event("tool.failed", { toolCallId: callId(call), toolName: name, error: error.message, code: error.code || "tool_execution_failed",
|
|
318
|
+
outcome: "unknown", durationMs: Date.now() - toolStarted });
|
|
319
|
+
throw error;
|
|
320
|
+
}
|
|
321
|
+
activeGuards.ensureActive();
|
|
322
|
+
if (result && result.executionState) executionState = result.executionState;
|
|
323
|
+
toolCallsExecuted += 1;
|
|
324
|
+
if (!result || result.ok === false) toolErrors += 1;
|
|
325
|
+
if (resumeCall && result && result.deferToolResult) {
|
|
326
|
+
for (const policy of policies) if (policy.onDeferred) policy.onDeferred({ executionState, resume: resumeCall, provider });
|
|
327
|
+
ledgerApi.deferCall(activeLedger, callId(call), { reason: name });
|
|
328
|
+
deferred = { interactionId: result.interactionId || "" };
|
|
329
|
+
await event("interaction.requested", { toolCallId: callId(call), interactionId: deferred.interactionId });
|
|
330
|
+
continue;
|
|
331
|
+
}
|
|
332
|
+
resolve(call, result);
|
|
333
|
+
await event("tool.completed", { toolCallId: callId(call), toolName: name, result: sanitizeResult(result), durationMs: Date.now() - toolStarted });
|
|
334
|
+
toolStop = await policyStop("afterTool", { call, result });
|
|
335
|
+
if (toolStop) continue;
|
|
336
|
+
if (toolBudget.maxToolCalls != null && toolCallsExecuted >= toolBudget.maxToolCalls) throw new Error(`tool call budget exceeded (${toolBudget.maxToolCalls})`);
|
|
337
|
+
if (toolErrors >= (toolBudget.maxToolErrors ?? 20)) {
|
|
338
|
+
const detail = [call.name, result && result.error].filter(Boolean).join(": ");
|
|
339
|
+
throw new Error(`tool error budget exceeded (${toolBudget.maxToolErrors ?? 20})${detail ? `: ${detail}` : ""}`);
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
flush(pending);
|
|
343
|
+
if (toolStop) return finish(toolStop);
|
|
344
|
+
const interaction = pendingInteraction();
|
|
345
|
+
if (deferred || interaction) return finish({ waitingUserInteraction: true, interactionId: deferred && deferred.interactionId || interaction && interaction.id || "" });
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
const LOOP_IMPLEMENTATION_FINGERPRINT = observationFingerprint(runAgentLoop.toString());
|
|
350
|
+
|
|
351
|
+
module.exports = { runAgentLoop, createExecutionGuards };
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const DEFAULT_TASK_TIMEOUT_MS = 43200000;
|
|
4
|
+
const DEFAULT_MAX_TOOL_ERRORS = 20;
|
|
5
|
+
|
|
6
|
+
function parseMaxToolCalls(value) {
|
|
7
|
+
if (value == null || String(value).trim().toLowerCase() === "none") return null;
|
|
8
|
+
const text = String(value).trim();
|
|
9
|
+
const count = Number(text);
|
|
10
|
+
if (!/^\d+$/.test(text) || !Number.isSafeInteger(count) || count <= 0) {
|
|
11
|
+
throw new Error("max tool calls must be a positive integer or none");
|
|
12
|
+
}
|
|
13
|
+
return count;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
function resolveMaxToolCalls(value, env = process.env) {
|
|
17
|
+
if (value !== undefined) return parseMaxToolCalls(value);
|
|
18
|
+
const configured = env.UFOO_UCODE_MAX_TOOL_CALLS;
|
|
19
|
+
return configured == null || String(configured).trim() === "" ? null : parseMaxToolCalls(configured);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function resolveToolBudget(maxToolCalls, env = process.env) {
|
|
23
|
+
const errors = Number.parseInt(String(env.UFOO_UCODE_MAX_TOOL_ERRORS || ""), 10);
|
|
24
|
+
return {
|
|
25
|
+
maxToolCalls: resolveMaxToolCalls(maxToolCalls, env),
|
|
26
|
+
maxToolErrors: Number.isFinite(errors) && errors > 0 ? errors : DEFAULT_MAX_TOOL_ERRORS,
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function resolveTaskTimeoutMs(value, env = process.env) {
|
|
31
|
+
if (Number.isFinite(value) && value > 0) return Math.max(1000, Math.floor(value));
|
|
32
|
+
const configured = Number(env.UFOO_UCODE_TASK_TIMEOUT_MS);
|
|
33
|
+
return Number.isFinite(configured) && configured > 0 ? Math.max(1000, Math.floor(configured)) : DEFAULT_TASK_TIMEOUT_MS;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
module.exports = { DEFAULT_TASK_TIMEOUT_MS, DEFAULT_MAX_TOOL_ERRORS, parseMaxToolCalls, resolveMaxToolCalls, resolveToolBudget, resolveTaskTimeoutMs };
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
function stableValue(value) {
|
|
4
|
+
if (value === null || typeof value !== "object") return value;
|
|
5
|
+
if (Array.isArray(value)) return value.map((item) => stableValue(item));
|
|
6
|
+
const keys = Object.keys(value).sort();
|
|
7
|
+
const out = Object.create(null);
|
|
8
|
+
for (const key of keys) {
|
|
9
|
+
out[key] = stableValue(value[key]);
|
|
10
|
+
}
|
|
11
|
+
return out;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
function stableStringify(value) {
|
|
15
|
+
try {
|
|
16
|
+
return JSON.stringify(stableValue(value));
|
|
17
|
+
} catch {
|
|
18
|
+
try {
|
|
19
|
+
return JSON.stringify(value);
|
|
20
|
+
} catch {
|
|
21
|
+
return String(value || "");
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
module.exports = {
|
|
27
|
+
stableValue,
|
|
28
|
+
stableStringify,
|
|
29
|
+
};
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const { createHash } = require("crypto");
|
|
4
|
+
const { stableStringify } = require("./stableJson");
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
// One observation is a model step, including its complete parallel tool batch.
|
|
8
|
+
// Ignore call IDs, JSON key order, and parallel ordering when comparing steps.
|
|
9
|
+
class ToolLoopGuard {
|
|
10
|
+
constructor({ tightTools = [] } = {}) {
|
|
11
|
+
this.tightTools = new Set(tightTools);
|
|
12
|
+
this.reset();
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
reset() {
|
|
16
|
+
this.signature = "";
|
|
17
|
+
this.count = 0;
|
|
18
|
+
this.warned = false;
|
|
19
|
+
this.names = [];
|
|
20
|
+
this.tight = false;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
observe(calls) {
|
|
24
|
+
if (!calls.length) return this.reset();
|
|
25
|
+
const parts = calls.map((call) => stableStringify({ name: call.name, args: call.args }));
|
|
26
|
+
const signature = createHash("sha256").update(JSON.stringify(parts.sort())).digest("hex");
|
|
27
|
+
if (signature !== this.signature) this.reset();
|
|
28
|
+
this.signature = signature;
|
|
29
|
+
this.count += 1;
|
|
30
|
+
this.names = [...new Set(calls.map((call) => call.name))].sort();
|
|
31
|
+
this.tight = calls.every((call) => this.tightTools.has(call.name));
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
nextAction() {
|
|
35
|
+
const warnAt = this.tight ? 4 : 8;
|
|
36
|
+
const stopAt = this.tight ? 8 : 12;
|
|
37
|
+
const tools = this.names.join(", ");
|
|
38
|
+
if (this.count >= stopAt) {
|
|
39
|
+
return {
|
|
40
|
+
kind: "stop",
|
|
41
|
+
message: `Stopped repeated tool calls: ${tools} used identical arguments for ${this.count} consecutive model steps after a warning. Change the approach or provide new information to continue.`,
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
if (this.count >= warnAt && !this.warned) {
|
|
45
|
+
this.warned = true;
|
|
46
|
+
return {
|
|
47
|
+
kind: "warn",
|
|
48
|
+
message: `You have repeated the same tool batch (${tools}) with identical arguments for ${this.count} consecutive model steps. Stop repeating it and use a different approach. If waiting for a task, use its supported waiting mechanism instead of repeatedly checking. If blocked, explain the blocker to the user. This run will stop at ${stopAt} consecutive identical steps.`,
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
return null;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
module.exports = { ToolLoopGuard };
|