toolfmt

package
v0.14.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 28, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package toolfmt provides a token-lean, information-preserving re-encoder for tool-call RESULTS before they enter an LLM's context. JSON is verbose (repeated keys, punctuation); EncodeTightC restates a uniform array of flat objects as a count-anchored table and drops needless quotes, cutting tokens for the same data while staying reversible.

Contract:

  • Input that is NOT valid JSON (prose — file contents, `go test` output, plain text) is returned UNCHANGED. Only structured JSON is transformed.
  • The transform is information-preserving and reversible: an LLM (or a decoder) reading the encoded form recovers every datum and its key/position.

JSON itself is the identity encoding — there is no EncodeJSON; the caller simply leaves Session.EncodeToolResult nil. tightc (EncodeTightC) is the one non-identity format, tuned for comprehension on small/quantized models.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func EncodeTightC

func EncodeTightC(raw string) string

EncodeTightC is TIGHT tuned for COMPREHENSION on small / quantized models, after the bonsai accuracy benchmark showed plain tight's token wins came at a real comprehension cost (aggregation/filtering/nested all degraded vs JSON and TOON). It keeps tight's cheap wins (bare tokens, unquoted-unless-needed, inline key:val objects, uniform tables) but spends a few tokens back where the data showed the model losing structure:

  1. ROW-COUNT ANCHOR on every table — `[N]col1,col2` header. bonsai answered "how many rows" questions with an EMPTY string on tight (no count to read) but correctly on TOON (which declares [N]). A count is not math the model computes; it is a structural anchor it reads. ~1 token per table.
  2. UNIFORM-ONLY tables. tight's SPARSE union table (`,,` empty cells for missing keys) forced the model to count commas to realign columns — the exact place filtering/aggregation misfired. Here a table is used ONLY when every row has every column; any irregularity drops to loose (explicit braces + keys on every value), which measured BETTER than tight on the nested dataset.
  3. NESTED OBJECTS render as loose JSON (explicit {}), not tab-indentation. Indentation is positional structure the model has to track; braces are explicit. loose beat tight by ~10 points on nested data.

Recoverability is unchanged (delimiters + header + [N] + loose braces). Non-JSON passes through. It is deliberately LESS token-minimal than tight — the bet is that on small models the comprehension gain outweighs the extra tokens.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL