Skip to content

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

docs(tokenjuice): document REPL tools and handle preview mode

Steven Enamakel5da7d7e1ddd1
diff --git a/crates/openhuman-core/src/inference/tokenjuice/README.md b/crates/openhuman-core/src/inference/tokenjuice/README.md
index 40893ee1f6..4d81559584 100644
--- a/crates/openhuman-core/src/inference/tokenjuice/README.md
+++ b/crates/openhuman-core/src/inference/tokenjuice/README.md
@@ -21,6 +21,7 @@ OpenHuman-owned files:
| `types.rs` | Re-export of the `tinyjuice-bus` contract (`tinyjuice_bus::types::{AgentTokenjuiceCompression, CompressOptions, CompressedOutput, CompressorKind, ContentHint, ContentKind}` and `tinyjuice_bus::wire::{CacheStats, CompactResponse, InstallRequest, RangeUnit, RetrieveRange}`) under the paths ~40 call sites in this crate already use. |
| `schemas.rs` | JSON-RPC controller schemas and handlers. |
| `config_patch.rs` | Partial update shape for the `[tokenjuice]` config block. |
+| `repl_tools.rs` | The three REPL tools (`juice_find`, `juice_extract`, `juice_summarize`) over a stored result. TinyJuice owns the ops and declarations (`tinyjuice::repl::tools`, cargo feature `tinytools`); the CCR store lives in the module, so each call fetches the original with `Retrieve` and hands the stock tool a one-entry store. Registered by `tools/ops.rs` only while `repl_handle_active(config)`. |
| `tools.rs` | OpenHuman agent tool implementation for the retrieve tool (`RETRIEVE_TOOL_NAME = "tinyjuice_retrieve"`; `"tokenjuice_retrieve"` is a recognized recovery-tool alias, not the tool's registered name, see `RECOVERY_TOOL_NAMES`). |
| `ml/` | Bridge from TinyJuice's optional ML callback into the shared `runtime::python_server` Kompress backend (ModernBERT token/sentence salience); opt-in via `config.tokenjuice.ml_compression_enabled` (default off), degrades gracefully when the flag is off or the runtime server is unavailable. |
| `savings.rs` | OpenHuman model-pricing attribution and persisted dashboard stats. |
@@ -44,11 +45,12 @@ not.**
`openhuman-core` depends on `tinyjuice` directly, with
`default-features = false` (dropping `tinyjuice-treesitter` and its three
-tree-sitter grammars, which serve the code compressor). The only thing it calls
-is the pure half:
+tree-sitter grammars, which serve the code compressor) and the `tinytools`
+feature. It calls the pure half, and takes the REPL tool declarations:
| Linked and called directly | Why it may be |
| --- | --- |
+| `repl::tools::repl_tools` | Only the declarations and the stateless ops. The store they read is the module's, reached over `Retrieve`. `tinytools` resolves to the one copy `tinyagents` vendors (root `[patch]`), so these are the harness's `Tool` type. |
| `compressors::html::html_to_markdown` | Pure `&str -> String`. `web_fetch` runs it on every HTML response so the model reads a page's prose, headings and links instead of its minified JS. |
Everything with state stays where it was, reached only through TinyBus:
@@ -61,7 +63,7 @@ Everything with state stays where it was, reached only through TinyBus:
Why a content transform is not allowed to go through the bus: reaching it there
needs the `modules` feature, a loaded cdylib, and `config.tokenjuice` /
-`context.compaction_enabled`: which defaults to `false`. A core tool's default
+`context.compaction_enabled`: which a user can switch off. A core tool's default
output would then depend on whether an optional module happened to load, so the
same URL would come back as Markdown on one install and as raw markup on
another. That is not a defensible way to decide what a fetched page looks like.
@@ -96,5 +98,14 @@ callback stay here.
the aliases stay registered for transcript replay but off the wire. It is
added when compaction is on or the agent's results can be summarized
(`summarizes_tool_output`), since a summary's footer names it too.
+- Handle mode: `install_request` sets `CompressOptions.repl_handle` (and
+ `repl_save_dir` when `repl_save_enabled`) from `repl_handle_active(config)`,
+ which needs `context.compaction_enabled`, `router_enabled`, `ccr_enabled` and
+ `repl_handle_enabled`. `tools/ops.rs` registers the REPL tools under the same
+ test, `session_host/builder/mod.rs::ensure_repl_tools_visible` adds them to a
+ curated belt, and `middleware/tool_output.rs::is_compaction_exempt` keeps
+ their answers from being stored behind a second handle (their own
+ `max_result_size_chars` still caps them). The bus `Repl` member is not used
+ from here: it is not yet a `tinyjuice-bus` name constant.
- Contract crate: `tinyjuice-bus` (`vendor/tinyjuice/crates/tinyjuice-bus`,
path dependency in `crates/openhuman-core/Cargo.toml`).
diff --git a/gitbooks/features/token-compression.md b/gitbooks/features/token-compression.md
index 27b88046db..ef763a195d 100644
--- a/gitbooks/features/token-compression.md
+++ b/gitbooks/features/token-compression.md
@@ -77,6 +77,29 @@ Multi-byte text (CJK, emoji, combining marks) is handled grapheme-by-grapheme th
---
+## Handle preview and the REPL tools (default)
+
+Compaction is **on by default**. For a result of at least `ccr_min_tokens` the router does not compress to one blob. It stores the original in the CCR cache and shows the model a small preview instead:
+
+- a one-line **stats** description of the shape (estimated tokens, bytes, lines, JSON keys or a Markdown outline, never values),
+- the **first 500 characters**,
+- an extractive outline, and
+- a footer naming the **handle** (the CCR token).
+
+The model then queries the stored original with three read-only tools, none of which calls a model:
+
+| Tool | Does |
+| ---- | ---- |
+| `juice_find` | `text`, `grep`, `regex`, `rank` (BM25), `sed`, `awk` and `jq` over the output, with a Python-style `scope` slice. |
+| `juice_extract` | Links or headings from HTML or Markdown output. |
+| `juice_summarize` | Size, outline or JSON shape, then head and tail, or the parts most relevant to a `hint`. |
+
+Answers are size-capped, and an unknown or evicted handle is an error. `tinyjuice_retrieve` still returns the whole original. Because a handle preview is built without a model call, it also replaces the LLM summary for results big enough to get one, so a slow summarizer cannot stall the turn. The three tools are registered (about 1.5 KB of schema) only while this mode is in effect.
+
+Opt out of the whole feature with `context.compaction_enabled = false` or `OPENHUMAN_COMPACTION=0`. Keep compaction but return to the one-blob compression and `tinyjuice_retrieve` with `tokenjuice.repl_handle_enabled = false` (`OPENHUMAN_TOKENJUICE_REPL_HANDLE_ENABLED=0`). Set `tokenjuice.repl_save_enabled = true` to also write each stored original to `<workspace>/.tokenjuice/repl/<handle>.txt` (mode 0600) so an agent can script over it; that puts raw tool output on disk and nothing prunes it.
+
+---
+
## ML compression (opt-in)
Beyond the deterministic compressors, TokenJuice can route plain text through a **ModernBERT** token-salience model that scores and drops low-information spans. The TinyJuice compressor exposes the optional ML slot, and OpenHuman bridges it to Kompress in `crates/openhuman-core/src/inference/tokenjuice/ml/`.
@@ -127,12 +150,13 @@ Each rule names a command/tool pattern and a reduction strategy (skip/keep filte
Everything lives under the `[tokenjuice]` config block (`crates/openhuman-core/src/config/schema/tokenjuice.rs`) and can be changed live.
-- **Master switch:** `router_enabled` (default `true`).
+- **Master switches:** `context.compaction_enabled` (default `true`; `OPENHUMAN_COMPACTION=0` opts out) and `router_enabled` (default `true`).
+- **Handle preview:** `repl_handle_enabled` (default `true`), `repl_save_enabled` (default `false`).
- **Thresholds:** `min_bytes_to_compress`, `ccr_min_tokens`.
- **CCR:** `ccr_enabled`, `ccr_disk_enabled`, `max_cache_entries`, `max_cache_bytes`, `ccr_ttl_secs`.
- **Per-kind:** `search_enabled`, `code_enabled`, `html_enabled`, plus the `ml_*` keys.
- **RPC** (`openhuman.tokenjuice_*`): `detect`, `compress` (dry-run the pipeline), `settings_get` / `settings_update` (live partial patch), `cache_stats`, `retrieve`, `savings_stats`, `savings_reset`.
-- **Agent tool:** `tokenjuice_retrieve` (read-only) recovers offloaded originals.
+- **Agent tools:** `tinyjuice_retrieve` recovers a whole offloaded original; `juice_find`, `juice_extract` and `juice_summarize` query one by handle. All are read-only.
- **Debugging:** start the core with `RUST_LOG=openhuman_core::inference::tokenjuice=debug` to watch detection, matching, and how much each blob is trimmed.
---