Skip to content

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

docs: expand prompt token budget plan with disclosure architecture

Steven Enamakel369a8f638452
diff --git a/docs/plans/2026-08-31-prompt-token-budget.md b/docs/plans/2026-08-31-prompt-token-budget.md
index 00e70d6157..9f746ce479 100644
--- a/docs/plans/2026-08-31-prompt-token-budget.md
+++ b/docs/plans/2026-08-31-prompt-token-budget.md
@@ -162,9 +162,113 @@ Worth trimming, but it is ~3k of a 37k problem. Do it after F1–F5.
---
+## The structural problem: everything is disclosed up front
+
+F1–F7 are byte-level. Underneath them is one architectural choice: **every
+tool OpenHuman registers is advertised**. There is no per-tool notion of
+"registered but not on the wire". The toolpack system is the only lever, it
+is per-*group* rather than per-tool, it is a config posture rather than a
+property of the tool, and its recovery path is a `load_skill` round trip
+rather than a search.
+
+Both reference implementations treat disclosure as the primary axis.
+
+### Codex: exposure is a property of the tool
+
+`codex-rs/tools/src/tool_executor.rs` defines `ToolExposure` per tool:
+
+```rust
+pub enum ToolExposure {
+ Direct, // in the initial model-visible list
+ Deferred, // registered, omitted from the list, found via tool search
+ DeferredModelOnly,
+ DirectModelOnly,
+ CodeModeOnly, // only callable from nested Code Mode scripts
+ Hidden, // registered for dispatch, never shown
+}
+```
+
+`tools/handlers/tool_search.rs` builds a **BM25 index** over every entry where
+`tool.exposure.is_deferred()` and exposes one `tool_search` tool. The model
+searches for a capability, gets the schema back, and calls it. A deferred tool
+costs zero tokens until it is needed.
+
+Codex goes one step further with **Code Mode**
+(`codex-rs/core/src/tools/code_mode/`): tools are callable from inside a
+nested script rather than as individual function schemas, so one tool replaces
+an entire namespace on the wire.
+
+OpenHuman already has the machinery — `search_tool_catalog` and
+`get_tool_contract` — but they are pointed at the **Composio action
+catalogue**, not at its own registry, and they are gated behind `flows`.
+
+### Hermes: capabilities live in skills, and tools collapse to verbs
+
+Hermes' full-fat coding profile is **31 tools**. OpenHuman's orchestrator
+advertises **139**. The difference is not that Hermes does less; it is
+where the surface lives.
+
+- Its entire skill system is **three tools** — `skills_list`, `skill_view`,
+ `skill_manage` — plus a one-line-per-skill index. Everything a skill can do
+ is behind `skill_view`.
+- Tool families collapse to a single tool with an action argument:
+ `memory` is one tool, `cronjob` is one tool, `todo` is one tool,
+ `discord` is one tool, `spotify_playback` covers play/pause/skip.
+
+Measured against OpenHuman's advertised set:
+
+| Family | OpenHuman | ~tokens | Hermes | Collapsed cost |
+| --- | --- | --- | --- | --- |
+| memory | 12 tools | 2,831 | 1 (`memory`) | ~780 |
+| todo | 6 tools | 1,375 | 1 (`todo`) | ~450 |
+| cron | 6 tools | 1,040 | 1 (`cronjob`) | ~790 |
+| task | 6 tools | 632 | — | ~200 |
+| spawn | 3 tools | 1,895 | 1 (`delegate_task`) | ~910 |
+| delegate | 3 tools | 900 | — | ~380 |
+| **total** | **36 tools** | **8,673** | **6 tools** | **~3,510** |
+
+That is ~5,200 tokens from arity alone, with no capability removed.
+
+### What deferring buys on top
+
+Ranked by schema size, the orchestrator's advertised set concentrates hard:
+
+```
+top 20 tools 8,638 tok tail 119 tools 19,367 tok
+top 30 tools 11,585 tok tail 109 tools 16,420 tok
+top 50 tools 16,870 tok tail 89 tools 11,135 tok
+```
+
+Keeping ~25 tools `Direct` and deferring the rest behind one `tool_search`
+removes roughly **16,000 tokens** from every orchestrator turn.
+
+### Where the workflow surface should go
+
+The `workflows` pack is 32 tools and 10,200 tokens — the single largest line
+item in the catalogue, and larger than the orchestrator's entire system
+prompt. On the orchestrator it is already withheld, so it costs nothing
+there today; the cost lands on `workflow_builder` and `flow_discovery`, which
+*own* the pack and therefore get all 32 advertised **plus** a 20,100-token
+system prompt. That agent pays over 30k tokens of fixed prefix to build a
+flow.
+
+A skill is the right container for it, and the arithmetic is stark: a skill
+costs one line in the index. OpenHuman's `## Installed Skills` block is 1,078
+tokens for 19 skills — **~57 tokens per capability** against ~319 tokens per
+tool. The flow DSL reference currently living in `workflow_builder/prompt.md`
+is exactly what a `SKILL.md` body is for: loaded when the agent is building a
+flow, absent otherwise.
+
+The same argument applies to `crypto` (20 tools), `documents`, `audio`, and
+`app_update`. The toolpack table is already a list of candidates — it was
+built as a compression mechanism, and a skill is the same mechanism with a
+body attached and no bespoke `load_skill` protocol.
+
+---
+
## Plan
-### P0 — Make the budget visible (prerequisite for everything else)
+### P0 — Make the budget visible (prerequisite)
1. Fix `render_via_session` to model the wire: apply the definition's
`ToolScope` belt and call `strip_packed_from_visible(&mut visible,
@@ -173,60 +277,78 @@ Worth trimming, but it is ~3k of a 37k problem. Do it after F1–F5.
2. Add `openhuman-core agent prompt-size [--agent <id>] [--json]`, modelled
on `hermes_cli/prompt_size.py`: total, per-section bytes/tokens, tool
schemas with a per-tool table, skills index, memory + profile, AGENTS.md
- layers. `--json` for CI.
+ layers.
3. Add `scripts/prompt-budget.limits` + a ratchet lane, same shape as
`scripts/kernel-floor.limits` / `check-kernel-floor.sh` — fail on growth,
- fail on an unratcheted improvement. An unmeasured prompt grows.
+ fail on an unratcheted improvement.
-*Exit criteria: `SUMMARY.txt` shows `researcher tools=2`, and CI fails if
-the orchestrator prefix grows.*
+*Exit: `SUMMARY.txt` shows `researcher tools=2`; CI fails if the orchestrator
+prefix grows.*
-### P1 — Prompt caching (largest single win)
+### P1 — Prompt caching
4. Split `build_system_prompt` into three tiers mirroring Hermes'
- `build_system_prompt_parts`: `stable` (identity, role, grounding, safety,
- style, delegation, rules), `context` (AGENTS.md layers, workspace), and
- `volatile` (skills index, connected integrations, memory, profile,
- date/time). Join for the wire; keep the tier boundaries as offsets.
-5. Emit `cache_control: {type: "ephemeral"}` breakpoints at the tier
- boundaries for Anthropic-family providers, and place the tool array
- ahead of the system block so the schemas are inside the cached prefix.
- Add the equivalent for the backend's OpenAI-compatible proxy.
+ `build_system_prompt_parts`: `stable`, `context`, `volatile`. Join for the
+ wire; keep the tier boundaries as offsets.
+5. Emit `cache_control: {type: "ephemeral"}` at the tier boundaries for
+ Anthropic-family providers, with the tool array ahead of the system block
+ so schemas fall inside the cached prefix. Same on the backend proxy.
6. Reorder `SystemPromptBuilder::with_defaults()` to match the tiers —
- `UserFilesSection` and `UserMemorySection` move to the tail, after
- `DateTimeSection`; `WorkspaceSection` and the style block move ahead of
- it.
-
-*Estimated: ~37k tokens/turn at ~10% of list price on cache hits.*
-
-### P2 — Tool-schema diet
-
-7. Add a per-tool schema budget to the P0 ratchet (suggested: warn > 400
- tok, fail > 800). Rewrite the six offenders above `600`; `propose_workflow`
- at 1,892 is the priority.
-8. Add `GroupMode::NamesOnly` between `Advertised` and `Withheld`: renders
- the tool name and a one-line description, no parameter schema, with a
- note that `get_tool_contract` fetches the full signature. Default the
- `workflows` pack (10,200 tok on the orchestrator) to it.
-9. Audit the orchestrator's 139 advertised tools against actual call
- frequency from Langfuse traces; demote the long tail.
+ `UserFilesSection` and `UserMemorySection` to the tail after
+ `DateTimeSection`; workspace and style ahead of it.
+
+*~37k tokens/turn at roughly 10% of list price on a hit.*
+
+### P2 — Disclosure architecture (the structural fix)
+
+7. **Per-tool exposure.** Add `Tool::exposure() -> ToolExposure` with
+ `Direct` / `Deferred` / `Hidden`, defaulting to `Direct` so nothing moves
+ until it is opted in. This replaces the per-group `GroupMode` as the
+ primary axis; `ToolGroups` stays as the embedder-facing override.
+8. **Tool search over our own registry.** Add `tool_search` backed by a BM25
+ index over deferred tools (Codex uses the `bm25` crate for exactly this).
+ Ungate it from `flows` — the existing `search_tool_catalog` /
+ `get_tool_contract` pair stays pointed at Composio.
+9. **Defer the long tail.** Keep ~25 tools `Direct`; mark the rest
+ `Deferred`. Drive the choice from Langfuse call-frequency data, not
+ intuition. *(~16,000 tok)*
+10. **Collapse tool families to verbs.** `memory_*` (12 → 1), `todo_*` (6 → 1),
+ `cron_*` (6 → 1), `task_*` (6 → 1), `spawn_*` + `delegate_*` (6 → 2).
+ Keep the old names as dispatch aliases for one release. *(~5,200 tok)*
+11. **Move whole capability surfaces into skills**, starting with
+ `workflows` — 32 tools and 10,200 tokens, plus the flow DSL reference
+ now inlined in `workflow_builder/prompt.md`. Then `crypto`, `documents`,
+ `audio`, `app_update`. A capability costs ~57 tokens as a skill entry
+ against ~319 as a tool.
+12. Add a per-tool schema budget to the P0 ratchet — warn above 400 tokens,
+ fail above 800. Rewrite the six offenders; `propose_workflow` (1,892) first.
+
+*Target: 28,006 → roughly 6,000 tokens of advertised schema.*
### P3 — Budget-aware injection
-10. Replace the flat `BOOTSTRAP_MAX_CHARS` with a cap scaled to the resolved
- context window, and give the *combined* injected-file set one budget
- rather than one cap each.
-11. Surface truncation to the user as a status event, not only a log line.
+13. Replace the flat `BOOTSTRAP_MAX_CHARS` with a cap scaled to the resolved
+ context window, and give the combined injected-file set one budget rather
+ than one cap each.
+14. Surface truncation to the user as a status event, not only a log line.
### P4 — Prose trim
-12. `workflow_builder` (~20k tok) — split the reference material out into a
- skill the agent loads on demand.
-13. Trim Delegation and Rules on the orchestrator; both read as accreted
- rather than authored.
+15. `workflow_builder` (~20k tok) — most of it becomes the `workflows`
+ SKILL.md body in P2/11; trim what remains.
+16. Rewrite Delegation and Rules on the orchestrator.
+
+### P5 — Horizon: Code Mode
+
+17. Evaluate Codex's `code_mode` seam — tools callable from a nested script
+ instead of as individual function schemas. It is the endgame for schema
+ cost, and it composes with P2 rather than replacing it. Not before P0–P2
+ land and the ratchet has real numbers behind it.
## Sequencing note
-P0 before everything: three of these findings (F2, F3, F4) exist because the
-numbers were never on screen. Land the measurement and the ratchet first,
-then P1, which is worth more than P2–P4 combined.
+P0 before everything: three findings (F2, F3, F4) exist only because the
+numbers were never on screen. Then P1, which is a pricing change with no
+behavioural risk. P2 is the largest and the riskiest — it changes what the
+model can see — so it wants the measurement and the caching in place first,
+and it should land tool family by tool family behind the ratchet.