Skip to content
中文

ContextStrategyOptions ​

SUPPORT · type · Type contract

One history declaration that generates a step, or an explicit step list with optional history fields (fragment, field, preset, targetChars, keepGroups, grouping).

Import ​

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

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

Definition ​

Type: ContextStrategyOptions

Type expression
ts
type ContextStrategyOptions = | GeneratedContextStrategyOptions
  | (ContextStrategySettings &
      Partial<HistoryStrategy> & {
        readonly steps: readonly ContextReduction[];
        readonly kind?: 'recent' | 'continuity';
        readonly compressor?: ContextCompressor;
      });

Union branch structure ​

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

Branch 1
FieldTypeRequiredDescription
fragmentPick<ContextFragment, "id" | "maxChars">RequiredRead-only. Reuse the registered fragment identity and its existing hard size allowance.
fieldstringRequiredRead-only. See the type definition and usage context.
preset"compact" | "balanced" | "extended" | undefinedOptionalRead-only. See the type definition and usage context.
targetCharsnumber | undefinedOptionalRead-only. See the type definition and usage context.
keepGroupsnumber | undefinedOptionalRead-only. See the type definition and usage context.
groupingContextHistoryGrouping | undefinedOptionalRead-only. See the type definition and usage context.
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.
kind"recent"RequiredRead-only. See the type definition and usage context.
compressorundefinedOptionalRead-only. See the type definition and usage context.
Branch 2
FieldTypeRequiredDescription
fragmentPick<ContextFragment, "id" | "maxChars">RequiredRead-only. Reuse the registered fragment identity and its existing hard size allowance.
fieldstringRequiredRead-only. See the type definition and usage context.
preset"compact" | "balanced" | "extended" | undefinedOptionalRead-only. See the type definition and usage context.
targetCharsnumber | undefinedOptionalRead-only. See the type definition and usage context.
keepGroupsnumber | undefinedOptionalRead-only. See the type definition and usage context.
groupingContextHistoryGrouping | undefinedOptionalRead-only. See the type definition and usage context.
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.
kind"continuity"RequiredRead-only. See the type definition and usage context.
compressorContextCompressorRequiredRead-only. See the type definition and usage context.
Branch 3
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[]RequiredRead-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.
fragmentPick<ContextFragment, "id" | "maxChars"> | undefinedOptionalRead-only. Reuse the registered fragment identity and its existing hard size allowance.
fieldstring | undefinedOptionalRead-only. See the type definition and usage context.
preset"compact" | "balanced" | "extended" | undefinedOptionalRead-only. See the type definition and usage context.
targetCharsnumber | undefinedOptionalRead-only. See the type definition and usage context.
keepGroupsnumber | undefinedOptionalRead-only. See the type definition and usage context.
groupingContextHistoryGrouping | undefinedOptionalRead-only. See the type definition and usage context.
kind"recent" | "continuity" | undefinedOptionalRead-only. See the type definition and usage context.
compressorContextCompressor | 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.