Skip to content
中文

ModelInvocationRequest ​

KIT · interface · Type contract

One model call: registered binding id, the input to hand over and its timeout.

Import ​

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

Other public entry points:@jangts/agent-core/types, @jangts/agent-core/kits, @jangts/agent-core/kits/inference.

Definition ​

ts
interface ModelInvocationRequest<Input>

Type parameters ​

Type parameterConstraintDefault type
Input——

Field structure ​

FieldTypeRequiredDescription
modelIdstringRequiredRead-only. Registered binding id; unknown ids fail before any provider work happens.
inputInputRequiredRead-only. Input handed to the binding unchanged; Core never clones App objects here.
timeoutMsnumberRequiredRead-only. Per-call timeout in milliseconds, 1..2147483647 (the platform timer ceiling).

Examples ​

First bind an offline demonstration vector algorithm ​

Beginner · Node.js

The algorithm only demonstrates I/O binding and does not provide real language embedding quality.

ts
import { ModelCalls } from '@jangts/agent-core/kits/inference';
const models = new ModelCalls([
  { id: 'demo-vector', identity: 'length-direction-v1', invoke: (text: string) => [text.length, 1] },
] as const);
const result = await models.invoke({ modelId: 'demo-vector', input: 'Agent Core', timeoutMs: 1000 }, { signal: new AbortController().signal });
console.log(result.value, result.invocation.modelId);
js
import { ModelCalls } from '@jangts/agent-core/kits/inference';
const models = new ModelCalls([
    { id: 'demo-vector', identity: 'length-direction-v1', invoke: (text) => [text.length, 1] },
]);
const result = await models.invoke({ modelId: 'demo-vector', input: 'Agent Core', timeoutMs: 1000 }, { signal: new AbortController().signal });
console.log(result.value, result.invocation.modelId);

Add input and output checks plus cancellation to the same invoke ​

Configuration · Node.js

ts
import { ModelCalls } from '@jangts/agent-core/kits/inference';
const models = new ModelCalls([
  { id: 'demo-vector', identity: 'length-direction-v1',
    assertInput(text: string) { if (!text.trim()) throw new Error('文本为空'); },
    invoke(text: string, context) { context.signal.throwIfAborted(); return [text.length, 1]; },
    assertOutput(vector: number[]) { if (vector.length !== 2 || vector.some(value => !Number.isFinite(value))) throw new Error('向量无效'); },
  },
] as const);
const controller = new AbortController();
const result = await models.invoke({ modelId: 'demo-vector', input: 'Agent Core', timeoutMs: 1000 }, { signal: controller.signal });
console.log(models.identity('demo-vector'), result.value);
js
import { ModelCalls } from '@jangts/agent-core/kits/inference';
const models = new ModelCalls([
    { id: 'demo-vector', identity: 'length-direction-v1',
        assertInput(text) { if (!text.trim())
            throw new Error('文本为空'); },
        invoke(text, context) { context.signal.throwIfAborted(); return [text.length, 1]; },
        assertOutput(vector) { if (vector.length !== 2 || vector.some(value => !Number.isFinite(value)))
            throw new Error('向量无效'); },
    },
]);
const controller = new AbortController();
const result = await models.invoke({ modelId: 'demo-vector', input: 'Agent Core', timeoutMs: 1000 }, { signal: controller.signal });
console.log(models.identity('demo-vector'), result.value);

API reference, usage examples and developer guides.