refactor: compute tool_result content once, annotate as Final

This commit is contained in:
Mrunmayee Daware 2026-10-07 19:25:14 +05:30 • committed by GitHub
parent 65c92ee6bf
commit 67426ac263
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -525,9 +525,12 @@ class LiteLLMAnthropicMessagesAdapter:
self._add_cache_control_if_applicable(content, doc_obj, model)
new_user_content_list.append(doc_obj)
elif content.get("type") == "tool_result":
tool_result_content = self._tool_result_content(content.get("content"))
if content.get("is_error"):
tool_result_content = self._mark_tool_result_as_error(tool_result_content)
raw_tool_result_content: Final = self._tool_result_content(content.get("content"))
tool_result_content: Final = (
self._mark_tool_result_as_error(raw_tool_result_content)
if content.get("is_error")
else raw_tool_result_content
)
tool_result = ChatCompletionToolMessage(
role="tool",
tool_call_id=content.get("tool_use_id", ""),