Skip to content
中文

ContextSelectionCall ​

SUPPORT · interface · Type contract

Everything a selector may inspect for one decision.

Import ​

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

Other public entry points:@jangts/agent-core/support, @jangts/agent-core/support/context.

Definition ​

ts
interface ContextSelectionCall

Field structure ​

FieldTypeRequiredDescription
stageIdstringRequiredRead-only. See the type definition and usage context.
candidatesreadonly ContextSelectionCandidate[]RequiredReducible candidates, already filtered and measured.
fragmentsreadonly ContextFragment[]RequiredOnly reducible fragments; never protected request or system fragments.
currentTokensnumber | undefinedOptionalCurrent input tokens, when a token budget applies.
requiredReductionTokensnumber | undefinedOptionalTokens that must be removed to satisfy the token budget.
currentCharsnumberRequiredSee the type definition and usage context.
requiredReductionCharsnumberRequiredCharacters that must be removed to satisfy the character budget.
remainingCallsnumberRequiredCalls the selector may still spend through callModel.
callModelContextModelCallRequiredSee the type definition and usage context.

Member index ​

MemberPurpose
callModelSee the overload below for full inputs and outputs.

Member details ​

callModel ​

ts
ContextSelectionCall.callModel(request: ContextModelRequest): Promise<ModelResult<unknown>>
ParameterTypePassingDescription
requestContextModelRequestRequired—
Fields of request
FieldTypeRequiredDescription
modelIdstring | undefinedOptionalRead-only. See the type definition and usage context.
stageIdstringRequiredRead-only. See the type definition and usage context.
inputreadonly ModelMessage[] | BuiltContextRequiredRead-only. See the type definition and usage context.
maxOutputTokensnumberRequiredRead-only. See the type definition and usage context.
transportstringRequiredRead-only. See the type definition and usage context.

Returns: Promise<ModelResult<unknown>>.

Awaited value: ModelResult<unknown>.

Return value structure
FieldTypeRequiredDescription
valueunknownRequiredRead-only. See the type definition and usage context.
invocationReadonly<ModelCallRecord>RequiredRead-only. See the type definition and usage context.

Examples ​

Process in registered order ​

Beginner · 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));

Choose a policy per scenario with exact overrides ​

Configuration · 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);

API reference, usage examples and developer guides.