Skip to content
中文

validateContextPolicy ​

SUPPORT · function · Runtime value

Validate a complete context policy and every handler it can reference.

Handler IDs must be unique and each handler must declare a non-negative integer call ceiling. Reduction targets and selection modes are checked by their own catalog entries.

Import ​

ts
import { validateContextPolicy } from '@jangts/agent-core/support';
js
import { validateContextPolicy } from '@jangts/agent-core/support';

Other public entry points:@jangts/agent-core/support, @jangts/agent-core/support/context.

Definition ​

Call ​

ts
validateContextPolicy(policy: ContextPolicy, compressors: readonly ContextCompressor[], selectors?: readonly ContextSelector[]): void

Validate a complete context policy and every handler it can reference.

Handler IDs must be unique and each handler must declare a non-negative integer call ceiling. Reduction targets and selection modes are checked by their own catalog entries.

ParameterTypePassingDescription
policyContextPolicyRequired—
compressorsreadonly ContextCompressor[]Required—
selectorsreadonly ContextSelector[]Optional—

Optional shapes of Parameter policy: choose one shape; required fields for each branch are listed separately.

Branch 1
FieldTypeRequiredDescription
mode"validate"RequiredSee the type definition and usage context.
Branch 2
FieldTypeRequiredDescription
mode"reduce"RequiredSee the type definition and usage context.
triggerCharsnumber | undefinedOptionalSee the type definition and usage context.
targetInputCharsnumber | undefinedOptionalSee the type definition and usage context.
triggerTokensnumber | undefinedOptionalSee the type definition and usage context.
targetInputTokensnumber | undefinedOptionalSee the type definition and usage context.
selectionContextSelection | undefinedOptionalSee the type definition and usage context.
stepsreadonly ContextReduction[]RequiredSee the type definition and usage context.
Branch 3
FieldTypeRequiredDescription
mode"audit"RequiredSee the type definition and usage context.
mutableFragmentIdsreadonly string[]RequiredSee the type definition and usage context.

Returns: void.

Examples ​

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);

Limit the mutable range for the App's own processing ​

Extension · Node.js

Auditing also requires the ContextPlan to carry the original fragments; listing IDs alone does not modify or publish material by itself.

ts
import { Support } from '@jangts/agent-core';
import type { ContextPolicy } from '@jangts/agent-core/support/context';
const policy: ContextPolicy = { mode: 'audit', mutableFragmentIds: ['history'] };
Support.validateContextPolicy(policy, [], []);
console.log(policy.mutableFragmentIds);
js
import { Support } from '@jangts/agent-core';
const policy = { mode: 'audit', mutableFragmentIds: ['history'] };
Support.validateContextPolicy(policy, [], []);
console.log(policy.mutableFragmentIds);

API reference, usage examples and developer guides.