Skip to content

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

feat(media): add image generation tool

Steven Enamakelc9b291aa2a56
diff --git a/Cargo.lock b/Cargo.lock
index 2e8e5b1f48..327c689344 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -5697,6 +5697,7 @@ dependencies = [
"tempfile",
"thiserror 2.0.20",
"tinyagents-live",
+ "tinybus",
"tinychannels-bus",
"tinyhumans-sdk",
"tinyinference-core 0.4.1",
diff --git a/crates/openhuman-core/src/media/generation/mod.rs b/crates/openhuman-core/src/media/generation/mod.rs
index e2d0229444..43c241bf04 100644
--- a/crates/openhuman-core/src/media/generation/mod.rs
+++ b/crates/openhuman-core/src/media/generation/mod.rs
@@ -1,6 +1,5 @@
-//! Media generation domain — image and video generation agent tools backed by
-//! OpenRouter through the OpenHuman backend's `/agent-integrations/openrouter`
-//! proxy.
+//! Media generation domain — image and video generation agent tools over
+//! generators a host supplies (the core ships none of its own).
//!
//! The work is split by ownership:
//!
@@ -10,9 +9,11 @@
//! rule that a billed call returns media or an error, never an empty success.
//! - **TinyAgents** (`tinyagents_harness::media`) owns the tools: argument
//! parsing, artifact persistence into the workspace, and result wording.
-//! - **This module** owns the host policy: endpoint, credential, egress,
-//! privacy and budget gates ([`provider`]), plus tool names, descriptions and
-//! the local-reference policy ([`tools`]).
+//! - **This module** owns tool names, descriptions and the local-reference
+//! policy ([`tools`]), and the [`MediaGenerators`] pair the tools run over
+//! ([`provider`]). The host that owns the media service (endpoint, credential,
+//! egress, privacy and budget gates) builds the generators and registers the
+//! tools through a tool source.
mod artifact_tool;
mod progress;
@@ -20,9 +21,8 @@ pub mod provider;
pub mod tools;
pub use artifact_tool::MediaArtifactTool;
-pub use provider::{managed_generators, MediaGenerators, OPENROUTER_PROXY_PATH};
-pub(crate) use tools::build_media_tools_with_allowlist;
+pub use provider::{GeneratorRouter, MediaGenerators};
pub use tools::{
- build_media_tools, media_tools_from, MediaListModelsTool, IMAGE_TOOL_NAME,
+ media_tools_for_config, media_tools_from, MediaReferenceAllowlist, MediaListModelsTool, IMAGE_TOOL_NAME,
LIST_MODELS_TOOL_NAME, VIDEO_TOOL_NAME,
};
diff --git a/crates/openhuman-core/src/media/generation/tools.rs b/crates/openhuman-core/src/media/generation/tools.rs
index 78d14e8ef4..7f7ce56fb2 100644
--- a/crates/openhuman-core/src/media/generation/tools.rs
+++ b/crates/openhuman-core/src/media/generation/tools.rs
@@ -19,7 +19,7 @@ use tinyagents_harness::tinyinference_video::{VideoGenerator, WaitPolicy};
use tinytools::{PermissionLevel, Tool, ToolCategory, ToolResult};
use super::artifact_tool::MediaArtifactTool;
-use super::provider::{managed_generators, MediaGenerators};
+use super::provider::MediaGenerators;
use crate::agent::artifacts::ArtifactKind;
use crate::config::Config;
@@ -34,7 +34,7 @@ pub const LIST_MODELS_TOOL_NAME: &str = "media_list_models";
const VIDEO_POLL_INTERVAL: Duration = Duration::from_secs(5);
const VIDEO_WAIT_BUDGET: Duration = Duration::from_secs(600);
-pub(crate) type MediaReferenceAllowlist = Arc<Mutex<HashSet<PathBuf>>>;
+pub type MediaReferenceAllowlist = Arc<Mutex<HashSet<PathBuf>>>;
const IMAGE_DESCRIPTION: &str = "Generate or edit images from a text prompt via OpenRouter \
(default model: Seedream 5.0 Lite). Pass `references` (https URLs, workspace paths, or \
@@ -50,23 +50,17 @@ const VIDEO_DESCRIPTION: &str = "Generate a short video clip via OpenRouter (def
ready (minutes) and saves it in the Files folder. Billed per call: if it times out, \
call again with `resume_job_id` instead of submitting a new job.";
-/// Registers the media tools, or nothing when no backend is reachable.
-pub fn build_media_tools(root_config: &Config, action_dir: &Path) -> Vec<Box<dyn Tool>> {
- build_media_tools_with_allowlist(
- root_config,
- action_dir,
- Arc::new(Mutex::new(HashSet::new())),
- )
-}
-
-pub(crate) fn build_media_tools_with_allowlist(
+/// Builds the media tools over `generators` for a configuration: the
+/// reference-file policy, the files roots and the video wait come from
+/// `root_config`; `allowed_references` is the session's shared allowlist of
+/// artifact paths. The generators come from the host that owns the media
+/// service (the core has none of its own).
+pub fn media_tools_for_config(
+ generators: MediaGenerators,
root_config: &Config,
action_dir: &Path,
allowed_references: MediaReferenceAllowlist,
) -> Vec<Box<dyn Tool>> {
- let Some(generators) = managed_generators(root_config) else {
- return Vec::new();
- };
media_tools_from_with_allowlist(
generators,
action_dir,
diff --git a/crates/openhuman-core/src/tools/ops.rs b/crates/openhuman-core/src/tools/ops.rs
index 626d53631a..51220b5cad 100644
--- a/crates/openhuman-core/src/tools/ops.rs
+++ b/crates/openhuman-core/src/tools/ops.rs
@@ -400,10 +400,11 @@ pub fn all_tools_with_runtime(
tools.extend(crate::search::build_search_tools(root_config));
- // Media generation (image/video via GMI through the backend). Skipped when
- // no integration client is configured; artifacts land under `action_dir`.
- // Gated by the `media` compile-time feature (#4804); absent from slim
- // builds. Runtime `DomainSet::media` (#4796) still gates it when compiled.
+ // Media generation roots. The `media_generate_*` tools themselves come from
+ // a host's registered tool source (the core ships no media generators);
+ // this records the files roots their reference policy reads. Gated by the
+ // `media` compile-time feature (#4804); absent from slim builds. Runtime
+ // `DomainSet::media` (#4796) still gates the tools when compiled.
#[cfg(feature = "media")]
{
*security
@@ -411,20 +412,8 @@ pub fn all_tools_with_runtime(
.lock()
.unwrap_or_else(std::sync::PoisonError::into_inner) =
Some(crate::agent::artifacts::FileRoots::from_config(root_config));
- tools.extend(crate::media::generation::build_media_tools_with_allowlist(
- root_config,
- action_dir,
- Arc::clone(&security.media_artifact_paths),
- ));
}
- // Managed cloud file storage (S3 via the backend). Skipped when no
- // integration client is configured; downloads land under `action_dir`.
- tools.extend(crate::integrations::file_storage::build_file_storage_tools(
- root_config,
- action_dir,
- ));
-
// Hosting tools — deploy a workspace directory through the compiled
// TinyHosts module. Registered only once a credential
// actually resolves (`[hosting].api_key`, else the provider's environment
@@ -478,50 +467,6 @@ pub fn all_tools_with_runtime(
)));
}
- // ── Agent integration tools (backend-proxied) ─────────────────
- if let Some(client) = crate::integrations::build_client(root_config) {
- tracing::debug!("[integrations] client built successfully");
- if root_config.integrations.google_places.is_active() {
- tools.push(Box::new(
- crate::integrations::tools::GooglePlacesSearchTool::new(Arc::clone(&client)),
- ));
- tools.push(Box::new(
- crate::integrations::tools::GooglePlacesDetailsTool::new(Arc::clone(&client)),
- ));
- tracing::debug!("[integrations] registered google_places tools");
- } else {
- tracing::debug!("[integrations] google_places disabled — skipping");
- }
- // Web search providers (Exa, Gemini, TinyFish, ...) register through
- // the TinySearch module above, so `[search] enabled = false`
- // suppresses them too. `integrations.parallel` is parsed for old
- // config files and no longer does anything.
- if root_config.integrations.stock_prices.is_active() {
- tools.push(Box::new(crate::integrations::tools::StockQuoteTool::new(
- Arc::clone(&client),
- )));
- tools.push(Box::new(
- crate::integrations::tools::StockExchangeRateTool::new(Arc::clone(&client)),
- ));
- tools.push(Box::new(crate::integrations::tools::StockOptionsTool::new(
- Arc::clone(&client),
- )));
- tools.push(Box::new(
- crate::integrations::tools::StockCryptoSeriesTool::new(Arc::clone(&client)),
- ));
- tools.push(Box::new(
- crate::integrations::tools::StockCommodityTool::new(Arc::clone(&client)),
- ));
- tracing::debug!("[integrations] registered stock_prices tools");
- } else {
- tracing::debug!("[integrations] stock_prices disabled — skipping");
- }
- } else {
- tracing::debug!(
- "[integrations] build_client returned None — integration tools not registered"
- );
- }
-
let composio_tools = crate::integrations::composio::all_composio_agent_tools(root_config);
if composio_tools.is_empty() {
tracing::debug!("[integrations] composio unavailable — skipping");