Skip to content

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

feat(artifacts): add presentation artifact store

Steven Enamakel07cfe5d74102
diff --git a/crates/openhuman-core/src/agent/artifacts/mod.rs b/crates/openhuman-core/src/agent/artifacts/mod.rs
index 4e1065bb3c..faa254f38a 100644
--- a/crates/openhuman-core/src/agent/artifacts/mod.rs
+++ b/crates/openhuman-core/src/agent/artifacts/mod.rs
@@ -14,7 +14,7 @@ pub use schemas::{
all_registered_controllers as all_artifacts_registered_controllers,
};
pub use store::{
- create_artifact, create_artifact_for_call, fail_artifact, finalize_artifact,
- read_artifact_bytes,
+ create_artifact, create_artifact_for_call, create_artifact_regenerating, fail_artifact,
+ finalize_artifact, read_artifact_bytes,
};
pub use types::{ArtifactKind, ArtifactMeta, ArtifactStatus};
diff --git a/crates/openhuman-core/src/agent/artifacts/store.rs b/crates/openhuman-core/src/agent/artifacts/store.rs
index 727eff7d11..8d18b08158 100644
--- a/crates/openhuman-core/src/agent/artifacts/store.rs
+++ b/crates/openhuman-core/src/agent/artifacts/store.rs
@@ -14,15 +14,6 @@ const META_FILENAME: &str = "meta.json";
/// [`create_artifact`]; read by `ops::ai_regenerate`.
const ARGS_FILENAME: &str = "args.json";
-tokio::task_local! {
- /// When set (by `ops::ai_regenerate`), [`create_artifact`] reuses
- /// this id + its existing directory instead of minting a fresh
- /// UUID — so a Retry swaps the failed card in place rather than
- /// appending a second card (#3162). Unset for all normal
- /// generation paths, in which case a fresh UUID is minted.
- pub static REGENERATE_TARGET_ID: String;
-}
-
/// Returns the artifacts root directory, creating it if it doesn't exist.
///
/// The root lives at `<workspace_dir>/artifacts/`.
@@ -338,6 +329,34 @@ pub async fn create_artifact_for_call(
title: &str,
extension: &str,
tool_call_id: Option<&str>,
+) -> Result<(ArtifactMeta, PathBuf), String> {
+ create_artifact_regenerating(
+ workspace_dir,
+ files,
+ kind,
+ title,
+ extension,
+ tool_call_id,
+ None,
+ )
+ .await
+}
+
+/// As [`create_artifact_for_call`], but a `regenerate_target` (the id
+/// `ops::ai_regenerate` re-dispatches a failed card under) makes the call
+/// reuse that id and its existing record instead of minting a fresh UUID, so a
+/// Retry swaps the failed card in place rather than appending a second one
+/// (#3162). The target travels as an explicit argument from the regenerating
+/// caller to the tool that produces the artifact. A blank target mints a fresh
+/// id like `None`.
+pub async fn create_artifact_regenerating(
+ workspace_dir: &Path,
+ files: impl Into<FileRoots>,
+ kind: super::types::ArtifactKind,
+ title: &str,
+ extension: &str,
+ tool_call_id: Option<&str>,
+ regenerate_target: Option<&str>,
) -> Result<(ArtifactMeta, PathBuf), String> {
let roots = files.into();
let files_dir = roots.current();
@@ -356,14 +375,13 @@ pub async fn create_artifact_for_call(
}
// Normal path mints a fresh UUID. A regenerate (#3162) runs inside
- // `REGENERATE_TARGET_ID.scope(...)` and reuses the original id so the
+ // an explicit `regenerate_target` and reuses the original id so the
// Pending/Ready/Failed events that follow carry the same artifact_id
// and the card swaps in place. The reused dir already exists; the
// `create_dir_all` below is idempotent and the meta/file are
// overwritten with the fresh generation.
- let reused_id = REGENERATE_TARGET_ID
- .try_with(|target| target.clone())
- .ok()
+ let reused_id = regenerate_target
+ .map(str::to_owned)
.filter(|target| !target.trim().is_empty());
let is_regenerate = reused_id.is_some();
let id = reused_id.unwrap_or_else(|| uuid::Uuid::new_v4().to_string());
diff --git a/crates/openhuman-core/src/tools/impl/presentation/mod.rs b/crates/openhuman-core/src/tools/impl/presentation/mod.rs
index 605c49a360..bdc03b09f2 100644
--- a/crates/openhuman-core/src/tools/impl/presentation/mod.rs
+++ b/crates/openhuman-core/src/tools/impl/presentation/mod.rs
@@ -115,6 +115,9 @@ pub struct PresentationTool {
/// `validate_path` checks (allowed-location, symlink-escape, forbidden
/// dirs) as any other file-read operation.
security: Arc<SecurityPolicy>,
+ /// The artifact id a Retry re-dispatches this generation under
+ /// (`artifacts::ops::ai_regenerate`); `None` mints a fresh artifact.
+ regenerate_target: Option<String>,
}
impl PresentationTool {
@@ -132,6 +135,7 @@ impl PresentationTool {
files_dir: files_dir.into(),
config: None,
security,
+ regenerate_target: None,
}
}
@@ -158,8 +162,16 @@ impl PresentationTool {
files_dir: files_dir.into(),
config: Some(config),
security,
+ regenerate_target: None,
}
}
+
+ /// Re-dispatch this generation under an existing artifact id, so the
+ /// failed card is replaced in place (#3162).
+ pub(crate) fn with_regenerate_target(mut self, artifact_id: impl Into<String>) -> Self {
+ self.regenerate_target = Some(artifact_id.into());
+ self
+ }
}
#[async_trait]
@@ -310,12 +322,14 @@ impl Tool for PresentationTool {
);
}
- let (meta, output_path) = create_artifact(
+ let (meta, output_path) = create_artifact_regenerating(
&self.workspace_dir,
&self.files_dir,
ArtifactKind::Presentation,
&input.title,
"pptx",
+ None,
+ self.regenerate_target.as_deref(),
)
.await
.map_err(anyhow::Error::msg)?;