Skip to content

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

fix(agent): render the tool catalogue for a text-mode integrations_agent under a native parent

M3gA-Mind98d5b716685c
diff --git a/crates/openhuman-core/src/agent/harness/subagent_runner/ops/runner.rs b/crates/openhuman-core/src/agent/harness/subagent_runner/ops/runner.rs
index f510c0f83a..f49c6684c2 100644
--- a/crates/openhuman-core/src/agent/harness/subagent_runner/ops/runner.rs
+++ b/crates/openhuman-core/src/agent/harness/subagent_runner/ops/runner.rs
@@ -33,7 +33,7 @@ use crate::agent::harness::subagent_runner::subagent_iter_cap_with_autonomous_li
use crate::agent::harness::subagent_runner::tool_prep::{
build_text_mode_tool_instructions, filter_tool_indices, is_subagent_spawn_tool,
load_prompt_source, select_actions_with_essentials, strip_spawn_tools_from_dynamic,
- top_k_for_toolkit,
+ subagent_prompt_protocol, top_k_for_toolkit,
};
use crate::agent::harness::subagent_runner::types::{
SubagentMode, SubagentRunError, SubagentRunOptions, SubagentRunOutcome, SubagentRunStatus,
@@ -1333,21 +1333,8 @@ async fn run_typed_mode(
.collect();
let visible_tool_names: std::collections::HashSet<String> =
prompt_tools.iter().map(|t| t.name.to_string()).collect();
- let dispatcher_instructions = {
- use crate::agent::context::prompt::ToolCallFormat;
- use crate::agent::dispatcher::{
- NativeToolDispatcher, PFormatToolDispatcher, ToolDispatcher, XmlToolDispatcher,
- };
- use crate::agent::pformat::PFormatRegistry;
- let empty_tools: Vec<Box<dyn Tool>> = Vec::new();
- match parent.tool_call_format {
- ToolCallFormat::PFormat => {
- PFormatToolDispatcher::new(PFormatRegistry::new()).prompt_instructions(&empty_tools)
- }
- ToolCallFormat::Native => NativeToolDispatcher.prompt_instructions(&empty_tools),
- ToolCallFormat::Json => XmlToolDispatcher.prompt_instructions(&empty_tools),
- }
- };
+ let (prompt_tool_call_format, dispatcher_instructions) =
+ subagent_prompt_protocol(parent.tool_call_format, is_integrations_agent_with_toolkit);
// Load AGENTS.md instruction layers once, at prompt-build time, when the
// config gate is on. The global layer comes from the workspace dir; the
// project layer comes from the sub-agent's `worktree_action_dir` override
@@ -1386,7 +1373,7 @@ async fn run_typed_mode(
dispatcher_instructions: &dispatcher_instructions,
learned: crate::agent::context::prompt::LearnedContextData::default(),
visible_tool_names: &visible_tool_names,
- tool_call_format: parent.tool_call_format,
+ tool_call_format: prompt_tool_call_format,
connected_integrations: &narrowed_integrations,
connected_identities_md: crate::agent::prompts::render_connected_identities(),
include_profile: !definition.omit_profile,
@@ -1417,7 +1404,7 @@ async fn run_typed_mode(
&dynamic_tools,
&archetype_prompt_body,
render_options,
- parent.tool_call_format,
+ prompt_tool_call_format,
&narrowed_integrations,
agents_md.global.as_deref(),
agents_md.local.as_deref(),
diff --git a/crates/openhuman-core/src/agent/harness/subagent_runner/tool_prep.rs b/crates/openhuman-core/src/agent/harness/subagent_runner/tool_prep.rs
index dcca414f59..4533bd7747 100644
--- a/crates/openhuman-core/src/agent/harness/subagent_runner/tool_prep.rs
+++ b/crates/openhuman-core/src/agent/harness/subagent_runner/tool_prep.rs
@@ -218,6 +218,39 @@ pub(crate) fn build_text_mode_tool_instructions() -> String {
out
}
+/// The tool-call format a sub-agent's prompt is rendered for, and the
+/// dispatcher protocol block that goes with it.
+///
+/// Normally both follow the parent. A text-mode child (the toolkit-scoped
+/// `integrations_agent`) is sent no native `tools`, so it must render its own
+/// catalogue as text whatever the parent uses: under a native-tool parent,
+/// `ToolsSection` would otherwise emit no catalogue and the native JSON protocol,
+/// and the child would be told how to call tools but never which ones exist.
+/// Its protocol block is empty because the runner appends
+/// [`build_text_mode_tool_instructions`] itself.
+pub(crate) fn subagent_prompt_protocol(
+ parent_format: crate::agent::context::prompt::ToolCallFormat,
+ text_mode: bool,
+) -> (crate::agent::context::prompt::ToolCallFormat, String) {
+ use crate::agent::context::prompt::ToolCallFormat;
+ use crate::agent::dispatcher::{
+ NativeToolDispatcher, PFormatToolDispatcher, ToolDispatcher, XmlToolDispatcher,
+ };
+ use crate::agent::pformat::PFormatRegistry;
+ if text_mode {
+ return (ToolCallFormat::PFormat, String::new());
+ }
+ let empty_tools: Vec<Box<dyn Tool>> = Vec::new();
+ let instructions = match parent_format {
+ ToolCallFormat::PFormat => {
+ PFormatToolDispatcher::new(PFormatRegistry::new()).prompt_instructions(&empty_tools)
+ }
+ ToolCallFormat::Native => NativeToolDispatcher.prompt_instructions(&empty_tools),
+ ToolCallFormat::Json => XmlToolDispatcher.prompt_instructions(&empty_tools),
+ };
+ (parent_format, instructions)
+}
+
// ── Tool filtering ──────────────────────────────────────────────────────
/// Tools that spawn a new sub-agent turn. A sub-agent must never be
diff --git a/crates/openhuman-core/src/agent/harness/subagent_runner/tool_prep_tests.rs b/crates/openhuman-core/src/agent/harness/subagent_runner/tool_prep_tests.rs
index a21623d9a0..113cd495f5 100644
--- a/crates/openhuman-core/src/agent/harness/subagent_runner/tool_prep_tests.rs
+++ b/crates/openhuman-core/src/agent/harness/subagent_runner/tool_prep_tests.rs
@@ -412,3 +412,82 @@ fn a_dynamic_tool_list_without_spawn_tools_is_untouched() {
vec!["GMAIL_FETCH_EMAILS", "extract_from_result"]
);
}
+
+/// Render the `## Tools` section the way a sub-agent prompt does, at `format`.
+fn render_tools_at(
+ format: crate::agent::context::prompt::ToolCallFormat,
+ instructions: &str,
+) -> String {
+ use crate::agent::context::prompt::{LearnedContextData, PromptTool};
+ let tools = [PromptTool {
+ name: "composio_execute",
+ description: "Run one Composio action.",
+ parameters_schema: Some(
+ r#"{"type":"object","properties":{"action":{"type":"string"}}}"#.into(),
+ ),
+ }];
+ let visible = std::collections::HashSet::new();
+ let ctx = PromptContext {
+ workspace_dir: std::path::Path::new("/tmp"),
+ model_name: "test-model",
+ agent_id: "integrations_agent",
+ tools: &tools,
+ workflows: &[],
+ dispatcher_instructions: instructions,
+ learned: LearnedContextData::default(),
+ visible_tool_names: &visible,
+ tool_call_format: format,
+ connected_integrations: &[],
+ connected_identities_md: String::new(),
+ include_profile: false,
+ include_memory_md: false,
+ curated_snapshot: None,
+ user_identity: None,
+ personality_soul_md: None,
+ personality_memory_md: None,
+ personality_roster: vec![],
+ agents_md_global: None,
+ agents_md_local: None,
+ };
+ crate::agent::prompts::render_tools(&ctx).unwrap()
+}
+
+/// A text-mode child of a native-tool parent is sent no native `tools`, so its
+/// prompt must list them. Rendering at the parent's format is what used to
+/// happen: no catalogue at all, plus the native JSON protocol.
+#[test]
+fn text_mode_child_of_a_native_parent_renders_its_tool_catalogue() {
+ use crate::agent::context::prompt::ToolCallFormat;
+
+ let (format, instructions) = subagent_prompt_protocol(ToolCallFormat::Native, true);
+ assert_eq!(format, ToolCallFormat::PFormat);
+ assert!(
+ instructions.is_empty(),
+ "the runner appends the text-mode protocol itself; a second block conflicts: {instructions}"
+ );
+ let rendered = render_tools_at(format, &instructions);
+ assert!(
+ rendered.contains("- **composio_execute**:"),
+ "text-mode child has no tool catalogue: {rendered:?}"
+ );
+
+ let parents = render_tools_at(ToolCallFormat::Native, "");
+ assert!(
+ !parents.contains("- **composio_execute**:"),
+ "a native-format render is expected to omit the catalogue: {parents:?}"
+ );
+}
+
+#[test]
+fn native_child_keeps_the_parents_protocol() {
+ use crate::agent::context::prompt::ToolCallFormat;
+
+ for parent in [
+ ToolCallFormat::Native,
+ ToolCallFormat::PFormat,
+ ToolCallFormat::Json,
+ ] {
+ let (format, _) = subagent_prompt_protocol(parent, false);
+ assert_eq!(format, parent);
+ }
+}