Skip to content

Commit 62efcd7

Browse files
authored
Merge pull request #394 from trycua/fix/anthropic-multimodal-inputs
[Agent] Fix multimodal user inputs in the anthropic loop
2 parents d43f883 + 2dfaf00 commit 62efcd7

File tree

1 file changed

+11
-12
lines changed

1 file changed

+11
-12
lines changed

libs/python/agent/agent/loops/anthropic.py

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -132,23 +132,22 @@ def _convert_responses_items_to_completion_messages(messages: Messages) -> List[
132132
converted_content = []
133133
for item in content:
134134
if isinstance(item, dict) and item.get("type") == "input_image":
135-
# Convert input_image to Anthropic image format
135+
# Convert input_image to OpenAI image format
136136
image_url = item.get("image_url", "")
137137
if image_url and image_url != "[omitted]":
138-
# Extract base64 data from data URL
139-
if "," in image_url:
140-
base64_data = image_url.split(",")[-1]
141-
else:
142-
base64_data = image_url
143-
144138
converted_content.append({
145-
"type": "image",
146-
"source": {
147-
"type": "base64",
148-
"media_type": "image/png",
149-
"data": base64_data
139+
"type": "image_url",
140+
"image_url": {
141+
"url": image_url
150142
}
151143
})
144+
elif isinstance(item, dict) and item.get("type") == "input_text":
145+
# Convert input_text to OpenAI text format
146+
text = item.get("text", "")
147+
converted_content.append({
148+
"type": "text",
149+
"text": text
150+
})
152151
else:
153152
# Keep other content types as-is
154153
converted_content.append(item)

0 commit comments

Comments
 (0)