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';1
js
/** @typedef {import('@jangts/agent-core/support').ContextStrategyOptions} ContextStrategyOptions */1
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;
});1
2
3
4
5
6
7
2
3
4
5
6
7
Union branch structure
Optional shapes of ContextStrategyOptions: choose one shape; required fields for each branch are listed separately.
Branch 1
| Field | Type | Required | Description |
|---|---|---|---|
fragment | Pick<ContextFragment, "id" | "maxChars"> | Required | Read-only. Reuse the registered fragment identity and its existing hard size allowance. |
field | string | Required | Read-only. See the type definition and usage context. |
preset | "compact" | "balanced" | "extended" | undefined | Optional | Read-only. See the type definition and usage context. |
targetChars | number | undefined | Optional | Read-only. See the type definition and usage context. |
keepGroups | number | undefined | Optional | Read-only. See the type definition and usage context. |
grouping | ContextHistoryGrouping | undefined | Optional | Read-only. See the type definition and usage context. |
selection | ContextSelection | undefined | Optional | See the type definition and usage context. |
triggerChars | number | undefined | Optional | See the type definition and usage context. |
targetInputChars | number | undefined | Optional | See the type definition and usage context. |
targetInputTokens | number | undefined | Optional | See the type definition and usage context. |
triggerTokens | number | undefined | Optional | See the type definition and usage context. |
steps | readonly ContextReduction[] | undefined | Optional | Read-only. See the type definition and usage context. |
compressors | readonly ContextCompressor[] | undefined | Optional | Read-only. See the type definition and usage context. |
selectors | readonly ContextSelector[] | undefined | Optional | Read-only. See the type definition and usage context. |
kind | "recent" | Required | Read-only. See the type definition and usage context. |
compressor | undefined | Optional | Read-only. See the type definition and usage context. |
Branch 2
| Field | Type | Required | Description |
|---|---|---|---|
fragment | Pick<ContextFragment, "id" | "maxChars"> | Required | Read-only. Reuse the registered fragment identity and its existing hard size allowance. |
field | string | Required | Read-only. See the type definition and usage context. |
preset | "compact" | "balanced" | "extended" | undefined | Optional | Read-only. See the type definition and usage context. |
targetChars | number | undefined | Optional | Read-only. See the type definition and usage context. |
keepGroups | number | undefined | Optional | Read-only. See the type definition and usage context. |
grouping | ContextHistoryGrouping | undefined | Optional | Read-only. See the type definition and usage context. |
selection | ContextSelection | undefined | Optional | See the type definition and usage context. |
triggerChars | number | undefined | Optional | See the type definition and usage context. |
targetInputChars | number | undefined | Optional | See the type definition and usage context. |
targetInputTokens | number | undefined | Optional | See the type definition and usage context. |
triggerTokens | number | undefined | Optional | See the type definition and usage context. |
steps | readonly ContextReduction[] | undefined | Optional | Read-only. See the type definition and usage context. |
compressors | readonly ContextCompressor[] | undefined | Optional | Read-only. See the type definition and usage context. |
selectors | readonly ContextSelector[] | undefined | Optional | Read-only. See the type definition and usage context. |
kind | "continuity" | Required | Read-only. See the type definition and usage context. |
compressor | ContextCompressor | Required | Read-only. See the type definition and usage context. |
Branch 3
| Field | Type | Required | Description |
|---|---|---|---|
selection | ContextSelection | undefined | Optional | See the type definition and usage context. |
triggerChars | number | undefined | Optional | See the type definition and usage context. |
targetInputChars | number | undefined | Optional | See the type definition and usage context. |
targetInputTokens | number | undefined | Optional | See the type definition and usage context. |
triggerTokens | number | undefined | Optional | See the type definition and usage context. |
steps | readonly ContextReduction[] | Required | Read-only. See the type definition and usage context. |
compressors | readonly ContextCompressor[] | undefined | Optional | Read-only. See the type definition and usage context. |
selectors | readonly ContextSelector[] | undefined | Optional | Read-only. See the type definition and usage context. |
fragment | Pick<ContextFragment, "id" | "maxChars"> | undefined | Optional | Read-only. Reuse the registered fragment identity and its existing hard size allowance. |
field | string | undefined | Optional | Read-only. See the type definition and usage context. |
preset | "compact" | "balanced" | "extended" | undefined | Optional | Read-only. See the type definition and usage context. |
targetChars | number | undefined | Optional | Read-only. See the type definition and usage context. |
keepGroups | number | undefined | Optional | Read-only. See the type definition and usage context. |
grouping | ContextHistoryGrouping | undefined | Optional | Read-only. See the type definition and usage context. |
kind | "recent" | "continuity" | undefined | Optional | Read-only. See the type definition and usage context. |
compressor | ContextCompressor | undefined | Optional | Read-only. See the type definition and usage context. |
Examples
- Generate processing strategies from history semantics: Reuse fragment identity and hard budgets to generate complete steps and references for recent or continuity.
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);1
2
3
4
2
3
4
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);1
2
3
4
2
3
4
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);1
2
3
4
5
6
2
3
4
5
6
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);1
2
3
4
5
6
2
3
4
5
6