Skip to content
English

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';
js
/** @typedef {import('@jangts/agent-core/support').ContextStrategyOptions} ContextStrategyOptions */

其他公开入口:@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;
      });

联合分支结构 ​

ContextStrategyOptions的可选结构: 选择其中一种结构,各分支的字段要求分别列出。

分支 1
字段类型必需说明
fragmentPick<ContextFragment, "id" | "maxChars">必需只读。Reuse the registered fragment identity and its existing hard size allowance.
fieldstring必需只读。见类型定义及调用场景。
preset"compact" | "balanced" | "extended" | undefined可省略只读。见类型定义及调用场景。
targetCharsnumber | undefined可省略只读。见类型定义及调用场景。
keepGroupsnumber | undefined可省略只读。见类型定义及调用场景。
groupingContextHistoryGrouping | undefined可省略只读。见类型定义及调用场景。
selectionContextSelection | undefined可省略见类型定义及调用场景。
triggerCharsnumber | undefined可省略见类型定义及调用场景。
targetInputCharsnumber | undefined可省略见类型定义及调用场景。
targetInputTokensnumber | undefined可省略见类型定义及调用场景。
triggerTokensnumber | undefined可省略见类型定义及调用场景。
stepsreadonly ContextReduction[] | undefined可省略只读。见类型定义及调用场景。
compressorsreadonly ContextCompressor[] | undefined可省略只读。见类型定义及调用场景。
selectorsreadonly ContextSelector[] | undefined可省略只读。见类型定义及调用场景。
kind"recent"必需只读。见类型定义及调用场景。
compressorundefined可省略只读。见类型定义及调用场景。
分支 2
字段类型必需说明
fragmentPick<ContextFragment, "id" | "maxChars">必需只读。Reuse the registered fragment identity and its existing hard size allowance.
fieldstring必需只读。见类型定义及调用场景。
preset"compact" | "balanced" | "extended" | undefined可省略只读。见类型定义及调用场景。
targetCharsnumber | undefined可省略只读。见类型定义及调用场景。
keepGroupsnumber | undefined可省略只读。见类型定义及调用场景。
groupingContextHistoryGrouping | undefined可省略只读。见类型定义及调用场景。
selectionContextSelection | undefined可省略见类型定义及调用场景。
triggerCharsnumber | undefined可省略见类型定义及调用场景。
targetInputCharsnumber | undefined可省略见类型定义及调用场景。
targetInputTokensnumber | undefined可省略见类型定义及调用场景。
triggerTokensnumber | undefined可省略见类型定义及调用场景。
stepsreadonly ContextReduction[] | undefined可省略只读。见类型定义及调用场景。
compressorsreadonly ContextCompressor[] | undefined可省略只读。见类型定义及调用场景。
selectorsreadonly ContextSelector[] | undefined可省略只读。见类型定义及调用场景。
kind"continuity"必需只读。见类型定义及调用场景。
compressorContextCompressor必需只读。见类型定义及调用场景。
分支 3
字段类型必需说明
selectionContextSelection | undefined可省略见类型定义及调用场景。
triggerCharsnumber | undefined可省略见类型定义及调用场景。
targetInputCharsnumber | undefined可省略见类型定义及调用场景。
targetInputTokensnumber | undefined可省略见类型定义及调用场景。
triggerTokensnumber | undefined可省略见类型定义及调用场景。
stepsreadonly ContextReduction[]必需只读。见类型定义及调用场景。
compressorsreadonly ContextCompressor[] | undefined可省略只读。见类型定义及调用场景。
selectorsreadonly ContextSelector[] | undefined可省略只读。见类型定义及调用场景。
fragmentPick<ContextFragment, "id" | "maxChars"> | undefined可省略只读。Reuse the registered fragment identity and its existing hard size allowance.
fieldstring | undefined可省略只读。见类型定义及调用场景。
preset"compact" | "balanced" | "extended" | undefined可省略只读。见类型定义及调用场景。
targetCharsnumber | undefined可省略只读。见类型定义及调用场景。
keepGroupsnumber | undefined可省略只读。见类型定义及调用场景。
groupingContextHistoryGrouping | undefined可省略只读。见类型定义及调用场景。
kind"recent" | "continuity" | undefined可省略只读。见类型定义及调用场景。
compressorContextCompressor | undefined可省略只读。见类型定义及调用场景。

使用示例 ​

复用已有片段生成最近历史策略 ​

入门 · 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);

同一配置增加保留组数与目标大小 ​

配置 · 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);

相关策略源码 ​

相关定义 ​

接口参考、使用示例与开发指南。