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[];
};字段结构
| 字段 | 类型 | 必需 | 说明 |
|---|---|---|---|
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 | 可省略 | 只读。见类型定义及调用场景。 |
使用示例
- 从历史语义生成处理策略:复用片段身份与硬预算,生成 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);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);