Skip to content

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

feat(agent): flatten integration actions into direct tool search

Steven Enamakel7df470b7b8e7
diff --git a/crates/openhuman-core/src/agent/registry/agents/orchestrator/prompt.rs b/crates/openhuman-core/src/agent/registry/agents/orchestrator/prompt.rs
index 76163d6ad0..651c062445 100644
--- a/crates/openhuman-core/src/agent/registry/agents/orchestrator/prompt.rs
+++ b/crates/openhuman-core/src/agent/registry/agents/orchestrator/prompt.rs
@@ -2,14 +2,13 @@
//!
//! The orchestrator follows a direct-first policy: respond directly or use
//! cheap direct tools whenever possible, and delegate only for specialised
-//! execution. It never executes Composio actions itself; the integration
-//! block points to the single collapsed `delegate_to_integrations_agent`
-//! tool (synthesised by `orchestrator_tools::collect_orchestrator_tools`,
-//! #1335) for true external-service operations, with the toolkit slug
-//! passed as an argument. That prose lives here (not in the shared
-//! prompts module) so the skill-executor voice stays in
-//! `integrations_agent/prompt.rs` and nobody has to branch on `agent_id`
-//! in a shared section impl.
+//! execution. Connected Composio integrations are part of that direct
+//! surface: every connected toolkit's actions are registered as `Deferred`
+//! tools (`orchestrator_tools::collect_deferred_integration_actions`), so
+//! the `## Connected Integrations` block tells the model to `tool_search`
+//! for the action and call it — there is no integrations sub-agent to
+//! delegate to any more. That prose lives here (not in the shared prompts
+//! module) so nobody has to branch on `agent_id` in a shared section impl.
use crate::agent::harness::definition::SubagentEntry;
use crate::agent::harness::AgentDefinitionRegistry;
@@ -92,7 +91,7 @@ pub fn build(ctx: &PromptContext<'_>) -> Result<String> {
push(&mut out, &render_withheld_specialists(ctx));
push(
&mut out,
- &render_delegation_guide(ctx.connected_integrations, ctx.tool_call_format),
+ &render_connected_integrations(ctx.connected_integrations),
);
push(
&mut out,
@@ -146,8 +145,8 @@ fn render_withheld_specialists(ctx: &PromptContext<'_>) -> String {
let mut rows: Vec<(String, &'static str)> = Vec::new();
for entry in &definition.subagents {
- // `Skills(_)` expands to `delegate_to_integrations_agent`, which the
- // `## Connected Integrations` block below documents in full.
+ // `Skills(_)` expands to searchable integration actions, not a
+ // delegate tool; the `## Connected Integrations` block covers them.
let SubagentEntry::AgentId(agent_id) = entry else {
continue;
};
@@ -359,7 +358,7 @@ fn render_installed_skills(
}
/// Render the `## Connected MCP Servers` block from the live connection
-/// registry. The MCP analogue of [`render_delegation_guide`]: it lists each
+/// registry. The MCP analogue of [`render_connected_integrations`]: it lists each
/// connected MCP server and tells the orchestrator to hand matching requests to
/// the `mcp_agent` worker — NOT to call a server's tools itself or claim it
/// can't. This is what lets the orchestrator pick up a connected server
@@ -466,57 +465,49 @@ fn format_connected_mcp_block(
out
}
-/// Render the delegator-voice `## Connected Integrations` block. Only
-/// toolkits the user has actively connected are listed — unauthorised
-/// toolkits are hidden so the orchestrator cannot hallucinate a delegation
-/// to an integration whose `delegate_*` tool does not actually exist.
-/// When every toolkit is unconnected the whole section is omitted.
+/// Render the `## Connected Integrations` block. Only toolkits the user has
+/// actively connected are listed — unauthorised toolkits are hidden so the
+/// orchestrator cannot claim access to a service it does not have. When
+/// every toolkit is unconnected the whole section is omitted.
///
-/// The tool name printed in the prompt is derived with the same
-/// `sanitise_slug` function that `collect_orchestrator_tools` uses when
-/// synthesising the real tool objects, so the names in the prompt always
-/// match the names in the function-calling schema.
+/// The connected toolkits' actions are `Deferred` tools on this agent's own
+/// belt (`collect_deferred_integration_actions`), so the block teaches one
+/// route: `tool_search` for the action, then call it. The old collapsed
+/// `delegate_to_integrations_agent` spawn is gone; an integration action is
+/// a search and a call, not a sub-agent run.
///
-/// `tool_call_format` lets the guide adapt to the active provider. Providers
-/// with native structured tool-calling (`ToolCallFormat::Native`) get the
-/// historic guide unchanged. Text-protocol providers (`PFormat`/`Json`) — the
-/// dispatcher chosen for models that force `native_tool_calling = false`, i.e.
-/// local runtimes like Ollama / LM Studio / MLX / llama.cpp — additionally get
-/// an explicit "when NOT to delegate" carve-out. Weak local models over-select
-/// from the prose tool catalogue and the coercive "you MUST delegate" wording,
-/// spuriously routing greetings and local-filesystem actions into
-/// `delegate_to_integrations_agent` (issue #4361: "Ciao" → Connections,
-/// "create a folder on Desktop" → Calendar). The carve-out is additive: the
-/// always-delegate contract for genuine service requests is preserved.
-fn render_delegation_guide(
- integrations: &[ConnectedIntegration],
- tool_call_format: ToolCallFormat,
-) -> String {
+/// The slug printed beside each toolkit uses the same `sanitise_slug` as the
+/// rest of the prompt surface so the model's `composio_connect` argument and
+/// its searches name the toolkit consistently.
+///
+/// The gated-tools appendix used to live in the integrations sub-agent's
+/// prompt. It moves here with the catalogue: an action behind a permission
+/// toggle is not in the searchable set, so without this list the model would
+/// answer "can you do X?" with a wrong "no" instead of the unlock path.
+fn render_connected_integrations(integrations: &[ConnectedIntegration]) -> String {
let connected: Vec<&ConnectedIntegration> =
integrations.iter().filter(|ci| ci.connected).collect();
tracing::debug!(
total_integrations = integrations.len(),
connected_count = connected.len(),
- "[delegation-guide] rendering integration section ({} connected / {} total)",
+ "[connected-integrations] rendering integration section ({} connected / {} total)",
connected.len(),
integrations.len()
);
if connected.is_empty() {
- tracing::debug!("[delegation-guide] section omitted — no connected integrations");
+ tracing::debug!("[connected-integrations] section omitted — no connected integrations");
return String::new();
}
let mut out = String::from(
"## Connected Integrations\n\n\
- Their tools live in `integrations_agent`, not in your list: act on them only through \
- `delegate_to_integrations_agent` with the toolkit slug, and only when the request \
- operates on that service's data or actions (a connected service is not a reason to \
- touch it for general-knowledge, web/news, date/time or math questions). Never claim \
- you cannot access one without delegating first.\n\n",
+ Their actions are not in your listed tools: `tool_search` for the action in plain \
+ words (\"send an email\", \"list calendar events\"), then call the tool it returns — \
+ no sub-agent. Act on a service only when the request operates on that service's data \
+ or actions (a connected service is not a reason to touch it for general-knowledge, \
+ web/news, date/time or math questions). Never claim you cannot access one without \
+ searching first.\n\n",
);
- for ci in connected {
- // Use the same slug canonicalisation as `collect_orchestrator_tools`
- // so the `toolkit` arg the orchestrator emits always matches the
- // enum the synthesised tool accepts.
+ for ci in &connected {
let slug = sanitise_slug(&ci.toolkit);
if ci.connections.len() > 1 {
let _ = writeln!(
@@ -550,10 +541,8 @@ fn render_delegation_guide(
// SUBSET of the real per-toolkit catalogue (no bulk-delete, no
// batch-modify, no admin/destructive actions, etc.). The result is a
// confident wrong refusal ("nope, I can't delete emails") even when
- // the action is in the actual tool list. The `integrations_agent`
- // has the ground-truth tool catalogue (`tools` + `gated_tools`); only
- // it can answer "can I do X?" honestly. Force-delegate capability
- // questions, not just task requests.
+ // the action is in the catalogue. `tool_search` is the ground truth for
+ // callable actions and the gated appendix below for the rest.
// The cross-chat bullet names the canonical header literal verbatim
// so the model knows exactly which block to mistrust. Sourced from
// CROSS_CHAT_HEADER (single source of truth) — drift would silently
@@ -565,34 +554,56 @@ fn render_delegation_guide(
"\n### Capability questions about connected toolkits\n\n\
Your prior knowledge of what a toolkit can do is unreliable: the live catalogue and \
the user's scopes decide. For \"can you do X with {{toolkit}}?\" or any action on a \
- connected toolkit, delegate first and let `integrations_agent` inspect its tools \
- (including `gated_tools`); the only honest \"no\" is one it reported. A past \
- \"I can / can't\" in the `{cross_chat_header_for_prompt}` block is a stale snapshot, \
- never an answer.\n\n",
+ connected toolkit, `tool_search` first; the only honest \"no\" is an empty search that \
+ the permission-gated list below does not explain. A past \"I can / can't\" in the \
+ `{cross_chat_header_for_prompt}` block is a stale snapshot, never an answer.\n\n",
);
- if tool_call_format != ToolCallFormat::Native {
+ // Pref-gated actions: the toolkit has them, the user has not granted the
+ // scope, so they are not in the searchable catalogue. The agent cannot
+ // call them and cannot flip the scope itself — the per-row `unlock
+ // paths` carry the exact UI hint to show the user.
+ let gated: Vec<&&ConnectedIntegration> = connected
+ .iter()
+ .filter(|ci| !ci.gated_tools.is_empty())
+ .collect();
+ tracing::debug!(
+ connected_with_gated = gated.len(),
+ "[connected-integrations] gated-tools scan complete"
+ );
+ if !gated.is_empty() {
out.push_str(
- "### When NOT to delegate\n\n\
- Some requests are NOT integration work — handle them directly and do NOT call \
- `delegate_to_integrations_agent`:\n\
- - **Greetings and small talk** (\"hi\", \"hello\", \"ciao\", \"thanks\", \"how are \
- you?\") — just reply.\n\
- - **Local-machine actions**: creating, reading, writing, moving, or listing files \
- and folders on this computer (e.g. \"create a folder on the Desktop\", \"make a \
- directory\", \"save this to a file\") — use your local filesystem tools. A local \
- folder/file request is NOT a Calendar, Drive, or any connected-service request.\n\n\
- Delegate ONLY when the request clearly names or operates on one of the connected \
- services listed above (its email, calendar, messages, documents, etc.). When a \
- request mixes a local action with a connected service (\"save my latest email to a \
- file on the Desktop\"), do the local part directly and delegate only the \
- service part.\n\n",
+ "### Additional capabilities behind a permission toggle\n\n\
+ These actions exist in the toolkit but are NOT searchable or callable — the user \
+ has not granted the required scope. Do NOT pretend they're unavailable. When the \
+ user asks for one (or you'd otherwise need it), tell them what the action does and \
+ present ALL of its `unlock paths` listed below so the user can choose how to enable \
+ it. Never drop a path or rewrite it into your own framing.\n\n",
);
+ for ci in gated {
+ let _ = writeln!(out, "- **{}**:", ci.toolkit);
+ for gt in &ci.gated_tools {
+ let desc = if gt.description.is_empty() {
+ "(no description)"
+ } else {
+ gt.description.as_str()
+ };
+ let _ = writeln!(
+ out,
+ " - `{}` — {} (requires `{}` scope)",
+ gt.name, desc, gt.required_scope
+ );
+ for path in &gt.unlock_paths {
+ let _ = writeln!(out, " - unlock path: {path}");
+ }
+ }
+ }
+ out.push('\n');
}
tracing::debug!(
section_len = out.len(),
- "[delegation-guide] section emitted ({} bytes)",
+ "[connected-integrations] section emitted ({} bytes)",
out.len()
);
out