Crux
GuidesContexts

Request budgets

Measure complete provider requests and authorize explicit representation ladders.

Assembled requests can outgrow a model's context window or a product's cost target. Set inputBudget on an Agent or invocation:

const result = await generate(reply, {
  model,
  input,
  inputBudget: {
    optimizeAt: 24_000,
    max: 30_000,
  },
});

Crux measures the complete request: system content, messages, Tools and schemas, media, output reserve, and provider framing. optimizeAt is soft; max is strict. If no authorized complete candidate fits, execution fails before the provider is called.

Context priority orders explicitly authorized fidelity decisions. It does not make a plain context droppable. Define the legal ladder:

import {
  context,
  droppable,
  offloadable,
  prefer,
  summarizable,
} from "@use-crux/core";

const complete = context({
  id: "reference",
  priority: 80,
  system: loadCompleteReference,
});
const compact = context({
  id: "reference-index",
  system: loadReferenceIndex,
});

const reference = droppable(
  offloadable(
    summarizable(
      prefer(complete, compact),
    ),
  ),
);

The order is full → authored alternative → generated summary → exact-recovery reference → omission. Every selected deviation is present in the request receipt.

Use preview() to observe prospective fit without executing:

const result = await preview(reply, {
  model,
  input,
  inputBudget: { max: 30_000 },
});

See Input budgets and Receipts and preview.

On this page

No Headings