Skip to content

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

feat(agent): load flow archetype into system prompts

Steven Enamakel9501a5d3f27f
diff --git a/crates/openhuman-core/src/agent/debug/mod.rs b/crates/openhuman-core/src/agent/debug/mod.rs
index 0c086a2c54..a092038a5f 100644
--- a/crates/openhuman-core/src/agent/debug/mod.rs
+++ b/crates/openhuman-core/src/agent/debug/mod.rs
@@ -191,8 +191,24 @@ async fn render_via_session(config: &Config, agent_id: &str) -> Result<DumpedPro
// Composio toolkits now that we know what's actually authorised.
agent.refresh_delegation_tools();
+ #[cfg(feature = "flows")]
+ let flow_archetype_text = match AgentDefinitionRegistry::current()
+ .and_then(|registry| registry.get(agent_id).cloned())
+ {
+ Some(definition) => {
+ crate::agent::prompts::flow_archetype::load_for_definition(
+ Some(config),
+ &definition,
+ )
+ .await?
+ }
+ None => None,
+ };
+ #[cfg(not(feature = "flows"))]
+ let flow_archetype_text: Option<String> = None;
+
let text = agent
- .build_system_prompt()
+ .build_system_prompt_with_flow_archetype(flow_archetype_text.as_deref())
.with_context(|| format!("rendering system prompt for `{agent_id}`"))?;
Ok(session_dump(&agent, agent_id, text))
@@ -228,3 +244,7 @@ fn session_dump(agent: &OpenHumanSessionHost, agent_id: &str, text: String) -> D
tool_specs,
}
}
+
+#[cfg(test)]
+#[path = "mod_tests.rs"]
+mod tests;
diff --git a/crates/openhuman-core/src/agent/debug/mod_tests.rs b/crates/openhuman-core/src/agent/debug/mod_tests.rs
new file mode 100644
index 0000000000..5f4d712725
--- /dev/null
+++ b/crates/openhuman-core/src/agent/debug/mod_tests.rs
@@ -0,0 +1,26 @@
+use super::*;
+
+#[cfg(feature = "flows")]
+#[tokio::test]
+async fn debug_dump_composes_each_flow_prompt_from_the_copilot_bus() {
+ let temp = tempfile::tempdir().expect("workspace");
+ let config = Config {
+ workspace_dir: temp.path().join("workspace"),
+ action_dir: temp.path().join("action"),
+ config_path: temp.path().join("config.toml"),
+ ..Config::default()
+ };
+ AgentDefinitionRegistry::init_global(&config.workspace_dir)
+ .expect("initialize builtin registry");
+
+ for (agent_id, required) in [
+ ("workflow_builder", "propose_workflow"),
+ ("flow_discovery", "suggest_workflows"),
+ ] {
+ let prompt = render_via_session(&config, agent_id)
+ .await
+ .unwrap_or_else(|error| panic!("rendering {agent_id}: {error:#}"));
+ assert!(prompt.text.contains(required), "{agent_id} prompt missing {required}");
+ assert!(prompt.text.contains("## Workspace"));
+ }
+}
diff --git a/crates/openhuman-core/src/agent/progress_tracing/graph_langfuse.rs b/crates/openhuman-core/src/agent/progress_tracing/graph_langfuse.rs
index 4716bd162c..ac1c8a5286 100644
--- a/crates/openhuman-core/src/agent/progress_tracing/graph_langfuse.rs
+++ b/crates/openhuman-core/src/agent/progress_tracing/graph_langfuse.rs
@@ -74,6 +74,7 @@ fn flow_otlp_requests(
)
}
+#[cfg(test)]
fn graph_otlp_requests(
flow_name: &str,
flow_id: &str,
diff --git a/crates/openhuman-core/src/agent/registry/agents/fleet_prompt_tests.rs b/crates/openhuman-core/src/agent/registry/agents/fleet_prompt_tests.rs
index 7aa3c3a0ba..27f2c381cc 100644
--- a/crates/openhuman-core/src/agent/registry/agents/fleet_prompt_tests.rs
+++ b/crates/openhuman-core/src/agent/registry/agents/fleet_prompt_tests.rs
@@ -60,6 +60,8 @@ fn render(def: &AgentDefinition, definitions: &[AgentDefinition]) -> String {
workspace_dir: workspace.path(),
model_name: "test",
agent_id: &def.id,
+ flow_archetype_text: matches!(def.id.as_str(), "workflow_builder" | "flow_discovery")
+ .then_some("synthetic flow archetype for registry coverage"),
tools: &[],
workflows: &[],
dispatcher_instructions: "",
diff --git a/crates/openhuman-core/src/agent/registry/agents/loader_tests_builtin_registration_tests.rs b/crates/openhuman-core/src/agent/registry/agents/loader_tests_builtin_registration_tests.rs
index d82ab3dfc7..98e9bec411 100644
--- a/crates/openhuman-core/src/agent/registry/agents/loader_tests_builtin_registration_tests.rs
+++ b/crates/openhuman-core/src/agent/registry/agents/loader_tests_builtin_registration_tests.rs
@@ -168,6 +168,11 @@ fn every_builtin_has_a_prompt_body() {
workspace_dir: std::path::Path::new("."),
model_name: "test",
agent_id: &def.id,
+ flow_archetype_text: matches!(
+ def.id.as_str(),
+ "workflow_builder" | "flow_discovery"
+ )
+ .then_some("synthetic flow archetype for loader coverage"),
tools: &empty_tools,
workflows: &[],
dispatcher_instructions: "",
diff --git a/crates/openhuman-core/src/agent/session_host/runtime_session.rs b/crates/openhuman-core/src/agent/session_host/runtime_session.rs
index b1cd7352b3..804d736d23 100644
--- a/crates/openhuman-core/src/agent/session_host/runtime_session.rs
+++ b/crates/openhuman-core/src/agent/session_host/runtime_session.rs
@@ -257,8 +257,31 @@ impl OpenHumanTurnPrelude {
)
.map_err(|error| anyhow::anyhow!(error.to_string()))?
};
+ let flow_archetype_text = if cold {
+ #[cfg(feature = "flows")]
+ {
+ match self.definition.as_deref() {
+ Some(definition) => {
+ crate::agent::prompts::flow_archetype::load_for_definition(
+ self.runtime_config.as_deref(),
+ definition,
+ )
+ .await?
+ }
+ None => None,
+ }
+ }
+ #[cfg(not(feature = "flows"))]
+ {
+ None
+ }
+ } else {
+ None
+ };
let prefix = if cold {
- let tiered = self.build_system_prompt_tiered()?;
+ let tiered = self.build_system_prompt_tiered_with_flow_archetype(
+ flow_archetype_text.as_deref(),
+ )?;
Some(super::prefix_snapshot::tiered_prefix_snapshot(&tiered))
} else {
None
@@ -270,6 +293,13 @@ impl OpenHumanTurnPrelude {
}
fn build_system_prompt_tiered(&self) -> Result<crate::agent::prompts::TieredPrompt> {
+ self.build_system_prompt_tiered_with_flow_archetype(None)
+ }
+
+ fn build_system_prompt_tiered_with_flow_archetype(
+ &self,
+ flow_archetype_text: Option<&str>,
+ ) -> Result<crate::agent::prompts::TieredPrompt> {
use crate::agent::prompts::{PromptContext, PromptTool};
let surface = self
.tool_surface
@@ -328,6 +358,7 @@ impl OpenHumanTurnPrelude {
workspace_dir: &self.workspace_dir,
model_name: &self.model_name,
agent_id: &self.agent_definition_name,
+ flow_archetype_text,
tools: &prompt_tools,
workflows: &mutable.workflows,
dispatcher_instructions: &instructions,
diff --git a/crates/openhuman-core/src/agent/session_host/turn/context.rs b/crates/openhuman-core/src/agent/session_host/turn/context.rs
index 8d5d486578..46571ec5b4 100644
--- a/crates/openhuman-core/src/agent/session_host/turn/context.rs
+++ b/crates/openhuman-core/src/agent/session_host/turn/context.rs
@@ -8,8 +8,19 @@ use anyhow::Result;
impl OpenHumanSessionHost {
/// Builds the system prompt for the current turn, including tool
- /// instructions.
+ /// instructions. Bus-backed flow prompts require the caller to use
+ /// [`Self::build_system_prompt_with_flow_archetype`] with an explicitly
+ /// fetched archetype.
pub fn build_system_prompt(&self) -> Result<String> {
+ self.build_system_prompt_with_flow_archetype(None)
+ }
+
+ /// Builds the system prompt with an optional TinyFlows archetype already
+ /// fetched by an async caller using its scoped runtime config.
+ pub(crate) fn build_system_prompt_with_flow_archetype(
+ &self,
+ flow_archetype_text: Option<&str>,
+ ) -> Result<String> {
// `visible_tool_specs` holds shared `Arc<ToolSpec>` leaves. Materialise
// the canonical dialect input for this prompt build.
let visible_specs_owned: Vec<tinytools::ToolSpec> = self
@@ -52,6 +63,7 @@ impl OpenHumanSessionHost {
workspace_dir: &self.workspace_dir,
model_name: &self.model_name,
agent_id: &self.agent_definition_name,
+ flow_archetype_text,
tools: &prompt_tools,
workflows: &self.workflows,
dispatcher_instructions: &instructions,