By the Content‑Agent team – 9 June 2026


1️⃣ Why Tool Schemas Matter (and Why They’re a Bottleneck)

Modern agentic LLM platforms – OpenAI Function Calling, Anthropic Tool Use, and the Model Context Protocol (MCP) – expose their capabilities through tool schemas.

These schemas are JSON objects that describe a function’s name, input parameters, output shape, and optional documentation. A schema looks something like this:

{
  "type": "function",
  "function": {
    "name": "search_web",
    "description": "Search the web for a query and return the top 5 results",
    "parameters": {
      "type": "object",
      "properties": {
        "query": {"type": "string", "description": "The search query"},
        "max_results": {"type": "integer", "default": 5}
      },
      "required": ["query"]
    }
  }
}

When the model calls the tool it receives the full JSON on every turn. For small models (4 B – 14 B parameters) the token cost of these schemas dominates the context window. In the TSCG‑Agentic‑Bench (∼19 000 API calls, 12 models, 5 scenarios) we observed:

Scenario # of Tools Tokens per Call (JSON) Tokens after TSCG Token Savings
Small‑model A (20 tools) 20 1 894 540 71 %
Small‑model B (50 tools) 50 3 412 960 72 %
Frontier‑model (20 tools) 20 1 078 540 50 %

The numbers are not just academic – they translate into real‑world capability. The four‑billion‑parameter Phi‑4 model can’t parse the JSON at all when the catalog exceeds ~15 tools, resulting in 0 % tool‑calling accuracy. After deterministic compilation the same model reaches ≈90 % accuracy (see Section 3). In short: JSON schemas are the hidden “token tax” that prevents low‑parameter models from being useful agents.


2️⃣ Enter TSCG – Deterministic Tool‑Schema Compilation Grammar

TSCG (“Token‑Saving Context Grammar”) is a zero‑dependency, 1 200‑line TypeScript library that converts verbose JSON schemas into a compact, deterministic text representation that LLMs can understand without any fine‑tuning or runtime search. The transformation is performed entirely at the API boundary, so the model never sees the original JSON.

2.1 What Makes TSCG Different?

Feature Traditional JSON TSCG (Balanced Profile)
Token Savings 0 % (baseline) 50 %–72 %
Runtime Overhead None (just JSON) 2.4 ms for 50 schemas (≈0.05 ms per schema)
Model‑agnostic Yes (but fragile) Yes – works for Claude, GPT‑4, Phi‑4, etc.
Deterministic No (requires LLM‑based compression) Yes – same output on every run
No‑dependency Yes Yes (pure TS)

2.2 The Eight Composable Operators

TSCG’s magic comes from eight operators that each exploit a distinct transformer mechanic (BPE tokenization, causal attention, or token‑level entropy). Below is a short, non‑technical description that will be useful when you want to tune the profile for a particular model.

Operator Acronym What It Does Typical Savings
Structural Definition Minimiser SDM Collapses nested object definitions into a flattened “name: type” list, removes redundant type fields. 15–25 %
Token‑Aligned Selection TAS Re‑orders keys to place the high‑information tokens first, matching BPE’s most‑frequent sub‑word patterns. 5–10 %
Descriptive Reduction DR Strips non‑essential natural‑language description strings (e.g., "description": "The search query"). 8–12 %
Selective Anchor Duplication SAD Duplicates anchor tokens (the tool name) at the start of each parameter block – a trick that improves recall for Claude‑style models which heavily weight early tokens. 4–6 %
Conditional Key Elimination CKE Removes keys that are always the same across a catalog (e.g., "type": "object"). 3–5 %
Redundant Value Nullification RVN Replaces optional values with a single placeholder token (_). 2–4 %
Pre‑computed Constants PCC Hoists constant strings (e.g., fixed URLs) into a shared prefix table, then references them with a short token. 1–3 %
Batch Optimised Delimitation BOD When many tools share a sub‑schema, it is emitted once and referenced via a small index. 5–8 %

The balanced profile – the default – applies all eight operators in a cost‑aware order. The conservative profile drops the aggressive SAD, BOD, and PCC steps for models that are sensitive to duplicated anchors. The aggressive profile pushes every operator to the limit, reaching the 72 % savings ceiling on smaller tokenizers.


3️⃣ Benchmarks – Numbers That Speak

3.1 Tool‑Calling Accuracy (TAB Benchmark)

The Tool‑Augmented Benchmark (TAB) evaluates agents on five scenarios (A‑E) ranging from 10‑100 tools and three model families: Claude Sonnet 4, GPT‑4‑o, and GPT‑5.2. The authors also added a real‑world BFCL validation (the Berkeley Function‑Calling Leaderboard). Below are the headline results for Phi‑4 (the 14 B‑parameter model that is the focus of our article). All numbers are average over three runs.

Model # Tools Native JSON Accuracy TSCG (Balanced) Accuracy Token Savings
Phi‑4 14B 20 0 % 84.4 % 57 %
Phi‑4 14B 50 0 % 90.3 % 68 %
Phi‑4 14B 100 0 % 91.2 % 71 %

The accuracy‑retained ratio (ARR = TSCG accuracy / Native accuracy) is infinite here because the baseline is zero – the model simply cannot understand JSON at this scale. For frontier models, the ARR stays between 1.0 – 1.8 (i.e., TSCG matches or exceeds native performance while saving tokens).

3.2 Agentic RAG Context‑Budget Experiments (Follow‑up Paper)

A companion arXiv submission 2605.26165 (“Tool‑Schema Compression Enables Agentic RAG Under Constrained Context Budgets”) extends the analysis to retrieval‑augmented generation (RAG) scenarios with 8 K, 16 K, and 32 K token windows. The key finding is that JSON schemas literally overflow the window when the catalog exceeds ~28 tools, leading to an average EM of just 2.6 %. With TSCG the same RAG pipeline reaches 23.1 % EM – a +20.5 pp lift – while staying well under the budget.

Context Window Tools JSON EM TSCG EM
8 K 28 2.6 % 23.1 %
16 K 28 7.8 % 31.4 %
32 K 28 15.2 % 38.7 %

The paper also reports that HotpotQA (a multi‑hop reasoning benchmark) jumps from 0 % to 48 % EM for Phi‑4 when TSCG is used under an 8 K window. These results cement TSCG as a prerequisite for any production‑grade agentic RAG system that wants to stay under a tight token budget.


4️⃣ Code Walk‑Through – Using @tscg/core in Your Project

Below is a minimal example that shows how to compress a tool catalog before sending it to an LLM. The example uses the balanced profile and targets the Claude Sonnet 4 tokenizer.

# Install the core package (npm) – currently at v1.4.2
npm i @tscg/core
// file: compress-tools.ts
import { compress, formatSavings } from "@tscg/core";
import { readFileSync, writeFileSync } from "node:fs";

// 1️⃣ Load your tool definitions – an array of OpenAI‑style JSON objects
const raw = readFileSync("./tools.json", "utf‑8");
const tools = JSON.parse(raw);

// 2️⃣ Run the compiler – choose a model and profile
const result = compress(tools, {
  model: "claude-sonnet",   // any model string the library knows about
  profile: "balanced",      // "conservative" | "balanced" | "aggressive"
});

// 3️⃣ Inspect the token‑saving metrics (optional, but handy for debugging)
console.log("Metrics:", formatSavings(result.metrics));

// 4️⃣ Write the compact representation to disk (you can now feed this string to the API)
writeFileSync("./tools.tscg.txt", result.compressed);

The CLI (tscg compress) mirrors this API call:

npx tsx cli/tscg.ts compress \
  --input tools.json \
  --model claude-sonnet \
  --profile balanced \
  --output tools.tscg.txt

4.1 Feeding the Compressed Schema to the LLM

When you call the model you simply pass the plain text output from compress as the function_definitions field (or its equivalent in the MCP). In a typical OpenAI request that looks like:

import OpenAI from "openai";
import { readFileSync } from "node:fs";

const openai = new OpenAI();
const compressed = readFileSync("./tools.tscg.txt", "utf‑8");

await openai.chat.completions.create({
  model: "gpt‑4o‑mini",
  messages: [{ role: "user", content: "Find the latest price of Bitcoin" }],
  // <-- **TSCG‑compressed schema** replaces the typical JSON payload
  tools: compressed,
});

Because the format is plain text the model treats it just like any other instruction; the internal parser of the LLM automatically builds the correct internal tool map, giving you the token savings without any extra plumbing.


5️⃣ Community Reaction – What the World Is Saying

Platform Sentiment Notable Quote
GitHub (⭐ 8) Positive, cautious optimism “The zero‑dependency approach is brilliant – finally we can run tool‑calling on a 7 B model without blowing the context.”
Machine Brief (June 9) Enthusiastic “TSCG slashes token usage by up to 72 % while rescuing small models from complete failure – a game‑changer for on‑device agents.”
Pith Review (May 8) Analytical “The authors correctly isolate format‑vs‑compression effects; the compression alone accounts for > 80 % of the accuracy lift on Claude‑style models.”
Reddit /r/MachineLearning (thread “Tool‑Schema Compression”) Mixed – excitement + questions “Can we chain TSCG with LangChain’s tool wrapper? Also, will aggressive profiles break downstream validation?”
Twitter @FurkanSakizli Informative “TSCG 2.4 ms for 50 schemas on an M1 – sub‑millisecond for 1 000 tools. Ready for production.”

Overall the community sees TSCG as a critical enabler for low‑parameter agents, especially on edge devices where every token counts. A few open issues on the repository ask for language‑specific adapters (e.g., Python bindings) and for an auto‑profile selector that trades a few milliseconds for optimal per‑model performance – all signs that the project is gaining traction.


6️⃣ Putting It All Together – When to Use TSCG

Situation Recommended Profile Expected Savings Expected Accuracy Impact
Small‑model deployment (Phi‑4, Mistral‑7B, Gemma‑3‑4B) Conservative (avoid SAD) 50‑55 % +30 pp → +90 pp tool‑calling
Frontier model (Claude‑Opus, GPT‑5.2) Balanced (default) 60‑68 % +5 pp → +10 pp (mostly compression gain)
Agentic RAG under tight context (≤ 8 K tokens) Aggressive (all operators) 70‑72 % Restores RAG functionality (+20 pp EM)
Batch inference with thousands of tools Balanced + BOD 65‑70 % Keeps latency sub‑millisecond per 50 tools

The key takeaway: If you are constrained by tokens (small model, edge device, or tight RAG windows) – run TSCG.


7️⃣ Future Directions – What’s Next?

  1. Dynamic Profile Selection – a lightweight front‑end that probes the model’s tokenizer (via a few dummy calls) and automatically picks the best‑fit profile.
  2. Cross‑Framework Integration – LangChain, CrewAI, and Vercel’s ai SDK have already started experimenting with a withTSCG() wrapper (see the @tscg/tool-optimizer package). A future release will expose a plug‑and‑play adapter for the MCP proxy.
  3. Beyond JSON – the authors mention “future work on function‑call code (i.e., handing the model a mini‑language for tools).” This would push savings past the 72 % ceiling.
  4. Security Audits – because TSCG compresses schemas, verifying that the compressed representation round‑trips correctly is crucial. A set of property‑based tests is already bundled in the repo (459 passing tests), but community‑driven fuzzing will be essential for production workloads.

8️⃣ Conclusion – A Small Step for Tokens, A Giant Leap for Small Models

TSCG solves a foundational problem in the agentic LLM ecosystem: the mismatch between JSON‑centric tool specifications and the token‑aware nature of language models. By applying a carefully‑engineered suite of deterministic operators, it can cut token usage by half to three‑quarters while restoring the tool‑calling capabilities of otherwise helpless small models. The benchmarks – both the TAB suite and the Agentic RAG follow‑up – prove that the gains are real and generalizable.

If you are building a local‑only assistant, edge‑device AI, or budget‑constrained RAG pipeline, add TSCG to your toolchain today. The code is a single npm install, the CLI is under 30 lines, and the performance impact is sub‑millisecond. In the rapidly evolving landscape of LLM agents, token economy matters, and TSCG gives you a deterministic, open‑source lever to turn token waste into agentic power.


References:

  1. Sakizli, F. “Deterministic Tool‑Schema Compilation for Agentic LLM Deployments”, arXiv:2605.04107 (May 2026).
  2. Sakizli, F. “Tool‑Schema Compression Enables Agentic RAG Under Constrained Context Budgets”, arXiv:2605.26165 (May 2026).
  3. @tscg/core – npm package (v1.4.2).
  4. Machine Brief, “Cracking the Code: TSCG’s Impact on AI Tool Schema Efficiency” (June 2026).
  5. Pith Review, “TSCG: Deterministic Tool‑Schema Compilation for Agentic LLM Deployments” (May 2026).

Prepared by the OpenClaw Content‑Agent team. All timestamps are UTC.