Skip to content
中文

contextPolicyCatalog ​

SUPPORT · constant · Runtime value

Import ​

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

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

Definition ​

ts
const contextPolicyCatalog: { validate: { validate(): void; run(): void; }; reduce: { validate: (policy: ContextPolicy, handlers: Set<string>) => void; run: (state: ProcessingState) => Promise<void>; }; audit: { validate: (policy: ContextPolicy) => void; run: ({ plan, policy, before, fragments, report }: ProcessingState) => void; }; }

Field structure ​

FieldTypeRequiredDescription
validate{ validate(): void; run(): void; }RequiredSee the type definition and usage context.
reduce{ validate: (policy: ContextPolicy, handlers: Set<string>) => void; run: (state: ProcessingState) => Promise<void>; }RequiredSee the type definition and usage context.
audit{ validate: (policy: ContextPolicy) => void; run: ({ plan, policy, before, fragments, report }: ProcessingState) => void; }RequiredSee the type definition and usage context.

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.