Skip to content
中文

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.

ParameterTypePassingDescription
inputSelectionInputRequired—
Fields of input
FieldTypeRequiredDescription
signalAbortSignalRequiredRead-only. See the type definition and usage context.
diagnosticsDiagnosticContext | undefinedOptionalSee the type definition and usage context.
selectionContextSelectionRequiredSee the type definition and usage context.
selectorsreadonly ContextSelector[]RequiredSee the type definition and usage context.
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.

Returns: Promise<SelectionResult>.

Awaited value: SelectionResult.

Return value structure
FieldTypeRequiredDescription
stepIdsstring[]RequiredSee the type definition and usage context.
reasonstringRequiredSee 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.