diff --git a/crates/goose-cli/src/cli.rs b/crates/goose-cli/src/cli.rs index 8229fe92205e..e1198028d766 100644 --- a/crates/goose-cli/src/cli.rs +++ b/crates/goose-cli/src/cli.rs @@ -546,6 +546,24 @@ enum Command { action = clap::ArgAction::Append )] additional_sub_recipes: Vec, + + /// Provider to use for this run (overrides environment variable) + #[arg( + long = "provider", + value_name = "PROVIDER", + help = "Specify the LLM provider to use (e.g., 'openai', 'anthropic')", + long_help = "Override the GOOSE_PROVIDER environment variable for this run. Available providers include openai, anthropic, ollama, databricks, gemini-cli, claude-code, and others." + )] + provider: Option, + + /// Model to use for this run (overrides environment variable) + #[arg( + long = "model", + value_name = "MODEL", + help = "Specify the model to use (e.g., 'gpt-4o', 'claude-3.5-sonnet')", + long_help = "Override the GOOSE_MODEL environment variable for this run. The model must be supported by the specified provider." + )] + model: Option, }, /// Recipe utilities for validation and deeplinking @@ -700,6 +718,8 @@ pub async fn cli() -> Result<()> { extensions_override: None, additional_system_prompt: None, settings: None, + provider: None, + model: None, debug, max_tool_repetitions, max_turns, @@ -761,6 +781,8 @@ pub async fn cli() -> Result<()> { scheduled_job_id, quiet, additional_sub_recipes, + provider, + model, }) => { let (input_config, session_settings, sub_recipes, final_output_response) = match ( instructions, @@ -845,6 +867,8 @@ pub async fn cli() -> Result<()> { extensions_override: input_config.extensions_override, additional_system_prompt: input_config.additional_system_prompt, settings: session_settings, + provider, + model, debug, max_tool_repetitions, max_turns, @@ -970,6 +994,8 @@ pub async fn cli() -> Result<()> { extensions_override: None, additional_system_prompt: None, settings: None::, + provider: None, + model: None, debug: false, max_tool_repetitions: None, max_turns: None, diff --git a/crates/goose-cli/src/commands/bench.rs b/crates/goose-cli/src/commands/bench.rs index 9d774098f1fe..76f9b7cbf1a5 100644 --- a/crates/goose-cli/src/commands/bench.rs +++ b/crates/goose-cli/src/commands/bench.rs @@ -41,6 +41,8 @@ pub async fn agent_generator( extensions_override: None, additional_system_prompt: None, settings: None, + provider: None, + model: None, debug: false, max_tool_repetitions: None, interactive: false, // Benchmarking is non-interactive diff --git a/crates/goose-cli/src/session/builder.rs b/crates/goose-cli/src/session/builder.rs index b5d3da1d7f45..86db3d2c1f63 100644 --- a/crates/goose-cli/src/session/builder.rs +++ b/crates/goose-cli/src/session/builder.rs @@ -37,6 +37,10 @@ pub struct SessionBuilderConfig { pub additional_system_prompt: Option, /// Settings to override the global Goose settings pub settings: Option, + /// Provider override from CLI arguments + pub provider: Option, + /// Model override from CLI arguments + pub model: Option, /// Enable debug printing pub debug: bool, /// Maximum number of consecutive identical tool calls allowed @@ -167,16 +171,24 @@ pub async fn build_session(session_config: SessionBuilderConfig) -> Session { let config = Config::global(); let provider_name = session_config - .settings - .as_ref() - .and_then(|s| s.goose_provider.clone()) + .provider + .or_else(|| { + session_config + .settings + .as_ref() + .and_then(|s| s.goose_provider.clone()) + }) .or_else(|| config.get_param("GOOSE_PROVIDER").ok()) .expect("No provider configured. Run 'goose configure' first"); let model_name = session_config - .settings - .as_ref() - .and_then(|s| s.goose_model.clone()) + .model + .or_else(|| { + session_config + .settings + .as_ref() + .and_then(|s| s.goose_model.clone()) + }) .or_else(|| config.get_param("GOOSE_MODEL").ok()) .expect("No model configured. Run 'goose configure' first"); @@ -523,6 +535,8 @@ mod tests { extensions_override: None, additional_system_prompt: Some("Test prompt".to_string()), settings: None, + provider: None, + model: None, debug: true, max_tool_repetitions: Some(5), max_turns: None,