createStageModelTransport
SUPPORT · function · 运行时值
Build a transport that projects a capability source through declared stage references.
导入
ts
import { createStageModelTransport } from '@jangts/agent-core/support';js
import { createStageModelTransport } from '@jangts/agent-core/support';其他公开入口:@jangts/agent-core/support、@jangts/agent-core/support/model。
定义
泛型参数
| 类型参数 | 约束 | 默认类型 |
|---|---|---|
Result | — | — |
Id | string | string |
调用
ts
createStageModelTransport<Result, const Id extends string = string>(registration: ModelStageTransportRegistration<Result> & { readonly id: Id; }): ModelTransportDefinition<Result> & { readonly id: Id; }Build a transport that projects a capability source through declared stage references.
| 类型参数 | 约束 | 默认类型 |
|---|---|---|
Result | — | — |
Id | string | string |
| 参数 | 类型 | 传递 | 说明 |
|---|---|---|---|
registration | ModelStageTransportRegistration<Result> & { readonly id: Id; } | 必需 | — |
registration 的字段
| 字段 | 类型 | 必需 | 说明 |
|---|---|---|---|
stages | readonly { readonly id: string; readonly toolIds: readonly string[]; }[] | 必需 | 只读。Declared stages; each id is unique and lists non-empty, unique capability ids. |
id | Id | 必需 | 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. |
返回: ModelTransportDefinition<Result> & { readonly id: Id; }。
返回值结构
| 字段 | 类型 | 必需 | 说明 |
|---|---|---|---|
id | Id | 必需 | 只读。Transport id used by call requests and reported in diagnostics. |
prepare | (stageId: string) => PreparedModelTransport<Result> | 必需 | Builds the prepared transport for stageId; must not spend a call by itself. |
使用示例
- 模型传输与阶段投影:从 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);保留 Tool,只替换明确的交互适配
扩展 · Node.js
模型调用仍是 invoke({input,transport}) 并返回 ModelResult;切换交互不重新设计业务结果。
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: 'status', description: '查询服务状态', inputSchema, resolve: () => 'status' },
]);
const native = Support.createModelTransport({ id: 'native', tools });
const adapterId: keyof typeof Support.modelInteractionCatalog = 'json-object';
const json = Support.createModelTransport({ id: 'json', tools, adapter: Support.modelInteractionCatalog[adapterId] });
console.log(native.id, json.id);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: 'status', description: '查询服务状态', inputSchema, resolve: () => 'status' },
]);
const native = Support.createModelTransport({ id: 'native', tools });
const adapterId = 'json-object';
const json = Support.createModelTransport({ id: 'json', tools, adapter: Support.modelInteractionCatalog[adapterId] });
console.log(native.id, json.id);