BerriAI/litellm · error · ValueError
Exceeded max_agentic_loops=
Error message
Exceeded max_agentic_loops={max_loops} for model={model} What it means
Agentic-loop safety guard: the rerun loop reached the configured depth equal to max_agentic_loops for the model without finishing. This is the cap that stops unbounded agent/tool-call reruns (distinct from the repeated-fingerprint abort checked just before it).
Solutions
- Raise max_agentic_loops if the task legitimately needs more iterations.
- Inspect the loop's tool calls to find why the model never finishes; adjust the prompt or tools.
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at litellm/litellm_core_utils/chat_completion_agentic_loop.py:79 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of BerriAI/litellm@77b7c6c40c (2026-08-18).
Data as JSON: /api/errors/70a1c02b63159227.
Report an issue: GitHub.
Appendix: source
Thrown at litellm/litellm_core_utils/chat_completion_agentic_loop.py:79
def _fingerprint_tools(tool_calls: object) -> str:
try:
return json.dumps(tool_calls, sort_keys=True, default=str)
except Exception:
return str(tool_calls)
def _check_agentic_loop_safety(
tool_calls: object,
fingerprints: list[str],
depth: int,
max_loops: int,
model: str,
) -> str:
fingerprint: Final = _fingerprint_tools(tool_calls)
if fingerprint in fingerprints:
raise ValueError("Agentic loop detected repeated tool-call fingerprint; aborting rerun")
if depth >= max_loops:
raise ValueError(f"Exceeded max_agentic_loops={max_loops} for model={model}")
return fingerprint
def _wrap_response_as_fake_stream(response: object) -> object:
if getattr(response, "object", None) == "chat.completion.chunk":
return response
if not hasattr(response, "choices"):
return response
from litellm.llms.base_llm.base_model_iterator import (
convert_model_response_to_streaming,
)
return convert_model_response_to_streaming(cast(ModelResponse, response))
def _add_agentic_loop_metadata(kwargs_for_followup: dict[str, object]) -> None:
metadata = kwargs_for_followup.get("litellm_metadata")
metadata = dict(metadata) if isinstance(metadata, dict) else {}View on GitHub (pinned to 77b7c6c40c)