Skip to content
中文

ModelInteractionAdapter ​

CORE · interface · Type contract

Pluggable implementations all consume the same business registry. No automatic fallback.

Import ​

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

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

Definition ​

ts
interface ModelInteractionAdapter

Field structure ​

FieldTypeRequiredDescription
idstringRequiredRead-only. Adapter id, reported when a transport is validated or rejected.
features{ readonly strictArguments: boolean; }RequiredRead-only. See the type definition and usage context.
prepare(tools: readonly RegisteredModelTool[]) => Omit<PreparedModelInteraction, "resolve">RequiredCompiles one stage's tools.

Member index ​

MemberPurpose
prepareCompiles one stage's tools.

Member details ​

prepare ​

Compiles one stage's tools.

ts
ModelInteractionAdapter.prepare(tools: readonly RegisteredModelTool[]): Omit<PreparedModelInteraction, "resolve">

Compiles one stage's tools.

ParameterTypePassingDescription
toolsreadonly Readonly<ModelTool<unknown, unknown, any>>[]Required—

Returns: Omit<PreparedModelInteraction<unknown>, "resolve">.

Return value structure
FieldTypeRequiredDescription
optionsPick<ModelOptions, "functions" | "json" | "toolChoice" | "parallelToolCalls">RequiredRead-only. Provider options produced from the stage's tools.
schemaCharsnumberRequiredRead-only. Characters the compiled schemas add to the input, counted against the schema budget.
instructionstring | undefinedOptionalRead-only. Instruction text that teaches the model how to answer; absent when the format is native.
createResponse() => ModelResponseCollectorRequiredCreates a fresh collector for one call; never reuse a collector across calls.

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

API reference, usage examples and developer guides.