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(agent): load turn-time config from the agent context (#7032)
oxoxDevc8fe489fd59c
diff --git a/crates/openhuman-core/src/agent/multimodal.rs b/crates/openhuman-core/src/agent/multimodal.rsindex 19e5190401..877911a5f2 100644--- a/crates/openhuman-core/src/agent/multimodal.rs+++ b/crates/openhuman-core/src/agent/multimodal.rs@@ -125,7 +125,7 @@ impl TextExtractor for DocumentsTextExtractor {use crate::modules::documents;match tokio::time::timeout(PDF_EXTRACTION_TIMEOUT, async {- let config = crate::config::Config::load_or_init()+ let config = crate::config::ops::load_current_or_init().await.map_err(|error| format!("config unavailable for pdf extraction: {error}"))?;documents::extract_text(&config, bytes)diff --git a/crates/openhuman-core/src/agent/orchestration/background_delivery.rs b/crates/openhuman-core/src/agent/orchestration/background_delivery.rsindex d6f6d38e21..435d6a8302 100644--- a/crates/openhuman-core/src/agent/orchestration/background_delivery.rs+++ b/crates/openhuman-core/src/agent/orchestration/background_delivery.rs@@ -205,7 +205,7 @@ async fn try_deliver(session: String) {/// failing as well as the agent.async fn persist_undelivered(thread_id: String, notice: String) {let run_id = format!("bgdeliver-undelivered-{}", uuid::Uuid::new_v4());- let config = match crate::config::Config::load_or_init().await {+ let config = match crate::config::ops::load_current_or_init().await {Ok(config) => config,Err(error) => {log::error!(@@ -359,7 +359,7 @@ where/// later cold-boot resume would prefer — which is how a restart used to drop/// every turn before the delivery notice.async fn run_system_turn_on_thread(thread_id: String, prompt: String) -> Result<String, String> {- let config = crate::config::Config::load_or_init()+ let config = crate::config::ops::load_current_or_init().await.map_err(|error| format!("load config: {error:#}"))?;let run_id = format!("bgdeliver-{}", uuid::Uuid::new_v4());diff --git a/crates/openhuman-core/src/agent/orchestration/tools/delegate_graph.rs b/crates/openhuman-core/src/agent/orchestration/tools/delegate_graph.rsindex 46e18e27b0..d795c944c9 100644--- a/crates/openhuman-core/src/agent/orchestration/tools/delegate_graph.rs+++ b/crates/openhuman-core/src/agent/orchestration/tools/delegate_graph.rs@@ -12,7 +12,6 @@use crate::agent::harness::definition::AgentDefinitionRegistry;use crate::agent::orchestration::delegation::run_subagent_delegation_with_parent_context;-use crate::config::Config;use async_trait::async_trait;use serde_json::json;use std::sync::Arc;@@ -229,7 +228,7 @@ impl DelegateGraphTool {}};- let config = match Config::load_or_init().await {+ let config = match crate::config::ops::load_current_or_init().await {Ok(cfg) => Arc::new(cfg),Err(e) => {return Ok(ToolResult::error(format!(diff --git a/crates/openhuman-core/src/agent/orchestration/workflow_runs/engine/lifecycle.rs b/crates/openhuman-core/src/agent/orchestration/workflow_runs/engine/lifecycle.rsindex 143dcdc640..d16a303246 100644--- a/crates/openhuman-core/src/agent/orchestration/workflow_runs/engine/lifecycle.rs+++ b/crates/openhuman-core/src/agent/orchestration/workflow_runs/engine/lifecycle.rs@@ -69,7 +69,7 @@ pub async fn start_workflow_run(// Inherit-only: `None` leaves the loop unlabelled and failing closed.let inherited_origin = crate::agent::turn_origin::capture();crate::core::runtime::spawn_scoped(async move {- match Config::load_or_init().await {+ match crate::config::ops::load_current_or_init().await {Ok(task_config) => {crate::agent::turn_origin::with_inherited_origin(inherited_origin,@@ -209,7 +209,7 @@ pub async fn resume_workflow_run(config: &Config, id: &str) -> Result<WorkflowRu// loop runs on a fresh task, which would otherwise drop the caller's label.let inherited_origin = crate::agent::turn_origin::capture();crate::core::runtime::spawn_scoped(async move {- match Config::load_or_init().await {+ match crate::config::ops::load_current_or_init().await {Ok(task_config) => {crate::agent::turn_origin::with_inherited_origin(inherited_origin,diff --git a/crates/openhuman-core/src/agent/session_host/prelude_integrations.rs b/crates/openhuman-core/src/agent/session_host/prelude_integrations.rsindex f57d7ffe69..70acceab48 100644--- a/crates/openhuman-core/src/agent/session_host/prelude_integrations.rs+++ b/crates/openhuman-core/src/agent/session_host/prelude_integrations.rs@@ -195,7 +195,7 @@ impl OpenHumanTurnPrelude {}let config = match self.runtime_config.clone() {Some(config) => Some(config),- None => crate::config::Config::load_or_init()+ None => crate::config::ops::load_current_or_init().await.ok().map(Arc::new),@@ -244,7 +244,7 @@ impl OpenHumanTurnPrelude {let skills_changed = self.drain_host_events();let config = match self.runtime_config.clone() {Some(config) => Some(config),- None => crate::config::Config::load_or_init()+ None => crate::config::ops::load_current_or_init().await.ok().map(Arc::new),diff --git a/crates/openhuman-core/src/agent/session_import/live.rs b/crates/openhuman-core/src/agent/session_import/live.rsindex 1dd6aca711..de4e3cfb21 100644--- a/crates/openhuman-core/src/agent/session_import/live.rs+++ b/crates/openhuman-core/src/agent/session_import/live.rs@@ -99,7 +99,7 @@ pub async fn session_kv_store() -> Option<Arc<dyn Store>> {log::debug!("[session-store] registering the host session store's kv on RunContext.stores");return Some(stores.kv);}- let cfg = match crate::config::Config::load_or_init().await {+ let cfg = match crate::config::ops::load_current_or_init().await {Ok(cfg) => cfg,Err(err) => {log::warn!("[session-store] cannot resolve config for store registration: {err:#}");diff --git a/crates/openhuman-core/src/agent/subagent_host/ops/runner.rs b/crates/openhuman-core/src/agent/subagent_host/ops/runner.rsindex 1dcafc655b..7f89843dc1 100644--- a/crates/openhuman-core/src/agent/subagent_host/ops/runner.rs+++ b/crates/openhuman-core/src/agent/subagent_host/ops/runner.rs@@ -322,7 +322,7 @@ pub(crate) async fn run_subagent_direct(// Deliberately placed *after* `tier_gate_decision`: `load_or_init` can// initialize config on first run, and a spawn the tier gate rejects// should not have that side effect.- let loaded_config: LoadedConfig = Box::pin(crate::config::Config::load_or_init())+ let loaded_config: LoadedConfig = Box::pin(crate::config::ops::load_current_or_init()).await.map(std::sync::Arc::new).map_err(|e| e.to_string());diff --git a/crates/openhuman-core/src/agent/tinyagents/journal.rs b/crates/openhuman-core/src/agent/tinyagents/journal.rsindex 4b81b1187f..6a1e3eb52a 100644--- a/crates/openhuman-core/src/agent/tinyagents/journal.rs+++ b/crates/openhuman-core/src/agent/tinyagents/journal.rs@@ -95,7 +95,7 @@ pub(crate) fn take_request_journal_run(request_id: &str) -> Option<String> {/// `tinyagents_store/` subtree holds the journal + kv stores. Async because the/// config load is async; errors are surfaced so callers can log-and-skip.async fn resolve_workspace() -> anyhow::Result<PathBuf> {- let config = crate::config::Config::load_or_init()+ let config = crate::config::ops::load_current_or_init().await.map_err(|e| anyhow::anyhow!("[journal] load config for workspace: {e}"))?;Ok(config.workspace_dir)diff --git a/crates/openhuman-core/src/agent/tinyagents/payload_summarizer.rs b/crates/openhuman-core/src/agent/tinyagents/payload_summarizer.rsindex f2977283ad..70b0ce4890 100644--- a/crates/openhuman-core/src/agent/tinyagents/payload_summarizer.rs+++ b/crates/openhuman-core/src/agent/tinyagents/payload_summarizer.rs@@ -110,7 +110,7 @@ impl PayloadSummarizer for SubagentPayloadSummarizer {Ok(Box::new(move |request: GenerateRequest| {Box::pin(async move {- let config_loaded = crate::config::Config::load_or_init().await;+ let config_loaded = crate::config::ops::load_current_or_init().await;let (source, model) = subagent_host::resolve_subagent_source(&definition.model,&definition.id,diff --git a/crates/openhuman-core/src/agent/tinyagents/replay/schemas.rs b/crates/openhuman-core/src/agent/tinyagents/replay/schemas.rsindex a17edb970f..9393c5a9b9 100644--- a/crates/openhuman-core/src/agent/tinyagents/replay/schemas.rs+++ b/crates/openhuman-core/src/agent/tinyagents/replay/schemas.rs@@ -221,7 +221,7 @@ fn replay_schema(function: &str) -> ControllerSchema {/// Resolve the configured internal workspace whose `tinyagents_store/` holds the/// journal + status stores.async fn configured_workspace() -> Result<std::path::PathBuf, String> {- let config = crate::config::Config::load_or_init()+ let config = crate::config::ops::load_current_or_init().await.map_err(|e| format!("failed to load config: {e}"))?;Ok(config.workspace_dir)diff --git a/crates/openhuman-core/src/agent/tools/todo.rs b/crates/openhuman-core/src/agent/tools/todo.rsindex 59fb348e13..93e53bea7e 100644--- a/crates/openhuman-core/src/agent/tools/todo.rs+++ b/crates/openhuman-core/src/agent/tools/todo.rs@@ -59,7 +59,7 @@ impl ToolDispatch<(), crate::agent::tinyagents::host::OpenHumanRunContext> for Tlet context = ToolExecutionContext::from_run_context(parent, call_id);let workspace_dir = match parent.data.parent.as_ref() {Some(parent_ctx) => parent_ctx.workspace_dir.clone(),- None => crate::config::Config::load_or_init()+ None => crate::config::ops::load_current_or_init().await.map(|c| c.workspace_dir).map_err(|e| anyhow::anyhow!("[tool][todo] load config: {e}"))?,diff --git a/crates/openhuman-core/src/agent/triage/escalation.rs b/crates/openhuman-core/src/agent/triage/escalation.rsindex 53f72804be..cf9b0336a0 100644--- a/crates/openhuman-core/src/agent/triage/escalation.rs+++ b/crates/openhuman-core/src/agent/triage/escalation.rs@@ -240,7 +240,7 @@ async fn dispatch_target_agent(agent_id: &str, prompt: &str) -> anyhow::Result<S));}- let config = Config::load_or_init()+ let config = crate::config::ops::load_current_or_init().await.context("loading config for sub-agent dispatch")?;diff --git a/crates/openhuman-core/src/agent/triage/evaluator/chain.rs b/crates/openhuman-core/src/agent/triage/evaluator/chain.rsindex 36df152441..08f116b842 100644--- a/crates/openhuman-core/src/agent/triage/evaluator/chain.rs+++ b/crates/openhuman-core/src/agent/triage/evaluator/chain.rs@@ -7,7 +7,6 @@ use std::time::Duration;use anyhow::Context;-use crate::config::Config;use crate::cron::scheduler_gate::LlmPermit;use super::super::envelope::TriggerEnvelope;@@ -77,7 +76,7 @@ fn retry_state() -> &'static RetryState {/// 5. On local failure, return `TriageOutcome::Deferred` so the/// caller can retry when a local arm is available.pub async fn run_triage(envelope: &TriggerEnvelope) -> anyhow::Result<TriageOutcome> {- let config = Config::load_or_init()+ let config = crate::config::ops::load_current_or_init().await.context("loading config for triage turn")?;let cloud = resolve_provider_with_config(&config)diff --git a/crates/openhuman-core/src/config/ops/loader.rs b/crates/openhuman-core/src/config/ops/loader.rsindex fa25a8f0fa..8e58075f63 100644--- a/crates/openhuman-core/src/config/ops/loader.rs+++ b/crates/openhuman-core/src/config/ops/loader.rs@@ -7,8 +7,8 @@ mod runtime_flags;mod snapshot;pub use load::{- load_config_for_workspace_with_timeout, load_config_with_timeout, reload_config_from_paths,- reload_config_snapshot_with_timeout,+ load_config_for_workspace_with_timeout, load_config_with_timeout, load_current_or_init,+ reload_config_from_paths, reload_config_snapshot_with_timeout,};pub(crate) use paths::fallback_workspace_dir;#[cfg(test)]diff --git a/crates/openhuman-core/src/config/ops/loader/load.rs b/crates/openhuman-core/src/config/ops/loader/load.rsindex 0f991b6e4e..ccbab1f5d0 100644--- a/crates/openhuman-core/src/config/ops/loader/load.rs+++ b/crates/openhuman-core/src/config/ops/loader/load.rs@@ -49,6 +49,27 @@ pub async fn load_config_with_timeout() -> Result<Config, String> {}}+/// The config of the ambient context: an embedded agent's own config under+/// its context, else the persisted config (initialised on first run).+///+/// The context-aware counterpart of [`Config::load_or_init`] for code that+/// runs inside a turn. Unlike [`load_config_with_timeout`], it keeps the+/// `anyhow` error and adds no timeout.+pub async fn load_current_or_init() -> anyhow::Result<Config> {+ if let Some(mut config) = crate::core::runtime::context::CoreContext::current_embedder_config()+ {+ tracing::trace!(+ agent = crate::core::runtime::agent_scope::current_agent_id()+ .as_deref()+ .unwrap_or(""),+ "[config] using the context's config"+ );+ normalize_loaded_config(&mut config).await;+ return Ok(config);+ }+ Config::load_or_init().await+}+/// Loads the config that belongs to `workspace_dir`, rather than whichever one/// the process-global active-user / `OPENHUMAN_WORKSPACE` resolution currently/// selects.diff --git a/crates/openhuman-core/src/config/ops/mod.rs b/crates/openhuman-core/src/config/ops/mod.rsindex d3718bddad..36a739dd29 100644--- a/crates/openhuman-core/src/config/ops/mod.rs+++ b/crates/openhuman-core/src/config/ops/mod.rs@@ -24,9 +24,9 @@ pub use loader::{agent_server_status, client_config_json, core_rpc_url_from_env, get_config_snapshot,get_dashboard_settings, get_data_paths, get_data_paths_for_user, get_runtime_flags,load_and_get_client_config_snapshot, load_and_get_config_snapshot,- load_config_for_workspace_with_timeout, load_config_with_timeout, reload_config_from_paths,- reload_config_snapshot_with_timeout, reset_local_data, set_browser_allow_all,- snapshot_config_json, RuntimeFlagsOut,+ load_config_for_workspace_with_timeout, load_config_with_timeout, load_current_or_init,+ reload_config_from_paths, reload_config_snapshot_with_timeout, reset_local_data,+ set_browser_allow_all, snapshot_config_json, RuntimeFlagsOut,};// expose internal helpers needed by tests (ops_tests.rs uses super::*)#[cfg(test)]