ContextStrategyOptions
SUPPORT · type · 类型合同
One history declaration that generates a step, or an explicit step list with optional history fields (fragment, field, preset, targetChars, keepGroups, grouping).
导入
ts
import type { ContextStrategyOptions } from '@jangts/agent-core/support';1
js
/** @typedef {import('@jangts/agent-core/support').ContextStrategyOptions} ContextStrategyOptions */1
其他公开入口:@jangts/agent-core/support、@jangts/agent-core/support/context。
定义
类型: ContextStrategyOptions
类型表达式
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
联合分支结构
ContextStrategyOptions的可选结构: 选择其中一种结构,各分支的字段要求分别列出。
分支 1
| 字段 | 类型 | 必需 | 说明 |
|---|---|---|---|
fragment | Pick<ContextFragment, "id" | "maxChars"> | 必需 | 只读。Reuse the registered fragment identity and its existing hard size allowance. |
field | string | 必需 | 只读。见类型定义及调用场景。 |
preset | "compact" | "balanced" | "extended" | undefined | 可省略 | 只读。见类型定义及调用场景。 |
targetChars | number | undefined | 可省略 | 只读。见类型定义及调用场景。 |
keepGroups | number | undefined | 可省略 | 只读。见类型定义及调用场景。 |
grouping | ContextHistoryGrouping | undefined | 可省略 | 只读。见类型定义及调用场景。 |
selection | ContextSelection | undefined | 可省略 | 见类型定义及调用场景。 |
triggerChars | number | undefined | 可省略 | 见类型定义及调用场景。 |
targetInputChars | number | undefined | 可省略 | 见类型定义及调用场景。 |
targetInputTokens | number | undefined | 可省略 | 见类型定义及调用场景。 |
triggerTokens | number | undefined | 可省略 | 见类型定义及调用场景。 |
steps | readonly ContextReduction[] | undefined | 可省略 | 只读。见类型定义及调用场景。 |
compressors | readonly ContextCompressor[] | undefined | 可省略 | 只读。见类型定义及调用场景。 |
selectors | readonly ContextSelector[] | undefined | 可省略 | 只读。见类型定义及调用场景。 |
kind | "recent" | 必需 | 只读。见类型定义及调用场景。 |
compressor | undefined | 可省略 | 只读。见类型定义及调用场景。 |
分支 2
| 字段 | 类型 | 必需 | 说明 |
|---|---|---|---|
fragment | Pick<ContextFragment, "id" | "maxChars"> | 必需 | 只读。Reuse the registered fragment identity and its existing hard size allowance. |
field | string | 必需 | 只读。见类型定义及调用场景。 |
preset | "compact" | "balanced" | "extended" | undefined | 可省略 | 只读。见类型定义及调用场景。 |
targetChars | number | undefined | 可省略 | 只读。见类型定义及调用场景。 |
keepGroups | number | undefined | 可省略 | 只读。见类型定义及调用场景。 |
grouping | ContextHistoryGrouping | undefined | 可省略 | 只读。见类型定义及调用场景。 |
selection | ContextSelection | undefined | 可省略 | 见类型定义及调用场景。 |
triggerChars | number | undefined | 可省略 | 见类型定义及调用场景。 |
targetInputChars | number | undefined | 可省略 | 见类型定义及调用场景。 |
targetInputTokens | number | undefined | 可省略 | 见类型定义及调用场景。 |
triggerTokens | number | undefined | 可省略 | 见类型定义及调用场景。 |
steps | readonly ContextReduction[] | undefined | 可省略 | 只读。见类型定义及调用场景。 |
compressors | readonly ContextCompressor[] | undefined | 可省略 | 只读。见类型定义及调用场景。 |
selectors | readonly ContextSelector[] | undefined | 可省略 | 只读。见类型定义及调用场景。 |
kind | "continuity" | 必需 | 只读。见类型定义及调用场景。 |
compressor | ContextCompressor | 必需 | 只读。见类型定义及调用场景。 |
分支 3
| 字段 | 类型 | 必需 | 说明 |
|---|---|---|---|
selection | ContextSelection | undefined | 可省略 | 见类型定义及调用场景。 |
triggerChars | number | undefined | 可省略 | 见类型定义及调用场景。 |
targetInputChars | number | undefined | 可省略 | 见类型定义及调用场景。 |
targetInputTokens | number | undefined | 可省略 | 见类型定义及调用场景。 |
triggerTokens | number | undefined | 可省略 | 见类型定义及调用场景。 |
steps | readonly ContextReduction[] | 必需 | 只读。见类型定义及调用场景。 |
compressors | readonly ContextCompressor[] | undefined | 可省略 | 只读。见类型定义及调用场景。 |
selectors | readonly ContextSelector[] | undefined | 可省略 | 只读。见类型定义及调用场景。 |
fragment | Pick<ContextFragment, "id" | "maxChars"> | undefined | 可省略 | 只读。Reuse the registered fragment identity and its existing hard size allowance. |
field | string | undefined | 可省略 | 只读。见类型定义及调用场景。 |
preset | "compact" | "balanced" | "extended" | undefined | 可省略 | 只读。见类型定义及调用场景。 |
targetChars | number | undefined | 可省略 | 只读。见类型定义及调用场景。 |
keepGroups | number | undefined | 可省略 | 只读。见类型定义及调用场景。 |
grouping | ContextHistoryGrouping | undefined | 可省略 | 只读。见类型定义及调用场景。 |
kind | "recent" | "continuity" | undefined | 可省略 | 只读。见类型定义及调用场景。 |
compressor | ContextCompressor | undefined | 可省略 | 只读。见类型定义及调用场景。 |
使用示例
- 从历史语义生成处理策略:复用片段身份与硬预算,生成 recent 或 continuity 的完整步骤和引用。
复用已有片段生成最近历史策略
入门 · 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
同一配置增加保留组数与目标大小
配置 · 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