Skip to content
中文

ContextStrategySettings ​

SUPPORT · type · Type contract

Shared reduce-policy settings applied to the whole strategy.

Trigger and target fields follow the Core policy contract; omitted values fall back to the plan budget or to the trigger. Supplying steps disables generation and uses the explicit list.

Import ​

ts
import type { ContextStrategySettings } from '@jangts/agent-core/support';
js
/** @typedef {import('@jangts/agent-core/support').ContextStrategySettings} ContextStrategySettings */

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

Definition ​

Type: ContextStrategySettings

Type expression
ts
type ContextStrategySettings = Omit<
  Extract<ContextPolicy, { mode: 'reduce' }>,
  'mode' | 'steps'
> & {
  readonly steps?: readonly ContextReduction[];
  readonly compressors?: readonly ContextCompressor[];
  readonly selectors?: readonly ContextSelector[];
};

Field structure ​

FieldTypeRequiredDescription
selectionContextSelection | undefinedOptionalSee the type definition and usage context.
triggerCharsnumber | undefinedOptionalSee the type definition and usage context.
targetInputCharsnumber | undefinedOptionalSee the type definition and usage context.
targetInputTokensnumber | undefinedOptionalSee the type definition and usage context.
triggerTokensnumber | undefinedOptionalSee the type definition and usage context.
stepsreadonly ContextReduction[] | undefinedOptionalRead-only. See the type definition and usage context.
compressorsreadonly ContextCompressor[] | undefinedOptionalRead-only. See the type definition and usage context.
selectorsreadonly ContextSelector[] | undefinedOptionalRead-only. See the type definition and usage context.

Examples ​

Reuse an existing fragment to generate a recent-history strategy ​

Beginner · Node.js

ts
import { Support } from '@jangts/agent-core';
const fragment = { id: 'history', maxChars: 4000 };
const strategy = Support.createContextStrategy({ kind: 'recent', fragment, field: 'messages' });
console.log(strategy.policy, strategy.compressors);
js
import { Support } from '@jangts/agent-core';
const fragment = { id: 'history', maxChars: 4000 };
const strategy = Support.createContextStrategy({ kind: 'recent', fragment, field: 'messages' });
console.log(strategy.policy, strategy.compressors);

Add kept groups and target size to the same configuration ​

Configuration · Node.js

ts
import { Support } from '@jangts/agent-core';
const fragment = { id: 'history', maxChars: 4000 };
const strategy = Support.createContextStrategy({ kind: 'recent', fragment, field: 'messages',
  keepGroups: 3, targetChars: 2500, grouping: { kind: 'user-turn' },
});
console.log(strategy.policy);
js
import { Support } from '@jangts/agent-core';
const fragment = { id: 'history', maxChars: 4000 };
const strategy = Support.createContextStrategy({ kind: 'recent', fragment, field: 'messages',
    keepGroups: 3, targetChars: 2500, grouping: { kind: 'user-turn' },
});
console.log(strategy.policy);

API reference, usage examples and developer guides.