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
14 changes: 8 additions & 6 deletions crates/goose-cli/src/commands/acp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -230,18 +230,22 @@ impl GooseAcpAgent {
};
let provider = create(&provider_name, model_config).await?;

// Create a shared agent instance
let session = SessionManager::create_session(
std::env::current_dir().unwrap_or_else(|_| std::path::PathBuf::from(".")),
"ACP Session".to_string(),
SessionType::Hidden,
)
.await?;

let agent = Agent::new();
agent.update_provider(provider.clone()).await?;
agent.update_provider(provider.clone(), &session.id).await?;

// Load and add extensions just like the normal CLI
let extensions_to_run: Vec<_> = get_all_extensions()
.into_iter()
.filter(|ext| ext.enabled)
.map(|ext| ext.config)
.collect();

// Add extensions to the agent in parallel
let agent_ptr = Arc::new(agent);
let mut set = JoinSet::new();
let mut waiting_on = HashSet::new();
Expand All @@ -257,7 +261,6 @@ impl GooseAcpAgent {
});
}

// Wait for all extensions to load
while let Some(result) = set.join_next().await {
match result {
Ok((name, Ok(_))) => {
Expand All @@ -274,7 +277,6 @@ impl GooseAcpAgent {
}
}

// Unwrap the Arc to get the agent back
let agent = Arc::try_unwrap(agent_ptr)
.map_err(|_| anyhow::anyhow!("Failed to unwrap agent Arc"))?;

Expand Down
14 changes: 9 additions & 5 deletions crates/goose-cli/src/commands/configure.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ use goose::conversation::message::Message;
use goose::model::ModelConfig;
use goose::providers::provider_test::test_provider_configuration;
use goose::providers::{create, providers};
use goose::session::{SessionManager, SessionType};
use serde_json::Value;
use std::collections::HashMap;

Expand Down Expand Up @@ -1368,7 +1369,6 @@ pub async fn configure_tool_permissions_dialog() -> anyhow::Result<()> {
.collect();
extensions.push("platform".to_string());

// Sort extensions alphabetically by name
extensions.sort();

let selected_extension_name = cliclack::select("Choose an extension to configure tools")
Expand All @@ -1380,8 +1380,6 @@ pub async fn configure_tool_permissions_dialog() -> anyhow::Result<()> {
)
.interact()?;

// Fetch tools for the selected extension
// Load config and get provider/model
let config = Config::global();

let provider_name: String = config
Expand All @@ -1393,10 +1391,16 @@ pub async fn configure_tool_permissions_dialog() -> anyhow::Result<()> {
.expect("No model configured. Please set model first");
let model_config = ModelConfig::new(&model)?;

// Create the agent
let session = SessionManager::create_session(
std::env::current_dir().unwrap_or_else(|_| std::path::PathBuf::from(".")),
"Tool Permission Configuration".to_string(),
SessionType::Hidden,
)
.await?;

let agent = Agent::new();
let new_provider = create(&provider_name, model_config).await?;
agent.update_provider(new_provider).await?;
agent.update_provider(new_provider, &session.id).await?;
if let Some(config) = get_extension_by_name(&selected_extension_name) {
agent
.add_extension(config.clone())
Expand Down
12 changes: 8 additions & 4 deletions crates/goose-cli/src/commands/web.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,12 +158,17 @@ pub async fn handle_web(

let model_config = goose::model::ModelConfig::new(&model)?;

// Create the agent
let init_session = SessionManager::create_session(
std::env::current_dir().unwrap_or_else(|_| std::path::PathBuf::from(".")),
"Web Agent Initialization".to_string(),
SessionType::Hidden,
)
.await?;

let agent = Agent::new();
let provider = goose::providers::create(&provider_name, model_config).await?;
agent.update_provider(provider).await?;
agent.update_provider(provider, &init_session.id).await?;

// Load and enable extensions from config
let enabled_configs = goose::config::get_enabled_extensions();
for config in enabled_configs {
if let Err(e) = agent.add_extension(config.clone()).await {
Expand All @@ -177,7 +182,6 @@ pub async fn handle_web(
auth_token,
};

// Build router
let app = Router::new()
.route("/", get(serve_index))
.route("/session/{session_name}", get(serve_session))
Expand Down
12 changes: 8 additions & 4 deletions crates/goose-cli/src/scenario_tests/scenario_runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -217,16 +217,20 @@ where
)
.await;

agent
.update_provider(provider_arc as Arc<dyn goose::providers::base::Provider>)
.await?;

let session = SessionManager::create_session(
PathBuf::default(),
"scenario-runner".to_string(),
SessionType::Hidden,
)
.await?;

agent
.update_provider(
provider_arc as Arc<dyn goose::providers::base::Provider>,
&session.id,
)
.await?;

let mut cli_session = CliSession::new(
agent,
session.id,
Expand Down
78 changes: 51 additions & 27 deletions crates/goose-cli/src/session/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,15 @@ async fn offer_extension_debugging_help(

// Create a minimal agent for debugging
let debug_agent = Agent::new();
debug_agent.update_provider(provider).await?;

let session = SessionManager::create_session(
std::env::current_dir()?,
"CLI Session".to_string(),
SessionType::Hidden,
)
.await?;

debug_agent.update_provider(provider, &session.id).await?;

// Add the developer extension if available to help with debugging
let extensions = get_all_extensions();
Expand All @@ -166,12 +174,6 @@ async fn offer_extension_debugging_help(
}
}

let session = SessionManager::create_session(
std::env::current_dir()?,
"CLI Session".to_string(),
SessionType::Hidden,
)
.await?;
let mut debug_session = CliSession::new(
debug_agent,
session.id,
Expand Down Expand Up @@ -246,11 +248,24 @@ pub struct SessionSettings {
}

pub async fn build_session(session_config: SessionBuilderConfig) -> CliSession {
// Load config and get provider/model
let config = Config::global();

let (saved_provider, saved_model_config) = if session_config.resume {
if let Some(ref session_id) = session_config.session_id {
match SessionManager::get_session(session_id, false).await {
Ok(session_data) => (session_data.provider_name, session_data.model_config),
Err(_) => (None, None),
}
} else {
(None, None)
}
} else {
(None, None)
};

let provider_name = session_config
.provider
.or(saved_provider)
.or_else(|| {
session_config
.settings
Expand All @@ -262,6 +277,7 @@ pub async fn build_session(session_config: SessionBuilderConfig) -> CliSession {

let model_name = session_config
.model
.or_else(|| saved_model_config.as_ref().map(|mc| mc.model_name.clone()))
.or_else(|| {
session_config
.settings
Expand All @@ -271,16 +287,26 @@ pub async fn build_session(session_config: SessionBuilderConfig) -> CliSession {
.or_else(|| config.get_goose_model().ok())
.expect("No model configured. Run 'goose configure' first");

let temperature = session_config.settings.as_ref().and_then(|s| s.temperature);

let model_config = goose::model::ModelConfig::new(&model_name)
.unwrap_or_else(|e| {
output::render_error(&format!("Failed to create model configuration: {}", e));
process::exit(1);
})
.with_temperature(temperature);
let model_config = if session_config.resume
&& saved_model_config
.as_ref()
.is_some_and(|mc| mc.model_name == model_name)
{
let mut config = saved_model_config.unwrap();
if let Some(temp) = session_config.settings.as_ref().and_then(|s| s.temperature) {
config = config.with_temperature(Some(temp));
}
config
} else {
let temperature = session_config.settings.as_ref().and_then(|s| s.temperature);
goose::model::ModelConfig::new(&model_name)
.unwrap_or_else(|e| {
output::render_error(&format!("Failed to create model configuration: {}", e));
process::exit(1);
})
.with_temperature(temperature)
};

// Create the agent
let agent: Agent = Agent::new();

agent
Expand All @@ -304,10 +330,8 @@ pub async fn build_session(session_config: SessionBuilderConfig) -> CliSession {
process::exit(1);
}
};
// Keep a reference to the provider for display_session_info
let provider_for_display = Arc::clone(&new_provider);

// Log model information at startup
if let Some(lead_worker) = new_provider.as_lead_worker() {
let (lead_model, worker_model) = lead_worker.get_model_info();
tracing::info!(
Expand All @@ -319,14 +343,6 @@ pub async fn build_session(session_config: SessionBuilderConfig) -> CliSession {
tracing::info!("🤖 Using model: {}", model_name);
}

agent
.update_provider(new_provider)
.await
.unwrap_or_else(|e| {
output::render_error(&format!("Failed to initialize agent: {}", e));
process::exit(1);
});

let session_id: String = if session_config.no_session {
let working_dir = std::env::current_dir().expect("Could not get working directory");
let session = SessionManager::create_session(
Expand Down Expand Up @@ -362,6 +378,14 @@ pub async fn build_session(session_config: SessionBuilderConfig) -> CliSession {
session_config.session_id.unwrap()
};

agent
.update_provider(new_provider, &session_id)
.await
.unwrap_or_else(|e| {
output::render_error(&format!("Failed to initialize agent: {}", e));
process::exit(1);
});

agent
.extension_manager
.set_context(PlatformExtensionContext {
Expand Down
2 changes: 2 additions & 0 deletions crates/goose-server/src/openapi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use goose::agents::ExtensionConfig;
use goose::config::permission::PermissionLevel;
use goose::config::ExtensionEntry;
use goose::conversation::Conversation;
use goose::model::ModelConfig;
use goose::permission::permission_confirmation::PrincipalType;
use goose::providers::base::{ConfigKey, ModelInfo, ProviderMetadata, ProviderType};
use goose::session::{Session, SessionInsights, SessionType};
Expand Down Expand Up @@ -447,6 +448,7 @@ derive_utoipa!(Icon as IconSchema);
PermissionLevel,
PrincipalType,
ModelInfo,
ModelConfig,
Session,
SessionInsights,
SessionType,
Expand Down
Loading
Loading