Token Efficiency Encyclopedia

Generator Invocation

When a deterministic generator can produce an artifact, have the model emit the call rather than the artifact. The model writes a command; code writes the file.

The token cost of a generated file drops from the length of the file to the length of the invocation — a scaffolding command is tens of tokens where its output is thousands — and the result is correct by construction rather than correct by luck.

How It Works

  1. The model recognizes that the requested artifact has a generator: a scaffolder, a compiler plugin, a template engine, a codemod, a formatter.
  2. It emits a single tool call: openapi-generator generate -i spec.yaml -g java, protoc --python_out=..., cargo new, django-admin startapp, a jscodeshift transform, ruff --fix.
  3. The generator writes the files.
  4. The model observes the exit code and the list of touched paths — not the contents.

The artifact exists on disk having passed through neither the model's output nor its context.

Why It Beats Generating the Text

Where It Applies

The Boundary

Generator invocation applies only where a generator exists and the request lands squarely inside what it produces. Three things push work back to the model:

Compared to Write-Path Delegation, this is the stricter and cheaper option: deterministic output, no second model, no verification anxiety — but far narrower coverage. Delegated LLM generation applies anywhere a reference file exists; generator invocation applies only where a generator already encodes the pattern.

Enabling It

Agents do not reach for generators unless the generators are visible and cheap to call:

Anti-patterns

See Also

Tools