The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.
Rust agent-orchestrationai-agentsai-assistantdesktopllmlocal-firstmcppersonal-aiprivacyrustsecond-braintauri
feat(agent): offload large tool outputs to artifacts
Steven Enamakel24b417651135
diff --git a/crates/openhuman-core/src/agent/harness/artifact_offload/artifact_offload_tests.rs b/crates/openhuman-core/src/agent/harness/artifact_offload/artifact_offload_tests.rsindex c0187a3a8c..6fc2158dd3 100644--- a/crates/openhuman-core/src/agent/harness/artifact_offload/artifact_offload_tests.rs+++ b/crates/openhuman-core/src/agent/harness/artifact_offload/artifact_offload_tests.rs@@ -104,6 +104,14 @@ fn workspace_guard_defers_to_the_security_policy_for_internal_state() {}}+fn memory_blobs() -> Arc<dyn tinystoragedrivers::BlobStore> {+ use tinystoragedrivers::StorageBackend as _;+ let scoped = tinystoragedrivers::MemoryStorage::new()+ .for_scope(&tinystoragedrivers::Scope::local())+ .expect("the memory backend binds the local scope");+ Arc::clone(scoped.blobs())+}+// ── Wiring (the point of `new_artifact_offload`) ──────────────────────────────#[tokio::test]@@ -118,7 +126,7 @@ async fn a_wired_writer_refuses_a_target_inside_workspace_dir() {std::fs::create_dir_all(&action_dir).expect("action dir");let offload = new_artifact_offload(- action_dir,+ memory_blobs(),Some(policy_with(dir.path().join("action"),workspace_dir.clone(),@@ -151,7 +159,7 @@ async fn a_wired_writer_redacts_before_the_bytes_reach_disk() {std::fs::create_dir_all(&workspace_dir).expect("workspace dir");let offload = new_artifact_offload(- action_dir,+ memory_blobs(),Some(policy_with(dir.path().join("action"), workspace_dir)),"agent","task",@@ -163,16 +171,18 @@ async fn a_wired_writer_redacts_before_the_bytes_reach_disk() {.await.expect("write");- let on_disk = tokio::fs::read_to_string(&artifact.absolute_path)+ let on_disk = offload+ .read(&artifact.relative_path).await- .expect("read back");+ .expect("read back")+ .expect("stored");// Whether this particular shape trips `sanitize_text` is that function's// business; what this pins is that the two agree. A redactor reported as// having fired must have actually rewritten the stored bytes.assert_eq!(artifact.redacted,on_disk != secret,- "the redacted flag must match what actually reached disk"+ "the redacted flag must match what actually reached the blob store");}@@ -185,7 +195,7 @@ async fn oversized_result_is_offloaded_and_the_parent_gets_a_readable_pointer()std::fs::create_dir_all(&workspace_dir).expect("workspace dir");let offload = new_artifact_offload(- action_dir,+ memory_blobs(),Some(policy_with(dir.path().join("action"), workspace_dir)),"worker","task-1",@@ -193,7 +203,13 @@ async fn oversized_result_is_offloaded_and_the_parent_gets_a_readable_pointer()let big = "x".repeat(10_000);let (text, artifact) =- offload_oversized_result(big.clone(), &offload, DEFAULT_OFFLOAD_THRESHOLD_BYTES).await;+ offload_oversized_result(+ big.clone(),+ &offload,+ DEFAULT_OFFLOAD_THRESHOLD_BYTES,+ &action_dir,+ )+ .await;let artifact = artifact.expect("an artifact was written");assert!(text.starts_with(ARTIFACT_POINTER_PREFIX));@@ -206,7 +222,8 @@ async fn oversized_result_is_offloaded_and_the_parent_gets_a_readable_pointer()// And the path it quotes must be the one a parent can actually extract.assert_eq!(extract_artifact_paths(&text), vec![artifact.relative_path]);- let on_disk = tokio::fs::read_to_string(&artifact.absolute_path)+ // The pointer's path is openable by `file_read` against the action root.+ let on_disk = tokio::fs::read_to_string(action_dir.join(&artifact.relative_path)).await.expect("read back");assert_eq!(on_disk, big, "full fidelity is preserved on disk");diff --git a/crates/openhuman-core/src/agent/harness/artifact_offload/mod.rs b/crates/openhuman-core/src/agent/harness/artifact_offload/mod.rsindex a0c137e786..9ff94093f2 100644--- a/crates/openhuman-core/src/agent/harness/artifact_offload/mod.rs+++ b/crates/openhuman-core/src/agent/harness/artifact_offload/mod.rs@@ -48,10 +48,11 @@pub mod policy;-use std::path::PathBuf;+use std::path::Path;use std::sync::Arc;use tinyagents_harness::artifacts::ArtifactOffload;+use tinystoragedrivers::BlobStore;use crate::security::SecurityPolicy;@@ -77,18 +78,19 @@ use tinyagents_harness::artifacts::OffloadedArtifact;/// its agent actually holds, and the reader and the writer are different agents.pub const READ_TOOL: &str = "file_read";-/// Build a writer for one sub-agent run, wired to OpenHuman's policies.+/// Build a writer for one sub-agent run over `blobs`, wired to OpenHuman's+/// policies.////// Supplies both host policies every time, so no call site can accidentally/// construct an unguarded or unredacted writer — the crate permits `None` for/// each, and OpenHuman never wants either.pub fn new_artifact_offload(- action_dir: PathBuf,+ blobs: Arc<dyn BlobStore>,policy: Option<Arc<SecurityPolicy>>,agent_id: impl Into<String>,task_id: impl Into<String>,) -> ArtifactOffload {- let offload = ArtifactOffload::new(action_dir, agent_id, task_id)+ let offload = ArtifactOffload::new(blobs, agent_id, task_id).with_redactor(Arc::new(SanitizingRedactor));match policy {Some(policy) => offload.with_path_policy(Arc::new(WorkspaceGuard::new(policy))),@@ -102,21 +104,66 @@ pub fn new_artifact_offload(/// Offload `output` when it exceeds `threshold_bytes`, returning the text the/// parent should receive plus the artifact when one was written.///-/// Thin wrapper over the crate's function that pins OpenHuman's [`READ_TOOL`].-/// Every failure mode is soft: the caller gets the original payload back and-/// the summarizer detour and tool-result budget stay in charge as the fallback.+/// The artifact lives on the blob store, but the parent opens it with+/// [`READ_TOOL`], which reads the filesystem. So the stored body is also+/// materialised at `materialize_root/<key>` (the parent's action root), which+/// is the path the pointer quotes. Every failure mode is soft: the caller gets+/// the original payload back and the summarizer detour and tool-result budget+/// stay in charge as the fallback. A pointer is never returned for a file that+/// could not be written.pub async fn offload_oversized_result(output: String,offload: &ArtifactOffload,threshold_bytes: usize,+ materialize_root: &Path,) -> (String, Option<OffloadedArtifact>) {- tinyagents_harness::artifacts::offload_oversized_result(- output,+ let (pointer, artifact) = tinyagents_harness::artifacts::offload_oversized_result(+ output.clone(),offload,threshold_bytes,READ_TOOL,)- .await+ .await;+ let Some(artifact) = artifact else {+ return (output, None);+ };+ match materialize(offload, &artifact, materialize_root).await {+ Ok(()) => (pointer, Some(artifact)),+ Err(error) => {+ tracing::warn!(+ path = %artifact.relative_path,+ error = %error,+ "[artifact] could not materialize the stored artifact; keeping the inline result"+ );+ (output, None)+ }+ }+}++/// Write the stored (redacted) body of `artifact` to `root/<key>`.+async fn materialize(+ offload: &ArtifactOffload,+ artifact: &OffloadedArtifact,+ root: &Path,+) -> Result<(), String> {+ let body = offload+ .read(&artifact.relative_path)+ .await+ .map_err(|error| error.to_string())?+ .ok_or_else(|| "the artifact vanished from the blob store".to_string())?;+ // `read` re-ran the fail-closed key checks (no absolute names, `..`, or+ // control characters), so the join cannot leave `root`.+ let target = root.join(&artifact.relative_path);+ if let Some(parent) = target.parent() {+ tokio::fs::create_dir_all(parent)+ .await+ .map_err(|error| error.to_string())?;+ }+ tokio::fs::write(&target, body)+ .await+ .map_err(|error| error.to_string())?;+ tracing::debug!(path = %artifact.relative_path, "[artifact] materialized for file_read");+ Ok(())}#[cfg(test)]diff --git a/crates/openhuman-core/src/agent/subagent_host/ops/runner.rs b/crates/openhuman-core/src/agent/subagent_host/ops/runner.rsindex cc1ba08265..697f99c349 100644--- a/crates/openhuman-core/src/agent/subagent_host/ops/runner.rs+++ b/crates/openhuman-core/src/agent/subagent_host/ops/runner.rs@@ -474,19 +474,41 @@ async fn offload_outcome_artifacts(let threshold =effective_offload_threshold(DEFAULT_OFFLOAD_THRESHOLD_BYTES, definition.max_result_chars);- // Worktree-isolated workers write inside their own checkout, but the parent- // that receives the pointer resolves relative paths against ITS action root.- // Render against that root so the handed-back path is one the parent can- // actually open (relative when the worktree nests inside it, absolute when- // it does not) rather than a bare `outputs/…` that silently misses.- let render_root = policy+ // The parent that receives the pointer resolves relative paths against ITS+ // action root, so the stored artifact is materialised there (also for a+ // worktree-isolated worker) and the handed-back `outputs/…` path opens.+ let materialize_root = policy.as_ref().map(|p| p.action_dir.clone()).unwrap_or_else(|| action_dir.clone());- let offload = new_artifact_offload(action_dir, policy, outcome.agent_id.clone(), task_id)- .with_render_root(render_root);- let (output, _artifact) =- offload_oversized_result(std::mem::take(&mut outcome.output), &offload, threshold).await;+ let workspace_dir = policy+ .as_ref()+ .map(|p| p.workspace_dir.clone())+ .unwrap_or_else(|| action_dir.clone());+ let blobs = crate::agent::session_store::artifact_blobs_for(&workspace_dir);+ let Some(blobs) = blobs else {+ tracing::debug!(+ task_id = %task_id,+ agent_id = %outcome.agent_id,+ "[artifact] no blob store for the acting tenant — skipping offload (summarizer/truncation backstop applies)"+ );+ outcome.artifact_paths = paths;+ note_artifact_handoff(+ HANDOFF_STAGE_RECORDED,+ &outcome.agent_id,+ task_id,+ &outcome.artifact_paths,+ );+ return;+ };+ let offload = new_artifact_offload(blobs, policy, outcome.agent_id.clone(), task_id);+ let (output, _artifact) = offload_oversized_result(+ std::mem::take(&mut outcome.output),+ &offload,+ threshold,+ &materialize_root,+ )+ .await;outcome.output = output;// Merge: the harness pointer (if it fired) plus any worker-authored pointer