ModelTransportRegistration
CORE · interface · 类型合同
Binds an adapter to the tools one transport serves.
导入
ts
import type { ModelTransportRegistration } from '@jangts/agent-core/support';js
/** @typedef {import('@jangts/agent-core/support').ModelTransportRegistration} ModelTransportRegistration */其他公开入口:@jangts/agent-core、@jangts/agent-core/types、@jangts/agent-core/structs、@jangts/agent-core/support、@jangts/agent-core/support/model。
定义
ts
interface ModelTransportRegistration<Result>泛型参数
| 类型参数 | 约束 | 默认类型 |
|---|---|---|
Result | — | unknown |
字段结构
| 字段 | 类型 | 必需 | 说明 |
|---|---|---|---|
id | string | 必需 | Transport id used by call requests and reported in diagnostic events. |
tools | ModelToolSource<Result> | ((stage: string) => ModelToolSource<Result>) | 必需 | Static capability source, or a factory that selects tools per stage. |
adapter | ModelInteractionAdapter | undefined | 可省略 | Wire-format adapter; defaults to native function calling. |
options | Pick<ModelOptions, "temperature"> | undefined | 可省略 | Sampling defaults this transport contributes to every call. |
requireStrictArguments | boolean | undefined | 可省略 | Reject the registration when the chosen adapter cannot enforce strict arguments. |
使用示例
- 模型传输与阶段投影:从 Tool 定义生成封存目录与阶段投影,原生函数和 JSON 适配复用同一 Tool 合同。
创建具名文本传输
入门 · Node.js
ts
import { ModelRunner, Support } from '@jangts/agent-core';
const text = Support.createTextTransport({ id: 'brief', options: { temperature: 0.2 } });
const runner = new ModelRunner({ provider: { async *stream() { yield '服务正常'; } }, transports: [text] });
console.log((await runner.invoke({ input: '简答服务状态', transport: text })).value);js
import { ModelRunner, Support } from '@jangts/agent-core';
const text = Support.createTextTransport({ id: 'brief', options: { temperature: 0.2 } });
const runner = new ModelRunner({ provider: { async *stream() { yield '服务正常'; } }, transports: [text] });
console.log((await runner.invoke({ input: '简答服务状态', transport: text })).value);从同源 Tool 生成两个阶段的传输
配置 · Node.js
ts
import { Support } from '@jangts/agent-core';
const inputSchema = Support.defineSchema({
jsonSchema: { type: 'object', properties: {}, additionalProperties: false },
parse(value: unknown) {
if (!value || typeof value !== 'object' || Array.isArray(value) || Object.keys(value).length) throw new TypeError('需要空对象');
return {};
},
});
const tools = Support.defineModelTools([
{ id: 'greet', description: '问候', inputSchema, resolve: () => 'greet' },
{ id: 'status', description: '状态查询', inputSchema, resolve: () => 'status' },
]);
const transport = Support.createStageModelTransport({ id: 'intent', tools,
stages: [{ id: 'recognize', toolIds: ['greet', 'status'] }, { id: 'status-only', toolIds: ['status'] }],
});
console.log(transport.prepare('status-only').schemaChars);js
import { Support } from '@jangts/agent-core';
const inputSchema = Support.defineSchema({
jsonSchema: { type: 'object', properties: {}, additionalProperties: false },
parse(value) {
if (!value || typeof value !== 'object' || Array.isArray(value) || Object.keys(value).length)
throw new TypeError('需要空对象');
return {};
},
});
const tools = Support.defineModelTools([
{ id: 'greet', description: '问候', inputSchema, resolve: () => 'greet' },
{ id: 'status', description: '状态查询', inputSchema, resolve: () => 'status' },
]);
const transport = Support.createStageModelTransport({ id: 'intent', tools,
stages: [{ id: 'recognize', toolIds: ['greet', 'status'] }, { id: 'status-only', toolIds: ['status'] }],
});
console.log(transport.prepare('status-only').schemaChars);