Skip to content
English

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

字段结构 ​

字段类型必需说明
idstring必需见类型定义及调用场景。
kind"trim" | "compress"必需见类型定义及调用场景。
fragmentIdstring必需见类型定义及调用场景。
charsnumber必需Current size of the candidate fragment, in JSON characters.
targetCharsnumber必需Size the step would reduce the fragment to.
requiredCallsnumber必需Model calls required to apply the step; 0 for local steps.
projectedCharsnumber | undefined可省略Exact dry-run result for trim. Compression size is not predicted.
trimLossRationumber | undefined可省略Fraction of characters removed by a trim step; meaningless for compression.

使用示例 ​

按已登记顺序处理 ​

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

相关策略源码 ​

相关定义 ​

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