Skip to content
中文

ContextCompressor ​

SUPPORT · interface · Type contract

Registered compressor handler.

Import ​

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

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

Definition ​

ts
interface ContextCompressor

Field structure ​

FieldTypeRequiredDescription
idstringRequiredSee the type definition and usage context.
maxCallsnumber | undefinedOptionalMaximum model calls through callModel, default 1; declare 0 for local compression.
compress(call: ContextCompressionCall, context: ExecutionContext) => Promise<ContextFragment["value"]>RequiredProduces a replacement value no larger than the requested target where possible.

Member index ​

MemberPurpose
compressProduces a replacement value no larger than the requested target where possible.

Member details ​

compress ​

Produces a replacement value no larger than the requested target where possible.

ts
ContextCompressor.compress(call: ContextCompressionCall, context: ExecutionContext): Promise<ContextFragment["value"]>

Produces a replacement value no larger than the requested target where possible.

ParameterTypePassingDescription
callContextCompressionCallRequired—
contextExecutionContextRequired—
Fields of call
FieldTypeRequiredDescription
stageIdstringRequiredRead-only. See the type definition and usage context.
fragmentContextFragmentRequiredFragment to compress; its targetChars bound is enforced by the engine.
targetCharsnumberRequiredSee the type definition and usage context.
callModelContextModelCallRequiredSame runner's budget, timeout, transports and diagnostics. No recursive processing.
Fields of context
FieldTypeRequiredDescription
loggerSubFlowLog | undefinedOptionalRead-only. Explicit optional recorder for this operation; never inferred from diagnostics.
signalAbortSignalRequiredRead-only. Non-optional cancellation signal; never undefined once execution has started.
diagnosticsDiagnosticContext | undefinedOptionalRead-only. Diagnostic scope of the enclosing call, when recording is enabled.

Returns: Promise<string \| Record<string, unknown>>.

Awaited value: string \| Record<string, unknown>.

Examples ​

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

API reference, usage examples and developer guides.