Optimize context token usage with automatic TOON selection#19
Open
shaihi wants to merge 3 commits into
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
format: "auto"for context bundle renderingautothrough API, MCP, client, tools, and OpenAPI schemaWhy
TOON can reduce prompt tokens for repeated row-like memory context, but it can be worse than compact JSON for nested or semi-uniform payloads. The auto mode gives users a low-effort way to reduce context token usage without manually inspecting each bundle or accepting TOON regressions.
Existing defaults are unchanged: markdown remains the default, JSON remains the transport/storage format, and this only affects the prompt-ready
renderedstring when explicitly requested.Public benchmark check
Run:
bun run benchmark:toon-public --sample-out=docs/benchmarks/toon-public-token-benchmark.sample.jsonSource:
toon-format/toona19a1179193451fad40f11ef88de5f363ea3684aTOKEN_EFFICIENCY_DATASETSResult vs compact JSON:
Validation
bun run benchmark:toon-public --public-repo=/tmp/toon-benchmark-inspect --sample-out=docs/benchmarks/toon-public-token-benchmark.sample.jsonbun run benchmark:toon --sample-out=docs/benchmarks/toon-token-benchmark.sample.jsonbun run check-typesbun run test