ContextSelector
SUPPORT · interface · Type contract
Model or local selector that chooses which reductions to apply.
Import
ts
import type { ContextSelector } from '@jangts/agent-core/support';js
/** @typedef {import('@jangts/agent-core/support').ContextSelector} ContextSelector */Other public entry points:@jangts/agent-core/support, @jangts/agent-core/support/context.
Definition
ts
interface ContextSelectorField structure
| Field | Type | Required | Description |
|---|---|---|---|
id | string | Required | See the type definition and usage context. |
maxCalls | number | undefined | Optional | Maximum model calls made through callModel, default 1; 0 permits a local selector. |
select | (call: ContextSelectionCall, context: ExecutionContext) => Promise<readonly string[]> | Required | Returns selected reduction ids; unknown ids are rejected. |
Member index
| Member | Purpose |
|---|---|
select | Returns selected reduction ids; unknown ids are rejected. |
Member details
select
Returns selected reduction ids; unknown ids are rejected.
ts
ContextSelector.select(call: ContextSelectionCall, context: ExecutionContext): Promise<readonly string[]>Returns selected reduction ids; unknown ids are rejected.
| Parameter | Type | Passing | Description |
|---|---|---|---|
call | ContextSelectionCall | Required | — |
context | ExecutionContext | Required | — |
Fields of call
| Field | Type | Required | Description |
|---|---|---|---|
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. |
Fields of context
| Field | Type | Required | Description |
|---|---|---|---|
logger | SubFlowLog | undefined | Optional | Read-only. Explicit optional recorder for this operation; never inferred from diagnostics. |
signal | AbortSignal | Required | Read-only. Non-optional cancellation signal; never undefined once execution has started. |
diagnostics | DiagnosticContext | undefined | Optional | Read-only. Diagnostic scope of the enclosing call, when recording is enabled. |
Returns: Promise<readonly string[]>.
Awaited value: readonly string[].
Examples
- Compressors and selectors: recommended implementations and custom algorithms: Bind prompts, output parsing, and algorithms as handlers; model I/O goes through callModel of the same request.
Bind a text compression handler
Beginner · Node.js
ts
import { Support } from '@jangts/agent-core';
const compressor = Support.createContextCompressor({
id: 'history-summary', instruction: '保留事实、时间和未完成事项,精简重复表达。',
transport: 'core:plain-text', maxOutputTokens: 500,
parse(value: unknown) { if (typeof value !== 'string' || !value.trim()) throw new TypeError('需要非空摘要'); return value; },
});
console.log(compressor.id);js
import { Support } from '@jangts/agent-core';
const compressor = Support.createContextCompressor({
id: 'history-summary', instruction: '保留事实、时间和未完成事项,精简重复表达。',
transport: 'core:plain-text', maxOutputTokens: 500,
parse(value) { if (typeof value !== 'string' || !value.trim())
throw new TypeError('需要非空摘要'); return value; },
});
console.log(compressor.id);A selector explicitly controls the visible excerpt range
Configuration · Node.js
selector-json must be registered by the App and return value={stepIds:string[]}; an ordinary text transport must not be treated as already parsed JSON. This example only shows handler assembly and sends no request.
ts
import { Support } from '@jangts/agent-core';
const selector = Support.createContextSelector({ id: 'select-reduction',
transport: 'selector-json', maxOutputTokens: 200, maxExcerptChars: 1000,
});
console.log(selector.id);js
import { Support } from '@jangts/agent-core';
const selector = Support.createContextSelector({ id: 'select-reduction',
transport: 'selector-json', maxOutputTokens: 200, maxExcerptChars: 1000,
});
console.log(selector.id);