Add support for Anthropic Claude models via Google Vertex AI
Why are these changes needed?
This PR adds support for Anthropic Claude models via Google Vertex AI by introducing AnthropicVertexChatCompletionClient.
Background
While AutoGen already supports Anthropic Claude models through:
- Direct API (
AnthropicChatCompletionClient) - AWS Bedrock (
AnthropicBedrockChatCompletionClient)
This PR add support for accessing Claude models through Vertex AI.
Changes Made
-
New Client Class:
AnthropicVertexChatCompletionClientfollowing the same pattern as the existing Bedrock client -
Configuration Types: Added
VertexInfoand related config models for GCP project/region configuration - Tests: Added 11 comprehensive test cases covering initialization, serialization, config conversion, and mocked API calls
- Documentation: Added docstrings with usage examples and configuration loading patterns
Implementation Details
- Uses Anthropic's official
AsyncAnthropicVertexclient - Requires
project_idandregionviaVertexInfoconfiguration - Maintains consistency with existing AutoGen model client patterns
- Supports all standard Claude model capabilities (vision, function calling, streaming)
Usage Example
from autogen_ext.models.anthropic import AnthropicVertexChatCompletionClient, VertexInfo
client = AnthropicVertexChatCompletionClient(
model="claude-3-sonnet-20240229",
vertex_info=VertexInfo(
project_id="your-gcp-project-id",
region="us-east5"
)
)
Checks
- [x] I've included any doc changes needed for https://microsoft.github.io/autogen/. See https://github.com/microsoft/autogen/blob/main/CONTRIBUTING.md to build and test documentation locally.
- [x] I've added tests (if relevant) corresponding to the changes introduced in this PR.
- [x] I've made sure all auto checks have passed.
Codecov Report
:white_check_mark: All modified and coverable lines are covered by tests.
:white_check_mark: Project coverage is 81.30%. Comparing base (13e144e) to head (dc93a88).
Additional details and impacted files
@@ Coverage Diff @@
## main #7097 +/- ##
==========================================
+ Coverage 81.22% 81.30% +0.07%
==========================================
Files 244 244
Lines 18512 18564 +52
==========================================
+ Hits 15036 15093 +57
+ Misses 3476 3471 -5
| Flag | Coverage Δ | |
|---|---|---|
| unittests | 81.30% <100.00%> (+0.07%) |
:arrow_up: |
Flags with carried forward coverage won't be shown. Click here to find out more.
:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.
:rocket: New features to boost your workflow:
- :snowflake: Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
- :package: JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.
Hi @ekzhu, This change introduces support for Anthropic Claude models via Google Vertex AI along with tests. I kindly request you to review the PR whenever you get a chance. Please let me know if there are any additional adjustments or clarifications you’d like. Thanks so much for your time 🙏
I analyzed this issue but couldn't identify the affected files. Could you please provide more details about which files need to be modified?
I analyzed this issue but couldn't identify the affected files. Could you please provide more details about which files need to be modified?
This aims to add support for Anthropic Claude models via Google Vertex AI, and majorly affects the python/packages/autogen-ext/src/autogen_ext/models/anthropic/_anthropic_client.py file (in which a new class AnthropicVertexChatCompletionClient has been added) and its corresponding test.