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(media): add artifact tool for media generation
Steven Enamakelf3050e37cc19
diff --git a/crates/openhuman-core/src/media/generation/artifact_tool.rs b/crates/openhuman-core/src/media/generation/artifact_tool.rsindex 4cfcd5366e..275aeefae1 100644--- a/crates/openhuman-core/src/media/generation/artifact_tool.rs+++ b/crates/openhuman-core/src/media/generation/artifact_tool.rs@@ -40,6 +40,9 @@ use crate::agent::artifacts::{create_artifact_for_call, fail_artifact, finalize_artifact, ArtifactKind,};use crate::tools::host_extensions::tool_call_id;+use tinyagents_harness::tinyinference_video::ProgressFn;++use super::progress::{video_status_observer, JobStateSlot};/// Maximum characters of the prompt kept in a generated artifact's title.const TITLE_PROMPT_CHARS: usize = 60;@@ -52,8 +55,15 @@ pub struct MediaArtifactTool<T: Tool> {workspace_dir: PathBuf,/// Visible folder each generated file is moved into (#5505).files_dir: crate::agent::artifacts::FileRoots,+ /// Builds the inner tool for one call around that call's poll observer.+ /// Set for the video tool, whose `WaitPolicy::progress` hook is fixed at+ /// construction: a tool per call lets the observer record into the call's+ /// own [`JobStateSlot`]. `inner` still answers the static `Tool` metadata.+ per_call: Option<PerCallInner<T>>,}+type PerCallInner<T> = std::sync::Arc<dyn Fn(ProgressFn) -> T + Send + Sync>;+impl<T: Tool> MediaArtifactTool<T> {/// `kind` is the artifact category to file every generated output/// under (`ArtifactKind::Image` / `ArtifactKind::Video`); `workspace_dir`@@ -70,9 +80,21 @@ impl<T: Tool> MediaArtifactTool<T> {kind,workspace_dir: workspace_dir.into(),files_dir: files_dir.into(),+ per_call: None,}}+ /// Run each call on a tool built by `build` around that call's poll+ /// observer, so a long job's polled state reaches that call's heartbeat.+ #[must_use]+ pub fn with_per_call_inner(+ mut self,+ build: impl Fn(ProgressFn) -> T + Send + Sync + 'static,+ ) -> Self {+ self.per_call = Some(std::sync::Arc::new(build));+ self+ }+/// Derives a human-readable artifact title from the call's `prompt`/// argument, suffixed with `(i/n)` when the call produced more than one/// file (`n > 1`).@@ -291,12 +313,18 @@ impl<T: Tool> Tool for MediaArtifactTool<T> {ArtifactKind::Video => "Generating video",_ => "Generating image",};+ let job_state = JobStateSlot::default();+ let per_call_inner = self+ .per_call+ .as_ref()+ .map(|build| build(video_status_observer(job_state.clone())));+ let inner = per_call_inner.as_ref().unwrap_or(&self.inner);let result = super::progress::with_progress_heartbeat(context,label,super::progress::HEARTBEAT_INTERVAL,- self.inner- .execute_with_context(args.clone(), options, context),+ job_state,+ inner.execute_with_context(args.clone(), options, context),).await?;if result.is_error {diff --git a/crates/openhuman-core/src/media/generation/tools.rs b/crates/openhuman-core/src/media/generation/tools.rsindex 87599f67c6..2bb6e8bb0c 100644--- a/crates/openhuman-core/src/media/generation/tools.rs+++ b/crates/openhuman-core/src/media/generation/tools.rs@@ -56,9 +56,9 @@ pub fn build_media_tools(root_config: &Config, action_dir: &Path) -> Vec<Box<dyn&root_config.workspace_dir,crate::agent::artifacts::FileRoots::from_config(root_config),// Each poll's job state feeds the call's progress heartbeat- // (`super::progress`), so a multi-minute wait is not silent.- WaitPolicy::new(VIDEO_POLL_INTERVAL, VIDEO_WAIT_BUDGET)- .with_progress(super::progress::video_status_observer()),+ // (`super::progress`, wired per call by `MediaArtifactTool`), so a+ // multi-minute wait is not silent.+ WaitPolicy::new(VIDEO_POLL_INTERVAL, VIDEO_WAIT_BUDGET),)}@@ -87,23 +87,41 @@ pub fn media_tools_from(workspace_dir.to_path_buf(),files.clone(),)),- Box::new(MediaArtifactTool::new(- GenerateVideoTool::new(Arc::clone(&video), output)- .with_name(VIDEO_TOOL_NAME)- .with_description(VIDEO_DESCRIPTION)- .with_permission_level(PermissionLevel::Execute)- .with_category(ToolCategory::Workflow)- .with_wait_policy(video_wait),- ArtifactKind::Video,- workspace_dir.to_path_buf(),- files,- )),+ Box::new(+ MediaArtifactTool::new(+ video_tool(&video, &output, video_wait.clone()),+ ArtifactKind::Video,+ workspace_dir.to_path_buf(),+ files,+ )+ .with_per_call_inner({+ let video = Arc::clone(&video);+ let output = output.clone();+ move |observer| {+ video_tool(&video, &output, video_wait.clone().with_progress(observer))+ }+ }),+ ),Box::new(MediaListModelsTool { image, video }),];tracing::debug!("[media_generation] registered {} media tools", tools.len());tools}+/// The video generation tool over `video`, with `wait` bounding each job.+fn video_tool(+ video: &Arc<dyn VideoGenerator>,+ output: &MediaOutput,+ wait: WaitPolicy,+) -> GenerateVideoTool {+ GenerateVideoTool::new(Arc::clone(video), output.clone())+ .with_name(VIDEO_TOOL_NAME)+ .with_description(VIDEO_DESCRIPTION)+ .with_permission_level(PermissionLevel::Execute)+ .with_category(ToolCategory::Workflow)+ .with_wait_policy(wait)+}+/// Local reference files may be read and uploaded only from the action/// directory or the workspace directory, never through `..`, and never from/// an always-forbidden location (credential stores, system roots).