ContextSelectionCall
SUPPORT · interface · 类型合同
Everything a selector may inspect for one decision.
导入
ts
import type { ContextSelectionCall } from '@jangts/agent-core/support';js
/** @typedef {import('@jangts/agent-core/support').ContextSelectionCall} ContextSelectionCall */其他公开入口:@jangts/agent-core/support、@jangts/agent-core/support/context。
定义
ts
interface ContextSelectionCall字段结构
| 字段 | 类型 | 必需 | 说明 |
|---|---|---|---|
stageId | string | 必需 | 只读。见类型定义及调用场景。 |
candidates | readonly ContextSelectionCandidate[] | 必需 | Reducible candidates, already filtered and measured. |
fragments | readonly ContextFragment[] | 必需 | Only reducible fragments; never protected request or system fragments. |
currentTokens | number | undefined | 可省略 | Current input tokens, when a token budget applies. |
requiredReductionTokens | number | undefined | 可省略 | Tokens that must be removed to satisfy the token budget. |
currentChars | number | 必需 | 见类型定义及调用场景。 |
requiredReductionChars | number | 必需 | Characters that must be removed to satisfy the character budget. |
remainingCalls | number | 必需 | Calls the selector may still spend through callModel. |
callModel | ContextModelCall | 必需 | 见类型定义及调用场景。 |
成员目录
| 成员 | 用途 |
|---|---|
callModel | 完整输入输出见下方重载。 |
成员详情
callModel
ts
ContextSelectionCall.callModel(request: ContextModelRequest): Promise<ModelResult<unknown>>| 参数 | 类型 | 传递 | 说明 |
|---|---|---|---|
request | ContextModelRequest | 必需 | — |
request 的字段
| 字段 | 类型 | 必需 | 说明 |
|---|---|---|---|
modelId | string | undefined | 可省略 | 只读。见类型定义及调用场景。 |
stageId | string | 必需 | 只读。见类型定义及调用场景。 |
input | readonly ModelMessage[] | BuiltContext | 必需 | 只读。见类型定义及调用场景。 |
maxOutputTokens | number | 必需 | 只读。见类型定义及调用场景。 |
transport | string | 必需 | 只读。见类型定义及调用场景。 |
返回: Promise<ModelResult<unknown>>。
等待后的值: ModelResult<unknown>。
返回值结构
| 字段 | 类型 | 必需 | 说明 |
|---|---|---|---|
value | unknown | 必需 | 只读。见类型定义及调用场景。 |
invocation | Readonly<ModelCallRecord> | 必需 | 只读。见类型定义及调用场景。 |
使用示例
- 选择缩减步骤:顺序、固定、自动或模型:一套类型化策略表达多种场景,保留精确参数与 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);