Skip to content
中文

Selecting reduction steps: sequence, fixed, automatic, or model ​

One typed policy set expresses multiple scenarios while preserving exact parameters and App-defined selection.

sequence keeps the registered order; fixed selects a certain kind; auto prefers trimmable items whose loss ratio is within the threshold and otherwise selects compression; model calls a registered selector to return unique, feasible stepIds.

auto's maxTrimLossRatio defaults to 0.25 and is a heuristic for the JSON character reduction ratio, not a percentage of semantic information loss. auto/model default to reserveCalls=1 to keep a call for the final answer; handler maxCalls defaults to 1, and local algorithms can explicitly declare 0.

Infeasible candidates are excluded before selection based on the real available call quota. An empty stepIds means no reduction was executed and is not implicitly changed to all steps; if the budget is still exceeded, the request is rejected. A selector also cannot widen its capability by returning unknown IDs or accumulating calls beyond the quota.

Progressive examples for the same business case ​

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

Policies & implementations ​

API reference, usage examples and developer guides.