Skip to content

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

refactor(agent): thread DispatchCtx through session host construction

Steven Enamakel3bab57bdce89
diff --git a/crates/openhuman-core/src/agent/debug/mod.rs b/crates/openhuman-core/src/agent/debug/mod.rs
index d75c42c476..2c1b247b5e 100644
--- a/crates/openhuman-core/src/agent/debug/mod.rs
+++ b/crates/openhuman-core/src/agent/debug/mod.rs
@@ -175,7 +175,7 @@ async fn load_dump_config(
/// Build a real [`Agent`] via `from_config_for_agent`, populate live
/// connected integrations, and render the turn-1 system prompt.
async fn render_via_session(config: &Config, agent_id: &str) -> Result<DumpedPrompt> {
- let mut agent = OpenHumanSessionHost::from_config_for_agent(config, agent_id)
+ let mut agent = OpenHumanSessionHost::from_config_for_agent(&crate::core::runtime::DispatchCtx::host_default(), config, agent_id)
.with_context(|| format!("building session agent for `{agent_id}`"))?;
// Match turn-1 behaviour: fetch the user's active Composio
diff --git a/crates/openhuman-core/src/cron/scheduler/agent_run.rs b/crates/openhuman-core/src/cron/scheduler/agent_run.rs
index c2ae4d956a..2c6e176008 100644
--- a/crates/openhuman-core/src/cron/scheduler/agent_run.rs
+++ b/crates/openhuman-core/src/cron/scheduler/agent_run.rs
@@ -152,7 +152,7 @@ pub(super) async fn run_agent_job_for_run(
target = ?job.session_target,
"[cron] building isolated agent for scheduled job"
);
- match build_agent_for_cron_job(&effective, job) {
+ match build_agent_for_cron_job(&crate::core::runtime::DispatchCtx::ambient(), &effective, job) {
Ok(BuiltCronAgent { mut agent, context }) => {
// Tag events so downstream subscribers can correlate
// cron-triggered turns. `cron` is the channel so the
@@ -269,6 +269,7 @@ pub(super) struct BuiltCronAgent {
/// Build the session a cron agent job runs: the host-registered agent named
/// by `job.agent_id` when there is one, else the registry definition.
pub(super) fn build_agent_for_cron_job(
+ ctx: &crate::core::runtime::DispatchCtx,
config: &Config,
job: &CronJob,
) -> anyhow::Result<BuiltCronAgent> {
@@ -276,10 +277,11 @@ pub(super) fn build_agent_for_cron_job(
.agent_id
.as_deref()
.and_then(crate::agent::host_agents::resolve);
- build_cron_agent(config, job, host_agent)
+ build_cron_agent(ctx, config, job, host_agent)
}
fn build_cron_agent(
+ ctx: &crate::core::runtime::DispatchCtx,
config: &Config,
job: &CronJob,
host_agent: Option<crate::agent::host_agents::HostAgent>,
@@ -304,7 +306,7 @@ fn build_cron_agent(
});
}
let agent_id = job.agent_id.as_deref().unwrap_or("orchestrator");
- match OpenHumanSessionHost::from_config_for_agent(config, agent_id) {
+ match OpenHumanSessionHost::from_config_for_agent(ctx, config, agent_id) {
Ok(agent) => {
tracing::debug!(
job_id = %job.id,
@@ -323,7 +325,7 @@ fn build_cron_agent(
error = %e,
"[cron] failed to build agent from definition; falling back to canonical orchestrator"
);
- OpenHumanSessionHost::from_config_for_agent(config, "orchestrator").map(|agent| {
+ OpenHumanSessionHost::from_config_for_agent(ctx, config, "orchestrator").map(|agent| {
BuiltCronAgent {
agent,
context: None,
diff --git a/crates/openhuman-core/src/flows/tinyflows/caps/agent.rs b/crates/openhuman-core/src/flows/tinyflows/caps/agent.rs
index e090c45ff3..09897eaa51 100644
--- a/crates/openhuman-core/src/flows/tinyflows/caps/agent.rs
+++ b/crates/openhuman-core/src/flows/tinyflows/caps/agent.rs
@@ -375,7 +375,11 @@ impl OpenHumanAgentRunner {
let built = match &host {
Some(host) => host.session_host(effective.as_ref(), None),
- None => OpenHumanSessionHost::from_config_for_agent(effective.as_ref(), agent_ref),
+ None => OpenHumanSessionHost::from_config_for_agent(
+ &crate::core::runtime::DispatchCtx::ambient(),
+ effective.as_ref(),
+ agent_ref,
+ ),
};
let mut agent = built.map_err(|e| {
EngineError::Capability(format!(
diff --git a/crates/openhuman-core/src/skills/runtime/run_machinery.rs b/crates/openhuman-core/src/skills/runtime/run_machinery.rs
index aa8bcc250f..f0b6cb2f51 100644
--- a/crates/openhuman-core/src/skills/runtime/run_machinery.rs
+++ b/crates/openhuman-core/src/skills/runtime/run_machinery.rs
@@ -183,7 +183,11 @@ pub async fn spawn_workflow_run_background(
config.http_request.allowed_domains = vec!["*".to_string()];
}
let mut agent =
- match OpenHumanSessionHost::from_config_for_agent(&config, "orchestrator") {
+ match OpenHumanSessionHost::from_config_for_agent(
+ &crate::core::runtime::DispatchCtx::ambient(),
+ &config,
+ "orchestrator",
+ ) {
Ok(a) => a,
Err(e) => {
let _ = run_log::write_footer(