🤯 LobeHub - Super-Agents on Your Team. Add super-agents to the chats your team already uses.They take on work by themselves and get better every week.
TypeScript agentagent-collaborationagent-harnessloop-engineeringmcppersonal-assistantproactive-agentskillssuper-agenttask-management
🐛 fix: raise tool-call repeat limit from 5 to 20 (#18989)
Arvin Xu84f749e7dc06
diff --git a/packages/agent-runtime/src/executors/callLlmFinalizer.test.ts b/packages/agent-runtime/src/executors/callLlmFinalizer.test.tsindex 5c3b4a43f06..df927824e19 100644--- a/packages/agent-runtime/src/executors/callLlmFinalizer.test.ts+++ b/packages/agent-runtime/src/executors/callLlmFinalizer.test.ts@@ -7,6 +7,7 @@ import type {MessageTransport,StreamSink,} from '../transport';+import { TOOL_CALL_REPEAT_LIMIT } from '../utils/toolCallRepeatGuard';import {finalizeCallLlmTurn,persistInterruptedCallLlmResult,@@ -61,13 +62,14 @@ const createOutput = (overrides: Partial<LLMAttemptOutput> = {}): LLMAttemptOutp});describe('callLlmFinalizer', () => {- it('blocks the fifth consecutive identical tool call before it can execute', async () => {+ it('blocks the limit-th consecutive identical tool call before it can execute', async () => {const messages = createMessageTransport();const stream = createStreamSink();const state = AgentRuntime.createInitialState({ operationId: 'operation-1' });state.toolCallRepeatGuard = {counts: {- '["credentials","inject","{\\"keys\\":[\\"github\\"],\\"scope\\":\\"repo\\"}"]': 4,+ '["credentials","inject","{\\"keys\\":[\\"github\\"],\\"scope\\":\\"repo\\"}"]':+ TOOL_CALL_REPEAT_LIMIT - 1,},};const output = createOutput({@@ -108,7 +110,7 @@ describe('callLlmFinalizer', () => {payload: {hasToolsCalling: false,result: {- content: 'Stopped after the same tool call was requested 5 consecutive times.',+ content: `Stopped after the same tool call was requested ${TOOL_CALL_REPEAT_LIMIT} consecutive times.`,tool_calls: [],},toolsCalling: [],@@ -124,7 +126,7 @@ describe('callLlmFinalizer', () => {expect(messages.update).toHaveBeenCalledWith('assistant-5',expect.objectContaining({- content: 'Stopped after the same tool call was requested 5 consecutive times.',+ content: `Stopped after the same tool call was requested ${TOOL_CALL_REPEAT_LIMIT} consecutive times.`,tools: undefined,}),);@@ -136,11 +138,11 @@ describe('callLlmFinalizer', () => {);});- it('preserves user cancellation when an aborted stream emits the fifth repeated tool call', async () => {+ it('preserves user cancellation when an aborted stream emits the limit-th repeated tool call', async () => {const state = AgentRuntime.createInitialState({ operationId: 'operation-1' });state.toolCallRepeatGuard = {counts: {- '["credentials","inject","{\\"keys\\":[\\"github\\"]}"]': 4,+ '["credentials","inject","{\\"keys\\":[\\"github\\"]}"]': TOOL_CALL_REPEAT_LIMIT - 1,},};const toolCalling = {diff --git a/packages/agent-runtime/src/utils/toolCallRepeatGuard.test.ts b/packages/agent-runtime/src/utils/toolCallRepeatGuard.test.tsindex d339d6f355d..1bb566aaed7 100644--- a/packages/agent-runtime/src/utils/toolCallRepeatGuard.test.ts+++ b/packages/agent-runtime/src/utils/toolCallRepeatGuard.test.ts@@ -1,7 +1,11 @@import type { ChatToolPayload } from '@lobechat/types';import { describe, expect, it } from 'vitest';-import { hasRepeatedToolCall, updateToolCallRepeatGuard } from './toolCallRepeatGuard';+import {+ hasRepeatedToolCall,+ TOOL_CALL_REPEAT_LIMIT,+ updateToolCallRepeatGuard,+} from './toolCallRepeatGuard';const createToolCall = (argumentsValue: string): ChatToolPayload => ({apiName: 'inject',@@ -12,10 +16,10 @@ const createToolCall = (argumentsValue: string): ChatToolPayload => ({});describe('toolCallRepeatGuard', () => {- it('allows four consecutive calls and blocks the fifth with canonically equivalent arguments', () => {+ it('allows limit-1 consecutive calls and blocks the next with canonically equivalent arguments', () => {let guard: ReturnType<typeof updateToolCallRepeatGuard> | undefined;- for (let index = 0; index < 4; index++) {+ for (let index = 0; index < TOOL_CALL_REPEAT_LIMIT - 1; index++) {guard = updateToolCallRepeatGuard(guard, [createToolCall('{"keys":["github"],"scope":"repo"}'),]);diff --git a/packages/agent-runtime/src/utils/toolCallRepeatGuard.ts b/packages/agent-runtime/src/utils/toolCallRepeatGuard.tsindex 18c901aaebf..c7bfe60e24b 100644--- a/packages/agent-runtime/src/utils/toolCallRepeatGuard.ts+++ b/packages/agent-runtime/src/utils/toolCallRepeatGuard.ts@@ -2,7 +2,13 @@ import type { ChatToolPayload } from '@lobechat/types';import type { AgentState } from '../types';-export const TOOL_CALL_REPEAT_LIMIT = 5;+/**+ * Consecutive identical calls allowed before the turn is stopped. High enough+ * that legitimate fixed-argument polling loops (e.g. an MCP job-status check+ * repeated until the job finishes) don't get cut off, while a model stuck+ * replaying the same call forever is still caught.+ */+export const TOOL_CALL_REPEAT_LIMIT = 20;const canonicalize = (value: unknown): unknown => {if (Array.isArray(value)) return value.map(canonicalize);