fix: fix linting errors

This commit is contained in:
Krrish Dholakia 2026-04-15 11:35:35 -07:00
parent e23707dbc4
commit e80f12b8f1
2 changed files with 1 additions and 64 deletions

View file

@ -185,32 +185,17 @@ class AgenticAnthropicStreamingIterator:
try:
chunk = await self._inner.__anext__()
self._collected_bytes.append(chunk)
print(
f"\n[AgenticStreaming] Phase 1 — yielding chunk "
f"#{len(self._collected_bytes)} ({len(chunk)} bytes)"
)
return chunk
except StopAsyncIteration:
self._stream_exhausted = True
print(
f"\n[AgenticStreaming] Phase 1 complete — "
f"collected {len(self._collected_bytes)} chunks, "
f"total {sum(len(c) for c in self._collected_bytes)} bytes. "
f"Running agentic hooks..."
)
await self._process_agentic_hooks()
# Fall through to Phase 2
# Phase 2: yield from follow-up stream if one was created
if self._follow_up_iterator is not None:
chunk = await self._follow_up_iterator.__anext__()
print(
f"\n[AgenticStreaming] Phase 2 — yielding follow-up chunk "
f"({len(chunk)} bytes)"
)
return chunk
print("\n[AgenticStreaming] Stream fully exhausted (no follow-up)")
raise StopAsyncIteration
async def _process_agentic_hooks(self) -> None:
@ -220,31 +205,22 @@ class AgenticAnthropicStreamingIterator:
self._hook_processing_done = True
if not self._collected_bytes:
print("[AgenticStreaming] No bytes collected, skipping hooks")
return
try:
rebuilt = self._rebuild_anthropic_response_from_sse(self._collected_bytes)
if rebuilt is None:
print("[AgenticStreaming] Could not rebuild response from SSE bytes")
verbose_logger.debug(
"AgenticStreamingIterator: Could not rebuild response from SSE bytes"
)
return
print(
f"[AgenticStreaming] Rebuilt response: id={rebuilt.get('id')}, "
f"model={rebuilt.get('model')}, "
f"stop_reason={rebuilt.get('stop_reason')}, "
f"content_blocks={len(rebuilt.get('content', []))}"
)
content_types = [
[
f"{b.get('type')}({b.get('name', '')})"
if b.get("type") == "tool_use"
else b.get("type")
for b in rebuilt.get("content", [])
]
print(f"[AgenticStreaming] Content block types: {content_types}")
result = await self._http_handler._call_agentic_completion_hooks(
response=rebuilt,
@ -259,23 +235,11 @@ class AgenticAnthropicStreamingIterator:
)
if result is None:
print(
"[AgenticStreaming] Hooks returned None — "
"no managed tool detected, no follow-up"
)
return
if hasattr(result, "__aiter__"):
print(
f"[AgenticStreaming] Hooks returned async iterator "
f"({type(result).__name__}) — chaining as Phase 2"
)
self._follow_up_iterator = result.__aiter__()
elif isinstance(result, dict):
print(
f"[AgenticStreaming] Hooks returned dict response "
f"(id={result.get('id')}) — wrapping in FakeStreamIterator for Phase 2"
)
from litellm.llms.anthropic.experimental_pass_through.messages.fake_stream_iterator import (
FakeAnthropicMessagesStreamIterator,
)
@ -288,20 +252,12 @@ class AgenticAnthropicStreamingIterator:
)
self._follow_up_iterator = fake.__aiter__()
else:
print(
f"[AgenticStreaming] Hooks returned unexpected type: "
f"{type(result).__name__}"
)
verbose_logger.warning(
"AgenticStreamingIterator: Unexpected result type from hooks: %s",
type(result).__name__,
)
except Exception as e:
_call_id = getattr(self._logging_obj, "litellm_call_id", "unknown")
print(
f"[AgenticStreaming] ERROR in hook processing: {e} "
f"(call_id={_call_id})"
)
verbose_logger.exception(
"AgenticStreamingIterator: Error in agentic hook processing "
"[call_id=%s model=%s]: %s",

View file

@ -1978,10 +1978,6 @@ class BaseLLMHTTPHandler:
initial_response: Union[AsyncIterator, AnthropicMessagesResponse]
if stream:
print(
f"\n[llm_http_handler] stream=True for model={model}, "
f"wrapping in AgenticAnthropicStreamingIterator"
)
completion_stream = anthropic_messages_provider_config.get_async_streaming_response_iterator(
model=model,
httpx_response=response,
@ -4501,10 +4497,6 @@ class BaseLLMHTTPHandler:
fingerprint: str,
stream: bool = False,
) -> Any:
print(
f"\n[_execute_anthropic_agentic_plan] "
f"model={model}, stream={stream}, depth={depth}/{max_loops}"
)
from litellm.anthropic_interface import messages as anthropic_messages
patch = plan.request_patch or AgenticLoopRequestPatch()
@ -4637,12 +4629,6 @@ class BaseLLMHTTPHandler:
tools = anthropic_messages_optional_request_params.get("tools", [])
depth, max_loops, fingerprints = self._get_agentic_loop_settings(kwargs=kwargs)
print(
f"\n[_call_agentic_completion_hooks] model={model}, stream={stream}, "
f"depth={depth}/{max_loops}, "
f"response_type={type(response).__name__}, "
f"num_callbacks={len(callbacks)}"
)
for callback in callbacks:
try:
@ -4661,11 +4647,6 @@ class BaseLLMHTTPHandler:
kwargs=kwargs,
)
print(
f"[_call_agentic_completion_hooks] "
f"callback={callback.__class__.__name__}, "
f"should_run={should_run}"
)
if should_run:
fingerprint = self._fingerprint_agentic_tools(tool_calls)