This commit is contained in:
ump45nose 2026-09-29 09:40:31 +08:00 • committed by GitHub
commit dd21d9a54e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 34 additions and 3 deletions

View file

@ -305,9 +305,13 @@ class LiteLLMAnthropicToResponsesAPIAdapter:
elif isinstance(inner, str):
output_text = inner
elif isinstance(inner, list):
parts = [
c.get("text", "") for c in inner if isinstance(c, dict) and c.get("type") == "text"
]
parts = (
c.get("text", "")
if c.get("type") == "text"
else f"[Loaded tool: {c.get('tool_name', '')}]"
for c in inner
if isinstance(c, dict) and c.get("type") in {"text", "tool_reference"}
)
output_text = "\n".join(parts)
image_candidates = tuple(
self._translate_anthropic_image_source_to_url(c.get("source"))

View file

@ -481,6 +481,33 @@ class TestTranslateMessagesToResponsesInput:
result = _translate_messages(messages)
assert result[0]["output"] == "Line 1\nLine 2"
def test_user_tool_result_list_content_preserves_tool_references(self):
messages = [
{
"role": "user",
"content": [
{
"type": "tool_result",
"tool_use_id": "call_search",
"content": [
{"type": "text", "text": "Available:"},
{"type": "tool_reference", "tool_name": "get_weather"},
],
}
],
}
]
result = _translate_messages(messages)
assert result == [
{
"type": "function_call_output",
"call_id": "call_search",
"output": "Available:\n[Loaded tool: get_weather]",
}
]
def test_user_tool_result_null_content(self):
"""tool_result with null content becomes empty string output."""
messages = [