Skip to content

cli: add --provider flag to kagent install#1692

Open
tjorourke wants to merge 2 commits intokagent-dev:mainfrom
tjorourke:fix/install-provider-flag
Open

cli: add --provider flag to kagent install#1692
tjorourke wants to merge 2 commits intokagent-dev:mainfrom
tjorourke:fix/install-provider-flag

Conversation

@tjorourke
Copy link
Copy Markdown

Problem

kagent install defaults 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:

OPENAI_API_KEY is not set
Please set the OPENAI_API_KEY environment variable

The actual mechanism (KAGENT_DEFAULT_MODEL_PROVIDER) is undocumented and not surfaced in --help.

Solution

Add a --provider flag to kagent install that sets the provider explicitly:

ANTHROPIC_API_KEY=sk-ant-... kagent install --provider anthropic --profile demo
OPENAI_API_KEY=sk-...        kagent install --provider openAI    --profile demo
kagent install --provider ollama --profile minimal

Changes

  • InstallCfg — add Provider string field
  • ValidProviders() — new helper returning the accepted provider values (openAI, anthropic, azureOpenAI, ollama) used for flag validation and shell completion
  • applyProviderFlag() — validates the flag value and sets KAGENT_DEFAULT_MODEL_PROVIDER so GetModelProvider() picks it up
  • main.go — wire --provider flag with shell completion
  • Error messages — fix stale "If model provider is openai" comments; add a hint pointing to --provider and KAGENT_DEFAULT_MODEL_PROVIDER when the key is missing and no --provider was given

Before / After

Before:

$ ANTHROPIC_API_KEY=sk-ant-... kagent install --profile demo
OPENAI_API_KEY is not set
Please set the OPENAI_API_KEY environment variable

After:

$ ANTHROPIC_API_KEY=sk-ant-... kagent install --provider anthropic --profile demo
 Installing kagent [Anthropic] ...
kagent installed successfully

Or, if the user forgets the flag:

$ kagent install --profile demo
OPENAI_API_KEY is not set
Please set the OPENAI_API_KEY environment variable
Tip: use --provider to select a different LLM provider (e.g. --provider anthropic)
     or set KAGENT_DEFAULT_MODEL_PROVIDER=anthropic before running install

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
Copilot AI review requested due to automatic review settings April 18, 2026 14:33
Copy link
Copy Markdown
Contributor

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

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 InstallCfg with Provider and apply it early to override KAGENT_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.

Comment thread go/core/cli/cmd/kagent/main.go Outdated
Comment thread go/core/cli/internal/cli/agent/const.go Outdated
Comment thread go/core/cli/internal/cli/agent/install.go Outdated
…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>
valid := ValidProviders()
for _, v := range valid {
if provider == v {
return os.Setenv(env.KagentDefaultModelProvider.Name(), provider)
Copy link
Copy Markdown
Contributor

@iplay88keys iplay88keys Apr 28, 2026

Choose a reason for hiding this comment

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

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")

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.

3 participants