The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.
Rust agent-orchestrationai-agentsai-assistantdesktopllmlocal-firstmcppersonal-aiprivacyrustsecond-braintauri
feat(config): add computer settings update controller
Steven Enamakele3aebd1175a5
diff --git a/crates/openhuman-core/src/config/ops/computer.rs b/crates/openhuman-core/src/config/ops/computer.rsnew file mode 100644index 0000000000..ad369790e2--- /dev/null+++ b/crates/openhuman-core/src/config/ops/computer.rs@@ -0,0 +1,102 @@+//! TinyComputer model settings: the decision model and the planner and+//! rescue models the module runs a task with.++use crate::config::{ComputerConfig, Config, DecisionModel};+use crate::rpc::RpcOutcome;++use super::loader::{load_config_with_timeout, snapshot_config_json};++/// A partial update to `[computer]`. An empty model string restores the+/// module's default.+#[derive(Debug, Clone, Default)]+pub struct ComputerSettingsPatch {+ pub decision_model: Option<String>,+ pub sage_fast: Option<bool>,+ pub planner_model: Option<String>,+ pub rescue_model: Option<String>,+ pub max_rescues: Option<u32>,+}++/// The most rescues TinyComputer allows one task.+pub const MAX_RESCUES: u32 = 5;++fn parse_decision_model(raw: &str) -> Result<DecisionModel, String> {+ match raw.trim().to_ascii_lowercase().replace('-', "_").as_str() {+ "jev" => Ok(DecisionModel::Jev),+ "open_jev" | "openjev" => Ok(DecisionModel::OpenJev),+ "sage" => Ok(DecisionModel::Sage),+ other => Err(format!(+ "Unsupported decision model '{other}'. Use jev, open_jev, or sage"+ )),+ }+}++fn model_id(raw: String) -> Result<Option<String>, String> {+ let value = raw.trim();+ if value.is_empty() {+ return Ok(None);+ }+ if value.len() > 200 || value.chars().any(|c| c.is_whitespace() || c.is_control()) {+ return Err("model ids are at most 200 characters, without spaces".into());+ }+ Ok(Some(value.to_owned()))+}++/// Apply `update` to a copy of `[computer]`, validating every field first.+pub fn patched(current: &ComputerConfig, update: ComputerSettingsPatch) -> Result<ComputerConfig, String> {+ let mut computer = current.clone();+ if let Some(raw) = update.decision_model {+ computer.decision_model = parse_decision_model(&raw)?;+ }+ if let Some(fast) = update.sage_fast {+ computer.sage_fast = fast;+ }+ if let Some(raw) = update.planner_model {+ computer.planner_model = model_id(raw)?;+ }+ if let Some(raw) = update.rescue_model {+ computer.rescue_model = model_id(raw)?;+ }+ if let Some(rescues) = update.max_rescues {+ if rescues > MAX_RESCUES {+ return Err(format!("max_rescues must be 0..={MAX_RESCUES}"));+ }+ computer.max_rescues = Some(rescues);+ }+ Ok(computer)+}++/// Update `[computer]` and save.+pub async fn apply_computer_settings(+ config: &mut Config,+ update: ComputerSettingsPatch,+) -> Result<RpcOutcome<serde_json::Value>, String> {+ config.computer = patched(&config.computer, update)?;+ tracing::debug!(+ decision_model = config.computer.decision_model.as_str(),+ rescue_model = ?config.computer.rescue_model,+ max_rescues = ?config.computer.max_rescues,+ "[config] computer settings updated"+ );+ config.save().await.map_err(|e| e.to_string())?;+ let snapshot = snapshot_config_json(config)?;+ Ok(RpcOutcome::new(+ snapshot,+ vec![format!(+ "computer settings saved to {}",+ config.config_path.display()+ )],+ ))+}++/// Load the configuration, update `[computer]`, and save it.+pub async fn load_and_apply_computer_settings(+ update: ComputerSettingsPatch,+) -> Result<RpcOutcome<serde_json::Value>, String> {+ let mut config = load_config_with_timeout().await?;+ apply_computer_settings(&mut config, update).await+}++#[cfg(test)]+#[path = "computer_tests.rs"]+mod tests;diff --git a/crates/openhuman-core/src/config/ops/computer_tests.rs b/crates/openhuman-core/src/config/ops/computer_tests.rsnew file mode 100644index 0000000000..a023740d79--- /dev/null+++ b/crates/openhuman-core/src/config/ops/computer_tests.rs@@ -0,0 +1,77 @@+use super::*;++#[test]+fn patch_selects_decision_model_and_rescue_settings() {+ let next = patched(+ &ComputerConfig::default(),+ ComputerSettingsPatch {+ decision_model: Some("OpenJev".into()),+ rescue_model: Some(" openai/gpt-6-luna ".into()),+ planner_model: Some("anthropic/claude-sonnet-5".into()),+ max_rescues: Some(0),+ sage_fast: Some(true),+ },+ )+ .unwrap();+ assert_eq!(next.decision_model, DecisionModel::OpenJev);+ assert_eq!(next.rescue_model.as_deref(), Some("openai/gpt-6-luna"));+ assert_eq!(next.planner_model.as_deref(), Some("anthropic/claude-sonnet-5"));+ assert_eq!(next.max_rescues, Some(0));+ assert!(next.sage_fast);+}++#[test]+fn empty_model_restores_the_module_default() {+ let mut current = ComputerConfig::default();+ current.rescue_model = Some("x/y".into());+ let next = patched(+ ¤t,+ ComputerSettingsPatch {+ rescue_model: Some(" ".into()),+ ..ComputerSettingsPatch::default()+ },+ )+ .unwrap();+ assert_eq!(next.rescue_model, None);+}++#[test]+fn invalid_values_are_refused() {+ let base = ComputerConfig::default();+ for patch in [+ ComputerSettingsPatch {+ decision_model: Some("jet".into()),+ ..ComputerSettingsPatch::default()+ },+ ComputerSettingsPatch {+ max_rescues: Some(6),+ ..ComputerSettingsPatch::default()+ },+ ComputerSettingsPatch {+ rescue_model: Some("has space".into()),+ ..ComputerSettingsPatch::default()+ },+ ] {+ assert!(patched(&base, patch).is_err());+ }+}++#[tokio::test]+async fn apply_saves_the_section() {+ let dir = tempfile::tempdir().unwrap();+ let mut config = Config::default();+ config.config_path = dir.path().join("config.toml");+ config.workspace_dir = dir.path().join("workspace");+ apply_computer_settings(+ &mut config,+ ComputerSettingsPatch {+ decision_model: Some("sage".into()),+ ..ComputerSettingsPatch::default()+ },+ )+ .await+ .unwrap();+ let saved = std::fs::read_to_string(&config.config_path).unwrap();+ assert!(saved.contains("[computer]"), "{saved}");+ assert!(saved.contains("decision_model = \"sage\""), "{saved}");+}diff --git a/crates/openhuman-core/src/config/ops/mod.rs b/crates/openhuman-core/src/config/ops/mod.rsindex 0ea93c3bfe..3da143c00a 100644--- a/crates/openhuman-core/src/config/ops/mod.rs+++ b/crates/openhuman-core/src/config/ops/mod.rs@@ -58,6 +58,11 @@ pub use privacy::{apply_privacy_settings, get_privacy_mode, load_and_apply_privacy_settings, PrivacySettingsPatch,};+mod computer;+pub use computer::{+ apply_computer_settings, load_and_apply_computer_settings, ComputerSettingsPatch,+};+pub use sandbox::{apply_sandbox_settings, get_sandbox_settings, load_and_apply_sandbox_settings,SandboxSettingsPatch,diff --git a/crates/openhuman-core/src/config/schemas/controllers/agent.rs b/crates/openhuman-core/src/config/schemas/controllers/agent.rsindex 121c0b203e..363e1b163c 100644--- a/crates/openhuman-core/src/config/schemas/controllers/agent.rs+++ b/crates/openhuman-core/src/config/schemas/controllers/agent.rs@@ -7,7 +7,7 @@ use crate::core::all::ControllerFuture;use super::super::helpers::{deserialize_params, to_json, AgentSettingsUpdate, AutonomySettingsUpdate,- BrowserSettingsUpdate, MemorySyncSettingsUpdate, PrivacyModeUpdate, SandboxSettingsUpdate,+ BrowserSettingsUpdate, ComputerSettingsUpdate, MemorySyncSettingsUpdate, PrivacyModeUpdate, SandboxSettingsUpdate,SetBrowserAllowAllParams,};@@ -109,6 +109,20 @@ pub(super) fn handle_update_browser_settings(params: Map<String, Value>) -> Cont})}+pub(super) fn handle_update_computer_settings(params: Map<String, Value>) -> ControllerFuture {+ Box::pin(async move {+ let update = deserialize_params::<ComputerSettingsUpdate>(params)?;+ let patch = config_rpc::ComputerSettingsPatch {+ decision_model: update.decision_model,+ sage_fast: update.sage_fast,+ planner_model: update.planner_model,+ rescue_model: update.rescue_model,+ max_rescues: update.max_rescues,+ };+ to_json(config_rpc::load_and_apply_computer_settings(patch).await?)+ })+}+pub(super) fn handle_set_browser_allow_all(params: Map<String, Value>) -> ControllerFuture {Box::pin(async move {let payload = deserialize_params::<SetBrowserAllowAllParams>(params)?;diff --git a/crates/openhuman-core/src/config/schemas/controllers/registry.rs b/crates/openhuman-core/src/config/schemas/controllers/registry.rsindex 66dad3d514..dc3f15ca1e 100644--- a/crates/openhuman-core/src/config/schemas/controllers/registry.rs+++ b/crates/openhuman-core/src/config/schemas/controllers/registry.rs@@ -8,7 +8,7 @@ use super::agent::{handle_get_agent_settings, handle_get_autonomy_settings, handle_get_memory_sync_settings,handle_get_privacy_mode, handle_get_sandbox_settings, handle_set_browser_allow_all,handle_set_privacy_mode, handle_update_agent_settings, handle_update_autonomy_settings,- handle_update_browser_settings, handle_update_memory_sync_settings,+ handle_update_browser_settings, handle_update_computer_settings, handle_update_memory_sync_settings,handle_update_sandbox_settings,};use super::inference::{@@ -40,6 +40,7 @@ pub fn all_controller_schemas() -> Vec<ControllerSchema> {schemas("update_memory_settings"),schemas("update_runtime_settings"),schemas("update_browser_settings"),+ schemas("update_computer_settings"),schemas("update_local_ai_settings"),schemas("resolve_api_url"),schemas("get_runtime_flags"),@@ -103,6 +104,10 @@ pub fn all_registered_controllers() -> Vec<RegisteredController> {schema: schemas("update_browser_settings"),handler: handle_update_browser_settings,},+ RegisteredController {+ schema: schemas("update_computer_settings"),+ handler: handle_update_computer_settings,+ },RegisteredController {schema: schemas("update_local_ai_settings"),handler: handle_update_local_ai_settings,diff --git a/crates/openhuman-core/src/config/schemas/helpers.rs b/crates/openhuman-core/src/config/schemas/helpers.rsindex ef3449b9cd..e73e0050d8 100644--- a/crates/openhuman-core/src/config/schemas/helpers.rs+++ b/crates/openhuman-core/src/config/schemas/helpers.rs@@ -106,6 +106,16 @@ pub(super) struct BrowserSettingsUpdate {pub(super) task_timeout_secs: Option<u64>,}+#[derive(Debug, Deserialize)]+#[serde(deny_unknown_fields)]+pub(super) struct ComputerSettingsUpdate {+ pub(super) decision_model: Option<String>,+ pub(super) sage_fast: Option<bool>,+ pub(super) planner_model: Option<String>,+ pub(super) rescue_model: Option<String>,+ pub(super) max_rescues: Option<u32>,+}+#[derive(Debug, Deserialize)]pub(super) struct AnalyticsSettingsUpdate {pub(super) enabled: Option<bool>,diff --git a/crates/openhuman-core/src/config/schemas/schema_defs/agent.rs b/crates/openhuman-core/src/config/schemas/schema_defs/agent.rsindex 05e2fbf981..b7ac8630d3 100644--- a/crates/openhuman-core/src/config/schemas/schema_defs/agent.rs+++ b/crates/openhuman-core/src/config/schemas/schema_defs/agent.rs@@ -127,6 +127,19 @@ pub(super) fn lookup(function: &str) -> Option<ControllerSchema> {],outputs: vec![json_output("snapshot", "Updated config snapshot.")],}),+"update_computer_settings" => Some( ControllerSchema {+ namespace: "config",+ function: "update_computer_settings",+ description: "Update TinyComputer's decision, planner and rescue models.",+ inputs: vec![+ optional_string("decision_model", "Decision model: jev, open_jev, or sage."),+ optional_bool("sage_fast", "Use Sage's fast mode."),+ optional_string("planner_model", "Planner model id; empty restores the module default."),+ optional_string("rescue_model", "Rescue model id for failed steps; empty restores the module default."),+ optional_number("max_rescues", "Rescues allowed per task (0-5); 0 turns rescue off."),+ ],+ outputs: vec![json_output("snapshot", "Updated config snapshot.")],+ }),"set_browser_allow_all" => Some( ControllerSchema {namespace: "config",function: "set_browser_allow_all",