Skip to content

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

fix(memory): respect belt scoping and collapsed tool capability filtering

Steven Enamakel3b0ea41cae01
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 970b955cac..0af8b1a660 100644
--- a/crates/openhuman-core/src/agent/registry/agents/orchestrator/prompt.rs
+++ b/crates/openhuman-core/src/agent/registry/agents/orchestrator/prompt.rs
@@ -267,10 +267,14 @@ fn run_workflow_route(ctx: &PromptContext<'_>) -> Option<String> {
if ctx.visible_tool_names.is_empty() || ctx.visible_tool_names.contains(RUN_WORKFLOW) {
return Some(format!("`{RUN_WORKFLOW}`"));
}
- // Packed: only a route if this session can call `use_skill` itself.
+ // Packed: only a route if this session can call `use_skill` itself, AND its
+ // belt actually lists `run_workflow`. `use_skill` may be on the wire for
+ // some other pack while the `workflows` pack has nothing callable here, in
+ // which case the policy gate would refuse the call this names.
if !ctx
.visible_tool_names
.contains(tinyagents_harness::tool::packs::USE_SKILL)
+ || !belt_lists(ctx, RUN_WORKFLOW)
{
return None;
}
@@ -278,6 +282,23 @@ fn run_workflow_route(ctx: &PromptContext<'_>) -> Option<String> {
.map(|pack| format!("`{RUN_WORKFLOW}` (`use_skill` skill `{}`)", pack.id))
}
+/// Whether this agent's own belt lists `tool`: a wildcard belt holds everything,
+/// a named one only what it names. The prompt has no policy session, and a pack
+/// is callable for an agent only when its belt mentions one of the pack's tools.
+fn belt_lists(ctx: &PromptContext<'_>, tool: &str) -> bool {
+ use crate::agent::harness::definition::ToolScope;
+ let Some(registry) = AgentDefinitionRegistry::global() else {
+ return false;
+ };
+ let Some(definition) = resolve_definition(registry, ctx.agent_id) else {
+ return false;
+ };
+ match &definition.tools {
+ ToolScope::Wildcard => true,
+ ToolScope::Named(names) => names.iter().any(|name| name == tool),
+ }
+}
+
/// `prompt.md` with the route-tagged rows this build cannot honour removed.
///
/// A row tagged `<!--route:skills-->` or `<!--route:mcp-->` names a hand-off
diff --git a/crates/openhuman-core/src/agent/session_host/builder/helpers.rs b/crates/openhuman-core/src/agent/session_host/builder/helpers.rs
index 3169212b24..a732364d0d 100644
--- a/crates/openhuman-core/src/agent/session_host/builder/helpers.rs
+++ b/crates/openhuman-core/src/agent/session_host/builder/helpers.rs
@@ -124,7 +124,26 @@ pub(super) fn add_memory_prompt_sections(
crate::tools::toolpacks::strip_packed_from_visible(&mut after, agent_id);
after
};
- if any_tool_offered(&MEMORY_READ_TOOLS, tools, delegation_tools, visible) {
+ // The collapsed `memory` tool counts only for the actions it still
+ // advertises: a driver that cannot store drops `learn`, and one that cannot
+ // search leaves only writes, so the tool's name alone proves neither.
+ let memory_actions: Vec<String> = tools
+ .iter()
+ .chain(delegation_tools)
+ .find(|tool| tool.name() == MEMORY_TOOL)
+ .filter(|_| any_tool_offered(&[MEMORY_TOOL], tools, delegation_tools, visible))
+ .map(|tool| crate::memory::tools::advertised_actions(tool.as_ref()))
+ .unwrap_or_default();
+ let memory_can_read = memory_actions
+ .iter()
+ .any(|a| a == "ask" || a == "keyword_search");
+ let memory_can_learn = memory_actions.iter().any(|a| a == "learn");
+ let legacy_read: Vec<&str> = MEMORY_READ_TOOLS
+ .iter()
+ .copied()
+ .filter(|name| *name != MEMORY_TOOL)
+ .collect();
+ if memory_can_read || any_tool_offered(&legacy_read, tools, delegation_tools, visible) {
prompt_builder = prompt_builder.add_section(Box::new(MemoryAccessSection));
log::debug!("[memory_access] prompt section registered");
} else {
@@ -140,7 +159,7 @@ pub(super) fn add_memory_prompt_sections(
let store_offered = any_tool_offered(&[MEMORY_STORE_TOOL], tools, delegation_tools, visible);
// The collapsed `memory` tool writes through its `learn` action; the legacy
// `memory_store` wins the wording only when both are held.
- let memory_offered = any_tool_offered(&[MEMORY_TOOL], tools, delegation_tools, visible);
+ let memory_offered = memory_can_learn;
let facts = store_offered || memory_offered;
// #6200: asked for as well as the pair, not instead of it. An agent whose
// only write path is the delegate held the tool and no rule about using it
diff --git a/crates/openhuman-core/src/memory/tools.rs b/crates/openhuman-core/src/memory/tools.rs
index d89720e0df..2f26308201 100644
--- a/crates/openhuman-core/src/memory/tools.rs
+++ b/crates/openhuman-core/src/memory/tools.rs
@@ -24,7 +24,7 @@ pub mod search;
pub mod tool_memory;
pub use crate::memory::query::*;
-pub use collapsed::{MemoryTool, MEMORY_TOOL_NAME};
+pub use collapsed::{advertised_actions, MemoryTool, MEMORY_TOOL_NAME};
pub use doctor::MemoryDoctorTool;
pub use flavour::MemoryFlavourTool;
pub use forget::MemoryForgetTool;
diff --git a/crates/openhuman-core/src/memory/tools/collapsed.rs b/crates/openhuman-core/src/memory/tools/collapsed.rs
index 6d22ce9d11..ca58049972 100644
--- a/crates/openhuman-core/src/memory/tools/collapsed.rs
+++ b/crates/openhuman-core/src/memory/tools/collapsed.rs
@@ -119,6 +119,26 @@ impl MemoryTool {
}
}
+/// The actions a registered `memory` tool currently advertises, read from its
+/// schema enum. Capability filtering can drop one (a driver that searches but
+/// cannot store loses `learn`), so a prompt rule about an action must ask this
+/// rather than assume the tool's name implies every action.
+#[must_use]
+pub fn advertised_actions(tool: &dyn Tool) -> Vec<String> {
+ if tool.name() != MEMORY_TOOL_NAME {
+ return Vec::new();
+ }
+ tool.parameters_schema()["properties"]["action"]["enum"]
+ .as_array()
+ .map(|actions| {
+ actions
+ .iter()
+ .filter_map(|a| a.as_str().map(str::to_string))
+ .collect()
+ })
+ .unwrap_or_default()
+}
+
/// Translate the tool's `{action, text, namespace?, limit?}` call into the
/// member tool's own argument shape.
fn member_args(action: &str, args: &Value) -> Result<Value, String> {
diff --git a/crates/openhuman-core/src/memory/tools/collapsed_tests.rs b/crates/openhuman-core/src/memory/tools/collapsed_tests.rs
index f897fa2ae0..25c5b6dcdc 100644
--- a/crates/openhuman-core/src/memory/tools/collapsed_tests.rs
+++ b/crates/openhuman-core/src/memory/tools/collapsed_tests.rs
@@ -149,3 +149,20 @@ fn forget_takes_the_key_as_text_and_defaults_the_namespace() {
assert!(args["namespace"].is_string(), "forget requires a namespace");
assert!(args.get("query").is_none() && args.get("content").is_none());
}
+
+#[test]
+fn advertised_actions_reads_the_schema_enum_and_ignores_other_tools() {
+ let memory = tool();
+ let listed = advertised_actions(&memory);
+ assert!(
+ listed.iter().any(|a| a == ACTION_LEARN)
+ == memory.actions().iter().any(|e| e.action == ACTION_LEARN)
+ );
+ assert!(
+ listed.len() <= 4 && !listed.is_empty() || memory.actions().is_empty(),
+ "{listed:?}"
+ );
+ // Any tool that is not the collapsed `memory` tool advertises no actions,
+ // so a name check elsewhere cannot mistake it for one.
+ assert!(advertised_actions(&MemoryRecallTool::new()).is_empty());
+}
diff --git a/gitbooks/developing/architecture/agent-harness.md b/gitbooks/developing/architecture/agent-harness.md
index 19302fb2cb..a847217e24 100644
--- a/gitbooks/developing/architecture/agent-harness.md
+++ b/gitbooks/developing/architecture/agent-harness.md
@@ -342,7 +342,7 @@ Before a fresh tool result enters history (and ahead of the byte-budget backstop
- **HTML** → strip markup to readable text.
- **Plain text** → the opt-in Python/ML "Kompress" compressor (ModernBERT), or pass-through.
-Every lossy compression offloads the original to the **CCR (Compress-Cache-Retrieve)** store behind a `⟦tj:<hash>⟧` marker, so compaction is effectively lossless: the agent calls `tokenjuice_retrieve` (token + optional byte/line range) to fetch the full original on demand. The same engine is exposed as a universal `compress_content(content, hint, opts)` for any large payload (file reads, web fetches), and as read-only `tokenjuice.*` debug RPCs. Compaction is on by default (`context.compaction_enabled`; `OPENHUMAN_COMPACTION=0` opts out). A large result is stored and replaced by a stats line, a 500-character head and a handle that the read-only `juice_find` / `juice_extract` / `juice_summarize` tools query (`tokenjuice.repl_handle_enabled`), so the LLM summary stage is skipped for results that get a handle. Configured via the `[tokenjuice]` block / `OPENHUMAN_TOKENJUICE_*` env. Agent definitions can override tool-result compression with `tokenjuice_compression = "auto" | "full" | "light" | "off"`; `auto` resolves coding-model agents (`[model] hint = "coding"`) to `light`, which disables CCR-backed lossy compression so coding agents keep raw build/test/diff/search text unless a reduction is truly lossless. Other agents default to `full`. The ML (Kompress) path runs as a `kompress` backend of the shared [`runtime_python_server`](../../../crates/openhuman-core/src/runtime/python_server/) (torch + ModernBERT pip-installed at runtime), gated by the `ml_compression_enabled` flag and degrading gracefully to a native compressor when the Python runtime is unavailable.
+Every lossy compression offloads the original to the **CCR (Compress-Cache-Retrieve)** store behind a `⟦tj:<hash>⟧` marker, so compaction is effectively lossless: the agent calls `juice_retrieve` (token + optional byte/line range) to fetch the full original on demand. The same engine is exposed as a universal `compress_content(content, hint, opts)` for any large payload (file reads, web fetches), and as read-only `tokenjuice.*` debug RPCs. Compaction is on by default (`context.compaction_enabled`; `OPENHUMAN_COMPACTION=0` opts out). A large result is stored and replaced by a stats line, a 500-character head and a handle that the read-only `juice_find` / `juice_extract` / `juice_summarize` tools query (`tokenjuice.repl_handle_enabled`), so the LLM summary stage is skipped for results that get a handle. Configured via the `[tokenjuice]` block / `OPENHUMAN_TOKENJUICE_*` env. Agent definitions can override tool-result compression with `tokenjuice_compression = "auto" | "full" | "light" | "off"`; `auto` resolves coding-model agents (`[model] hint = "coding"`) to `light`, which disables CCR-backed lossy compression so coding agents keep raw build/test/diff/search text unless a reduction is truly lossless. Other agents default to `full`. The ML (Kompress) path runs as a `kompress` backend of the shared [`runtime_python_server`](../../../crates/openhuman-core/src/runtime/python_server/) (torch + ModernBERT pip-installed at runtime), gated by the `ml_compression_enabled` flag and degrading gracefully to a native compressor when the Python runtime is unavailable.
### Missing capabilities
diff --git a/gitbooks/features/token-compression.md b/gitbooks/features/token-compression.md
index 89546ac6eb..e12e8f58f5 100644
--- a/gitbooks/features/token-compression.md
+++ b/gitbooks/features/token-compression.md
@@ -117,8 +117,8 @@ Lossy compression would normally mean throwing data away. TokenJuice instead **o
- **In-memory tier** (always on): a process-global store keyed by SHA-256 hash, bounded by entry count (`max_cache_entries`, default 256) and total bytes (`max_cache_bytes`, default 64 MiB), FIFO eviction.
- **On-disk tier** (optional): `<workspace>/.tokenjuice/ccr/`, enabled with `ccr_disk_enabled`, survives memory eviction. Optional TTL via `ccr_ttl_secs`.
-- **The marker:** compacted output ends with a footer like `[compacted tool output — PARTIAL view; full original available via tokenjuice_retrieve with token "…"]` carrying the `⟦tj:<hash>⟧` token.
-- **Retrieval tool:** the agent calls the read-only **`tokenjuice_retrieve`** tool with that token (optionally a byte/line `range`) to pull back the full original or a slice. The token is an unguessable SHA-256 digest.
+- **The marker:** compacted output ends with a footer like `[compacted tool output — PARTIAL view; full original available via juice_retrieve with token "…"]` carrying the `⟦tj:<hash>⟧` token.
+- **Retrieval tool:** the agent calls the read-only **`juice_retrieve`** tool with that token (optionally a byte/line `range`) to pull back the full original or a slice. The token is an unguessable SHA-256 digest.
So the agent gets the cheap compacted view by default, and can transparently "zoom in" on the full text only when it actually needs it.