Agent context
Keep or trim a tool result
Ask whether an older tool call and its full output still matter to the current task.
01 The questions
Tool call t1 (read_file) should stay in the history: knowing this call was made, with its input, still matters for what the assistant does next
The full output of tool call t1 (read_file, 4200 chars) should stay in the history verbatim: the assistant still needs its contents and re-running the tool would not do
Copy includes the complete instructions, criteria, usage notes, and attribution.
02 Input
The current goal and chronological conversation, with tool identifiers matching the questions. The upstream implementation fits a full transcript into its request budget.
{
"goal": "Fix the failing checkout test.",
"history": [
{
"role": "user",
"text": "Inspect checkout.ts and fix the balance check."
},
{
"role": "assistant",
"tool_calls": [
{
"id": "t1",
"tool": "read_file",
"input": {
"path": "src/checkout.ts"
},
"result": "ok, 4200 chars (omitted)"
}
]
},
{
"role": "user",
"text": "The latest test still fails at the insufficient-funds branch."
}
]
}03 Answer & policy
Two Noul probabilities: keep the call, and keep the complete result.
Your code decides what happens next.
The source uses 0.5 by default. Keep pinned/recent messages regardless of scores. Only consider trimming an older completed call; an API error must preserve the transcript.
04 Use it in your code
Node.js 24 · TypeSafe SDK 0.6.0 · Set TYPESAFE_API_KEY in your environment. Run on your server; API calls incur provider charges.
import { noul, TypeSafeClient, type JsonValue } from "@typesafe-ai/sdk";
// Illustrative input, not a recorded model test.
const state: JsonValue = {
"goal": "Fix the failing checkout test.",
"history": [
{
"role": "user",
"text": "Inspect checkout.ts and fix the balance check."
},
{
"role": "assistant",
"tool_calls": [
{
"id": "t1",
"tool": "read_file",
"input": {
"path": "src/checkout.ts"
},
"result": "ok, 4200 chars (omitted)"
}
]
},
{
"role": "user",
"text": "The latest test still fails at the insufficient-funds branch."
}
]
};
const client = new TypeSafeClient();
try {
const response = await client.systemOne({
model: "jev-latest",
state,
questions: {
call_t1: noul(
"Tool call t1 (read_file) should stay in the history: knowing this call was made, with its input, still matters for what the assistant does next"
),
result_t1: noul(
"The full output of tool call t1 (read_file, 4200 chars) should stay in the history verbatim: the assistant still needs its contents and re-running the tool would not do"
)
},
});
const pinned = false; // Determine this from message age and your preservation rules.
const keepCall = response.answers.call_t1.noul;
const keepResult = response.answers.result_t1.noul;
const action = pinned || keepResult >= 0.5 ? "keep"
: keepCall >= 0.5 ? "truncate_result" : "drop_call_and_result";
console.log({ action }); // Suggest only; this example does not delete context.
} catch (error) {
console.error("Decision unavailable; use your fallback or human review.", error);
process.exitCode = 1;
}The wrapper and example input are provided by Jev Directory. Checked against SDK types; no live model call was made. Pin a model version before evaluating production behavior.
Before you adapt it
- A low keep probability does not establish that deletion is safe.
- Keep call/result pairs valid. The full project also budgets state size and provides fallback behavior.
More about the original project or pattern
What it does
Fast Jev Compaction asks whether older tool calls and tool results still matter to the current agent task. It then keeps them verbatim, truncates the head of a result, or removes a paired call and result. User and assistant text remains in the output, and the Claude Code hook falls back to built-in summarization when the Jev path fails or saves too little.
What you can reuse
The library exports the useful layers separately: collecting tool calls, fitting state to a request budget, batching questions, deciding each call, applying decisions, and adapting the transport. Its policy options expose preservation windows, size ceilings, truncation length, and a keep threshold.
How it fits
An agent transcript becomes shared state. Each candidate tool interaction receives a bounded relevance decision. Deterministic code then applies the policy and reports before-and-after statistics.
Setup and compatibility
The project is documented as both an npm library and a Claude Code plugin. The plugin route currently depends on an early-access Claude Code function-hook capability and a TypeSafe API key.
Limitations
Only tool calls and results are candidates for removal. Token counts are estimates, and a probability does not prove a result is safe to discard. Near the state ceiling, the full fitted state may be repeated across requests. The repository’s animated macOS demo is explicitly scripted and does not call the API.
Sources
Primary source: Fast Jev Compaction repository.