Skip to content
English

ContextStrategySettings ​

SUPPORT · type · 类型合同

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.

导入 ​

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

其他公开入口:@jangts/agent-core/support、@jangts/agent-core/support/context。

定义 ​

类型: ContextStrategySettings

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

字段结构 ​

字段类型必需说明
selectionContextSelection | undefined可省略见类型定义及调用场景。
triggerCharsnumber | undefined可省略见类型定义及调用场景。
targetInputCharsnumber | undefined可省略见类型定义及调用场景。
targetInputTokensnumber | undefined可省略见类型定义及调用场景。
triggerTokensnumber | undefined可省略见类型定义及调用场景。
stepsreadonly ContextReduction[] | undefined可省略只读。见类型定义及调用场景。
compressorsreadonly ContextCompressor[] | undefined可省略只读。见类型定义及调用场景。
selectorsreadonly ContextSelector[] | 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);

相关策略源码 ​

相关定义 ​

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