chore(backend): 放宽递归与循环检测阈值

- build_run_config recursion_limit 100 -> 250
- LoopDetectionMiddleware 默认阈值放宽(warn/hard/window/tool-freq)

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
吉鑫升andClaude Opus 4.8 committed 2026-06-23 17:48:23 +08:00
1 parent 23d170cde1
commit 5aa66fc07d
2 files changed
+11 -11

No files matched your search

@@ -314,7 +314,7 @@ def build_run_config(
the LangGraph Platform-compatible HTTP API and the IM channel path behave
identically.
"""
config: dict[str, Any] = {"recursion_limit": 100}
config: dict[str, Any] = {"recursion_limit": 250}
if request_config:
# LangGraph >= 0.6.0 introduced ``context`` as the preferred way to
# pass thread-level data and rejects requests that include both
@@ -28,12 +28,12 @@ from langgraph.runtime import Runtime
logger = logging.getLogger(__name__)
# Defaults — can be overridden via constructor
_DEFAULT_WARN_THRESHOLD = 3 # inject warning after 3 identical calls
_DEFAULT_HARD_LIMIT = 5 # force-stop after 5 identical calls
_DEFAULT_WINDOW_SIZE = 20 # track last N tool calls
_DEFAULT_WARN_THRESHOLD = 8 # inject warning after 8 identical calls
_DEFAULT_HARD_LIMIT = 20 # force-stop after 20 identical calls
_DEFAULT_WINDOW_SIZE = 60 # track last N tool calls (must be >= hard_limit)
_DEFAULT_MAX_TRACKED_THREADS = 100 # LRU eviction limit
_DEFAULT_TOOL_FREQ_WARN = 30 # warn after 30 calls to the same tool type
_DEFAULT_TOOL_FREQ_HARD_LIMIT = 50 # force-stop after 50 calls to the same tool type
_DEFAULT_TOOL_FREQ_WARN = 80 # warn after 80 calls to the same tool type
_DEFAULT_TOOL_FREQ_HARD_LIMIT = 120 # force-stop after 120 calls to the same tool type
def _normalize_tool_call_args(raw_args: object) -> tuple[dict, str | None]:
@@ -142,19 +142,19 @@ class LoopDetectionMiddleware(AgentMiddleware[AgentState]):
Args:
warn_threshold: Number of identical tool call sets before injecting
a warning message. Default: 3.
a warning message. Default: 8.
hard_limit: Number of identical tool call sets before stripping
tool_calls entirely. Default: 5.
tool_calls entirely. Default: 20.
window_size: Size of the sliding window for tracking calls.
Default: 20.
Default: 60.
max_tracked_threads: Maximum number of threads to track before
evicting the least recently used. Default: 100.
tool_freq_warn: Number of calls to the same tool *type* (regardless
of arguments) before injecting a frequency warning. Catches
cross-file read loops that hash-based detection misses.
Default: 30.
Default: 80.
tool_freq_hard_limit: Number of calls to the same tool type before
forcing a stop. Default: 50.
forcing a stop. Default: 120.
"""
def __init__(