Skip to content

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

feat(agent_chat): stage host attachments for definition turns

Steven Enamakele80361037f47
diff --git a/crates/openhuman-core/src/inference/host_runtime/ops/agent_chat.rs b/crates/openhuman-core/src/inference/host_runtime/ops/agent_chat.rs
index 2a92ebaa89..1f446ac0da 100644
--- a/crates/openhuman-core/src/inference/host_runtime/ops/agent_chat.rs
+++ b/crates/openhuman-core/src/inference/host_runtime/ops/agent_chat.rs
@@ -171,6 +171,17 @@ pub enum AgentChatTarget<'a> {
shape: Option<
&'a std::sync::Arc<crate::agent::tinyagents::response_shape::ResponseShapeScope>,
>,
+ /// Files the host attaches to this turn as bytes, in order.
+ ///
+ /// Rides the target for the same reason `host` does: only an
+ /// in-process caller can hand over bytes, and `AGENT_CHAT` carries a
+ /// string. Each is staged into the acting workspace and reaches the
+ /// model as an image or document block ahead of the message, under
+ /// the configured multimodal count and size limits. No local path is
+ /// read, so they are accepted whatever the turn's origin.
+ ///
+ /// Empty for every caller that attaches nothing.
+ attachments: &'a [crate::agent::HostAttachment],
},
}
@@ -190,6 +201,7 @@ impl std::fmt::Debug for AgentChatTarget<'_> {
host_only,
untrusted_input,
shape,
+ attachments,
} => f
.debug_struct("Definition")
.field("definition", &definition.id)
@@ -198,6 +210,7 @@ impl std::fmt::Debug for AgentChatTarget<'_> {
.field("meters", &usage.is_some())
.field("host_only", host_only)
.field("untrusted_input", untrusted_input)
+ .field("attachments", &attachments.len())
.field("shaped", &shape.is_some())
.finish(),
}
@@ -417,6 +430,42 @@ pub async fn agent_chat_reply_for(
agent.set_thread_id(Some(id));
log::debug!("[inference] agent_chat bound session for thread_id={id}");
}
+ // Host attachments, staged where the provider will look for them: the
+ // turn's root when it has one, the configured `action_dir` otherwise.
+ // Their references lead the message, so the model reads the files first
+ // and the caption after, as an upload with a caption reads.
+ let staged_message;
+ let message = match target {
+ AgentChatTarget::Definition { attachments, .. } if !attachments.is_empty() => {
+ let staging_config = match turn_cwd.as_ref() {
+ Some(root) => {
+ let mut scoped = config.clone();
+ scoped.action_dir = root.clone();
+ scoped
+ }
+ None => config.clone(),
+ };
+ let scope = crate::agent::attachments::AttachmentAccessScope {
+ external_channel: false,
+ workspace: turn_cwd.clone(),
+ };
+ let references = crate::agent::attachments::host::stage_host(
+ attachments,
+ turn_session_id.unwrap_or("direct"),
+ &staging_config,
+ &scope,
+ )
+ .await
+ .map_err(|e| e.to_string())?;
+ log::debug!(
+ "[inference] agent_chat staged {} host attachment(s)",
+ attachments.len()
+ );
+ staged_message = format!("{references}{message}");
+ staged_message.as_str()
+ }
+ _ => message,
+ };
if let AgentChatTarget::Definition {
untrusted_input: true,
..