Skip to content

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

feat(agent): add attachment support to delegation tools

Steven Enamakel1e7e0759b190
diff --git a/crates/openhuman-core/src/agent/attachments/mod.rs b/crates/openhuman-core/src/agent/attachments/mod.rs
index 3786cf3b51..526eea9353 100644
--- a/crates/openhuman-core/src/agent/attachments/mod.rs
+++ b/crates/openhuman-core/src/agent/attachments/mod.rs
@@ -427,6 +427,7 @@ pub(crate) async fn stage(
/// Explicit image forwarding for delegation. A filename mentioned in prose
/// grants no read; only the typed argument or a legacy image marker does.
pub(crate) async fn delegation_prompt(
+ ctx: &crate::core::runtime::DispatchCtx,
prompt: &str,
args: &serde_json::Value,
workspace: Option<&tinytools::WorkspaceDescriptor>,
@@ -454,9 +455,7 @@ pub(crate) async fn delegation_prompt(
) {
anyhow::bail!("local attachment reads are disabled for external channel input");
}
- let mut config = crate::config::rpc::load_config_with_timeout()
- .await
- .map_err(anyhow::Error::msg)?;
+ let mut config = ctx.load_config().await.map_err(anyhow::Error::msg)?;
if let Some(workspace) = workspace {
config.action_dir = workspace.root.clone();
}
@@ -469,6 +468,7 @@ pub(crate) async fn delegation_prompt(
/// Validate a vision task's explicit references before constructing inference.
pub(crate) async fn has_resolvable_image(
+ ctx: &crate::core::runtime::DispatchCtx,
prompt: &str,
workspace: Option<&tinytools::WorkspaceDescriptor>,
origin: Option<&crate::agent::turn_origin::AgentTurnOrigin>,
@@ -487,9 +487,7 @@ pub(crate) async fn has_resolvable_image(
if paths.is_empty() {
return Ok(false);
}
- let mut config = crate::config::rpc::load_config_with_timeout()
- .await
- .map_err(anyhow::Error::msg)?;
+ let mut config = ctx.load_config().await.map_err(anyhow::Error::msg)?;
if matches!(
origin,
Some(crate::agent::turn_origin::AgentTurnOrigin::ExternalChannel { .. })
diff --git a/crates/openhuman-core/src/agent/harness/graph.rs b/crates/openhuman-core/src/agent/harness/graph.rs
index b68220c0d1..0b5625f9f9 100644
--- a/crates/openhuman-core/src/agent/harness/graph.rs
+++ b/crates/openhuman-core/src/agent/harness/graph.rs
@@ -62,6 +62,9 @@ pub(crate) async fn run_channel_turn_via_graph(
memory_identity: crate::memory::scope::MemoryIdentity,
) -> Result<crate::agent::tinyagents::TinyagentsTurnOutcome> {
let extra_arc = Arc::new(extra_tools);
+ // A channel/CLI turn is entered without a run context: bind the calling
+ // task's context here, once, and carry it on the turn's run context.
+ let dispatch = crate::core::runtime::DispatchCtx::ambient();
// The callable set is the visibility whitelist. The runner advertises each via
// its own `spec()`, deduped by name (extras shadow the registry).
@@ -102,7 +105,8 @@ pub(crate) async fn run_channel_turn_via_graph(
anyhow::bail!("attachments are disabled for this channel input");
}
if attachment_config.is_none() {
- let mut config = crate::config::rpc::load_config_with_timeout()
+ let mut config = dispatch
+ .load_config()
.await
.map_err(anyhow::Error::msg)?;
config.multimodal = multimodal.clone();
@@ -140,7 +144,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();
+ let mut run_context = crate::agent::tinyagents::host::OpenHumanRunContext::new()
+ .with_core(dispatch.into_core());
run_context.origin = origin;
run_context.approval = approval;
run_context.memory_identity = Some(memory_identity);
diff --git a/crates/openhuman-core/src/agent/orchestration/tools/archetype_delegation.rs b/crates/openhuman-core/src/agent/orchestration/tools/archetype_delegation.rs
index c871e012bd..ccd3737059 100644
--- a/crates/openhuman-core/src/agent/orchestration/tools/archetype_delegation.rs
+++ b/crates/openhuman-core/src/agent/orchestration/tools/archetype_delegation.rs
@@ -113,7 +113,10 @@ impl Tool for ArchetypeDelegationTool {
_options: ToolCallOptions,
tool_context: Option<&dyn ToolRunContext>,
) -> anyhow::Result<ToolResult> {
- let mut run_context = crate::agent::tinyagents::host::OpenHumanRunContext::new();
+ let mut run_context = crate::agent::tinyagents::host::OpenHumanRunContext::new().with_core(
+ crate::agent::tinyagents::host::run_context::dispatch_ctx_for_tool(tool_context)
+ .into_core(),
+ );
run_context.thread_id = tool_context
.and_then(ToolRunContext::thread_id)
.map(ToOwned::to_owned);
@@ -176,6 +179,7 @@ pub(crate) async fn execute_archetype_delegation_with_live_parent(
}
let prompt = render_structured_handoff(&raw_prompt, &args);
let prompt = match crate::agent::attachments::delegation_prompt(
+ &run_context.dispatch_ctx(),
&prompt,
&args,
tool_context
diff --git a/crates/openhuman-core/src/agent/orchestration/tools/collapsed_delegation.rs b/crates/openhuman-core/src/agent/orchestration/tools/collapsed_delegation.rs
index 20aee7b8e8..5a1055a2e0 100644
--- a/crates/openhuman-core/src/agent/orchestration/tools/collapsed_delegation.rs
+++ b/crates/openhuman-core/src/agent/orchestration/tools/collapsed_delegation.rs
@@ -238,7 +238,10 @@ impl Tool for CollapsedDelegationTool {
_options: ToolCallOptions,
tool_context: Option<&dyn ToolRunContext>,
) -> anyhow::Result<ToolResult> {
- let mut run_context = crate::agent::tinyagents::host::OpenHumanRunContext::new();
+ let mut run_context = crate::agent::tinyagents::host::OpenHumanRunContext::new().with_core(
+ crate::agent::tinyagents::host::run_context::dispatch_ctx_for_tool(tool_context)
+ .into_core(),
+ );
run_context.thread_id = tool_context
.and_then(ToolRunContext::thread_id)
.map(ToOwned::to_owned);
@@ -364,6 +367,7 @@ pub(crate) async fn execute_collapsed_delegation_with_live_parent(
}
let prompt = render_structured_handoff(&raw_prompt, &args);
let prompt = match crate::agent::attachments::delegation_prompt(
+ &run_context.dispatch_ctx(),
&prompt,
&args,
tool_context
diff --git a/crates/openhuman-core/src/agent/orchestration/tools/dispatch.rs b/crates/openhuman-core/src/agent/orchestration/tools/dispatch.rs
index cd9fd71d3a..c0bfc6a94c 100644
--- a/crates/openhuman-core/src/agent/orchestration/tools/dispatch.rs
+++ b/crates/openhuman-core/src/agent/orchestration/tools/dispatch.rs
@@ -251,6 +251,7 @@ pub(crate) async fn dispatch_subagent_with_live_parent(
if agent_id == "vision_agent" {
match crate::agent::attachments::has_resolvable_image(
+ &run_context.dispatch_ctx(),
prompt,
parent_workspace_descriptor.as_ref(),
run_context.origin.as_ref(),