LangChain

Agent Infinite Loop Detection

critical
reliabilityUpdated Jan 28, 2026

Agents can enter infinite tool-calling loops when tool selection logic fails or tools return results that trigger repeated invocations, consuming tokens and delaying responses.

How to detect:

Monitor langchain_agent_intermediate_steps for iteration counts exceeding expected bounds (e.g., >10). Track langchain_tool_invocation patterns for repeated calls to the same tool. Correlate with elevated gen_ai_client_token_usage and langchain_chain_time without completion.

Recommended action:

Configure max_iterations limits on agent executors with early_stopping_method. Alert when intermediate_steps approach limits. Implement tool call deduplication logic. Add circuit breakers that terminate chains exceeding time or token budgets.