ContextReduction
SUPPORT · type · Type contract
One declared reduction step.
Import
ts
import type { ContextReduction } from '@jangts/agent-core/support';js
/** @typedef {import('@jangts/agent-core/support').ContextReduction} ContextReduction */Other public entry points:@jangts/agent-core/support, @jangts/agent-core/support/context.
Definition
Type: ContextReduction
Type expression
ts
type ContextReduction = | {
id: string;
kind: 'trim';
fragmentId: string;
field: string;
targetChars: number;
grouping: ContextHistoryGrouping;
keepGroups: number;
}
/** Rewrites one fragment through a registered compressor down to `targetChars`. */
| ({
id: string;
kind: 'compress';
fragmentId: string;
targetChars: number;
/** Recent history the compressor must preserve verbatim. */
preserve?: ContextRecentHistory;
} & ContextHandlerReference);Union branch structure
Optional shapes of ContextReduction: choose one shape; required fields for each branch are listed separately.
Branch 1
| Field | Type | Required | Description |
|---|---|---|---|
id | string | Required | See the type definition and usage context. |
kind | "trim" | Required | See the type definition and usage context. |
fragmentId | string | Required | See the type definition and usage context. |
field | string | Required | See the type definition and usage context. |
targetChars | number | Required | See the type definition and usage context. |
grouping | ContextHistoryGrouping | Required | See the type definition and usage context. |
keepGroups | number | Required | See the type definition and usage context. |
Branch 2
| Field | Type | Required | Description |
|---|---|---|---|
id | string | Required | See the type definition and usage context. |
kind | "compress" | Required | See the type definition and usage context. |
fragmentId | string | Required | See the type definition and usage context. |
targetChars | number | Required | See the type definition and usage context. |
preserve | ContextRecentHistory | undefined | Optional | Recent history the compressor must preserve verbatim. |
handlerId | string | Required | Read-only. Registered handler id; an unknown id is rejected before execution. |
Examples
- Context policy: validate, reduce, and audit: Support provides replaceable policy implementations while Core keeps the final input contract and budget checks.
Explicitly use a validation-only policy
Beginner · Node.js
ts
import { Support } from '@jangts/agent-core';
import type { ContextPolicy } from '@jangts/agent-core/support/context';
const policy: ContextPolicy = { mode: 'validate' };
Support.validateContextPolicy(policy, [], []);
console.log(policy.mode);js
import { Support } from '@jangts/agent-core';
const policy = { mode: 'validate' };
Support.validateContextPolicy(policy, [], []);
console.log(policy.mode);Configure reduction order from real business fragments
Configuration · Node.js
These numbers are explicit choices for the example business, not SDK recommendations for capacities that suit all models.
ts
import { Support } from '@jangts/agent-core';
import type { ContextPolicy } from '@jangts/agent-core/support/context';
const policy: ContextPolicy = { mode: 'reduce', triggerChars: 1800, targetInputChars: 1500,
selection: { mode: 'sequence' },
steps: [{ id: 'recent-history', kind: 'trim', fragmentId: 'history', field: 'messages',
grouping: { kind: 'user-turn' }, keepGroups: 2, targetChars: 1000 }],
};
Support.validateContextPolicy(policy, [], []);
console.log(policy.steps);js
import { Support } from '@jangts/agent-core';
const policy = { mode: 'reduce', triggerChars: 1800, targetInputChars: 1500,
selection: { mode: 'sequence' },
steps: [{ id: 'recent-history', kind: 'trim', fragmentId: 'history', field: 'messages',
grouping: { kind: 'user-turn' }, keepGroups: 2, targetChars: 1000 }],
};
Support.validateContextPolicy(policy, [], []);
console.log(policy.steps);