-
Notifications
You must be signed in to change notification settings - Fork 343
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Image Tool Use Result Causes Response Error in Anthropic API #94
Comments
@maxie thanks for reporting. Can you please share repro steps? It's quite possible there's an issue in the type converters that needs to be fixed. |
@saqadri I've written an example code to reproduce this issue. You can check it here: #100 By the way, I tried to write an example conversion method, and now the response from Anthropics is correct. However, I’m not sure if this is the right place to fix the issue. @classmethod
def convert_call_tool_result_content_to_tool_result_block_param_content(
cls, tool_result_content: list[TextContent | ImageContent | EmbeddedResource]
) -> Iterable[Union[TextBlockParam, ImageBlockParam]]:
result_content = []
for content in tool_result_content:
if isinstance(content, TextContent):
result_content.append(TextBlockParam(type=content.type, text=content.text))
elif isinstance(content, ImageContent):
result_content.append(ImageBlockParam(type="image", source=Base64ImageSourceParam(
type="base64",
media_type=content.mimeType,
data=content.data
)))
elif isinstance(content, EmbeddedResource):
if isinstance(content.resource, TextResourceContents):
result_content.append(TextBlockParam(type="text", text=content.resource.text))
else: # BlobResourceContents
result_content.append(TextBlockParam(
type="text", text=f"{content.resource.mimeType}:{content.resource.blob}"
))
else:
# Last effort to convert the content to a string
result_content.append(TextBlockParam(type="text", text=str(content)))
return result_content |
I was trying to return an image to Anthropic as a tool use result, but the message sent to the Anthropic API looks like this, which results in a response error:
I found that in augmented_llm_anthropic.py, after calling tools, the type of result.content added to the messages list does not seem to match the expected format:
Is there a missing type conversion for result.content before adding it to the message? Or Could AnthropicMCPTypeConverter already be handling this conversion elsewhere without me knowing?
Thanks a lot!
The text was updated successfully, but these errors were encountered: