The fastest, litest AI Gateway. Rust core with Python SDK. Call 100+ LLM APIs in OpenAI (or native) format with cost tracking, guardrails, load balancing, and logging [Bedrock, Azure, OpenAI, Anthropic, OpenAI, VertexAI, vLLM, Nvidia NIM]
Python ai-gatewayanthropicazure-openaibedrockgatewaylangchainlitellmllmllm-gatewayllmopsmcp-gatewayopenaiopenai-proxyrustrust-aivertex-ai
fix(advisor): restore AdvisorMaxIterationsError, raise on cap, fix max_uses=0 falsy
Ishaan Jaffer22f45c66668c
diff --git a/litellm/llms/anthropic/experimental_pass_through/messages/interceptors/advisor.py b/litellm/llms/anthropic/experimental_pass_through/messages/interceptors/advisor.pyindex 797fd535f47..02437c9b63f 100644--- a/litellm/llms/anthropic/experimental_pass_through/messages/interceptors/advisor.py+++ b/litellm/llms/anthropic/experimental_pass_through/messages/interceptors/advisor.py@@ -31,6 +31,10 @@ ADVISOR_TOOL_DESCRIPTION: str = _c.ADVISOR_TOOL_DESCRIPTIONfrom .base import MessagesInterceptor+class AdvisorMaxIterationsError(Exception):+ """Raised when the advisor loop exceeds max_uses."""++class AdvisorOrchestrationHandler(MessagesInterceptor):"""Orchestrates the advisor tool loop for non-native providers."""@@ -74,7 +78,8 @@ class AdvisorOrchestrationHandler(MessagesInterceptor):raise ValueError("advisor tool definition must include a 'model' field specifying the advisor model")- max_uses: int = advisor_tool.get("max_uses") or ADVISOR_MAX_USES+ _raw_max_uses = advisor_tool.get("max_uses")+ max_uses: int = ADVISOR_MAX_USES if _raw_max_uses is None else int(_raw_max_uses)# Optional routing overrides for the advisor sub-call (e.g. proxy routing).# If not set in the tool definition, litellm resolves from env vars.advisor_api_key: Optional[str] = advisor_tool.get("api_key")@@ -131,12 +136,10 @@ class AdvisorOrchestrationHandler(MessagesInterceptor):iteration += 1if iteration > max_uses:- # Per Anthropic spec: inject max_uses_exceeded error result so the- # executor sees the cap and continues without further advice.- current_messages = _inject_max_uses_error(- current_messages, executor_response, advisor_use_block+ raise AdvisorMaxIterationsError(+ f"Advisor orchestration loop exceeded max_uses={max_uses}. "+ "Increase max_uses in the advisor tool definition or cap the request.")- continue# --- Build advisor context ---advisor_messages = _build_advisor_context(