Skip to content

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

refactor(agent_chat): extract host attachment staging into its own module

Steven Enamakelc20a674f0a3f
diff --git a/crates/openhuman-core/src/agent/README.md b/crates/openhuman-core/src/agent/README.md
index ec8d603b53..853f661f11 100644
--- a/crates/openhuman-core/src/agent/README.md
+++ b/crates/openhuman-core/src/agent/README.md
@@ -372,7 +372,7 @@ All controllers register under `DomainGroup::Agent` in [`core/all.rs`](../core/a
| `subagent` | [`orchestration/subagent_control.rs`](./orchestration/subagent_control.rs) | `cancel`, `steer` for running sub-agents |
`agent.chat` and `agent.chat_simple` load config and call
-`inference::host_runtime::ops::agent_chat` / `agent_chat_simple`, which
+`agent_runs::agent_chat::agent_chat` / `inference::host_runtime::ops::agent_chat_simple`, which
build an `OpenHumanSessionHost`. `chat_simple` is a bare provider call with
no tools. The JSON-RPC server itself is in [`crates/openhuman-rpc`](../../../openhuman-rpc/).
diff --git a/crates/openhuman-core/src/agent_runs/agent_chat/attachments.rs b/crates/openhuman-core/src/agent_runs/agent_chat/attachments.rs
new file mode 100644
index 0000000000..dcf7dab567
--- /dev/null
+++ b/crates/openhuman-core/src/agent_runs/agent_chat/attachments.rs
@@ -0,0 +1,37 @@
+use crate::config::Config;
+
+/// Stage in-process attachments in the workspace exposed to this turn and
+/// prepend their model-visible references to the user's message.
+pub(super) async fn stage_host_attachments(
+ attachments: &[crate::agent::HostAttachment],
+ session_id: &str,
+ config: &Config,
+ cwd: Option<std::path::PathBuf>,
+ message: &str,
+) -> Result<String, String> {
+ let staging_config = match cwd.as_ref() {
+ Some(root) => {
+ let mut scoped = config.clone();
+ scoped.action_dir = root.clone();
+ scoped
+ }
+ None => config.clone(),
+ };
+ let scope = crate::attachments::AttachmentAccessScope {
+ external_channel: false,
+ workspace: cwd,
+ };
+ let references = crate::attachments::host::stage_host(
+ attachments,
+ session_id,
+ &staging_config,
+ &scope,
+ )
+ .await
+ .map_err(|error| error.to_string())?;
+ log::debug!(
+ "[inference] agent_chat staged {} host attachment(s)",
+ attachments.len()
+ );
+ Ok(format!("{references}{message}"))
+}
diff --git a/crates/openhuman-core/src/agent_runs/agent_chat/mod.rs b/crates/openhuman-core/src/agent_runs/agent_chat/mod.rs
index 61ee485a56..0f8a24d34c 100644
--- a/crates/openhuman-core/src/agent_runs/agent_chat/mod.rs
+++ b/crates/openhuman-core/src/agent_runs/agent_chat/mod.rs
@@ -2,6 +2,7 @@
pub(crate) mod guards;
mod envelope;
+mod attachments;
mod controllers;
pub(crate) mod params;
mod session_turn;
diff --git a/crates/openhuman-core/src/agent_runs/agent_chat/session_turn.rs b/crates/openhuman-core/src/agent_runs/agent_chat/session_turn.rs
index b2f5f99a05..d396f69e68 100644
--- a/crates/openhuman-core/src/agent_runs/agent_chat/session_turn.rs
+++ b/crates/openhuman-core/src/agent_runs/agent_chat/session_turn.rs
@@ -3,6 +3,7 @@
use crate::agent::OpenHumanSessionHost;
use crate::config::Config;
use crate::core::Outcome;
+use super::envelope::AgentChatReply;
use super::guards::{
effective_agent_chat_origin, enforce_user_prompt_or_reject, grant_turn_cwd,
@@ -428,42 +429,22 @@ 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 {
+ // Host attachments are staged where the provider will look for them: the
+ // turn root, or the configured action directory when no root was supplied.
+ let staged_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::attachments::AttachmentAccessScope {
- external_channel: false,
- workspace: turn_cwd.clone(),
- };
- let references = crate::attachments::host::stage_host(
+ super::attachments::stage_host_attachments(
attachments,
turn_session_id.unwrap_or("direct"),
- &staging_config,
- &scope,
+ config,
+ turn_cwd.clone(),
+ message,
)
- .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()
+ .await?
}
- _ => message,
+ _ => message.to_string(),
};
+ let message = staged_message.as_str();
if let AgentChatTarget::Definition {
untrusted_input: true,
..