refactor(anthropic): trim hold-back commentary and drop dead rebuilt-content expression

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
This commit is contained in:
mateo 2026-08-08 19:28:40 +00:00
parent f994068a73
commit 398e3d214c
2 changed files with 5 additions and 20 deletions

View file

@ -7,14 +7,10 @@ all bytes, and on stream exhaustion rebuilds the full Anthropic response
to run through agentic completion hooks. If an agentic hook fires, the
follow-up response is chained as Phase 2 of the same iterator.
In hold-back mode (``hold_back=True``), chunks are buffered instead of
yielded live, with SSE ping events emitted while the upstream message is
in flight and while the agentic hooks run. On exhaustion the hooks run
first: if a follow-up response replaces the message, only the follow-up
is yielded and the buffered message is dropped; otherwise the buffer is
replayed verbatim, unless it holds a tool_use for a server-fulfilled tool
(e.g. ``headroom_retrieve``), in which case an SSE ``error`` event is
emitted because such a block must never reach a client that cannot
In hold-back mode (``hold_back=True``) chunks are buffered instead of yielded
live, keepalive pings run until the hooks finish, and then either the follow-up
replaces the message or the buffer replays, except that a buffered tool_use for
a server-fulfilled tool fails the turn rather than reaching a client that cannot
execute it.
"""
@ -329,11 +325,6 @@ class AgenticAnthropicStreamingIterator:
verbose_logger.debug("AgenticStreamingIterator: Could not rebuild response from SSE bytes")
return
[
(f"{b.get('type')}({b.get('name', '')})" if b.get("type") == "tool_use" else b.get("type"))
for b in rebuilt.get("content", [])
]
result: Final = await self._http_handler._call_agentic_completion_hooks(
response=rebuilt,
model=self._model,

View file

@ -5041,13 +5041,7 @@ class BaseLLMHTTPHandler:
@staticmethod
def _server_fulfilled_tools_in_request(logging_obj: LiteLLMLoggingObj, tools: object) -> frozenset[str]:
"""
The request's tools that a registered callback fulfills server-side (e.g.
``headroom_retrieve``). The model's tool_use for such a tool must never
reach the client, which cannot execute it: the agentic loop replaces the
whole message with a follow-up response, so a stream carrying any of
these is buffered (with ping keepalives) instead of forwarded live.
"""
"""The request's tools that a registered callback fulfills server-side (e.g. ``headroom_retrieve``)."""
if not isinstance(tools, list) or not tools:
return frozenset()
from litellm.litellm_core_utils.prompt_templates.factory import has_tool_with_name