mirror of
https://github.com/yuangyaa/openclaw.git
synced 2026-07-14 11:07:29 +08:00
feat: add configurable tool loop detection
This commit is contained in:
@@ -6,6 +6,7 @@ import {
|
||||
readTool,
|
||||
} from "@mariozechner/pi-coding-agent";
|
||||
import type { OpenClawConfig } from "../config/config.js";
|
||||
import type { ToolLoopDetectionConfig } from "../config/types.tools.js";
|
||||
import type { ModelAuthMode } from "./model-auth.js";
|
||||
import type { AnyAgentTool } from "./pi-tools.types.js";
|
||||
import type { SandboxContext } from "./sandbox.js";
|
||||
@@ -124,6 +125,33 @@ function resolveFsConfig(params: { cfg?: OpenClawConfig; agentId?: string }) {
|
||||
};
|
||||
}
|
||||
|
||||
export function resolveToolLoopDetectionConfig(params: {
|
||||
cfg?: OpenClawConfig;
|
||||
agentId?: string;
|
||||
}): ToolLoopDetectionConfig | undefined {
|
||||
const global = params.cfg?.tools?.loopDetection;
|
||||
const agent =
|
||||
params.agentId && params.cfg
|
||||
? resolveAgentConfig(params.cfg, params.agentId)?.tools?.loopDetection
|
||||
: undefined;
|
||||
|
||||
if (!agent) {
|
||||
return global;
|
||||
}
|
||||
if (!global) {
|
||||
return agent;
|
||||
}
|
||||
|
||||
return {
|
||||
...global,
|
||||
...agent,
|
||||
detectors: {
|
||||
...global.detectors,
|
||||
...agent.detectors,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
export const __testing = {
|
||||
cleanToolSchemaForGemini,
|
||||
normalizeToolParams,
|
||||
@@ -451,6 +479,7 @@ export function createOpenClawCodingTools(options?: {
|
||||
wrapToolWithBeforeToolCallHook(tool, {
|
||||
agentId,
|
||||
sessionKey: options?.sessionKey,
|
||||
loopDetection: resolveToolLoopDetectionConfig({ cfg: options?.config, agentId }),
|
||||
}),
|
||||
);
|
||||
const withAbort = options?.abortSignal
|
||||
|
||||
Reference in New Issue
Block a user