Skip to content

Support returning ContentToolResultImage from a tool with ChatAnthropic #118

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

Merged
merged 4 commits into from
Jul 2, 2025

Conversation

cpsievert
Copy link
Collaborator

@cpsievert cpsievert commented Jun 24, 2025

ContentToolResultImage and ContentToolResultResouce were first added in #39 (since MCP tools can return images and resources), but that PR didn't add any logic to convert these tool results into a provider-specific content type for response generation

Unfortunately, Anthropic is currently the only provider to support non-text tool results. More specifically, it only supports images. This PR adds support for ContentToolResultImage from a tool for ChatAnthropic, but throws if ContentToolResultImage and ContentToolResultResouce are used in any other context.

Perhaps there is a trick we can apply to include these results in a clever way for some providers, but I'm punting on that for now.

@cpsievert cpsievert marked this pull request as ready for review July 2, 2025 20:51
@cpsievert cpsievert requested a review from Copilot July 2, 2025 20:51
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds support for returning tool results as ContentToolResultImage or ContentToolResultResource, implements image serialization for Anthropic, and raises errors for unsupported image/resource results in OpenAI and Google providers.

  • Switched the Anthropiс test helper to return ContentToolResultImage
  • Updated OpenAI/Google providers to detect and reject image/resource results
  • Extended Anthropic provider to serialize images and stub resource support

Reviewed Changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
tests/test_provider_anthropic.py Update test to use ContentToolResultImage instead of generic ContentToolResult.
chatlas/_openai.py Added imports and NotImplementedError for image/resource tool results.
chatlas/_google.py Added imports and NotImplementedError for image/resource tool results (with a matching check).
chatlas/_content.py Introduced get_model_value stub for new content types.
chatlas/_anthropic.py Implement image serialization and stub resource support.
chatlas/init.py Re-export ContentToolResultImage.
Comments suppressed due to low confidence (3)

chatlas/_openai.py:489

  • Add tests for the OpenAI provider to verify that NotImplementedError is raised when a tool returns an image or resource result.
                        ):

chatlas/_google.py:434

  • Add tests for the Google provider to ensure it raises NotImplementedError for image or resource tool results.
                )

chatlas/init.py:5

  • Consider also re-exporting ContentToolResultResource to keep the public API consistent with the newly supported content types.
from ._content import ContentToolRequest, ContentToolResult, ContentToolResultImage

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@cpsievert cpsievert changed the title Support ContentToolResultImage/ContentToolResultResource where we can Support returning ContentToolResultImage from a tool with ChatAnthropic Jul 2, 2025
@cpsievert cpsievert merged commit fcf72a0 into main Jul 2, 2025
6 of 7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant