Skip to content
中文

contextReductionCatalog ​

SUPPORT · constant · Runtime value

Import ​

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

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

Definition ​

ts
const contextReductionCatalog: { trim: { validate(step: ContextReduction): void; run: ({ step, fragment }: OperationCall) => Promise<ContextFragment["value"]>; }; compress: { validate(step: ContextReduction, handlers: Set<string>): void; run: (call: OperationCall) => Promise<ContextFragment["value"]>; }; }

Field structure ​

FieldTypeRequiredDescription
trim{ validate(step: ContextReduction): void; run: ({ step, fragment }: OperationCall) => Promise<ContextFragment["value"]>; }RequiredSee the type definition and usage context.
compress{ validate(step: ContextReduction, handlers: Set<string>): void; run: (call: OperationCall) => Promise<ContextFragment["value"]>; }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.