ContextProcessingOptions
SUPPORT · interface · 类型合同
Runtime inputs for one processing run.
导入
ts
import type { ContextProcessingOptions } from '@jangts/agent-core/support';1
js
/** @typedef {import('@jangts/agent-core/support').ContextProcessingOptions} ContextProcessingOptions */1
其他公开入口:@jangts/agent-core/support、@jangts/agent-core/support/context。
定义
ts
interface ContextProcessingOptions1
继承或实现: ExecutionContext。
字段结构
| 字段 | 类型 | 必需 | 说明 |
|---|---|---|---|
stageId | string | 必需 | 只读。Stage the processing belongs to; reported in diagnostics and selection calls. |
compressors | readonly ContextCompressor[] | 必需 | 只读。Compressors available by handler id. |
selectors | readonly ContextSelector[] | undefined | 可省略 | 只读。Selectors available by handler id; required only for model selection. |
callModel | ContextModelCall | 必需 | 只读。见类型定义及调用场景。 |
remainingCalls | (() => number) | undefined | 可省略 | 只读。Remaining model calls; used to reject unaffordable selections. |
tokenBudget | ContextTokenMeasurement | undefined | 可省略 | 只读。Token measurement; without it, token triggers and targets cannot apply. |
logger | SubFlowLog | undefined | 可省略 | 只读。Explicit optional recorder for this operation; never inferred from diagnostics. |
signal | AbortSignal | 必需 | 只读。Non-optional cancellation signal; never undefined once execution has started. |
diagnostics | DiagnosticContext | undefined | 可省略 | 只读。Diagnostic scope of the enclosing call, when recording is enabled. |
成员目录
| 成员 | 用途 |
|---|---|
callModel | 完整输入输出见下方重载。 |
成员详情
callModel
ts
ContextProcessingOptions.callModel(request: ContextModelRequest): Promise<ModelResult<unknown>>1
| 参数 | 类型 | 传递 | 说明 |
|---|---|---|---|
request | ContextModelRequest | 必需 | — |
request 的字段
| 字段 | 类型 | 必需 | 说明 |
|---|---|---|---|
modelId | string | undefined | 可省略 | 只读。见类型定义及调用场景。 |
stageId | string | 必需 | 只读。见类型定义及调用场景。 |
input | readonly ModelMessage[] | BuiltContext | 必需 | 只读。见类型定义及调用场景。 |
maxOutputTokens | number | 必需 | 只读。见类型定义及调用场景。 |
transport | string | 必需 | 只读。见类型定义及调用场景。 |
返回: Promise<ModelResult<unknown>>。
等待后的值: ModelResult<unknown>。
返回值结构
| 字段 | 类型 | 必需 | 说明 |
|---|---|---|---|
value | unknown | 必需 | 只读。见类型定义及调用场景。 |
invocation | Readonly<ModelCallRecord> | 必需 | 只读。见类型定义及调用场景。 |
使用示例
- 上下文策略:验证、缩减与审计:Support 给出可替换的策略实现,Core 保留最终输入合同和预算检查。
显式使用只校验策略
入门 · Node.js
ts
import { Support } from '@jangts/agent-core';
import type { ContextPolicy } from '@jangts/agent-core/support/context';
const policy: ContextPolicy = { mode: 'validate' };
Support.validateContextPolicy(policy, [], []);
console.log(policy.mode);1
2
3
4
5
2
3
4
5
js
import { Support } from '@jangts/agent-core';
const policy = { mode: 'validate' };
Support.validateContextPolicy(policy, [], []);
console.log(policy.mode);1
2
3
4
2
3
4
从真实业务片段配置缩减顺序
配置 · Node.js
这些数字是示例业务的显式选择,不是 SDK 推荐适用于所有模型的容量。
ts
import { Support } from '@jangts/agent-core';
import type { ContextPolicy } from '@jangts/agent-core/support/context';
const policy: ContextPolicy = { mode: 'reduce', triggerChars: 1800, targetInputChars: 1500,
selection: { mode: 'sequence' },
steps: [{ id: 'recent-history', kind: 'trim', fragmentId: 'history', field: 'messages',
grouping: { kind: 'user-turn' }, keepGroups: 2, targetChars: 1000 }],
};
Support.validateContextPolicy(policy, [], []);
console.log(policy.steps);1
2
3
4
5
6
7
8
9
2
3
4
5
6
7
8
9
js
import { Support } from '@jangts/agent-core';
const policy = { mode: 'reduce', triggerChars: 1800, targetInputChars: 1500,
selection: { mode: 'sequence' },
steps: [{ id: 'recent-history', kind: 'trim', fragmentId: 'history', field: 'messages',
grouping: { kind: 'user-turn' }, keepGroups: 2, targetChars: 1000 }],
};
Support.validateContextPolicy(policy, [], []);
console.log(policy.steps);1
2
3
4
5
6
7
8
2
3
4
5
6
7
8