Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 20 additions & 1 deletion go/core/cli/internal/cli/agent/const.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,14 @@ func GetModelProvider() v1alpha2.ModelProvider {
return v1alpha2.ModelProviderAnthropic
case GetModelProviderHelmValuesKey(v1alpha2.ModelProviderAzureOpenAI):
return v1alpha2.ModelProviderAzureOpenAI
case GetModelProviderHelmValuesKey(v1alpha2.ModelProviderGemini):
return v1alpha2.ModelProviderGemini
case GetModelProviderHelmValuesKey(v1alpha2.ModelProviderGeminiVertexAI):
return v1alpha2.ModelProviderGeminiVertexAI
case GetModelProviderHelmValuesKey(v1alpha2.ModelProviderAnthropicVertexAI):
return v1alpha2.ModelProviderAnthropicVertexAI
case GetModelProviderHelmValuesKey(v1alpha2.ModelProviderBedrock):
return v1alpha2.ModelProviderBedrock
default:
return v1alpha2.ModelProviderOpenAI
}
Expand All @@ -42,7 +50,9 @@ func GetModelProviderHelmValuesKey(provider v1alpha2.ModelProvider) string {
return helmKey
}

// GetProviderAPIKey returns API_KEY env var name from provider type
// GetProviderAPIKey returns the env var name for the provider's API key.
// Returns "" for providers that use cloud credentials instead of an API key
// (Ollama, Bedrock, GeminiVertexAI, AnthropicVertexAI).
func GetProviderAPIKey(provider v1alpha2.ModelProvider) string {
switch provider {
case v1alpha2.ModelProviderOpenAI:
Expand All @@ -51,7 +61,16 @@ func GetProviderAPIKey(provider v1alpha2.ModelProvider) string {
return env.AnthropicAPIKey.Name()
case v1alpha2.ModelProviderAzureOpenAI:
return env.AzureOpenAIAPIKey.Name()
case v1alpha2.ModelProviderGemini:
Comment thread
EItanya marked this conversation as resolved.
// Prefer GOOGLE_API_KEY, fall back to GEMINI_API_KEY to match the
// runtime behaviour in go/adk/pkg/agent/agent.go.
if _, ok := os.LookupEnv(env.GoogleAPIKey.Name()); ok {
return env.GoogleAPIKey.Name()
}
return "GEMINI_API_KEY"
default:
Comment on lines 56 to 71
Copy link

Copilot AI Apr 20, 2026

Choose a reason for hiding this comment

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

GetProviderAPIKey only matches exact enum values (e.g., ModelProviderAnthropic == "Anthropic"). Elsewhere the CLI commonly uses helm-key/lowercase provider strings (e.g., modelProvider: anthropic in manifests/tests), and ValidateAPIKey passes that string through as v1alpha2.ModelProvider(modelProvider), which will currently fall into the default branch and skip required API-key validation. Consider normalizing the input inside GetProviderAPIKey (e.g., accept both enum values and GetModelProviderHelmValuesKey(...) strings, or downcase/translate before switching) so it works with both representations.

Copilot uses AI. Check for mistakes.
// Ollama, Bedrock, GeminiVertexAI, AnthropicVertexAI use cloud
// credentials rather than a simple API key, so no check is needed.
return ""
}
}
Expand Down
2 changes: 2 additions & 0 deletions go/core/cli/internal/cli/agent/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ func InstallCmd(ctx context.Context, cfg *InstallCfg) *PortForward {
if apiKeyName != "" && apiKeyValue == "" {
fmt.Fprintf(os.Stderr, "%s is not set\n", apiKeyName)
fmt.Fprintf(os.Stderr, "Please set the %s environment variable\n", apiKeyName)
fmt.Fprintf(os.Stderr, "To use a different provider set KAGENT_DEFAULT_MODEL_PROVIDER (e.g. ollama, anthropic, gemini)\n")
return nil
}

Expand Down Expand Up @@ -127,6 +128,7 @@ func InteractiveInstallCmd(ctx context.Context, c *ishell.Context) *PortForward
if apiKeyName != "" && apiKeyValue == "" {
fmt.Fprintf(os.Stderr, "%s is not set\n", apiKeyName)
fmt.Fprintf(os.Stderr, "Please set the %s environment variable\n", apiKeyName)
fmt.Fprintf(os.Stderr, "To use a different provider set KAGENT_DEFAULT_MODEL_PROVIDER (e.g. ollama, anthropic, gemini)\n")
return nil
}

Expand Down
Loading