Llama 3.1 Tool calling gets stuck in an infinite loop #9036
-
What happened?Issue DescriptionWeb search functionality with Environment
Steps to Reproduce
Expected BehaviorWeb search should execute and return search results, regardless of streaming configuration. Actual BehaviorAn error occurred while processing the request: Recursion limit of 25 reached without hitting a stop condition. You can increase the limit by setting the "recursionLimit" config key. Root Cause AnalysisThis seems to be an architectural limitation in how LibreChat handles tool execution in non-streaming vs streaming modes: Streaming Mode (Works)
Non-Streaming Mode (Fails)
Technical EvidenceKey Code Path: if (metadata.provider === Providers.GOOGLE || graph.clientOptions?.disableStreaming) {
handleToolCalls(data?.output?.tool_calls, metadata, graph);
} The Problem:
ImpactThis affects users who:
Potential SolutionsOption 1: Streaming Override for Web SearchForce streaming mode when web search is enabled, regardless of disableStreaming configuration. Pros: Simple fix, preserves working web search Option 2: Improve Non-Streaming Tool Completion DetectionImplement proper completion signaling for web search in non-streaming mode to prevent recursive loops. Pros: Respects all configurations, comprehensive fix Related WorkThis issue was discovered while fixing the core disableStreaming configuration bug (PR #9021). The core streaming configuration now works correctly, but this architectural limitation affects web Additional Context
Version Informationlocalhost/librechat debug a5b67510002a About an hour ago 1.29 GB % git rev-parse HEAD Steps to Reproduce
What browsers are you seeing the problem on?Chrome Relevant log outputError Message from LibreChat Logs:
2025-08-13 03:17:00 [31merror[39m: [31m[api/server/controllers/agents/client.js #sendCompletion] Operation aborted Recursion limit of 25 reached without hitting a stop condition. You can increase
the limit by setting the "recursionLimit" config key.
Troubleshooting URL: https://langchain-ai.github.io/langgraphjs/troubleshooting/errors/GRAPH_RECURSION_LIMIT/
2025-08-13 03:17:00 [31merror[39m: [31m[api/server/controllers/agents/client.js #sendCompletion] Unhandled error type Recursion limit of 25 reached without hitting a stop condition. You can increase
the limit by setting the "recursionLimit" config key.
Troubleshooting URL: https://langchain-ai.github.io/langgraphjs/troubleshooting/errors/GRAPH_RECURSION_LIMIT/
Configuration Evidence:
LibreChat configuration correctly loaded with:
"disableStreaming": true
"webSearch": {
"searchProvider": "searxng",
"searxngInstanceUrl": "${SEARXNG_INSTANCE_URL}",
"safeSearch": 0,
"scraper": "firecrawl",
"reranker": "jina"
} Screenshots![]() ![]() Code of Conduct
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
This is an issue with the Llama model and the underlying service specifically. it's well known that smaller local models have recursive problems, see: |
Beta Was this translation helpful? Give feedback.
This is an issue with the Llama model and the underlying service specifically. it's well known that smaller local models have recursive problems, see:
https://discuss.huggingface.co/t/tool-calling-gets-stuck-in-an-infinite-loop/149792