-
Notifications
You must be signed in to change notification settings - Fork 4.4k
Expand file tree
/
Copy pathserver_factory.rs
More file actions
61 lines (52 loc) · 1.96 KB
/
server_factory.rs
File metadata and controls
61 lines (52 loc) · 1.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
use anyhow::Result;
use goose::providers::provider_registry::ProviderConstructor;
use std::sync::Arc;
use tracing::info;
use crate::server::GooseAcpAgent;
pub struct AcpServerFactoryConfig {
pub builtins: Vec<String>,
pub data_dir: std::path::PathBuf,
pub config_dir: std::path::PathBuf,
}
pub struct AcpServer {
config: AcpServerFactoryConfig,
}
impl AcpServer {
pub fn new(config: AcpServerFactoryConfig) -> Self {
Self { config }
}
pub async fn create_agent(&self) -> Result<Arc<GooseAcpAgent>> {
let config_path = self
.config
.config_dir
.join(goose::config::base::CONFIG_YAML_NAME);
let config = goose::config::Config::new(&config_path, "goose")?;
let goose_mode = config
.get_goose_mode()
.unwrap_or(goose::config::GooseMode::Auto);
let disable_session_naming = config.get_goose_disable_session_naming().unwrap_or(false);
let config_dir = self.config.config_dir.clone();
let provider_factory: ProviderConstructor = Arc::new(move |model_config, extensions| {
let config_dir = config_dir.clone();
Box::pin(async move {
let config_path = config_dir.join(goose::config::base::CONFIG_YAML_NAME);
let config = goose::config::Config::new(&config_path, "goose")?;
let provider_name = config
.get_goose_provider()
.map_err(|_| anyhow::anyhow!("No provider configured"))?;
goose::providers::create(&provider_name, model_config, extensions).await
})
});
let agent = GooseAcpAgent::new(
provider_factory,
self.config.builtins.clone(),
self.config.data_dir.clone(),
self.config.config_dir.clone(),
goose_mode,
disable_session_naming,
)
.await?;
info!("Created new ACP agent");
Ok(Arc::new(agent))
}
}