jevrecipes

Recipe catalog / context-prune

Prune agent context

context-prune is a Jev recipe from the jev-recipes TypeScript package. Which of items, earlier tool results and messages in an agent session, are still needed to finish objective, so the rest can be dropped from context? Use it when an agent session is growing long and you want to drop stale tool output and messages before the next model turn without summarizing what must stay verbatim.

Last updated .

Explore this recipe interactively · Source and implementation guide · Markdown version

How do I use context-prune in TypeScript?

Install with npm install jev-recipes. Requires Node.js 22.9 or newer and ES modules. Set TYPESAFE_API_KEY in your server environment for live calls, which send input to TypeSafe and use API quota. See the installation guide.

import { contextPrune } from 'jev-recipes/context-prune';

const result = await contextPrune({
  "objective": "Fix the failing test in tests/auth.test.ts, which expects a 401 for expired tokens but receives a 500, then run the suite and commit.",
  "items": [
    {
      "id": "ls-root",
      "text": "Tool result (ls): README.md package.json src tests docs node_modules"
    },
    {
      "id": "auth-source",
      "text": "Tool result (cat src/auth.ts): export function verify(token) { const payload = jwt.verify(token, SECRET); if (payload.exp < Date.now()) throw new Error('expired'); return payload; }"
    },
    {
      "id": "readme",
      "text": "Tool result (cat README.md): # Acme API. Install with npm ci. Run with npm start. See docs/ for endpoints."
    },
    {
      "id": "user-note",
      "text": "User: don't touch the token format, other services depend on it."
    },
    {
      "id": "test-output",
      "text": "Tool result (npm test): FAIL tests/auth.test.ts > returns 401 for expired token. Expected 401, received 500. TypeError: Cannot read properties of undefined (reading 'status') at src/auth.ts:9"
    }
  ],
  "recent": "The agent has read the failing test and the auth source and is about to edit src/auth.ts.",
  "minConfidence": 0.8
});
console.log(result);

What input does context-prune take?

FieldTypeNeeded
objectivestringRequired
itemsarrayRequired
recentstringOptional
minConfidencenumberOptional
Full input and result schemas
{
  "input": {
    "$schema": "https://json-schema.org/draft/2020-12/schema",
    "type": "object",
    "properties": {
      "objective": {
        "type": "string"
      },
      "items": {
        "minItems": 1,
        "maxItems": 50,
        "type": "array",
        "items": {
          "type": "object",
          "properties": {
            "id": {
              "type": "string"
            },
            "text": {
              "type": "string"
            }
          },
          "required": [
            "id",
            "text"
          ]
        }
      },
      "recent": {
        "type": "string"
      },
      "minConfidence": {
        "type": "number",
        "minimum": 0,
        "maximum": 1
      }
    },
    "required": [
      "objective",
      "items"
    ]
  },
  "result": {
    "$schema": "https://json-schema.org/draft/2020-12/schema",
    "type": "object",
    "properties": {
      "model": {
        "type": "string"
      },
      "usage": {
        "type": "object",
        "properties": {
          "input_tokens": {
            "type": "integer",
            "minimum": 0,
            "maximum": 9007199254740991
          },
          "output_tokens": {
            "type": "integer",
            "minimum": 0,
            "maximum": 9007199254740991
          }
        },
        "required": [
          "input_tokens",
          "output_tokens"
        ],
        "additionalProperties": false
      },
      "status": {
        "type": "string",
        "enum": [
          "ready",
          "review"
        ]
      },
      "items": {
        "type": "array",
        "items": {
          "type": "object",
          "properties": {
            "id": {
              "type": "string"
            },
            "status": {
              "type": "string",
              "enum": [
                "ready",
                "review"
              ]
            },
            "verdict": {
              "type": "string",
              "enum": [
                "keep",
                "drop"
              ]
            },
            "probability": {
              "type": "number",
              "minimum": 0,
              "maximum": 1
            },
            "confidence": {
              "type": "number",
              "minimum": 0,
              "maximum": 1
            }
          },
          "required": [
            "id",
            "status",
            "verdict",
            "probability",
            "confidence"
          ],
          "additionalProperties": false
        }
      },
      "keep": {
        "type": "array",
        "items": {
          "type": "string"
        }
      },
      "drop": {
        "type": "array",
        "items": {
          "type": "string"
        }
      },
      "evaluated": {
        "type": "integer",
        "minimum": 0,
        "maximum": 9007199254740991
      }
    },
    "required": [
      "model",
      "usage",
      "status",
      "items",
      "keep",
      "drop",
      "evaluated"
    ],
    "additionalProperties": false
  }
}

What does a context-prune result look like?

This hand-authored response demonstrates the contract. It is not a model accuracy measurement. Run it without an API key: npx jev-recipes demo context-prune.

{
  "model": "demo-fixture",
  "usage": {
    "input_tokens": 0,
    "output_tokens": 0
  },
  "status": "ready",
  "items": [
    {
      "id": "ls-root",
      "status": "ready",
      "verdict": "drop",
      "probability": 0.06,
      "confidence": 0.94
    },
    {
      "id": "auth-source",
      "status": "ready",
      "verdict": "keep",
      "probability": 0.95,
      "confidence": 0.95
    },
    {
      "id": "readme",
      "status": "ready",
      "verdict": "drop",
      "probability": 0.08,
      "confidence": 0.92
    },
    {
      "id": "user-note",
      "status": "ready",
      "verdict": "keep",
      "probability": 0.93,
      "confidence": 0.93
    },
    {
      "id": "test-output",
      "status": "ready",
      "verdict": "keep",
      "probability": 0.96,
      "confidence": 0.96
    }
  ],
  "keep": [
    "auth-source",
    "user-note",
    "test-output"
  ],
  "drop": [
    "ls-root",
    "readme"
  ],
  "evaluated": 5
}

Input

See shared options and behavior for client configuration, validation, and errors. Types are inferred from this folder's Zod 4 schemas.

objective is the remaining work, stated concretely. items are earlier tool results and messages with unique ids and up to 50 entries. recent summarizes what the agent has just done, so items that were consumed already can be released.

Result

Each entry in items has a verdict of keep or drop, the yes probability that the item is still needed, confidence, and its own status. drop lists the ids that are both judged unnecessary and ready; everything else, including uncertain items, is in keep. The result status is review when any item is uncertain, which is informational: keep and drop are already safe to apply.

evaluated is the number of items judged.

Reuse and calls

Builds one request with one yes/no question per item, sharing the objective across them. One live invocation makes one Jev request. This folder owns the retention question, the safe-default policy, and the aggregation.

Limits

The judgment is per item. Two items that only matter together will each look weak on their own; combine them into one item when that is a concern.

A vague objective pushes everything toward drop. Say what the agent still has to do, including verification and cleanup steps.

Example input

demo.json contains editable input and a hand-authored response. After installing jev-recipes, npx jev-recipes demo context-prune shows an offline illustration, not an accuracy measurement. Use npx jev-recipes describe context-prune to inspect the input and result schemas.

Decision boundary

Keep active constraints and results that the remaining work still needs. Completion of a step does not make its output disposable. Drop an item only when the remaining task no longer needs it; uncertain items remain for review.

How accurate is context-prune?

Current mixed-source measurement

jev-1.13.0 / 2026-10-04 / 136 development cases

Scoring revision 2.

90%All-case accuracy
55Sent for review
0Failed calls / cases

81 ready decisions, with 100% accuracy among those decisions.

95% case-level interval: 84% to 94%. Related synthetic cases are correlated.

This measures the recorded dataset, not general readiness. Label sources: unspecified: Existing repository labels; independent review and original authorship were not recorded.; author-synthetic: AI-authored synthetic boundary cases for jev-recipes; labels have not had independent human review.

Use the evaluation guide to measure this decision on your own labeled cases.

What are the limits of context-prune?