Skip to content

The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.

refactor(config): thread dispatch context into search settings

Steven Enamakele7182b2cf0ca
diff --git a/crates/openhuman-core/src/agent/harness/graph.rs b/crates/openhuman-core/src/agent/harness/graph.rs
index 890f62dadd..976464c6be 100644
--- a/crates/openhuman-core/src/agent/harness/graph.rs
+++ b/crates/openhuman-core/src/agent/harness/graph.rs
@@ -141,8 +141,8 @@ pub(crate) async fn run_channel_turn_via_graph(
"[channel:graph] routing channel turn through tinyagents harness"
);
let turn_origin = origin.clone();
- let mut run_context =
- crate::agent::tinyagents::host::OpenHumanRunContext::new().with_core(dispatch.core().cloned());
+ let mut run_context = crate::agent::tinyagents::host::OpenHumanRunContext::new()
+ .with_core(dispatch.core().cloned());
run_context.origin = origin;
run_context.approval = approval;
run_context.memory_identity = Some(memory_identity);
diff --git a/crates/openhuman-core/src/agent/hooks_scope.rs b/crates/openhuman-core/src/agent/hooks_scope.rs
index e3c2ac076f..153f398516 100644
--- a/crates/openhuman-core/src/agent/hooks_scope.rs
+++ b/crates/openhuman-core/src/agent/hooks_scope.rs
@@ -19,7 +19,8 @@ use super::{PostTurnHook, ToolHook};
pub struct HookScope {
tools: Vec<Arc<dyn ToolHook>>,
post_turn: Vec<Arc<dyn PostTurnHook>>,
- stop: Vec<Arc<dyn tinyagents_harness::middleware::StopHook<tinyagents_harness::cost::TurnCost>>>,
+ stop:
+ Vec<Arc<dyn tinyagents_harness::middleware::StopHook<tinyagents_harness::cost::TurnCost>>>,
}
impl HookScope {
@@ -54,7 +55,8 @@ impl HookScope {
/// The scope's own stop policies, in registration order.
pub fn stop_hooks(
&self,
- ) -> &[Arc<dyn tinyagents_harness::middleware::StopHook<tinyagents_harness::cost::TurnCost>>] {
+ ) -> &[Arc<dyn tinyagents_harness::middleware::StopHook<tinyagents_harness::cost::TurnCost>>]
+ {
&self.stop
}
diff --git a/crates/openhuman-core/src/agent/host_agents.rs b/crates/openhuman-core/src/agent/host_agents.rs
index 5dca46d031..51a6ae38a6 100644
--- a/crates/openhuman-core/src/agent/host_agents.rs
+++ b/crates/openhuman-core/src/agent/host_agents.rs
@@ -71,9 +71,9 @@ impl HostAgent {
"[host_agents] building session for host agent"
);
let mut session = CoreContext::sync_scope(Arc::clone(&self.context), || {
- if crate::profiles::capabilities::ProfileCapabilities::in_ctx(&DispatchCtx::new(Arc::clone(
- &self.context,
- )))
+ if crate::profiles::capabilities::ProfileCapabilities::in_ctx(&DispatchCtx::new(
+ Arc::clone(&self.context),
+ ))
.is_some()
{
return OpenHumanSessionHost::from_config_host_only(
diff --git a/crates/openhuman-core/src/agent/session_host/builder/profile_factory.rs b/crates/openhuman-core/src/agent/session_host/builder/profile_factory.rs
index 9367ac2630..61e66a1b74 100644
--- a/crates/openhuman-core/src/agent/session_host/builder/profile_factory.rs
+++ b/crates/openhuman-core/src/agent/session_host/builder/profile_factory.rs
@@ -1,8 +1,8 @@
//! Profile session construction carries the caller's exact conversation key.
-use crate::core::runtime::DispatchCtx;
use crate::agent::OpenHumanSessionHost;
use crate::config::Config;
+use crate::core::runtime::DispatchCtx;
impl OpenHumanSessionHost {
/// Build a config-routed agent with its caller's exact conversation key.
diff --git a/crates/openhuman-core/src/agent/session_host/runtime_session/memory_ingest.rs b/crates/openhuman-core/src/agent/session_host/runtime_session/memory_ingest.rs
index ba5dbbad92..4ea28ff3aa 100644
--- a/crates/openhuman-core/src/agent/session_host/runtime_session/memory_ingest.rs
+++ b/crates/openhuman-core/src/agent/session_host/runtime_session/memory_ingest.rs
@@ -128,7 +128,10 @@ impl OpenHumanTurnPrelude {
if self.omit_memory_context {
identity.recall = false;
}
- let profile_context = capture_profile_context(&self.dispatch_ctx(), crate::profiles::host::host().as_deref());
+ let profile_context = capture_profile_context(
+ &self.dispatch_ctx(),
+ crate::profiles::host::host().as_deref(),
+ );
if matches!(profile_context, ProfileMemoryContext::Denied) {
return None;
}
diff --git a/crates/openhuman-core/src/agent/session_host/runtime_session/memory_ingest_tests.rs b/crates/openhuman-core/src/agent/session_host/runtime_session/memory_ingest_tests.rs
index bb4a15aa52..b0cb9e3e6c 100644
--- a/crates/openhuman-core/src/agent/session_host/runtime_session/memory_ingest_tests.rs
+++ b/crates/openhuman-core/src/agent/session_host/runtime_session/memory_ingest_tests.rs
@@ -90,7 +90,8 @@ async fn deferred_memory_commit_survives_the_turn_scope_without_pinning_the_prof
let id = ProfileId::parse("deferred-memory").unwrap();
host.provision(&id).await.unwrap();
let profile = host.open(&id).await.unwrap();
- let captured = capture_profile_context(&DispatchCtx::new(profile.context().clone()), Some(&host));
+ let captured =
+ capture_profile_context(&DispatchCtx::new(profile.context().clone()), Some(&host));
// The entire temporary turn context is gone before this callback is polled.
let config = profile.config.clone();
let work = async {
diff --git a/crates/openhuman-core/src/channels/runtime/dispatch/host_agent/mod.rs b/crates/openhuman-core/src/channels/runtime/dispatch/host_agent/mod.rs
index afa4eb3310..fb15cf1809 100644
--- a/crates/openhuman-core/src/channels/runtime/dispatch/host_agent/mod.rs
+++ b/crates/openhuman-core/src/channels/runtime/dispatch/host_agent/mod.rs
@@ -56,7 +56,8 @@ pub(crate) fn bound_agent_id<'a>(config: &'a Config, channel: &str) -> Option<&'
pub(crate) fn route(ctx: &ChannelRuntimeContext, channel: &str) -> HostRoute {
// Transitional (#7801): the channel runtime context carries no core yet.
let dispatch = DispatchCtx::ambient();
- if let Some(capabilities) = crate::profiles::capabilities::ProfileCapabilities::in_ctx(&dispatch)
+ if let Some(capabilities) =
+ crate::profiles::capabilities::ProfileCapabilities::in_ctx(&dispatch)
{
if let (Some(context), Some(config), Some(definitions)) = (
dispatch.core().cloned(),
diff --git a/crates/openhuman-core/src/channels/runtime/startup/turn_parts.rs b/crates/openhuman-core/src/channels/runtime/startup/turn_parts.rs
index d77b8a3274..ad3e107baf 100644
--- a/crates/openhuman-core/src/channels/runtime/startup/turn_parts.rs
+++ b/crates/openhuman-core/src/channels/runtime/startup/turn_parts.rs
@@ -6,13 +6,13 @@
//! the caller's own config and policy, so a relayed turn never runs with the
//! operator's tools or workspace.
-use crate::core::runtime::DispatchCtx;
use super::chat_workload::{resolve_chat_workload, ChatWorkloadResolution};
use super::prompt::format_access_context;
use crate::agent::host_runtime;
use crate::channels::context::ChannelRuntimeContext;
use crate::channels::system_prompt::{ChannelPromptInputs, ChannelSystemPrompt};
use crate::config::Config;
+use crate::core::runtime::DispatchCtx;
use crate::inference::provider;
use crate::security::SecurityPolicy;
use crate::tools;
@@ -142,7 +142,8 @@ pub(crate) fn build_channel_turn_parts(
config.workspace_dir.clone(),
)?;
let workspace = config.workspace_dir.clone();
- let capabilities = crate::profiles::capabilities::ProfileCapabilities::in_ctx(&DispatchCtx::ambient());
+ let capabilities =
+ crate::profiles::capabilities::ProfileCapabilities::in_ctx(&DispatchCtx::ambient());
let tools_registry = Arc::new(if capabilities.is_some() {
// The profile host route builds the selected belt once with the exact
// durable thread. No second, unnamed factory invocation is needed here.
diff --git a/crates/openhuman-core/src/config/ops/search.rs b/crates/openhuman-core/src/config/ops/search.rs
index 70de133919..43de6c7f93 100644
--- a/crates/openhuman-core/src/config/ops/search.rs
+++ b/crates/openhuman-core/src/config/ops/search.rs
@@ -289,13 +289,14 @@ pub fn apply_search_patch(config: &mut Config, update: SearchSettingsPatch) -> R
/// Validate, save, refresh the module, and return the new settings.
pub async fn apply_search_settings(
+ ctx: &DispatchCtx,
config: &mut Config,
update: SearchSettingsPatch,
) -> Result<Outcome<Value>, String> {
apply_search_patch(config, update)?;
config.save().await.map_err(|e| e.to_string())?;
#[cfg(feature = "modules")]
- crate::modules::search::refresh_loaded(&crate::core::runtime::DispatchCtx::ambient(), config).await?;
+ crate::modules::search::refresh_loaded(ctx, config).await?;
tracing::debug!(
enabled = crate::search::is_active(config),
providers = ?config.search.enabled_provider_names(),
@@ -315,7 +316,7 @@ pub async fn load_and_apply_search_settings(
update: SearchSettingsPatch,
) -> Result<Outcome<Value>, String> {
let mut config = ctx.load_config().await?;
- apply_search_settings(&mut config, update).await
+ apply_search_settings(ctx, &mut config, update).await
}
/// The settings view: every listed provider's resolved state, the role
diff --git a/crates/openhuman-core/src/config/ops_loader_and_search_tests.rs b/crates/openhuman-core/src/config/ops_loader_and_search_tests.rs
index ad8546121b..ef46cfdbad 100644
--- a/crates/openhuman-core/src/config/ops_loader_and_search_tests.rs
+++ b/crates/openhuman-core/src/config/ops_loader_and_search_tests.rs
@@ -443,7 +443,13 @@ async fn apply_search_settings_sets_and_clears_allowed_domains() {
]),
..Default::default()
};
- apply_search_settings(&mut cfg, patch).await.expect("apply");
+ apply_search_settings(
+ &crate::core::runtime::DispatchCtx::unbound(),
+ &mut cfg,
+ patch,
+ )
+ .await
+ .expect("apply");
assert_eq!(
cfg.http_request.allowed_domains,
vec!["github.com".to_string(), "reuters.com".to_string()]
@@ -454,7 +460,13 @@ async fn apply_search_settings_sets_and_clears_allowed_domains() {
allow_all: Some(true),
..Default::default()
};
- apply_search_settings(&mut cfg, patch).await.expect("apply");
+ apply_search_settings(
+ &crate::core::runtime::DispatchCtx::unbound(),
+ &mut cfg,
+ patch,
+ )
+ .await
+ .expect("apply");
assert_eq!(cfg.http_request.allowed_domains, vec!["*".to_string()]);
// allow_all = false drops the wildcard (explicit hosts only / blocked).
@@ -462,7 +474,13 @@ async fn apply_search_settings_sets_and_clears_allowed_domains() {
allow_all: Some(false),
..Default::default()
};
- apply_search_settings(&mut cfg, patch).await.expect("apply");
+ apply_search_settings(
+ &crate::core::runtime::DispatchCtx::unbound(),
+ &mut cfg,
+ patch,
+ )
+ .await
+ .expect("apply");
assert!(cfg.http_request.allowed_domains.is_empty());
}
@@ -472,6 +490,7 @@ async fn apply_search_settings_accepts_disabled_engine() {
let mut cfg = tmp_config(&tmp);
let result = apply_search_settings(
+ &crate::core::runtime::DispatchCtx::unbound(),
&mut cfg,
SearchSettingsPatch {
engine: Some("disabled".to_string()),
@@ -495,9 +514,13 @@ async fn apply_search_settings_stores_and_clears_tavily_key() {
"roles": {"search": ["tavily", "exa"]}
}))
.unwrap();
- let result = apply_search_settings(&mut cfg, enable)
- .await
- .expect("save Tavily settings");
+ let result = apply_search_settings(
+ &crate::core::runtime::DispatchCtx::unbound(),
+ &mut cfg,
+ enable,
+ )
+ .await
+ .expect("save Tavily settings");
let tavily = result.value["providers"]
.as_array()
.unwrap()
@@ -515,9 +538,13 @@ async fn apply_search_settings_stores_and_clears_tavily_key() {
"providers": {"tavily": {"api_key": " "}}
}))
.unwrap();
- let result = apply_search_settings(&mut cfg, clear)
- .await
- .expect("clear Tavily key");
+ let result = apply_search_settings(
+ &crate::core::runtime::DispatchCtx::unbound(),
+ &mut cfg,
+ clear,
+ )
+ .await
+ .expect("clear Tavily key");
assert!(cfg.search.tavily.api_key.is_none());
assert!(!result.value["effective_roles"]["search"]
.as_array()
@@ -532,6 +559,7 @@ async fn apply_search_settings_rejects_unknown_search_engine() {
let mut cfg = tmp_config(&tmp);
let err = apply_search_settings(
+ &crate::core::runtime::DispatchCtx::unbound(),
&mut cfg,
SearchSettingsPatch {
engine: Some("unknown".to_string()),
diff --git a/crates/openhuman-core/src/core/runtime/dispatch_ctx_tests.rs b/crates/openhuman-core/src/core/runtime/dispatch_ctx_tests.rs
index 1c9a399fdf..356fd8ca7b 100644
--- a/crates/openhuman-core/src/core/runtime/dispatch_ctx_tests.rs
+++ b/crates/openhuman-core/src/core/runtime/dispatch_ctx_tests.rs
@@ -63,7 +63,9 @@ async fn explicit_turn_origin_wins_over_the_scoped_one_and_does_not_cross() {
assert_eq!(thread_of(&explicit), "b");
assert_eq!(explicit.turn_origin_or_scoped().map(|_| ()), Some(()));
let moved = explicit.clone();
- let from_task = tokio::spawn(async move { thread_of(&moved) }).await.unwrap();
+ let from_task = tokio::spawn(async move { thread_of(&moved) })
+ .await
+ .unwrap();
assert_eq!(from_task, "b");
assert_eq!(thread_of(&DispatchCtx::new(Arc::clone(&a))), "a");
})
diff --git a/crates/openhuman-core/src/modules/search/proxy_tests.rs b/crates/openhuman-core/src/modules/search/proxy_tests.rs
index 7a0ca2b362..1ccc36b247 100644
--- a/crates/openhuman-core/src/modules/search/proxy_tests.rs
+++ b/crates/openhuman-core/src/modules/search/proxy_tests.rs
@@ -168,7 +168,9 @@ async fn a_host_pinned_config_is_used_as_given_without_reading_config_path() {
)
.unwrap();
// No config.toml exists; a reload would come back without the pin.
- let current = current_config(&DispatchCtx::unbound(), &config).await.unwrap();
+ let current = current_config(&DispatchCtx::unbound(), &config)
+ .await
+ .unwrap();
assert_eq!(current.search.direct_key("tavily"), Some("agent-key"));
assert!(current.search.is_host_pinned());
assert!(!config.config_path.exists(), "nothing was written");
@@ -183,7 +185,9 @@ async fn an_unpinned_config_is_reloaded_from_config_path() {
std::fs::write(&on_disk.config_path, toml::to_string(&on_disk).unwrap()).unwrap();
// The caller's snapshot is stale: the file has since gained a key.
let stale = file_backed_config(dir.path());
- let current = current_config(&DispatchCtx::unbound(), &stale).await.unwrap();
+ let current = current_config(&DispatchCtx::unbound(), &stale)
+ .await
+ .unwrap();
assert_eq!(current.search.direct_key("tavily"), Some("file-key"));
}
diff --git a/crates/openhuman-core/src/platform/about_app/ops_tests.rs b/crates/openhuman-core/src/platform/about_app/ops_tests.rs
index fbb1be9d13..ef299ef6ed 100644
--- a/crates/openhuman-core/src/platform/about_app/ops_tests.rs
+++ b/crates/openhuman-core/src/platform/about_app/ops_tests.rs
@@ -82,7 +82,10 @@ async fn an_explicit_context_decides_which_capabilities_are_disabled() {
// The two contexts answer independently, concurrently and across awaits.
let ask = |ctx: DispatchCtx| async move {
tokio::task::yield_now().await;
- lookup_capability(&ctx, "voice.ptt").expect("voice.ptt").value.status
+ lookup_capability(&ctx, "voice.ptt")
+ .expect("voice.ptt")
+ .value
+ .status
};
let (disabled, enabled) = tokio::join!(ask(off), ask(on));
assert_eq!(disabled, CapabilityStatus::Disabled);
diff --git a/crates/openhuman-core/src/platform/about_app/schemas.rs b/crates/openhuman-core/src/platform/about_app/schemas.rs
index 7e9ad86f7e..9527d40b50 100644
--- a/crates/openhuman-core/src/platform/about_app/schemas.rs
+++ b/crates/openhuman-core/src/platform/about_app/schemas.rs
@@ -114,7 +114,9 @@ fn handle_about_app_list(ctx: DispatchCtx, params: Map<String, Value>) -> Contro
.transpose()?;
tracing::debug!(?category, "[about_app] list capabilities");
- to_json(crate::platform::about_app::list_capabilities(&ctx, category))
+ to_json(crate::platform::about_app::list_capabilities(
+ &ctx, category,
+ ))
})
}
@@ -122,7 +124,10 @@ fn handle_about_app_lookup(ctx: DispatchCtx, params: Map<String, Value>) -> Cont
Box::pin(async move {
let payload = deserialize_params::<AboutAppLookupParams>(params)?;
tracing::debug!(id = %payload.id, "[about_app] lookup capability");
- to_json(crate::platform::about_app::lookup_capability(&ctx, &payload.id)?)
+ to_json(crate::platform::about_app::lookup_capability(
+ &ctx,
+ &payload.id,
+ )?)
})
}
diff --git a/crates/openhuman-core/src/profiles/capabilities.rs b/crates/openhuman-core/src/profiles/capabilities.rs
index ea1b680a9c..37c7f36501 100644
--- a/crates/openhuman-core/src/profiles/capabilities.rs
+++ b/crates/openhuman-core/src/profiles/capabilities.rs
@@ -150,7 +150,9 @@ impl ProfileCapabilities {
.unwrap_or_default();
// Transitional (#7801): the host-tools factory carries no context yet.
let dispatch = DispatchCtx::ambient();
- supplied.tools.retain(|tool| self.admits(&dispatch, tool.name()));
+ supplied
+ .tools
+ .retain(|tool| self.admits(&dispatch, tool.name()));
if let Some(names) = &self.names {
let mut groups = ToolGroups::none();
for name in names.iter().filter(|name| self.admits(&dispatch, name)) {
@@ -206,7 +208,8 @@ impl ProfileCapabilities {
.filter(|tool| tool.name() != "web_search_tool")
.chain(search)
.filter(|tool| {
- self.admits(&dispatch, tool.name()) && !supplied_names.contains(tool.name())
+ self.admits(&dispatch, tool.name())
+ && !supplied_names.contains(tool.name())
}),
);
}
@@ -264,10 +267,7 @@ impl ToolHook for ProfilePermission {
async fn before_tool_decision(&self, context: &ToolHookContext) -> ToolHookDecision {
// The hook runs inside the turn's own task, so its tenant is the ambient one.
let dispatch = DispatchCtx::ambient();
- let tenant = dispatch
- .tenant()
- .ok()
- .and_then(|tenant| tenant.profile);
+ let tenant = dispatch.tenant().ok().and_then(|tenant| tenant.profile);
if tenant.as_deref() != Some(self.profile.as_str())
|| self.fence.check_local(super::lease::now_ms()).is_err()
|| !self.capabilities.admits(&dispatch, &context.tool_name)
diff --git a/crates/openhuman-core/src/profiles/tools.rs b/crates/openhuman-core/src/profiles/tools.rs
index 6798446940..721994c33e 100644
--- a/crates/openhuman-core/src/profiles/tools.rs
+++ b/crates/openhuman-core/src/profiles/tools.rs
@@ -27,8 +27,8 @@
use std::path::Path;
-use crate::core::runtime::{is_saas, DispatchCtx};
use crate::core::runtime::saas::SaasSandboxConfig;
+use crate::core::runtime::{is_saas, DispatchCtx};
use crate::sandbox::{DockerOverrides, SandboxBackendKind, SandboxPolicy};
/// A group of host tools an operator can opt users into.
diff --git a/crates/openhuman-core/src/threads/ops_title_and_cancellation_tests.rs b/crates/openhuman-core/src/threads/ops_title_and_cancellation_tests.rs
index f0ca714187..59656f869d 100644
--- a/crates/openhuman-core/src/threads/ops_title_and_cancellation_tests.rs
+++ b/crates/openhuman-core/src/threads/ops_title_and_cancellation_tests.rs
@@ -69,13 +69,17 @@ async fn run_to_completion_runs_the_tail_after_the_caller_is_dropped() {
let (release, parked) = tokio::sync::oneshot::channel::<()>();
let dispatch = crate::core::runtime::DispatchCtx::unbound();
- let mut call = Box::pin(run_to_completion(&dispatch, "test_destructive_op", async move {
- // Stands in for the blocking store mutation still in progress.
- let _ = parked.await;
- // Stands in for the cleanup that must never be skipped.
- flag.store(true, Ordering::SeqCst);
- Ok::<(), String>(())
- }));
+ let mut call = Box::pin(run_to_completion(
+ &dispatch,
+ "test_destructive_op",
+ async move {
+ // Stands in for the blocking store mutation still in progress.
+ let _ = parked.await;
+ // Stands in for the cleanup that must never be skipped.
+ flag.store(true, Ordering::SeqCst);
+ Ok::<(), String>(())
+ },
+ ));
// Poll once so the inner task is spawned, then abandon the caller — exactly
// what dropping the RPC future does.
diff --git a/crates/openhuman-core/src/tinymemes/search.rs b/crates/openhuman-core/src/tinymemes/search.rs
index 57325637ea..5d9c81fe75 100644
--- a/crates/openhuman-core/src/tinymemes/search.rs
+++ b/crates/openhuman-core/src/tinymemes/search.rs
@@ -50,8 +50,8 @@ impl OpenHumanSearch {
&self.config,
request,
)
- .await
- .map_err(|e| crate::search::tools::user_facing_error(&e))?;
+ .await
+ .map_err(|e| crate::search::tools::user_facing_error(&e))?;
Ok(response
.results
.into_iter()