Skip to content

Commit 13b8087

Browse files
sashankhCopilot
andcommitted
[Bugfix][Frontend] Convert Anthropic tool references to text
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Signed-off-by: Sai Sashankh D <530713+sashankh@users.noreply.github.com>
1 parent 8efa13b commit 13b8087

2 files changed

Lines changed: 20 additions & 1 deletion

File tree

tests/entrypoints/anthropic/test_anthropic_messages_conversion.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@
4848
validation_exception_handler,
4949
)
5050

51+
pytestmark = pytest.mark.skip_global_cleanup
52+
5153
_convert = AnthropicServingMessages._convert_anthropic_to_openai_request
5254
_img_url = AnthropicServingMessages._convert_image_source_to_url
5355

@@ -238,6 +240,20 @@ def test_tool_result_text_blocks(self):
238240
assert len(tool_msg) == 1
239241
assert tool_msg[0]["content"] == "line 1\nline 2"
240242

243+
def test_tool_result_with_tool_reference(self):
244+
request = self._make_tool_result_request(
245+
[
246+
{"type": "tool_reference", "tool_name": "list_files"},
247+
]
248+
)
249+
result = _convert(request)
250+
251+
tool_msg = [m for m in result.messages if m["role"] == "tool"]
252+
assert len(tool_msg) == 2
253+
assert tool_msg[1]["content"] == [
254+
{"type": "text", "text": "[tool reference: list_files]"}
255+
]
256+
241257
def test_tool_result_with_image(self):
242258
"""Image in tool_result should produce a follow-up user message."""
243259
request = self._make_tool_result_request(

vllm/entrypoints/anthropic/serving.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -431,7 +431,10 @@ def _convert_user_tool_result(
431431
ref_name = item.get("tool_name") or item.get("name")
432432
if ref_name:
433433
tool_reference.append(
434-
{"type": "tool_reference", "name": ref_name}
434+
{
435+
"type": "text",
436+
"text": f"[tool reference: {ref_name}]",
437+
}
435438
)
436439
tool_text = "\n".join(text_parts)
437440

0 commit comments

Comments
 (0)