Skip to content

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

test(prompts): cover tiered prompt boundaries and unmarked dynamic bodies

Steven Enamakel28f2774e86c8
diff --git a/crates/openhuman-core/src/agent/prompts/mod_tests_builder_sections_tests.rs b/crates/openhuman-core/src/agent/prompts/mod_tests_builder_sections_tests.rs
index 2dd3fbd545..b72a2330ab 100644
--- a/crates/openhuman-core/src/agent/prompts/mod_tests_builder_sections_tests.rs
+++ b/crates/openhuman-core/src/agent/prompts/mod_tests_builder_sections_tests.rs
@@ -692,9 +692,11 @@ fn verbatim_builder_renders_the_body_and_nothing_else() {
#[test]
fn composed_prompt_keeps_context_and_volatile_system_message_boundaries() {
+ static RENDERS: std::sync::atomic::AtomicUsize = std::sync::atomic::AtomicUsize::new(0);
fn dynamic_prompt(_ctx: &PromptContext<'_>) -> anyhow::Result<String> {
+ RENDERS.fetch_add(1, std::sync::atomic::Ordering::SeqCst);
Ok(format!(
- "## Grounding and tool use\n\nProduct grounding.\n{context}\n## Project context\nContext instructions.\n{volatile}\nVolatile identity.",
+ "## Grounding and tool use\n\nProduct grounding.\nStable πŸ“\n{context}\n## Project context\nContext instructions 🧭.\n{volatile}\nVolatile identity.",
context = PROMPT_TIER_CONTEXT_MARKER,
volatile = PROMPT_TIER_VOLATILE_MARKER,
))
@@ -724,13 +726,18 @@ fn composed_prompt_keeps_context_and_volatile_system_message_boundaries() {
agents_md_local: None,
};
+ RENDERS.store(0, std::sync::atomic::Ordering::SeqCst);
let rendered = SystemPromptBuilder::from_dynamic(dynamic_prompt)
.build_tiered(&ctx)
.unwrap();
+ assert_eq!(RENDERS.load(std::sync::atomic::Ordering::SeqCst), 1);
+ assert!(!rendered.breakpoints.is_empty());
+ assert!(rendered.breakpoints.iter().all(|offset| rendered.text.is_char_boundary(*offset)));
let messages = rendered.system_messages();
assert_eq!(messages.len(), 2, "Stable+Context remain first, Volatile second");
assert!(messages[0].contains("Product grounding."));
- assert!(messages[0].contains("Context instructions."));
+ assert!(messages[0].contains("Context instructions 🧭."));
+ assert!(messages[0].contains("Stable πŸ“"));
assert!(messages[0].contains(custom_style));
assert!(!messages[0].contains("Volatile identity."));
assert_eq!(messages[0].matches("## Grounding and tool use").count(), 1);
@@ -739,6 +746,44 @@ fn composed_prompt_keeps_context_and_volatile_system_message_boundaries() {
let _ = std::fs::remove_dir_all(workspace);
}
+#[test]
+fn unmarked_dynamic_body_stays_volatile_after_stable_and_context_messages() {
+ fn dynamic_prompt(_ctx: &PromptContext<'_>) -> anyhow::Result<String> {
+ Ok("Unmarked dynamic UTF-8 πŸ“Ž body.".to_string())
+ }
+ let workspace = std::env::temp_dir().join(format!(
+ "openhuman_unmarked_prompt_{}",
+ uuid::Uuid::new_v4()
+ ));
+ std::fs::create_dir_all(&workspace).unwrap();
+ let ctx = PromptContext {
+ workspace_dir: &workspace,
+ model_name: "test-model",
+ agent_id: "",
+ tools: &[],
+ workflows: &[],
+ dispatcher_instructions: "",
+ visible_tool_names: &NO_FILTER,
+ tool_call_format: ToolCallFormat::PFormat,
+ connected_integrations: &[],
+ connected_identities_md: String::new(),
+ user_identity: None,
+ personality_roster: vec![],
+ agents_md_global: None,
+ agents_md_local: None,
+ };
+ let rendered = SystemPromptBuilder::from_dynamic(dynamic_prompt)
+ .build_tiered(&ctx)
+ .unwrap();
+ let messages = rendered.system_messages();
+ assert_eq!(messages.len(), 1, "unmarked body is volatile, while the adapter keeps the stable prefix");
+ assert!(rendered.parts.iter().any(|(tier, part)| {
+ *tier == PromptTier::Volatile && part.contains("Unmarked dynamic UTF-8 πŸ“Ž body.")
+ }));
+ assert!(rendered.parts.iter().any(|(tier, _)| *tier == PromptTier::Stable));
+ let _ = std::fs::remove_dir_all(workspace);
+}
+
#[test]
fn empty_verbatim_prompt_keeps_legacy_flattened_newline_without_system_messages() {
let rendered = SystemPromptBuilder::verbatim(String::new())