Skip to content
中文

createModelTransport ​

CORE · function · Runtime value

Compose a registered selection transport.

The capability source may be a static catalog or a function of the stage id; the resulting definitions are captured when prepare runs and are used both to build the instruction and to reject unknown capability ids at finish time.

requireStrictArguments is a registration-time assertion: a transport cannot demand strict arguments from an adapter that does not support them.

Import ​

ts
import { createModelTransport } from '@jangts/agent-core/support';
js
import { createModelTransport } from '@jangts/agent-core/support';

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

Definition ​

Type parameters ​

Type parameterConstraintDefault type
Result——
Idstringstring

Call ​

ts
createModelTransport<Result, const Id extends string = string>(registration: ModelTransportRegistration<Result> & { readonly id: Id; }): ModelTransportDefinition<Result> & { readonly id: Id; }

Compose a registered selection transport.

The capability source may be a static catalog or a function of the stage id; the resulting definitions are captured when prepare runs and are used both to build the instruction and to reject unknown capability ids at finish time.

requireStrictArguments is a registration-time assertion: a transport cannot demand strict arguments from an adapter that does not support them.

Type parameterConstraintDefault type
Result——
Idstringstring
ParameterTypePassingDescription
registrationModelTransportRegistration<Result> & { readonly id: Id; }Required—
Fields of registration
FieldTypeRequiredDescription
idIdRequiredTransport id used by call requests and reported in diagnostic events.
toolsModelToolSource<Result> | ((stage: string) => ModelToolSource<Result>)RequiredStatic capability source, or a factory that selects tools per stage.
adapterModelInteractionAdapter | undefinedOptionalWire-format adapter; defaults to native function calling.
optionsPick<ModelOptions, "temperature"> | undefinedOptionalSampling defaults this transport contributes to every call.
requireStrictArgumentsboolean | undefinedOptionalReject the registration when the chosen adapter cannot enforce strict arguments.

Returns: ModelTransportDefinition<Result> & { readonly id: Id; }.

Return value structure
FieldTypeRequiredDescription
idIdRequiredRead-only. Transport id used by call requests and reported in diagnostics.
prepare(stageId: string) => PreparedModelTransport<Result>RequiredBuilds the prepared transport for stageId; must not spend a call by itself.

Examples ​

Create a named text transport ​

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

Generate transports for two stages from same-source tools ​

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

Keep the tools and replace only the explicit interaction adapter ​

Extension · Node.js

Model calls still use invoke({input,transport}) and return ModelResult; switching interaction does not redesign business results.

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

API reference, usage examples and developer guides.