feat(advisor): wire MessagesInterceptor registry into anthropic_messages handler

This commit is contained in:
Ishaan Jaffer 2026-04-11 17:43:13 -07:00
parent a89b0672c7
commit ebc57a157d
No known key found for this signature in database

View file

@ -26,6 +26,7 @@ from litellm.utils import ProviderConfigManager, client
from ..adapters.handler import LiteLLMMessagesToCompletionTransformationHandler
from ..responses_adapters.handler import LiteLLMMessagesToResponsesAPIHandler
from .interceptors import get_messages_interceptors
from .utils import AnthropicMessagesRequestUtils, mock_response
# Providers that are routed directly to the OpenAI Responses API instead of
@ -236,6 +237,23 @@ async def anthropic_messages(
if short_circuit_response is not None:
return short_circuit_response
# Run registered MessagesInterceptors (e.g. advisor orchestration loop).
# api_key and api_base are explicit params (not in **kwargs) so pass them
# explicitly so interceptor sub-calls can route to the same backend.
for interceptor in get_messages_interceptors():
if interceptor.can_handle(tools, custom_llm_provider):
return await interceptor.handle(
model=model,
messages=messages,
tools=tools,
stream=original_stream,
max_tokens=max_tokens,
custom_llm_provider=custom_llm_provider,
api_key=api_key,
api_base=api_base,
**kwargs,
)
loop = asyncio.get_event_loop()
kwargs["is_async"] = True