The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.
Rust agent-orchestrationai-agentsai-assistantdesktopllmlocal-firstmcppersonal-aiprivacyrustsecond-braintauri
fix(agent): scope load_skill's advertised index to what the session can call\n\nThe landing was fixed; the invitation was not. `pack_index_markdown()` is global\nand is baked into `LoadSkillTool`'s description at construction, before any\nsession exists, so every agent read all ten packs as loadable — including ones\nit can call nothing in. For the orchestrator that is `system` (26 tools),\n`documents` (2) and `audio` (3). The model was told to go somewhere it could not\nuse, found that out, and came back.\n\n`visible_tool_specs_for_policy` is the only place that turns tools into the\nspecs a provider sees AND holds the session, so the invitation is made to agree\nwith the gate there. It already clones every spec, so rewriting one is free, and\nit covers both the initial build and the Composio-reconcile rebuild.\n\nBoth halves are scoped, and the schema is the stronger one: narrowing the\n`skill` enum makes an unusable pack unrepresentable rather than merely\ndiscouraged in prose. The `Unknown skill` error's listing is scoped by the same\npredicate.\n\nCallability is `blocks_execution()`, not `is_denied()` — a withheld packed tool\nis `HideFromPrompt` and perfectly callable through `use_skill`. Reading the\ndisclosure mask as a denial would report no pack as reachable and drop\n`load_skill` and `use_skill` themselves, deleting the only route to every\nwithheld tool. `a_realistic_withheld_session_keeps_its_packs_advertised` pins\nthat with a session built the way the harness builds one, rather than a fixture\nwhose decisions are hand-written `Allow`s.\n\nDropped rather than annotated with an inline route, deliberately. A pack's\nowners already reach the model through their own `delegate_*` tools, whose\n`when_to_use` descriptions are on the wire and are what the model should call;\nlisting `system` with "delegate to `manage_settings`" would duplicate that\nrouting on every turn to save a round trip the model should not be taking. The\ncapability does not disappear — only the invitation to reach it the wrong way.\n\nThe description gets SMALLER: the orchestrator's index goes from 975 to 691\nchars, ~71 tokens saved every turn, plus three fewer enum entries.\n\nWhen a session can reach no pack at all, `load_skill` and `use_skill` are\ndropped from the wire — an empty index and an empty enum are not a tool.\n
M3gA-Mindeac55a0b994d
diff --git a/src/openhuman/agent/harness/session/builder/builder_tests.rs b/src/openhuman/agent/harness/session/builder/builder_tests.rsindex 6611dfa0ff..c9004fd23a 100644--- a/src/openhuman/agent/harness/session/builder/builder_tests.rs+++ b/src/openhuman/agent/harness/session/builder/builder_tests.rs@@ -2,6 +2,7 @@use super::{dedup_visible_tool_specs, ensure_recovery_tool_visible, should_synthesize_delegation_tools,+ visible_tool_specs_for_policy,};use crate::openhuman::tools::ToolSpec;use serde_json::json;@@ -69,3 +70,205 @@ mod part_01_tests;mod part_02_tests;#[path = "builder_tests_part_03_tests.rs"]mod part_03_tests;++// ── load_skill's advertised spec is scoped to the session ───────────────────++use crate::openhuman::tools::agent_policy::{+ TaskProfile, TaskRiskLevel, ToolPolicyAction, ToolPolicyDecision, ToolPolicySession,+};+use crate::openhuman::tools::traits::PermissionLevel;++fn session_allowing(names: &[&str]) -> ToolPolicySession {+ ToolPolicySession {+ profile: TaskProfile {+ agent_id: "orchestrator".to_string(),+ channel: "web_chat".to_string(),+ entrypoint: "chat".to_string(),+ risk_level: TaskRiskLevel::Low,+ allowed_permission: PermissionLevel::Dangerous,+ },+ capabilities: vec![],+ allowed_tool_names: names.iter().map(|n| n.to_string()).collect(),+ blocked_tool_names: Default::default(),+ hidden_tool_names: Default::default(),+ decisions: names+ .iter()+ .map(|n| {+ (+ n.to_string(),+ ToolPolicyDecision {+ tool_name: n.to_string(),+ action: ToolPolicyAction::Allow,+ required_permission: None,+ allowed_permission: PermissionLevel::Dangerous,+ },+ )+ })+ .collect(),+ }+}++fn load_skill_spec_from_registry() -> ToolSpec {+ let mut tools: Vec<Box<dyn crate::openhuman::tools::traits::Tool>> = Vec::new();+ crate::openhuman::tools::toolpacks::append_pack_tools(&mut tools);+ let tool = tools+ .iter()+ .find(|t| t.name() == crate::openhuman::tools::toolpacks::LOAD_SKILL)+ .expect("append_pack_tools registers load_skill");+ ToolSpec {+ name: tool.name().to_string(),+ description: tool.description().to_string(),+ parameters: tool.parameters_schema(),+ }+}++/// Proves the scoping is actually WIRED, not merely available. A correct helper+/// nobody calls advertises every pack exactly as before.+#[test]+fn visible_specs_scope_load_skills_index_to_the_session() {+ let specs = vec![+ load_skill_spec_from_registry(),+ spec(crate::openhuman::tools::toolpacks::USE_SKILL),+ ];+ let visible: std::collections::HashSet<String> = specs.iter().map(|s| s.name.clone()).collect();+ // Reachable: one workflows tool. Everything else in every other pack is+ // denied, exactly like the orchestrator against `system` / `audio`.+ let session = session_allowing(&[+ "run_workflow",+ crate::openhuman::tools::toolpacks::LOAD_SKILL,+ crate::openhuman::tools::toolpacks::USE_SKILL,+ ]);++ let out = visible_tool_specs_for_policy(&specs, &visible, &session);+ let load = out+ .iter()+ .find(|s| s.name == crate::openhuman::tools::toolpacks::LOAD_SKILL)+ .expect("load_skill is still offered — workflows is reachable");++ assert!(+ load.description.contains("`workflows`"),+ "the reachable pack must survive: {}",+ load.description+ );+ assert!(+ !load.description.contains("`system`"),+ "a pack with nothing callable must not reach the wire: {}",+ load.description+ );+ let ids = load+ .parameters+ .pointer("/properties/skill/enum")+ .and_then(|v| v.as_array())+ .expect("skill enum")+ .iter()+ .filter_map(|v| v.as_str())+ .collect::<Vec<_>>();+ assert_eq!(ids, vec!["workflows"], "the enum is scoped too");+}++/// A session that can reach no pack at all should not carry the pack tools.+#[test]+fn visible_specs_drop_the_pack_tools_when_no_pack_is_reachable() {+ let specs = vec![+ load_skill_spec_from_registry(),+ spec(crate::openhuman::tools::toolpacks::USE_SKILL),+ ];+ let visible: std::collections::HashSet<String> = specs.iter().map(|s| s.name.clone()).collect();+ let session = session_allowing(&[+ crate::openhuman::tools::toolpacks::LOAD_SKILL,+ crate::openhuman::tools::toolpacks::USE_SKILL,+ ]);++ let out = visible_tool_specs_for_policy(&specs, &visible, &session);+ assert!(+ out.is_empty(),+ "with no reachable pack, neither pack tool earns its schema: {:?}",+ out.iter().map(|s| &s.name).collect::<Vec<_>>()+ );+}++/// **The regression Codex caught on #6215, pinned with a realistic session.**+///+/// My first tests hand-built a `ToolPolicySession` whose `decisions` were+/// explicit `Allow`s — a fixture that cannot express the state every packed+/// tool is actually in. The real harness strips packed names from `visible`,+/// which classifies them `HideFromPrompt`, and `is_denied()` answers true for+/// that. A predicate built on `is_denied` therefore reported *no* pack as+/// reachable and dropped `load_skill` and `use_skill` from the wire — deleting+/// the only route to every withheld tool.+#[test]+fn a_realistic_withheld_session_keeps_its_packs_advertised() {+ use crate::openhuman::tools::agent_policy::ToolPolicyEngine;+ use crate::openhuman::tools::toolpacks::{append_pack_tools, strip_packed_from_visible};++ struct Fake(&'static str);+ #[async_trait::async_trait]+ impl crate::openhuman::tools::traits::Tool for Fake {+ fn name(&self) -> &str {+ self.0+ }+ fn description(&self) -> &str {+ "fake"+ }+ fn parameters_schema(&self) -> serde_json::Value {+ json!({ "type": "object" })+ }+ async fn execute(+ &self,+ _a: serde_json::Value,+ ) -> anyhow::Result<crate::openhuman::tools::traits::ToolResult> {+ Ok(crate::openhuman::tools::traits::ToolResult::success("ok"))+ }+ }++ let mut tools: Vec<Box<dyn crate::openhuman::tools::traits::Tool>> =+ vec![Box::new(Fake("goal_set")), Box::new(Fake("goal_get"))];+ append_pack_tools(&mut tools);++ let mut visible: std::collections::HashSet<String> =+ tools.iter().map(|t| t.name().to_string()).collect();+ strip_packed_from_visible(&mut visible, "orchestrator");+ assert!(+ !visible.contains("goal_set"),+ "precondition: the pack is withheld from the prompt"+ );++ let session = ToolPolicyEngine::build_session(+ "orchestrator",+ "web_chat",+ "chat",+ &Default::default(),+ &tools,+ &visible,+ );++ let specs: Vec<ToolSpec> = tools+ .iter()+ .map(|t| ToolSpec {+ name: t.name().to_string(),+ description: t.description().to_string(),+ parameters: t.parameters_schema(),+ })+ .collect();++ let out = visible_tool_specs_for_policy(&specs, &visible, &session);+ let names: Vec<&str> = out.iter().map(|s| s.name.as_str()).collect();++ assert!(+ names.contains(&crate::openhuman::tools::toolpacks::LOAD_SKILL),+ "load_skill must survive — the pack it opens is reachable: {names:?}"+ );+ assert!(+ names.contains(&crate::openhuman::tools::toolpacks::USE_SKILL),+ "use_skill must survive alongside it: {names:?}"+ );+ let load = out+ .iter()+ .find(|s| s.name == crate::openhuman::tools::toolpacks::LOAD_SKILL)+ .expect("load_skill spec");+ assert!(+ load.description.contains("`goals`"),+ "the withheld-but-callable pack must still be advertised: {}",+ load.description+ );+}diff --git a/src/openhuman/agent/harness/session/builder/mod.rs b/src/openhuman/agent/harness/session/builder/mod.rsindex ad788c919a..7cb04362bf 100644--- a/src/openhuman/agent/harness/session/builder/mod.rs+++ b/src/openhuman/agent/harness/session/builder/mod.rs@@ -91,6 +91,23 @@ pub(super) fn visible_tool_specs_for_policy(visible_names: &std::collections::HashSet<String>,tool_policy: &ToolPolicySession,) -> Vec<ToolSpec> {+ // `load_skill`'s description carries the pack index, and its `skill` enum+ // carries the pack ids. Both are built once in `LoadSkillTool::new`, before+ // any session exists, so every agent was told all ten packs were loadable —+ // including ones it can call nothing in. The model went, found out, and came+ // back.+ //+ // This is the only place that turns tools into the specs a provider sees AND+ // holds the session, so it is where the invitation is made to agree with the+ // gate. The same predicate the gate uses (`decision_for(..).is_denied()`),+ // not `is_allowed` — matching the filter above would re-introduce the two+ // sources of truth this whole fix exists to collapse.+ // `blocks_execution`, not `is_denied`: a withheld packed tool is+ // `HideFromPrompt` and perfectly callable through `use_skill`. Using+ // `is_denied` here would drop every pack from the index and then drop+ // `load_skill` / `use_skill` themselves — the exact capability the pack+ // mechanism exists to preserve.+ let is_callable = |name: &str| !tool_policy.decision_for(name).blocks_execution();tool_specs.iter().filter(|spec| {@@ -98,6 +115,25 @@ pub(super) fn visible_tool_specs_for_policy(&& tool_policy.is_allowed(&spec.name)}).cloned()+ .filter_map(|mut spec| {+ if spec.name == crate::openhuman::tools::toolpacks::LOAD_SKILL {+ // `false` means no pack has a callable tool: an empty index and+ // an empty enum are not a tool, so drop it rather than ship one.+ return crate::openhuman::tools::toolpacks::scope_load_skill_spec(+ &mut spec,+ &is_callable,+ )+ .then_some(spec);+ }+ if spec.name == crate::openhuman::tools::toolpacks::USE_SKILL {+ // `use_skill` is only reachable through a loaded pack, so it+ // goes wherever `load_skill` goes.+ let any_callable =+ !crate::openhuman::tools::toolpacks::callable_pack_ids(&is_callable).is_empty();+ return any_callable.then_some(spec);+ }+ Some(spec)+ }).collect()}diff --git a/src/openhuman/tools/toolpacks/mod.rs b/src/openhuman/tools/toolpacks/mod.rsindex 3146c60b03..29ec710eb3 100644--- a/src/openhuman/tools/toolpacks/mod.rs+++ b/src/openhuman/tools/toolpacks/mod.rs@@ -29,8 +29,14 @@ pub mod types;pub use groups::{GroupMode, ToolGroups, GROUP_COUNT};pub use ops::{append_pack_tools, bind_pack_registry, strip_packed_from_visible};-pub use registry::{all_packed_tool_names, pack, pack_for_tool, PACKS};-pub use tools::{render_pack_filtered, route_sentence, PackRegistryHandle, LOAD_SKILL, USE_SKILL};+pub use registry::{+ all_packed_tool_names, callable_pack_ids, pack, pack_for_tool, pack_index_markdown_filtered,+ PACKS,+};+pub use tools::{+ render_pack_filtered, route_sentence, scope_load_skill_spec, PackRegistryHandle, LOAD_SKILL,+ USE_SKILL,+};pub use types::ToolPack;#[cfg(test)]diff --git a/src/openhuman/tools/toolpacks/registry.rs b/src/openhuman/tools/toolpacks/registry.rsindex e0ab40c41b..f095ffc478 100644--- a/src/openhuman/tools/toolpacks/registry.rs+++ b/src/openhuman/tools/toolpacks/registry.rs@@ -259,9 +259,35 @@ pub fn packed_tool_names_for_agent(agent_id: &str) -> Vec<&'static str> {/// The always-on index: one line per pack, rendered into `load_skill`'s own/// description so the model can pick a pack without a round trip.pub fn pack_index_markdown() -> String {+ pack_index_markdown_filtered(&|_| true)+}++/// The pack index, limited to packs this session can call at least one tool in.+///+/// A pack with nothing callable is not an answer to "which skills can I load",+/// and advertising it costs a round trip: the model loads it, learns it cannot+/// use it, and comes back. The capability does not disappear — a pack's owners+/// reach the model through their own `delegate_*` tools, whose `when_to_use`+/// descriptions are already on the wire and are what the model should call+/// anyway. Keeping the pack listed here would duplicate that routing on every+/// single turn.+pub fn pack_index_markdown_filtered(is_callable: &dyn Fn(&str) -> bool) -> String {let mut out = String::new();for p in PACKS {+ if !p.tools.iter().any(|t| is_callable(t)) {+ continue;+ }out.push_str(&format!("- `{}` — {}\n", p.id, p.summary));}out}++/// Pack ids with at least one tool this session can call — the `skill` enum+/// `load_skill` should actually offer.+pub fn callable_pack_ids(is_callable: &dyn Fn(&str) -> bool) -> Vec<&'static str> {+ PACKS+ .iter()+ .filter(|p| p.tools.iter().any(|t| is_callable(t)))+ .map(|p| p.id)+ .collect()+}diff --git a/src/openhuman/tools/toolpacks/toolpacks_tests_part_02_tests.rs b/src/openhuman/tools/toolpacks/toolpacks_tests_part_02_tests.rsindex f139a998fe..9fb0fe7ab7 100644--- a/src/openhuman/tools/toolpacks/toolpacks_tests_part_02_tests.rs+++ b/src/openhuman/tools/toolpacks/toolpacks_tests_part_02_tests.rs@@ -3,6 +3,102 @@use super::*;+// ── the index must agree with the gate too ──────────────────────────────────++/// A spec shaped like the one `LoadSkillTool` publishes.+fn load_skill_spec() -> crate::openhuman::tools::traits::ToolSpec {+ let tools = registry_with_all(&["build_workflow"]);+ let tool = find(&tools, LOAD_SKILL);+ crate::openhuman::tools::traits::ToolSpec {+ name: tool.name().to_string(),+ description: tool.description().to_string(),+ parameters: tool.parameters_schema(),+ }+}++/// The landing was fixed first; this is the invitation. A pack the session can+/// call nothing in must not be advertised as loadable — the model would go,+/// find out, and come back, which is a wasted round trip on every turn it is+/// tempted.+#[test]+fn the_index_drops_a_pack_this_session_can_call_nothing_in() {+ let mut spec = load_skill_spec();+ assert!(+ spec.description.contains("`system`"),+ "precondition: the unscoped index advertises every pack"+ );++ // Only the workflows pack is reachable.+ let workflows = pack("workflows").expect("workflows pack");+ let kept = scope_load_skill_spec(&mut spec, &|name| workflows.tools.contains(&name));+ assert!(+ kept,+ "workflows is callable, so load_skill stays on the wire"+ );++ assert!(+ spec.description.contains("`workflows`"),+ "a reachable pack must still be offered: {}",+ spec.description+ );+ for dead in ["`system`", "`crypto`", "`audio`", "`documents`"] {+ assert!(+ !spec.description.contains(dead),+ "{dead} has no callable tool here and must not be advertised: {}",+ spec.description+ );+ }+}++/// The schema is the stronger half: an unusable pack becomes unrepresentable,+/// not merely discouraged in prose.+#[test]+fn the_skill_enum_offers_only_reachable_packs() {+ let mut spec = load_skill_spec();+ let workflows = pack("workflows").expect("workflows pack");+ scope_load_skill_spec(&mut spec, &|name| workflows.tools.contains(&name));++ let values = spec+ .parameters+ .pointer("/properties/skill/enum")+ .and_then(Value::as_array)+ .expect("the skill enum survives scoping")+ .iter()+ .filter_map(Value::as_str)+ .collect::<Vec<_>>();+ assert_eq!(+ values,+ vec!["workflows"],+ "the enum must name exactly the reachable packs"+ );+}++/// An empty index and an empty enum are not a tool. The caller is told to drop+/// `load_skill` rather than ship one that can do nothing.+#[test]+fn a_session_that_can_reach_no_pack_loses_load_skill() {+ let mut spec = load_skill_spec();+ assert!(+ !scope_load_skill_spec(&mut spec, &|_| false),+ "with nothing reachable, load_skill must be dropped, not emptied"+ );+}++/// Scoping must not quietly cost more context than it saves — the index is+/// charged to every turn.+#[test]+fn scoping_the_index_only_ever_shrinks_it() {+ let mut spec = load_skill_spec();+ let before = spec.description.len();+ let workflows = pack("workflows").expect("workflows pack");+ scope_load_skill_spec(&mut spec, &|name| workflows.tools.contains(&name));+ assert!(+ spec.description.len() < before,+ "scoped index ({}) must be smaller than the full one ({before})",+ spec.description.len()+ );+}+/// **The contract this fix must not break** (AGENTS.md: `Withheld` = "Registered/// and callable: yes"). A withheld packed tool is hidden from the prompt and/// still callable through `use_skill` — that is the entire point of a pack.diff --git a/src/openhuman/tools/toolpacks/tools.rs b/src/openhuman/tools/toolpacks/tools.rsindex 341f4edc4e..9c694c509e 100644--- a/src/openhuman/tools/toolpacks/tools.rs+++ b/src/openhuman/tools/toolpacks/tools.rs@@ -6,7 +6,9 @@ use async_trait::async_trait;use serde_json::{json, Value};use super::registry;-use crate::openhuman::tools::traits::{PermissionLevel, Tool, ToolCallOptions, ToolResult};+use crate::openhuman::tools::traits::{+ PermissionLevel, Tool, ToolCallOptions, ToolResult, ToolSpec,+};use tinytools::ToolRunContext;pub const LOAD_SKILL: &str = "load_skill";@@ -97,9 +99,11 @@ pub fn render_pack_filtered(route: &str,) -> Result<String, String> {let Some(pack) = registry::pack(skill) else {+ // Scoped too: offering a hallucinating model a pack it cannot use is the+ // same wrong turn the advertised index used to take, one error later.return Err(format!("Unknown skill `{skill}`. Available:\n{}",- registry::pack_index_markdown()+ registry::pack_index_markdown_filtered(is_callable)));};let Some(tools) = handle.tools() else {@@ -199,6 +203,45 @@ fn render_pack(skill: &str, handle: &PackRegistryHandle) -> Result<String, Strinrender_pack_filtered(skill, handle, &|_| true, "")}+/// Rewrite `load_skill`'s advertised spec to match what this session can do.+///+/// The description is built once in [`LoadSkillTool::new`], before any session+/// exists, so every agent was told all ten packs were loadable — including ones+/// it can call nothing in. Post-#(routing fix) that costs one wasted round trip+/// instead of a dead turn; it should cost zero.+///+/// Both halves are rewritten, and the schema is the stronger one: narrowing the+/// `skill` enum makes an unusable pack *unrepresentable* rather than merely+/// discouraged in prose, and a shorter enum is fewer tokens, not more.+///+/// Returns `false` when this session can call nothing in any pack — the caller+/// should then drop `load_skill` / `use_skill` from the wire entirely, because+/// an empty index and an empty enum are not a tool.+pub fn scope_load_skill_spec(spec: &mut ToolSpec, is_callable: &dyn Fn(&str) -> bool) -> bool {+ let ids = registry::callable_pack_ids(is_callable);+ if ids.is_empty() {+ return false;+ }+ if let Some(index) = spec.description.find("\n\nSkills:\n") {+ spec.description.truncate(index);+ spec.description.push_str("\n\nSkills:\n");+ spec.description+ .push_str(®istry::pack_index_markdown_filtered(is_callable));+ }+ if let Some(enum_slot) = spec+ .parameters+ .pointer_mut("/properties/skill/enum")+ .filter(|v| v.is_array())+ {+ *enum_slot = Value::Array(+ ids.iter()+ .map(|id| Value::String((*id).to_string()))+ .collect(),+ );+ }+ true+}+fn skill_enum() -> Vec<&'static str> {registry::PACKS.iter().map(|p| p.id).collect()}