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(user_agents): add host management operations
Steven Enamakeldf12cb1ee587
diff --git a/crates/openhuman-core/src/user_agents/host.rs b/crates/openhuman-core/src/user_agents/host.rsindex 7f21d826e5..c51a6c30ad 100644--- a/crates/openhuman-core/src/user_agents/host.rs+++ b/crates/openhuman-core/src/user_agents/host.rs@@ -170,6 +170,16 @@ impl AgentHost {Ok(true)}+ /// The forced config of provisioned agent `id`, without opening it (and+ /// so without taking an agent slot).+ pub fn provisioned_config(&self, id: &UserAgentId) -> Result<crate::config::Config, String> {+ let layout = self.layout(id);+ if !layout.meta_path.exists() {+ return Err(format!("agent {id} is not provisioned"));+ }+ Ok(layout::agent_config(&layout, id))+ }+/// Agent `id`, opening it if it is provisioned and not open yet.pub fn open(&self, id: &UserAgentId) -> Result<Arc<UserAgentState>, String> {let now = Instant::now();@@ -256,8 +266,12 @@ impl AgentHost {let Ok(id) = UserAgentId::parse(&name) else {continue;};- if let Some(summary) = self.summary(&id)? {- found.push(summary);+ // One unreadable agent must not hide the rest (or stop the+ // background loop for everyone): log it and move on.+ match self.summary(&id) {+ Ok(Some(summary)) => found.push(summary),+ Ok(None) => {}+ Err(error) => log::warn!("[user_agents] skipping agent={id} in listing: {error}"),}}found.sort_by(|a, b| a.agent_id.cmp(&b.agent_id));diff --git a/crates/openhuman-core/src/user_agents/host_tests.rs b/crates/openhuman-core/src/user_agents/host_tests.rsindex 5db1a50f2f..aeff78d688 100644--- a/crates/openhuman-core/src/user_agents/host_tests.rs+++ b/crates/openhuman-core/src/user_agents/host_tests.rs@@ -231,3 +231,33 @@ fn opening_an_open_agent_sweeps_the_idle_ones() {assert!(host.is_open(&b), "bob is in use and stays");drop((held, again));}++#[test]+fn one_unreadable_agent_does_not_hide_the_rest() {+ let tmp = tempfile::tempdir().unwrap();+ let host = host(&tmp, 4, 60);+ let (a, b) = (agent("alice"), agent("bob"));+ host.provision(&a).unwrap();+ host.provision(&b).unwrap();+ std::fs::write(+ UserAgentLayout::new(tmp.path(), &a).meta_path,+ "not toml = [",+ )+ .unwrap();+ let listed = host.list().unwrap();+ assert_eq!(listed.len(), 1);+ assert_eq!(listed[0].agent_id, b);+}++#[test]+fn a_provisioned_config_needs_no_agent_slot() {+ let tmp = tempfile::tempdir().unwrap();+ let host = host(&tmp, 1, 60);+ let (a, b) = (agent("alice"), agent("bob"));+ host.provision(&a).unwrap();+ host.provision(&b).unwrap();+ let _held = host.open(&a).unwrap();+ assert!(host.open(&b).is_err(), "the only slot is taken");+ assert!(host.provisioned_config(&b).is_ok());+ assert!(host.provisioned_config(&agent("nobody")).is_err());+}diff --git a/crates/openhuman-core/src/user_agents/ops.rs b/crates/openhuman-core/src/user_agents/ops.rsindex cc91288838..31b57227d4 100644--- a/crates/openhuman-core/src/user_agents/ops.rs+++ b/crates/openhuman-core/src/user_agents/ops.rs@@ -102,8 +102,10 @@ pub(crate) fn set_credential_on(expires_at: Option<&str>,) -> Result<Outcome<CredentialResult>, String> {let agent_id = UserAgentId::parse(agent_id)?;- let state = host.open(&agent_id)?;- credentials::store(&state.config, kind, token, expires_at)?;+ // From the layout, not `open`: installing or revoking a credential must+ // work even when every agent slot is busy.+ let config = host.provisioned_config(&agent_id)?;+ credentials::store(&config, kind, token, expires_at)?;log::info!("[user_agents] credential installed for agent={agent_id} kind={kind:?}");Ok(Outcome::single_log(CredentialResult {@@ -124,8 +126,8 @@ pub(crate) fn clear_credential_on(agent_id: &str,) -> Result<Outcome<CredentialResult>, String> {let agent_id = UserAgentId::parse(agent_id)?;- let state = host.open(&agent_id)?;- let removed = credentials::clear(&state.config)?;+ let config = host.provisioned_config(&agent_id)?;+ let removed = credentials::clear(&config)?;log::info!("[user_agents] credential cleared for agent={agent_id} removed={removed}");let log = if removed {format!("credential cleared for {agent_id}")