cli: add --provider flag to kagent install#1692
Open
tjorourke wants to merge 2 commits intokagent-dev:mainfrom
Open
cli: add --provider flag to kagent install#1692tjorourke wants to merge 2 commits intokagent-dev:mainfrom
tjorourke wants to merge 2 commits intokagent-dev:mainfrom
Conversation
The install command previously only read the provider from the undocumented
KAGENT_DEFAULT_MODEL_PROVIDER env var, defaulting silently to OpenAI. Users
trying to install with Anthropic, Ollama or Azure OpenAI would see a
confusing "OPENAI_API_KEY is not set" error with no indication that other
providers were supported or how to select them.
- Add --provider flag to kagent install (openAI, anthropic, azureOpenAI, ollama)
- Flag overrides KAGENT_DEFAULT_MODEL_PROVIDER when set
- Add shell completion for --provider values
- Fix misleading error comments ("If model provider is openai") to be provider-agnostic
- Add a hint in the error output pointing to --provider and KAGENT_DEFAULT_MODEL_PROVIDER
when no provider flag was explicitly set
Contributor
There was a problem hiding this comment.
Pull request overview
Adds an explicit LLM provider selection to kagent install so users can avoid the implicit OpenAI default and get clearer guidance when the required API key is missing.
Changes:
- Extend
InstallCfgwithProviderand apply it early to overrideKAGENT_DEFAULT_MODEL_PROVIDER. - Add
ValidProviders()+applyProviderFlag()helper to validate provider values and drive shell completion. - Improve missing-API-key messaging with guidance toward
--provider/KAGENT_DEFAULT_MODEL_PROVIDER.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| go/core/cli/internal/cli/agent/install.go | Applies --provider precedence and enhances missing API key error guidance. |
| go/core/cli/internal/cli/agent/const.go | Adds provider validation helpers and env var application for the new flag. |
| go/core/cli/cmd/kagent/main.go | Wires the new --provider flag and shell completion into kagent install. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
…der tip - Generate --provider help string from ValidProviders() instead of hard-coding the list (keeps docs, completion, and validation in sync) - Replace Unicode em dash with ASCII colon in error message - Only show --provider tip when the error is for the default OpenAI selection, not when a user explicitly chose a non-OpenAI provider Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
iplay88keys
requested changes
Apr 28, 2026
| valid := ValidProviders() | ||
| for _, v := range valid { | ||
| if provider == v { | ||
| return os.Setenv(env.KagentDefaultModelProvider.Name(), provider) |
Contributor
There was a problem hiding this comment.
I don't think we should be setting the env var here. We are already using Viper for our CLI, so we should be able to utilize viper.MustBindEnv when we read in the config. Something like:
// Config struct - add provider
type Config struct {
KAgentURL string `mapstructure:"kagent_url"`
Namespace string `mapstructure:"namespace"`
OutputFormat string `mapstructure:"output_format"`
Verbose bool `mapstructure:"verbose"`
Timeout time.Duration `mapstructure:"timeout"`
Provider string `mapstructure:"provider"`
}
// Init() - add defaults and env bindings alongside existing ones
viper.SetDefault("provider", "openAI")
viper.MustBindEnv("provider", "KAGENT_DEFAULT_MODEL_PROVIDER")
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
kagent installdefaults silently to OpenAI and has no way to select a different provider via the CLI. Users installing with Anthropic, Ollama, or Azure OpenAI see this confusing error with no guidance:The actual mechanism (
KAGENT_DEFAULT_MODEL_PROVIDER) is undocumented and not surfaced in--help.Solution
Add a
--providerflag tokagent installthat sets the provider explicitly:Changes
InstallCfg— addProvider stringfieldValidProviders()— new helper returning the accepted provider values (openAI,anthropic,azureOpenAI,ollama) used for flag validation and shell completionapplyProviderFlag()— validates the flag value and setsKAGENT_DEFAULT_MODEL_PROVIDERsoGetModelProvider()picks it upmain.go— wire--providerflag with shell completion--providerandKAGENT_DEFAULT_MODEL_PROVIDERwhen the key is missing and no--providerwas givenBefore / After
Before:
After:
Or, if the user forgets the flag: