Skip to content

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

test(prompts): cover delegated dialect rendering

Steven Enamakelcc39db18499a
diff --git a/crates/openhuman-core/src/agent/prompts/mod_tests_subagent_render_tests.rs b/crates/openhuman-core/src/agent/prompts/mod_tests_subagent_render_tests.rs
index dffffb9336..df298a39da 100644
--- a/crates/openhuman-core/src/agent/prompts/mod_tests_subagent_render_tests.rs
+++ b/crates/openhuman-core/src/agent/prompts/mod_tests_subagent_render_tests.rs
@@ -64,6 +64,46 @@ fn render_subagent_system_prompt_renders_workspace_tail() {
let _ = std::fs::remove_dir_all(workspace);
}
+#[test]
+fn subagent_prompt_defaults_to_python_and_omits_protocol_without_tools() {
+ let workspace = std::env::temp_dir().join(format!(
+ "openhuman_prompt_default_dialect_{}",
+ uuid::Uuid::new_v4()
+ ));
+ std::fs::create_dir_all(&workspace).unwrap();
+
+ let tools: Vec<Box<dyn Tool>> = vec![Box::new(TestTool)];
+ let default_rendered = render_subagent_system_prompt(
+ &workspace,
+ "test-model",
+ &[0],
+ &tools,
+ &[],
+ "You are a focused sub-agent.",
+ SubagentRenderOptions::narrow(),
+ ToolCallFormat::default(),
+ &[],
+ );
+ assert!(default_rendered.contains("def test_tool() -> str"));
+ assert!(!default_rendered.contains("test_tool[]"));
+
+ let no_tools = render_subagent_system_prompt(
+ &workspace,
+ "test-model",
+ &[],
+ &[],
+ &[],
+ "You are a focused sub-agent.",
+ SubagentRenderOptions::narrow(),
+ ToolCallFormat::Json,
+ &[],
+ );
+ assert!(!no_tools.contains("## Tools"));
+ assert!(!no_tools.contains("## Tool Use Protocol"));
+
+ let _ = std::fs::remove_dir_all(workspace);
+}
+
#[test]
fn subagent_render_options_invert_definition_flags() {
// (omit_identity, omit_safety_preamble,
diff --git a/crates/openhuman-core/src/agent/prompts/render_helpers.rs b/crates/openhuman-core/src/agent/prompts/render_helpers.rs
index 95eb13c2aa..f8a621d0b5 100644
--- a/crates/openhuman-core/src/agent/prompts/render_helpers.rs
+++ b/crates/openhuman-core/src/agent/prompts/render_helpers.rs
@@ -22,6 +22,7 @@ pub use section_renderers::{
render_tools, render_user_files, render_user_identity, render_user_memory,
render_user_reflections, render_workspace,
};
+pub(crate) use subagent::harness_json_tool_prompt;
pub use subagent::{render_subagent_system_prompt, render_subagent_system_prompt_with_format};
pub(crate) use workspace_files::write_agents_md_blocks;
pub use workspace_files::{
diff --git a/crates/openhuman-core/src/agent/prompts/render_helpers/subagent.rs b/crates/openhuman-core/src/agent/prompts/render_helpers/subagent.rs
index e4a60d279a..c81b1d32ba 100644
--- a/crates/openhuman-core/src/agent/prompts/render_helpers/subagent.rs
+++ b/crates/openhuman-core/src/agent/prompts/render_helpers/subagent.rs
@@ -192,7 +192,9 @@ pub fn render_subagent_system_prompt_with_format(
description: tool.description().to_string(),
parameters: tool.parameters_schema(),
}));
- out.push_str(&render_tool_dialect_prompt(tool_call_format, &tool_specs));
+ if !tool_specs.is_empty() {
+ out.push_str(&render_tool_dialect_prompt(tool_call_format, &tool_specs));
+ }
out.push_str("\nUse the provided tools to accomplish the task. Reply with a concise, dense final answer when you have one — the parent agent will weave it back into the user-visible response.\n\n");
// 3b. Optional safety preamble. Definitions that do work with real
@@ -273,7 +275,7 @@ fn render_tool_dialect_prompt(format: ToolCallFormat, tools: &[tinytools::ToolSp
/// Use TinyAgents' complete text-mode prompt contract rather than teaching a
/// local JSON convention that could drift from transcript replay and parsing.
-fn harness_json_tool_prompt(tools: &[tinytools::ToolSpec]) -> String {
+pub(crate) fn harness_json_tool_prompt(tools: &[tinytools::ToolSpec]) -> String {
let schemas: Vec<tinyinference_llm::tool::ToolSchema> = tools
.iter()
.map(|tool| {
diff --git a/crates/openhuman-core/src/agent/subagent_host/tool_prep.rs b/crates/openhuman-core/src/agent/subagent_host/tool_prep.rs
index 6659122083..71201c248b 100644
--- a/crates/openhuman-core/src/agent/subagent_host/tool_prep.rs
+++ b/crates/openhuman-core/src/agent/subagent_host/tool_prep.rs
@@ -187,7 +187,10 @@ pub(crate) fn subagent_prompt_protocol(
CodeDialect, CodeStyle, NativeDialect, PFormatDialect, ToolDialect,
};
if text_mode {
- return (ToolCallFormat::Json, harness_json_tool_prompt(tools));
+ return (
+ ToolCallFormat::Json,
+ crate::agent::prompts::render_helpers::harness_json_tool_prompt(tools),
+ );
}
let instructions = match parent_format {
ToolCallFormat::PFormat => {
@@ -201,29 +204,15 @@ pub(crate) fn subagent_prompt_protocol(
// The native request carries its own structured catalogue; retain
// only the dialect guidance in the text prompt.
ToolCallFormat::Native => NativeDialect.prompt_instructions(&[]),
- ToolCallFormat::Json => harness_json_tool_prompt(tools),
+ ToolCallFormat::Json => {
+ crate::agent::prompts::render_helpers::harness_json_tool_prompt(tools)
+ }
ToolCallFormat::Python => CodeDialect::instructions(CodeStyle::Python),
ToolCallFormat::TypeScript => CodeDialect::instructions(CodeStyle::TypeScript),
};
(parent_format, instructions)
}
-/// TinyAgents owns the JSON text-mode contract, including the result replay
-/// instructions paired with its `<tool_call>` parser.
-fn harness_json_tool_prompt(tools: &[tinytools::ToolSpec]) -> String {
- let schemas: Vec<tinyinference_llm::tool::ToolSchema> = tools
- .iter()
- .map(|tool| {
- tinyinference_llm::tool::ToolSchema::new(
- tool.name.clone(),
- tool.description.clone(),
- tool.parameters.clone(),
- )
- })
- .collect();
- tinyagents_harness::tool::prompt_tool_instructions(&schemas)
-}
-
// ── Tool filtering ──────────────────────────────────────────────────────
/// Tools that spawn a new sub-agent turn. A sub-agent must never be