selectContextSteps
SUPPORT · function · Runtime value
Choose steps that fit the remaining call budget.
Feasibility uses exact trim previews and declared call ceilings; the reply reserve and the selector's own allowance are subtracted before candidates are considered, so neither can be spent on reductions.
Import
ts
import { selectContextSteps } from '@jangts/agent-core/support';js
import { selectContextSteps } from '@jangts/agent-core/support';Other public entry points:@jangts/agent-core/support, @jangts/agent-core/support/context.
Definition
Call
ts
selectContextSteps(input: SelectionInput): Promise<SelectionResult>Choose steps that fit the remaining call budget.
Feasibility uses exact trim previews and declared call ceilings; the reply reserve and the selector's own allowance are subtracted before candidates are considered, so neither can be spent on reductions.
| Parameter | Type | Passing | Description |
|---|---|---|---|
input | SelectionInput | Required | — |
Fields of input
| Field | Type | Required | Description |
|---|---|---|---|
signal | AbortSignal | Required | Read-only. See the type definition and usage context. |
diagnostics | DiagnosticContext | undefined | Optional | See the type definition and usage context. |
selection | ContextSelection | Required | See the type definition and usage context. |
selectors | readonly ContextSelector[] | Required | See the type definition and usage context. |
stageId | string | Required | Read-only. See the type definition and usage context. |
candidates | readonly ContextSelectionCandidate[] | Required | Reducible candidates, already filtered and measured. |
fragments | readonly ContextFragment[] | Required | Only reducible fragments; never protected request or system fragments. |
currentTokens | number | undefined | Optional | Current input tokens, when a token budget applies. |
requiredReductionTokens | number | undefined | Optional | Tokens that must be removed to satisfy the token budget. |
currentChars | number | Required | See the type definition and usage context. |
requiredReductionChars | number | Required | Characters that must be removed to satisfy the character budget. |
remainingCalls | number | Required | Calls the selector may still spend through callModel. |
callModel | ContextModelCall | Required | See the type definition and usage context. |
Returns: Promise<SelectionResult>.
Awaited value: SelectionResult.
Return value structure
| Field | Type | Required | Description |
|---|---|---|---|
stepIds | string[] | Required | See the type definition and usage context. |
reason | string | Required | See the type definition and usage context. |
Examples
- Selecting reduction steps: sequence, fixed, automatic, or model: One typed policy set expresses multiple scenarios while preserving exact parameters and App-defined selection.
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);