ContextPolicy
SUPPORT · type · Type contract
Declared context policy for one stage.
Import
ts
import type { ContextPolicy } from '@jangts/agent-core/support';js
/** @typedef {import('@jangts/agent-core/support').ContextPolicy} ContextPolicy */Other public entry points:@jangts/agent-core/support, @jangts/agent-core/support/context.
Definition
Type: ContextPolicy
Type expression
ts
type ContextPolicy = | { mode: 'validate' }
/**
* Reduce content when a trigger is exceeded.
*
* Character and token triggers/targets may be combined; `targetInputChars`/`targetInputTokens`
* define the size the reduction must reach.
*/
| {
mode: 'reduce';
triggerChars?: number;
targetInputChars?: number;
triggerTokens?: number;
targetInputTokens?: number;
selection?: ContextSelection;
steps: readonly ContextReduction[];
}
/** Verify that only the listed fragments changed value, without reducing anything. */
| { mode: 'audit'; mutableFragmentIds: readonly string[] };Union branch structure
Optional shapes of ContextPolicy: choose one shape; required fields for each branch are listed separately.
Branch 1
| Field | Type | Required | Description |
|---|---|---|---|
mode | "validate" | Required | See the type definition and usage context. |
Branch 2
| Field | Type | Required | Description |
|---|---|---|---|
mode | "reduce" | Required | See the type definition and usage context. |
triggerChars | number | undefined | Optional | See the type definition and usage context. |
targetInputChars | number | undefined | Optional | See the type definition and usage context. |
triggerTokens | number | undefined | Optional | See the type definition and usage context. |
targetInputTokens | number | undefined | Optional | See the type definition and usage context. |
selection | ContextSelection | undefined | Optional | See the type definition and usage context. |
steps | readonly ContextReduction[] | Required | See the type definition and usage context. |
Branch 3
| Field | Type | Required | Description |
|---|---|---|---|
mode | "audit" | Required | See the type definition and usage context. |
mutableFragmentIds | readonly string[] | Required | See the type definition and usage context. |
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);