Skip to content

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

fix(agent): key tinyflows prompts by stamped owner instead of actor id

Steven Enamakelb58e60554d08
diff --git a/crates/openhuman-core/src/agent/harness/host_definition.rs b/crates/openhuman-core/src/agent/harness/host_definition.rs
index d2f3d325e8..18555754be 100644
--- a/crates/openhuman-core/src/agent/harness/host_definition.rs
+++ b/crates/openhuman-core/src/agent/harness/host_definition.rs
@@ -65,6 +65,10 @@ pub struct AgentExt {
/// Runtime only: never serialised and not authorable in TOML.
#[serde(skip)]
pub prompt_builder: Option<PromptBuilder>,
+ /// Original builtin archetype whose prompt is loaded through TinyFlows.
+ /// Runtime only: actor ids may change when an embedder clones a builtin.
+ #[serde(skip)]
+ pub tinyflows_prompt_owner: Option<String>,
}
impl Default for AgentExt {
@@ -76,6 +80,7 @@ impl Default for AgentExt {
tokenjuice_compression: AgentTokenjuiceCompression::default(),
searches_connected_mcp: false,
prompt_builder: None,
+ tinyflows_prompt_owner: None,
}
}
}
diff --git a/crates/openhuman-core/src/agent/prompts/flow_archetype.rs b/crates/openhuman-core/src/agent/prompts/flow_archetype.rs
index d1ee10ebfd..52ccd79986 100644
--- a/crates/openhuman-core/src/agent/prompts/flow_archetype.rs
+++ b/crates/openhuman-core/src/agent/prompts/flow_archetype.rs
@@ -1,7 +1,7 @@
//! Scoped TinyFlows archetype prompt loading for the two flow builtins.
use anyhow::{anyhow, ensure, Result};
-use tinyagents_definition::{DefinitionSource, PromptSource};
+use tinyagents_definition::PromptSource;
use crate::{agent::harness::host_definition::AgentDefinition, config::Config};
@@ -10,12 +10,17 @@ use crate::{agent::harness::host_definition::AgentDefinition, config::Config};
/// User definitions and static/session prompt overrides keep their own source
/// and never cause a TinyFlows module lookup, even when they reuse a builtin id.
pub(crate) fn is_bus_backed_builtin(definition: &AgentDefinition) -> bool {
- matches!(&definition.source, DefinitionSource::Builtin)
- && matches!(&definition.system_prompt, PromptSource::Dynamic(()))
- && matches!(
- definition.id.as_str(),
- "workflow_builder" | "flow_discovery"
- )
+ prompt_owner(definition).is_some()
+}
+
+/// Prompt owner stamped by the builtin loader and preserved by cloned specs.
+/// Actor identity may change for embedded agents, so it is not a prompt key.
+pub(crate) fn prompt_owner(definition: &AgentDefinition) -> Option<&str> {
+ if !matches!(&definition.system_prompt, PromptSource::Dynamic(())) {
+ return None;
+ }
+ let owner = definition.extensions.tinyflows_prompt_owner.as_deref()?;
+ matches!(owner, "workflow_builder" | "flow_discovery").then_some(owner)
}
/// Fetch the archetype for a resolved definition through the module bus.
@@ -30,13 +35,14 @@ pub(crate) async fn load_for_definition(
return Ok(None);
}
+ let owner = prompt_owner(definition).expect("bus-backed definitions have an owner");
let config = config.ok_or_else(|| {
anyhow!(
"cannot render TinyFlows builtin `{}` without its scoped runtime config",
- definition.id
+ owner
)
})?;
- fetch_prompt(config, &definition.id).await.map(Some)
+ fetch_prompt(config, owner).await.map(Some)
}
/// Fetch one of the two builtin flow archetypes through TinyFlows Copilot.
diff --git a/crates/openhuman-core/src/agent/prompts/flow_archetype_tests.rs b/crates/openhuman-core/src/agent/prompts/flow_archetype_tests.rs
index 40db6ef64f..9782308583 100644
--- a/crates/openhuman-core/src/agent/prompts/flow_archetype_tests.rs
+++ b/crates/openhuman-core/src/agent/prompts/flow_archetype_tests.rs
@@ -29,6 +29,7 @@ fn renamed_dynamic_flow_builtin_keeps_its_prompt_owner() {
is_bus_backed_builtin(&definition),
"a library actor id must not erase the resolved builtin prompt owner"
);
+ assert_eq!(prompt_owner(&definition), Some("workflow_builder"));
}
#[tokio::test]
diff --git a/crates/openhuman-core/src/agent/registry/agents/flow_discovery/prompt_tests.rs b/crates/openhuman-core/src/agent/registry/agents/flow_discovery/prompt_tests.rs
index 88e96d3e8f..a903c16ccb 100644
--- a/crates/openhuman-core/src/agent/registry/agents/flow_discovery/prompt_tests.rs
+++ b/crates/openhuman-core/src/agent/registry/agents/flow_discovery/prompt_tests.rs
@@ -1,4 +1,4 @@
-use super::*;
+use super::build;
use crate::agent::prompts::{PromptContext, ToolCallFormat};
fn ctx<'a>(
diff --git a/crates/openhuman-core/src/agent/registry/agents/loader.rs b/crates/openhuman-core/src/agent/registry/agents/loader.rs
index f39231ac83..432641f938 100644
--- a/crates/openhuman-core/src/agent/registry/agents/loader.rs
+++ b/crates/openhuman-core/src/agent/registry/agents/loader.rs
@@ -272,6 +272,10 @@ fn parse_builtin(b: &BuiltinAgent) -> Result<AgentDefinition> {
// Install the function-driven prompt builder and stamp the source.
def.system_prompt = PromptSource::Dynamic(());
def.extensions.prompt_builder = Some(b.prompt_fn);
+ def.extensions.tinyflows_prompt_owner = match b.id {
+ "workflow_builder" | "flow_discovery" => Some(b.id.to_owned()),
+ _ => None,
+ };
def.source = DefinitionSource::Builtin;
// Sanity check: file layout id must match declared TOML id. This