Skip to content
English

ContextModelCall ​

SUPPORT · interface · 类型合同

Same runner and same fixed invocation result as public model calls.

导入 ​

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

其他公开入口:@jangts/agent-core/support、@jangts/agent-core/support/context。

定义 ​

ts
interface ContextModelCall

调用 ​

ts
ContextModelCall(request: ContextModelRequest): Promise<ModelResult<unknown>>
参数类型传递说明
requestContextModelRequest必需—
request 的字段
字段类型必需说明
modelIdstring | undefined可省略只读。见类型定义及调用场景。
stageIdstring必需只读。见类型定义及调用场景。
inputreadonly ModelMessage[] | BuiltContext必需只读。见类型定义及调用场景。
maxOutputTokensnumber必需只读。见类型定义及调用场景。
transportstring必需只读。见类型定义及调用场景。

返回: Promise<ModelResult<unknown>>。

等待后的值: ModelResult<unknown>。

返回值结构
字段类型必需说明
valueunknown必需只读。见类型定义及调用场景。
invocationReadonly<ModelCallRecord>必需只读。见类型定义及调用场景。

使用示例 ​

绑定一个文本压缩 handler ​

入门 · 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);

选择器明确控制可见摘录范围 ​

配置 · Node.js

selector-json 必须由 App 注册,返回 value={stepIds:string[]};不能把普通文本传输当成已解析 JSON。此例只展示 handler 装配,不发请求。

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

相关策略源码 ​

相关定义 ​

接口参考、使用示例与开发指南。