Skip to content
中文

ContextSelection ​

SUPPORT · type · Type contract

Selection is independent of ownership; omitted selection preserves ordered execution.

Import ​

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

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

Definition ​

Type: ContextSelection

Type expression
ts
type ContextSelection = | { mode: 'sequence' }
  /** Apply only steps of the given kind. */
  | { mode: 'fixed'; kind: ContextReduction['kind'] }
  /** maxTrimLossRatio is a JSON-character reduction heuristic, not semantic information loss. */
  | { mode: 'auto'; maxTrimLossRatio?: number; reserveCalls?: number }
  /** Ask a registered model selector; `reserveCalls` keeps calls for later stages. */
  | ({ mode: 'model'; reserveCalls?: number } & ContextHandlerReference);

Union branch structure ​

Optional shapes of ContextSelection: choose one shape; required fields for each branch are listed separately.

Branch 1
FieldTypeRequiredDescription
mode"sequence"RequiredSee the type definition and usage context.
Branch 2
FieldTypeRequiredDescription
mode"fixed"RequiredSee the type definition and usage context.
kind"trim" | "compress"RequiredSee the type definition and usage context.
Branch 3
FieldTypeRequiredDescription
mode"auto"RequiredSee the type definition and usage context.
maxTrimLossRationumber | undefinedOptionalSee the type definition and usage context.
reserveCallsnumber | undefinedOptionalSee the type definition and usage context.
Branch 4
FieldTypeRequiredDescription
mode"model"RequiredSee the type definition and usage context.
reserveCallsnumber | undefinedOptionalSee the type definition and usage context.
handlerIdstringRequiredRead-only. Registered handler id; an unknown id is rejected before execution.

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.