ContextSelectionCandidate
SUPPORT · interface · 类型合同
Candidate step considered by selection, with its measured cost.
导入
ts
import type { ContextSelectionCandidate } from '@jangts/agent-core/support';js
/** @typedef {import('@jangts/agent-core/support').ContextSelectionCandidate} ContextSelectionCandidate */其他公开入口:@jangts/agent-core/support、@jangts/agent-core/support/context。
定义
ts
interface ContextSelectionCandidate字段结构
| 字段 | 类型 | 必需 | 说明 |
|---|---|---|---|
id | string | 必需 | 见类型定义及调用场景。 |
kind | "trim" | "compress" | 必需 | 见类型定义及调用场景。 |
fragmentId | string | 必需 | 见类型定义及调用场景。 |
chars | number | 必需 | Current size of the candidate fragment, in JSON characters. |
targetChars | number | 必需 | Size the step would reduce the fragment to. |
requiredCalls | number | 必需 | Model calls required to apply the step; 0 for local steps. |
projectedChars | number | undefined | 可省略 | Exact dry-run result for trim. Compression size is not predicted. |
trimLossRatio | number | undefined | 可省略 | Fraction of characters removed by a trim step; meaningless for compression. |
使用示例
- 选择缩减步骤:顺序、固定、自动或模型:一套类型化策略表达多种场景,保留精确参数与 App 自定义选择。
按已登记顺序处理
入门 · Node.js
ts
import { Support } from '@jangts/agent-core';
Support.validateContextSelection({ mode: 'sequence' }, []);
console.log(Object.keys(Support.contextSelectionCatalog));js
import { Support } from '@jangts/agent-core';
Support.validateContextSelection({ mode: 'sequence' }, []);
console.log(Object.keys(Support.contextSelectionCatalog));按场景选择策略并精确覆盖
配置 · Node.js
ts
import { Support } from '@jangts/agent-core';
const localOnly = { mode: 'fixed' as const, kind: 'trim' as const };
const preserveMore = { mode: 'auto' as const, maxTrimLossRatio: 0.1, reserveCalls: 2 };
Support.validateContextSelection(localOnly, []);
Support.validateContextSelection(preserveMore, []);
console.log(localOnly, preserveMore);js
import { Support } from '@jangts/agent-core';
const localOnly = { mode: 'fixed', kind: 'trim' };
const preserveMore = { mode: 'auto', maxTrimLossRatio: 0.1, reserveCalls: 2 };
Support.validateContextSelection(localOnly, []);
Support.validateContextSelection(preserveMore, []);
console.log(localOnly, preserveMore);