Skip to content

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]

refactor(responses): build agentic follow-up kwargs as one frozen mapping

Tejas Chopra3298b416878e
diff --git a/litellm/llms/custom_httpx/llm_http_handler.py b/litellm/llms/custom_httpx/llm_http_handler.py
index b4f2a74b3e6..50420ab3301 100644
--- a/litellm/llms/custom_httpx/llm_http_handler.py
+++ b/litellm/llms/custom_httpx/llm_http_handler.py
@@ -4,6 +4,7 @@ import ssl
from collections.abc import AsyncIterator, Coroutine, Iterator, Mapping, Sequence
from contextlib import asynccontextmanager
from functools import lru_cache
+from itertools import chain
from types import MappingProxyType, ModuleType
from typing import TYPE_CHECKING, Any, Final, Literal, Optional, TypedDict, TypeVar, Union, cast, get_type_hints
from urllib.parse import parse_qs, urlencode, urlparse, urlunparse
@@ -5572,20 +5573,29 @@ class BaseLLMHTTPHandler:
}
internal_keys: Final = {"litellm_logging_obj"}
- kwargs_for_followup: Final = {
- **{
- k: v
- for k, v in kwargs.items()
- if not is_interception_internal_key(k, prefixes=NON_CODE_INTERPRETER_INTERCEPTION_INTERNAL_PREFIXES)
- and k != "_code_interpreter_interception_converted_stream"
- and k not in internal_keys
- and k not in optional_params
- },
- **{k: v for k, v in patch.kwargs.items() if k not in optional_params},
- "_agentic_loop_depth": depth + 1,
- "max_agentic_loops": max_loops,
- "_agentic_loop_fingerprints": fingerprints + [fingerprint],
- }
+ kwargs_for_followup: Final = MappingProxyType(
+ {
+ key: value
+ for key, value in chain(
+ (
+ (k, v)
+ for k, v in kwargs.items()
+ if not is_interception_internal_key(
+ k, prefixes=NON_CODE_INTERPRETER_INTERCEPTION_INTERNAL_PREFIXES
+ )
+ and k != "_code_interpreter_interception_converted_stream"
+ and k not in internal_keys
+ and k not in optional_params
+ ),
+ ((k, v) for k, v in patch.kwargs.items() if k not in optional_params),
+ (
+ ("_agentic_loop_depth", depth + 1),
+ ("max_agentic_loops", max_loops),
+ ("_agentic_loop_fingerprints", fingerprints + [fingerprint]),
+ ),
+ )
+ }
+ )
try:
response: ResponsesAPIResponse | BaseResponsesAPIStreamingIterator = await litellm.aresponses(