feat: add Google Vertex AI provider (AnthropicVertex SDK) - #55742
Conversation
|
Verified e2e functionality. |
Hermes Agent Review — PR #55742Verdict: changes requested (configuration persistence bug) Blocking finding
Reproduction evidenceIn a detached PR worktree, I wrote a temp model:
provider: vertex
default: claude-sonnet-4-6
vertex:
project_id: config-project
region: europe-west4with all Vertex env vars cleared, then called Suggested fixTeach Checks run
Reviewed by Hermes Agent hourly commander. |
Competing-implementation cluster for native Google Vertex AI support (Claude via the AnthropicVertex SDK), all currently OPEN: #3569 (earliest, canonical), #6491, #27356, and this PR. The Gemini-on-Vertex sibling is #36253. Feature issues: #13484, #12639. Per triage duplicate-discipline these are related, not duplicates of one another — a maintainer should pick one of the AnthropicVertex-Claude implementations to carry forward. |
|
Thanks for the triage. A few notes on why this PR may be the one to carry forward: Scope comparison:
Architecture: Named Already verified: live smoke-tested against real Vertex credentials (plain text + tool calls), and the config persistence bug flagged in review is fixed. Happy to cherry-pick any useful ideas from the other PRs if there's something I missed. |
bac2abe to
133342c
Compare
|
@teknium1 rebased upon your PR |
|
Local validation (enterprise GCP / ADC) Tested branch feat/vertex-provider on macOS with Application Default Credentials against a private corporate GCP project with Vertex Claude access. hermes auth status vertex → logged in |
|
@teknium1 can we proceed with this addition? |
133342c to
d6b7e6a
Compare
teknium1
left a comment
There was a problem hiding this comment.
Thanks for carrying the AnthropicVertex implementation through runtime, switching, recovery, tests, and documentation. Current main already ships Vertex Gemini support in c73e74386, so this needs to extend that dual-provider surface rather than replace its assumptions.
Problems
agent/agent_init.py:455unconditionally mapsprovider="vertex"toanthropic_messageswhen no API mode is supplied. That bypasses the PR's model-based routing for direct GeminiAIAgentconstruction.agent/auxiliary_client.py:5137checksauth_type == "gcp_adc", butplugins/model-providers/vertex/__init__.py:71still defines Vertex asauth_type="vertex"; the new AnthropicVertex auxiliary branch is unreachable.hermes_cli/model_setup_flows.py:2428-2445remains Gemini-only, whilewebsite/docs/guides/vertex-ai.md:11-12incorrectly says Gemini is unsupported. The new page is not registered inwebsite/sidebars.ts, which still linksguides/google-vertexat line 704.
Suggested changes
- Preserve the existing Gemini OAuth/OpenAI path and make Claude-vs-Gemini routing model-aware across initialization and auxiliary clients.
- Add focused tests for direct initialization, auxiliary resolution, and both wizard-selected model families.
- Consolidate the docs with
website/docs/guides/google-vertex.mdand keep provider documentation truthful for both paths.
This is an automated hermes-sweeper review.
| @@ -452,6 +452,8 @@ def init_agent( | |||
| elif (provider_name is None) and agent._base_url_hostname == "api.x.ai": | |||
| agent.api_mode = "codex_responses" | |||
| agent.provider = "xai" | |||
| elif agent.provider == "vertex": | |||
There was a problem hiding this comment.
This forces every direct AIAgent(provider="vertex") construction into Anthropic mode before the model can be considered. Preserve the current Gemini chat_completions path and select AnthropicVertex only when the resolved model is Claude.
| @@ -5134,6 +5134,40 @@ def _wrap_if_needed(client_obj, final_model_str: str, base_url_str: str = "", | |||
| return (_to_async_client(client, final_model, is_vision=is_vision) if async_mode | |||
| else (client, final_model)) | |||
|
|
|||
| elif pconfig.auth_type == "gcp_adc": | |||
There was a problem hiding this comment.
This branch is unreachable for Vertex: the provider profile still declares auth_type="vertex", so resolve_provider_client("vertex", claude_model) takes the existing Gemini branch. Route Claude model selection within the existing Vertex branch and add an auxiliary-client regression test.
|
|
||
| Hermes Agent supports Google Vertex AI as a native provider using Anthropic's **AnthropicVertex SDK** -- the same `.messages.create()` interface as the regular Anthropic client. This gives you full Claude feature parity (prompt caching, thinking budgets) while authenticating through Google Cloud's credential chain. | ||
|
|
||
| :::info Claude models only (for now) |
There was a problem hiding this comment.
This conflicts with current main's shipped Gemini-on-Vertex path (hermes_cli/runtime_provider.py:1579-1610) and with this PR's Gemini else path. Consolidate this with the existing guides/google-vertex.md instead of documenting Vertex as Claude-only.
Add native support for running Claude models on Google Vertex AI using
Anthropic's AnthropicVertex SDK adapter. The provider is named 'vertex'
(following the Bedrock pattern) with model-based routing: Claude models
use the AnthropicVertex SDK for full feature parity (prompt caching,
thinking budgets), while non-Claude models raise a clear error noting
that Gemini/other model support is planned.
Configuration uses Google Application Default Credentials (ADC):
export ANTHROPIC_VERTEX_PROJECT_ID=your-gcp-project
export CLOUD_ML_REGION=global # optional, defaults to 'global'
gcloud auth application-default login
Provider registration:
- plugins/model-providers/vertex/ — ProviderProfile with gcp_adc auth
- hermes_cli/auth.py — ProviderConfig, auth status, credential resolver
- hermes_cli/runtime_provider.py — model-based routing with
_is_anthropic_vertex_model() (mirrors is_anthropic_bedrock_model)
- hermes_cli/models.py — ProviderEntry, aliases, static model catalog
- hermes_cli/main.py + model_setup_flows.py — 'hermes model' wizard
Runtime wiring:
- agent/anthropic_adapter.py — build_anthropic_vertex_client()
- agent/agent_init.py — Vertex client construction branch
- run_agent.py — _rebuild_anthropic_client Vertex dispatch
- agent/agent_runtime_helpers.py — runtime recovery + switch_model
- agent/chat_completion_helpers.py — fallback activation
- agent/auxiliary_client.py — vision backend + auxiliary resolution
Dependencies:
- pyproject.toml — anthropic-vertex optional extra
- tools/lazy_deps.py — lazy install entry
Tests: 7 new tests covering adapter, runtime resolution, client init.
Docs: vertex-ai.md guide + providers table entry.
Aliases: google-vertex, gcp-vertex, vertex-ai, vertex-anthropic.
Closes NousResearch#13484, closes NousResearch#12639.
Related: NousResearch#3569, NousResearch#6491 (prior attempts, smaller scope).
The credential resolver only checked env vars, so a user who completed 'hermes model' successfully (which saves vertex.project_id and vertex.region to config.yaml) could still fail at runtime unless they also exported env vars manually. Now resolve_vertex_anthropic_runtime_credentials() reads config.yaml's vertex section as a fallback, mirroring how Bedrock reads bedrock.region. Resolution order: 1. Env vars (ANTHROPIC_VERTEX_PROJECT_ID, GOOGLE_CLOUD_PROJECT, etc.) 2. config.yaml vertex.project_id / vertex.region 3. Default region 'global' Added 3 regression tests: - config-only path resolves from config.yaml - env vars take precedence over config.yaml - runtime resolver works with config-only credentials
…s consolidation - agent_init.py: vertex api_mode is now model-aware (Claude→anthropic_messages, Gemini→chat_completions) instead of unconditionally forcing anthropic_messages - auxiliary_client.py: merged Claude+Gemini into single auth_type=='vertex' block with model-based routing; removed unreachable gcp_adc branch - auth.py: aligned auth_type from 'gcp_adc' to 'vertex' to match plugin registry; fixed downstream gcp_adc references - model_setup_flows.py: confirmation message shows correct SDK path per model family - models.py: removed duplicate ProviderEntry with stale description - docs: consolidated vertex-ai.md into google-vertex.md (already in sidebars.ts); removed incorrect 'Gemini unsupported' claim; updated providers.md table - tests: 7 new tests for direct init, auxiliary resolution, runtime provider routing
f4fb512 to
b99adcb
Compare
|
@teknium1 Any progress with getting this merged? |
What does this PR do?
Adds native support for running Claude models on Google Vertex AI using Anthropic's
AnthropicVertexSDK adapter. Users setprovider: vertexin config and authenticate via Google Application Default Credentials (ADC) — no Anthropic API key needed. Useful for corporate GCP environments where direct Anthropic API access is unavailable.Architecture: follows the Bedrock pattern
The provider is named
vertex(notvertex-anthropic) because Vertex AI is a cloud platform that hosts models from multiple vendors analogous to how Bedrock is namedbedrock, notbedrock-anthropic.The implementation mirrors Bedrock's dual-path routing:
_is_anthropic_vertex_model()(mirrorsis_anthropic_bedrock_model())api_mode: anthropic_messages+AnthropicVertexSDK for full feature parity (prompt caching, thinking budgets)Configuration
Related Issue
Closes #13484
Closes #12639
Related: #3569, #6491 (prior attempts with smaller scope — this PR covers full CLI integration, model-based routing, docs, and tests)
Type of Change
Changes Made
Provider registration
plugins/model-providers/vertex/— ProviderProfile withgcp_adcauth type, aliases (google-vertex,gcp-vertex,vertex-ai,vertex-anthropic)hermes_cli/auth.py— ProviderConfig,get_vertex_auth_status(),resolve_vertex_anthropic_runtime_credentials()hermes_cli/runtime_provider.py— model-based routing with_is_anthropic_vertex_model()CLI integration
hermes_cli/models.py— ProviderEntry, aliases, static model cataloghermes_cli/main.py+model_setup_flows.py—_model_flow_vertex()setup wizard (project ID, region, model selection)Runtime wiring
agent/anthropic_adapter.py—build_anthropic_vertex_client()(lazy-installsanthropic[vertex], excludescontext-1mbeta)agent/agent_init.py— Vertex client construction branch (parallel to Bedrock)run_agent.py—_rebuild_anthropic_clientVertex dispatchagent/agent_runtime_helpers.py— runtime recovery, restore, switch_model Vertex pathsagent/chat_completion_helpers.py— fallback activation Vertex pathagent/auxiliary_client.py— vision backend + auxiliary resolution forgcp_adcauth typeDependencies
pyproject.toml—anthropic-vertexoptional extra (anthropic[vertex]==0.87.0)tools/lazy_deps.py— lazy install entryTests (7 new, 702 total passing)
tests/agent/test_anthropic_adapter.py— 2 tests (client construction, SDK requirement)tests/hermes_cli/test_runtime_provider_resolution.py— 3 tests (env var precedence, fallback, missing project)tests/run_agent/test_run_agent.py— 2 tests (init dispatch, rebuild dispatch)Docs
website/docs/guides/vertex-ai.md— full guide (prerequisites, quick start, config, troubleshooting)website/docs/integrations/providers.md— providers table entryHow to Test
Set up GCP credentials:
export ANTHROPIC_VERTEX_PROJECT_ID=your-project gcloud auth application-default loginRun the setup wizard:
hermes model # choose "Google Vertex AI"Chat:
hermes chat -q "Hello from Vertex"Run tests:
Checklist