BerriAI/litellm · error · ValueError

Exceeded max_agentic_loops={max_loops} for model={model}

Error message

Exceeded max_agentic_loops={max_loops} for model={model}

What it means

Error "Exceeded max_agentic_loops={max_loops} for model={model}" thrown in BerriAI/litellm.

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 6c2dcb801b)

Solutions

  1. Increase max_agentic_loops or adjust the prompt/tools so the task completes within fewer iterations.

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@6c2dcb801b (2026-08-15). Data as JSON: /api/errors/70a1c02b63159227. Report an issue: GitHub.