2024-09-12 13:44:06 +03:00
|
|
|
mod config;
|
|
|
|
|
mod controller;
|
|
|
|
|
mod utils;
|
|
|
|
|
|
|
|
|
|
pub use config::Config;
|
|
|
|
|
pub use controller::Controller;
|
|
|
|
|
|
|
|
|
|
use super::super::AgentInstantiationError;
|
|
|
|
|
use super::super::AgentInstantiationResult;
|
|
|
|
|
use super::ConfigTrait;
|
2025-02-27 07:46:16 +02:00
|
|
|
use super::controller::ControllerType;
|
2024-09-12 13:44:06 +03:00
|
|
|
|
|
|
|
|
pub fn create_controller_from_yaml_value_config(
|
|
|
|
|
agent_id: &str,
|
2026-02-10 14:34:57 +02:00
|
|
|
config: serde_yaml_ng::Value,
|
2024-09-12 13:44:06 +03:00
|
|
|
) -> AgentInstantiationResult<ControllerType> {
|
|
|
|
|
let config = match &config {
|
2026-02-10 14:34:57 +02:00
|
|
|
serde_yaml_ng::Value::Mapping(_) => {
|
2024-09-12 13:44:06 +03:00
|
|
|
let config: Config =
|
2026-02-10 14:34:57 +02:00
|
|
|
serde_yaml_ng::from_value(config).map_err(AgentInstantiationError::Yaml)?;
|
2024-09-12 13:44:06 +03:00
|
|
|
|
|
|
|
|
config
|
|
|
|
|
.validate()
|
|
|
|
|
.map_err(AgentInstantiationError::ConfigFailsValidation)?;
|
|
|
|
|
|
|
|
|
|
config
|
|
|
|
|
}
|
|
|
|
|
_ => {
|
|
|
|
|
return Err(AgentInstantiationError::ConfigForAgentIsNotAMapping(
|
|
|
|
|
agent_id.to_owned(),
|
|
|
|
|
));
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
let controller =
|
|
|
|
|
Controller::new(config).map_err(AgentInstantiationError::ConstructionFailed)?;
|
|
|
|
|
|
|
|
|
|
Ok(ControllerType::Anthropic(Box::new(controller)))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub fn default_config() -> Config {
|
|
|
|
|
Config::default()
|
|
|
|
|
}
|